Skip to content

Commit

Permalink
Merge pull request #19279 from snukhulov/feat-add-minmax-sampler
Browse files Browse the repository at this point in the history
feat(sampler): add min-max sampler function
  • Loading branch information
Ovilia authored Nov 27, 2023
2 parents b07ce79 + 4a63340 commit c5e0910
Show file tree
Hide file tree
Showing 3 changed files with 131 additions and 2 deletions.
18 changes: 17 additions & 1 deletion src/processor/dataSample.ts
Original file line number Diff line number Diff line change
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
113 changes: 113 additions & 0 deletions test/line-sampling.html

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit c5e0910

Please sign in to comment.