Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(sampler): add min-max sampler function #19279

Merged
merged 2 commits into from
Nov 27, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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.