Skip to content

Commit

Permalink
feat(sampler): add min-max sampler function
Browse files Browse the repository at this point in the history
  • Loading branch information
snukhulov committed Nov 6, 2023
1 parent fd9e62d commit a15892e
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 5 deletions.
24 changes: 20 additions & 4 deletions src/processor/dataSample.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,10 @@
* under the License.
*/

import { StageHandler, SeriesOption, SeriesSamplingOptionMixin } from '../util/types';
import { Dictionary } from 'zrender/src/core/types';
import {StageHandler, SeriesOption, SeriesSamplingOptionMixin} from '../util/types';
import {Dictionary} from 'zrender/src/core/types';
import SeriesModel from '../model/Series';
import { isFunction, isString } from 'zrender/src/core/util';
import {isFunction, isString} from 'zrender/src/core/util';


type Sampler = (frame: ArrayLike<number>) => number;
Expand Down Expand Up @@ -61,6 +61,22 @@ const samplers: Dictionary<Sampler> = {
// 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) {
Expand Down Expand Up @@ -116,4 +132,4 @@ export default function dataSample(seriesType: string): StageHandler {
}
}
};
}
}
2 changes: 1 addition & 1 deletion src/util/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1675,7 +1675,7 @@ export interface SeriesStackOptionMixin {
type SamplingFunc = (frame: ArrayLike<number>) => number;

export interface SeriesSamplingOptionMixin {
sampling?: 'none' | 'average' | 'min' | 'max' | 'sum' | 'lttb' | SamplingFunc
sampling?: 'none' | 'average' | 'min' | 'max' | 'minmax' | 'sum' | 'lttb' | SamplingFunc
}

export interface SeriesEncodeOptionMixin {
Expand Down

0 comments on commit a15892e

Please sign in to comment.