fix(sample): fix minmax sampling behaviour #20315
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Brief Information
This pull request is in the type of:
What does this PR do?
This fixes the minmax sampling behaviour to follow the standard as described here.
Fixed issues
No open issue, but the problem was discussed in the original PR for this feature: #19279 (comment)
Details
Before: What was the problem?
I generated some fake data, 16000 data points for each graph (green random walk, yellow sine wave, and blue pseudo-random).
I added two artificial "spikes" for each graph: a downward spike at index 7000, and an upward spike at index 9000.
The original minmax implementation appears to act just like the "max" downsampling method for data points that are above y=0, and thereby it misses out on any downward spikes.
After: How does it behave after the fixing?
The new implementation more closely follows the actual trend, and ensures that it captures all up and down spikes.
Brief example of the minmax downsampling method, as described here:
Discussion Point A: the link above suggests using two frames for each pixel, whereby each frame results in two data points, for a total density of 4 data points per pixel. Personally I think this is a bit overkill, as it results in less performance for minimal graph quality increase.
The current implementation in this PR has 2 data points per pixel, however this could be halved to 1 data point if you agree. The benefit of 1 data point per pixel is that the graph is more likely to allow graph animations, whereas the higher density may be above the threshold for animations still to play.
See comparison below:
I suggest opening the images in fullscreen for a better comparison.
Discussion Point B: Regarding the code, I referenced the lttb method for implementing this minmax method in a similar way (i.e. having a separate function for downsampling), since the regular downsampling method would not work due to the minmax method requiring the ability to output two samples per frame. It may be needed to add an extra condition to the downsample method selection logic, to check if the rate is high enough (>2) to warrant downsampling, since this method isn't as efficient as the others. However, this will depend on the decision for Discussion Point A above.
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
Other information