-
Notifications
You must be signed in to change notification settings - Fork 715
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
new(xychart): refine TooltipContext + Tooltip functionality #846
Conversation
/** Whether to show a horizontal line at tooltip position. */ | ||
showHorizontalCrosshair?: boolean; | ||
/** Whether to show a circle at the tooltip position for the (single) nearest Datum. */ | ||
showDatumCircle?: boolean; |
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.
Perhaps name this showDatumMark
or showDatumMarker
? In case you want to support other shapes (that is not circle) in the future.
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.
good call. maybe I should make these use @visx/glyph
🤔 maybe I'll do that as a followup 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.
updated to glyph
throughout with the future glyph support in mind
@@ -34,7 +39,7 @@ function LineSeries<XScale extends AxisScale, YScale extends AxisScale, Datum ex | |||
(params: HandlerParams | undefined) => { | |||
const { svgPoint } = params || {}; | |||
if (svgPoint && width && height && showTooltip) { | |||
const datum = findNearestDatumXY({ | |||
const datum = (horizontal ? findNearestDatumX : findNearestDatumY)({ |
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.
how to specify if the nearest XY is what developer want?
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.
these are controlled with the horizontal
prop right now. I removed xy
because I realized that series should use the same logic for x vs y. Previously if bar used x
and line used xy
, you might have mismatched x
values in the tooltip context (because voronoi
don't map cleanly to x, it might not match the same x
that the bar finds).
I agree this needs a better hook for dev experience or could be provided by DataContext
at some point (you suggested this in the POC, maybe it'd be straightforward to infer from scale types 🤔 ).
Pull Request Test Coverage Report for Build 130
💛 - Coveralls |
* test(xychart): add more Tooltip tests * test(xychart): add more TooltipProvider tests
TODO
🚀 Enhancements
@visx/tooltip
allow function signatures for
useTooltip
'supdateTooltip
+showTooltip
why? this mirrors how
react
setState
works, and was needed to implement tooltip data merging properly inxychart/TooltipProvider
. whenTooltipProvider
tries to mergetooltipData
when the hook state is updated in quick succession, the hook-provided value may be stale.@visx/xychart
Builds on #825 and adds more fully-featured
Tooltip
functionality:TooltipProvider
no longer simply returns theuseTooltip
hook state, but adds additional functionality so thatTooltipContext.tooltipData
now includes both the globally closest datum as well as the closest datum per-Series. Functionally this allowsTooltip
to snap to data values instead of simply following the cursorTooltip
now supports the followingprops
snapTooltipToDatumX
,snapTooltipToDatumY
(tooltip position snaps to data coord instead of mouse coord)showVerticalCrosshair
,showHorizontalCrosshair
showDatumCircle
,showSeriesCircles
verticalCrosshairStyle
,horizontalCrosshairStyle
,circleStyle
debounce
tohideTooltip
for better UX@visx/demo
Updates the
XYChart
demo with allTooltip
controlsAlso want to demo how you can do cool things like linked tooltips trivially with a shared
EventEmitterContext
which is TIGHT 🔥🔥@kristw @hshoff @techniq