-
-
Notifications
You must be signed in to change notification settings - Fork 1.7k
[charts] Use more performant data structure for closest point #19615
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
[charts] Use more performant data structure for closest point #19615
Conversation
|
Deploy preview: https://deploy-preview-19615--material-ui-x.netlify.app/ Updated pages: Bundle size report
|
1aec288 to
9e757ee
Compare
CodSpeed Instrumentation Performance ReportMerging #19615 will degrade performances by 21.92%Comparing Summary
Benchmarks breakdown
Footnotes |
c8c57d5 to
5b6526f
Compare
| defaultXAxisId, | ||
| defaultYAxisId, | ||
| ) { | ||
| // FIXME: Do we want to support non-scatter series here? |
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.
Would it be possible to use this to calculate closest bar/line/point based on mouse position for other charts? (for tooltip for example)
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.
Point, yes. Bar probably. Line I don't think so. We might need a separate algorithm or adapt this one.
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.
We can divide a line in multiple points (for better precision), same for bar, the closest point would still be the closest bar/line is most cases no?
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.
There is no need for such a complex data structure for the line/bar charts
Those algorithms are designed for 2D points locations because you can not sort 2D points in a meaning full way.
But line and bar charts have a simple x-axis
- For bar chart, you get with O(1) the band index according to the x position. That's already what we do for axis highlight
- For line chart, if points are sorted you can do a quick search, get the closest dataIndex and then loop on the different value associated to this index
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.
I'm ok with the perf changes on zoomed if it means an overall perf improvement
...als/plugins/featurePlugins/useChartCartesianAxis/useChartCartesianAxisRendering.selectors.ts
Show resolved
Hide resolved
...als/plugins/featurePlugins/useChartCartesianAxis/useChartCartesianAxisRendering.selectors.ts
Outdated
Show resolved
Hide resolved
...als/plugins/featurePlugins/useChartCartesianAxis/useChartCartesianAxisRendering.selectors.ts
Outdated
Show resolved
Hide resolved
...s/x-charts/src/internals/plugins/featurePlugins/useChartClosestPoint/useChartClosestPoint.ts
Show resolved
Hide resolved
...s/x-charts/src/internals/plugins/featurePlugins/useChartClosestPoint/useChartClosestPoint.ts
Outdated
Show resolved
Hide resolved
080742c to
84fb630
Compare
aad3946 to
d0cb89e
Compare
|
This pull request has conflicts, please resolve those before we can evaluate the pull request. |
d0cb89e to
12b2d90
Compare
| @@ -0,0 +1,274 @@ | |||
| /* eslint-disable no-underscore-dangle,no-plusplus */ | |||
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.
| - Overriding the `marker` slot is not supported; | ||
| - Transparent highlight style: for performance reasons, the highlighted state creates a highlighted circle on top of the original marker. Applying transparency to the highlighted circle can cause the original circle to be partially visible. | ||
| - Transparent highlight style: for performance reasons, the highlighted state creates a highlighted circle on top of the original marker. Applying transparency to the highlighted circle can cause the original circle to be partially visible; | ||
| - `disableHover` for scatter series does not work. |
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.
disableHover still works when using the svg-single renderer. It just isn't implemented for the svg-batch renderer.
347c205 to
2478fc5
Compare
I'm sorry but it seems this implementation does the same 🫣 I placed a I think the issue comes from Those selectors are too far in the processing pipeline. They already take into account the zoom. SO each time you zoom in/out the scales get updated an you need to recompute your flatbrush I assume what you would need is to divide the creation of scales in a |
Yes, I'm working on fixing it. I'll need to re-organize the selectors.
Yes, that's what I'll have to do. |
|
This pull request has conflicts, please resolve those before we can evaluate the pull request. |
2478fc5 to
97de2d3
Compare
|
@alexfauquette your suggestion paid off! Thanks 😄 Implementation is here. I'll update this PR once that one is merged. |
…cate `disableHover`.
97de2d3 to
8776e41
Compare
|
This pull request has conflicts, please resolve those before we can evaluate the pull request. |
|
Superseded by #19790 |

Part of #12960.
Cherry-picked from #18941.
This implementation is basically a trade-off. We're moving the
Flatbushcreation to the start which allows zooming without having to re-create. This contrasts with the current implementation where theDelaunayis created whenever zoom stops interacting.Even if we're frontloading the computation, for 10k data points the
Flatbushimplementation is still faster: the whole render takes 480ms vs 600ms with a 6x CPU slowdown. For 2k and 1k data points thatFlatbushimplementation remains faster.Regarding the CodSpeed regressions: it's normal that this happens in this use case. The
Flatbushis indexing all data points so that it doesn't need to re-index them when the drawing area changes. TheDelaunayonly indexes visible points. This means that in the regressed examples, where zoom span is small,Delaunayis faster because checkingisPointInsideis quicker than indexing usingFlatbush. That's why the regression exists.Assuming that most charts will start zoomed out, I think this is an acceptable regression. @alexfauquette @JCQuintas let me know what you think.