-
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): add PointerEvent handlers to XYChart and *Series #947
Conversation
…tations, add source filtering
…ntEmitters/Handlers
…nterEventEmitters/Handlers
…nterEventEmitters/Handlers
…interEventEmitters/Handlers
…terEventEmitters/Handlers
…terEventEmitters/Handlers
…terEventEmitters/Handlers
svgPoint, | ||
}: PointerEventParams<Datum>) => void; | ||
/** Whether to invoke PointerEvent handlers for all dataKeys, or the nearest dataKey. */ | ||
pointerEvents?: 'all' | 'nearest'; |
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.
maybe should be called pointerEventDataKey
🤔
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 guess this probably should mirror the implementation and could also support specific dataKey | dataKey[]
as well.
EDIT: gonna punt on this until it's a feature request, makes the type-ing more error prone because string | 'all'
becomes string
.
packages/visx-xychart/src/components/series/private/BaseAreaSeries.tsx
Outdated
Show resolved
Hide resolved
|
||
const handlePointerOut = useCallback( | ||
(params?: HandlerParams) => { | ||
if (params && onPointerOut) onPointerOut(params.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.
because we have to always use the same # of hooks, we can't conditionally create this and have to do the check in the handler. we conditionally return the handler below, tho.
Pull Request Test Coverage Report for Build 393068437
💛 - Coveralls |
const entry = dataRegistry.get(key); | ||
const childData = barSeriesChildren.find(child => child.props.dataKey === key)?.props.data; | ||
if (childData && svgPoint && width && height && showTooltip) { | ||
const datum = findNearestStackDatum( |
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.
noting as a TODO that this logic was lost in this refactor
TODO
🚀 Enhancements
This PR
PointerEvent
handlers onXYChart
, or on individual*Series
(previously the only mouse events which were handled were to show/hide tooltips)onPointerMove/Out/Up
are currently supportedpointerEvents: boolean
to all*Series
, which enables users to prevent aSeries
from emitting, or responding to anyPointerEvent
s (including tooltips; see demo below)mousemove/out
+touchmove/end
references were simplified topointermove/out
/xychart
example to demonstrateonPointerUp
=> if you click on the chart, theAnnotation
will move to the nearestDatum
in the nearestSeries
Usage examples
Implementation notes
EventEmitterContext
rather than being handled within a given component.BarSeries
events to thatBarSeries
, I added the notion ofEventEmitter
source
s so that aSeries
can subscribe to only it's own events + events emitted byXYChart
Series
PointerEvent
handlers are set on individual bars, glyphs, or paths (rather than a container to capture events on all of them) to prevent oneSeries
blocking events for another series.Demo of
pointerEvents={false}
for all Series except SF (therefore tooltip only contains SF, even though mouse is closer to otherAreaSeries
)@kristw @hshoff