-
Notifications
You must be signed in to change notification settings - Fork 19.6k
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
Conversation
Thanks for your contribution! Document changes are required in this PR. Please also make a PR to apache/echarts-doc for document changes and update the issue id in the PR description. When the doc PR is merged, the maintainers will remove the |
a15892e
to
77a3723
Compare
The changes brought by this PR can be previewed at: https://echarts.apache.org/examples/editor?version=PR-19279@4a63340 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This seems to be a great idea. Can you explain what min-max mean first?
Thank you. |
Thanks for your explanation. Can you provide a link or something for further understanding? Is this a concept well-known or you invented it? |
It's my own implementation of the known min-max downsampling algorithm |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks! Please also add test cases in test/line-sampling.html
. Please pay special attention both to the cases where there are negative values or not.
I added the described test cases |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for your contribution! This will be released in the next version.
Updated demo here |
Congratulations! Your PR has been merged. Thanks for your contribution! 👍 |
Hi, @snukhulov I think there might be something wrong. If you change the number of samples in your example to 100,000, updated exemple ,you can see the problem with returning just the absolute max value. This is just a suggestion and has not been tested: You need two values for each frame for min and max, something like this: minmax: function (frame) {
let turningPointMaxValue = -Infinity;
let turningPointMinValue = Infinity;
for (let i = 0; i < frame.length; i++) {
const originalValue = frame[i];
if (originalValue > turningPointMaxValue) {
turningPointMaxValue = originalValue;
}
if (originalValue < turningPointMinValue) {
turningPointMinValue = originalValue;
}
}
// Return an array with the min and max values
return [turningPointMinValue, turningPointMaxValue];
} |
Hi! Thank you for the research and the suggestion! You're right about there are some problems with the proposed min-max sampler function. It's designed for a sine periodic data like Your suggestion looks great, but I have some doubts about returning type of your function. I think it only could be I thought about improvement of the proposed min-max sampler, but there is motivation to keep it simple like other existing sampling functions. But I'am still looking for an improvement of min-max sampler function that could solve sampling problem of data with aperiodic component like |
Brief Information
This pull request is in the type of:
What does this PR do?
Add min-max sampler function
Details
Before: What was the problem?
In some cases min-max sampling algorithm fits line data more naturally than the existing ones. For example, for a sine with a lot of data points min-max sampler is the best choice.
Example.
The original sine without sampling (200 000 data points).
Using 'average' sampler
Using 'lttb' sampler
Using 'max' sampler
Using 'min' sampler
After: How does it behave after the fixing?
Using new 'minmax' sampler
Document Info
One of the following should be checked.
Misc
ZRender Changes
Related test cases or examples to use the new APIs
N.A.
Others
Merging options
Other information