-
-
Notifications
You must be signed in to change notification settings - Fork 1.2k
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鈥檒l occasionally send you account related emails.
Already on GitHub? Sign in to your account
[charts] Use voronoi cells to trigger interaction with scatter items #10981
Conversation
Deploy preview: https://deploy-preview-10981--material-ui-x.netlify.app/ Updated pages: |
This pull request has conflicts, please resolve those before we can evaluate the pull request. |
5ca11d6
to
bff736b
Compare
packages/x-charts/src/ChartsVoronoiHandler/ChartsVoronoiHandler.tsx
Outdated
Show resolved
Hide resolved
packages/x-charts/src/ChartsVoronoiHandler/ChartsVoronoiHandler.tsx
Outdated
Show resolved
Hide resolved
packages/x-charts/src/ChartsVoronoiHandler/ChartsVoronoiHandler.tsx
Outdated
Show resolved
Hide resolved
@@ -94,7 +95,7 @@ function Scatter(props: ScatterProps) { | |||
key={dataPoint.id} | |||
cx={0} | |||
cy={0} | |||
r={markerSize} | |||
r={(dataPoint.isHighlighted ? 1.2 : 1) * markerSize} |
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.
r={(dataPoint.isHighlighted ? 1.2 : 1) * markerSize} | |
r={markerSize} |
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.
Note: Highcharts also do increase the point radius, when highlighted, but that is probably a separate story/functionality and would need to be controllable. 馃し 馃檲
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.
OK, so we agree it's interesting to discuss this point, but not for this PR :)
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.
Oh yes, clearly. 馃憤
@@ -71,6 +93,9 @@ const dataReducer: React.Reducer<Omit<InteractionState, 'dispatch'>, Interaction | |||
return { ...prevState, item: null }; | |||
|
|||
case 'updateAxis': | |||
if (action.data.x === prevState.axis.x && action.data.y === prevState.axis.y) { |
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 update is not directly for voronoi. It's a way to "improve perf" If axis do not change, we do not create a new object to avoid triggering rerender at each mouse movement
@@ -5,6 +5,9 @@ import { SVGContext, DrawingContext } from '../context/DrawingProvider'; | |||
import { isBandScale } from '../internals/isBandScale'; | |||
import { AxisDefaultized } from '../models/axis'; | |||
|
|||
function getAsANumber(value: number | Date) { |
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.
Fix TS errors
Signed-off-by: Alexandre Fauquette <45398769+alexfauquette@users.noreply.github.com>
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 is a major improvement, great work! 馃挴 馃挋
Leaving some nitpicks. 馃槈
// TODO: A perf optimisation of voronoi could be to use the last point as the intial point for the next search. | ||
const handleMouseMove = (event: MouseEvent) => { | ||
// Get mouse coordinate in global SVG space | ||
const pt = svgRef.current!.createSVGPoint(); |
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.
Nit: Have you considered using a full word (i.e.: point
, svgPoint
) for this variable?
Or do you have an argument as to why the shorthand form is better? 馃
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.
It's mostly because it's a trash variable. I create it to access the matrixTransform
method and then it's over, So I avoid to pick a meaining full variable name
An option could be to create a helper getSVGPoint
const svgPoint = getSVGPoint(svgRef, event)
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.
Gotcha. 馃憣
Yup, the suggested helper does sound nice. 馃憤
packages/x-charts/src/ChartsVoronoiHandler/ChartsVoronoiHandler.tsx
Outdated
Show resolved
Hide resolved
/** | ||
* Defines the maximal distance between a scatter point and the pointer that triggers the interaction. | ||
* If `undefined`, the radius is assumed to be infinite. | ||
* @default undefined |
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.
Have you considered going with a specific default? 馃
I checked that Highcharts also have the same behavior, but when exploring the demo, I felt that 25 seemed the most natural to me. 馃 馃し
What do others think? @flaviendelangle @joserodolfofreitas?
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.
Did not considered it because nivo don't even allow this
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.
Okay, if it's only my opinion, we can disregard it. There is nothing wrong with this default. 馃憣
In that case, WDYT about aligning the demo with defaults?
It's what initially tripped me a bit because after seeing the demo I expected the default radius to be 50
. 馃檲
@@ -94,7 +95,7 @@ function Scatter(props: ScatterProps) { | |||
key={dataPoint.id} | |||
cx={0} | |||
cy={0} | |||
r={markerSize} | |||
r={(dataPoint.isHighlighted ? 1.2 : 1) * markerSize} |
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.
Note: Highcharts also do increase the point radius, when highlighted, but that is probably a separate story/functionality and would need to be controllable. 馃し 馃檲
Co-authored-by: Lukas <llukas.tyla@gmail.com> Signed-off-by: Alexandre Fauquette <45398769+alexfauquette@users.noreply.github.com>
Fix #9358
Changelog
Users needed to hover the item to highlight the scatter item or show the tooltip.
Now they can interact with data by triggering the closest element. See the docs page for more info.