Skip to content
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 support for FocusEvents #959

Merged
merged 12 commits into from
Dec 8, 2020

Conversation

williaster
Copy link
Collaborator

🚀 Enhancements

This PR builds on #947 and adds support for FocusEvents to all series via the onFocus and onBlur handlers. This mostly involved

  • extending all of the event emitter/handler logic for the two new event types
  • added a useSeriesEvents hook to simplify a lot of the boilerplate
  • added support for overriding findNearestDatum logic in event handlers, this is needed for BarGroup and BarStack

xychart-focus-tooltips-all-series

Tests coming in another PR.

🐛 Bug Fix

@kristw @hshoff

@@ -5,18 +5,18 @@ import { AxisScaleOutput } from '@visx/axis';
import { ScaleConfig } from '@visx/scale';

import DataContext from '../context/DataContext';
import { Margin, PointerEventParams } from '../types';
import { Margin, EventHandlerParams } from '../types';
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

re-named since no longer specific to PointerEvents

@@ -7,6 +7,6 @@ export default function AnimatedAreaSeries<
XScale extends AxisScale,
YScale extends AxisScale,
Datum extends object
>({ ...props }: Omit<BaseAreaSeriesProps<XScale, YScale, Datum>, 'PathComponent'>) {
>(props: Omit<BaseAreaSeriesProps<XScale, YScale, Datum>, 'PathComponent'>) {
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

these were all double spread unnecessarily

@coveralls
Copy link

Pull Request Test Coverage Report for Build 406606163

  • 70 of 85 (82.35%) changed or added relevant lines in 16 files are covered.
  • No unchanged relevant lines lost coverage.
  • Overall coverage decreased (-0.2%) to 61.347%

Changes Missing Coverage Covered Lines Changed/Added Lines %
packages/visx-xychart/src/components/series/private/BaseAreaSeries.tsx 3 5 60.0%
packages/visx-xychart/src/components/series/private/BaseLineSeries.tsx 4 6 66.67%
packages/visx-xychart/src/hooks/useEventHandlers.ts 20 22 90.91%
packages/visx-xychart/src/hooks/useSeriesEvents.ts 11 15 73.33%
packages/visx-xychart/src/utils/findNearestGroupDatum.ts 11 16 68.75%
Totals Coverage Status
Change from base Build 401376407: -0.2%
Covered Lines: 1712
Relevant Lines: 2640

💛 - Coveralls

@@ -65,6 +66,7 @@ export default function AnimatedBars<XScale extends AxisScale, YScale extends Ax
item == null || key == null ? null : (
<animated.rect
key={key}
tabIndex={isFocusable ? 0 : undefined}
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

noting that this implementation requires the SVG 2.0 spec – SVG 1.1 doesn't support tabIndex which means this may not work on older browsers. the alternative approach (used in data-ui) was to wrap each element in an <a /> element, which are consistently tab-able by all browsers.

For now I think this more modern approach is more ideal since it's simpler and it is supported across all modern browsers
image

onPointerMove,
onPointerOut,
onPointerUp,
enableEvents = true,
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

pointerEvents => enableEvents throughout

source: string;
};

/** This hook simplifies the logic for initializing Series event emitters + handlers. */
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

all of this boilerplate was repeated in each *Series previously

const getNumericValue = <XScale extends AxisScale, YScale extends AxisScale>(
bar: BarStackDatum<XScale, YScale>,
) => getSecondItem(bar); // corresponds to y1, the upper value (topline).
) => (getFirstItem(bar) + getSecondItem(bar)) / 2;
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

when only accounting for the top line of a bar, logic for finding the nearest series datum to the middle of the bar bounding box was incorrect

@williaster williaster merged commit 8219a41 into master Dec 8, 2020
@williaster williaster deleted the chris--xychart-focusblur branch December 8, 2020 18:52
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants