From 77a3723716341e33767495d587341fd85202eef3 Mon Sep 17 00:00:00 2001 From: Said Nukhulov Date: Tue, 7 Nov 2023 01:01:05 +0300 Subject: [PATCH 1/2] feat(sampler): add min-max sampler function --- src/processor/dataSample.ts | 18 +++++++++++++++++- src/util/types.ts | 2 +- 2 files changed, 18 insertions(+), 2 deletions(-) diff --git a/src/processor/dataSample.ts b/src/processor/dataSample.ts index 28579a652e..cbd370f2ba 100644 --- a/src/processor/dataSample.ts +++ b/src/processor/dataSample.ts @@ -61,6 +61,22 @@ const samplers: Dictionary = { // NaN will cause illegal axis extent. return isFinite(min) ? min : NaN; }, + minmax: function (frame) { + let turningPointAbsoluteValue = -Infinity; + let turningPointOriginalValue = -Infinity; + + for (let i = 0; i < frame.length; i++) { + const originalValue = frame[i]; + const absoluteValue = Math.abs(originalValue); + + if (absoluteValue > turningPointAbsoluteValue) { + turningPointAbsoluteValue = absoluteValue; + turningPointOriginalValue = originalValue; + } + } + + return isFinite(turningPointOriginalValue) ? turningPointOriginalValue : NaN; + }, // TODO // Median nearest: function (frame) { @@ -116,4 +132,4 @@ export default function dataSample(seriesType: string): StageHandler { } } }; -} \ No newline at end of file +} diff --git a/src/util/types.ts b/src/util/types.ts index 4a212872dd..c7b0c4ef36 100644 --- a/src/util/types.ts +++ b/src/util/types.ts @@ -1675,7 +1675,7 @@ export interface SeriesStackOptionMixin { type SamplingFunc = (frame: ArrayLike) => number; export interface SeriesSamplingOptionMixin { - sampling?: 'none' | 'average' | 'min' | 'max' | 'sum' | 'lttb' | SamplingFunc + sampling?: 'none' | 'average' | 'min' | 'max' | 'minmax' | 'sum' | 'lttb' | SamplingFunc } export interface SeriesEncodeOptionMixin { From 4a633400807cae8392bf1fef88e32274bbe865bb Mon Sep 17 00:00:00 2001 From: Said Nukhulov Date: Sat, 25 Nov 2023 21:06:45 +0300 Subject: [PATCH 2/2] feat(sampler): add min-max sampler function --- test/line-sampling.html | 113 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 113 insertions(+) diff --git a/test/line-sampling.html b/test/line-sampling.html index ea8382734a..c288d893d1 100644 --- a/test/line-sampling.html +++ b/test/line-sampling.html @@ -36,6 +36,7 @@
+
+ +