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): handle rendering + tweening missing values #898

Merged
merged 15 commits into from
Nov 3, 2020

Conversation

williaster
Copy link
Collaborator

@williaster williaster commented Oct 28, 2020

๐Ÿš€ Enhancements

๐Ÿ› Bug Fix

๐Ÿ  Internal

This PR is a mix of improvements + new functionality for xychart which are all related by the rabbit hole ๐Ÿฐ โšซ I went down trying to fix one problem:

when transitioning between horizontal and vertical orientation in the /xychart demo, or transitioning between more or fewer data points, AnimatedPath would throw due to a cryptic react-spring error

The improvements are:

  1. does a sweep to handle missing values across all *Series and in scale domain calculation
  • tested by updating the /xychart demo
  1. (โœ… fix for above error) updates AnimatedPath to handle missing values and a changing number of values by using d3-interpolate-path for interpolating path d attributes
  • caveats: the only animation case this doesn't handle well is Area shapes with missing data (see below) but I think it's the best option
  • ๐Ÿ’ฌ reasoning
    • react-spring does this beautifully except when the # of points changes which is the cause of the above error ๐Ÿ˜ญ
      • I spent a long time trying to test [email protected] to see if it did ... but it does not
    • d3-interpolate does not handle path string interpolation well (well documented see e.g., here)
    • flubber is the best at handling all edge cases, but it assumes closed polygon shapes (doesn't apply for lines) and its bundle size is 10x what d3-interpolate-paths is.
  1. moves props.horizontal from all *Series types to DataProviders context.horizontal (the start of the ๐Ÿฐ โšซ )
  • horizontal determines orientation for Bar-type series, and it controls nearest datum logic for mouse events across all *Series
  • the goal of this was to make it easier for devs, most of the time horizontal can be inferred from scale types and this could be done once in context vs specified / computed in each *Series

Note issue with missing area data

@kristw @techniq


const xValues = registryEntries.reduce<XScaleInput[]>(
(combined, entry) =>
entry ? combined.concat(entry.data.map((d: Datum) => entry.xAccessor(d))) : combined,
entry
? combined.concat(entry.data.map((d: Datum) => entry.xAccessor(d)).filter(valueIsDefined))
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

verified that d3Extent handles this so no need to filter, will remove

@coveralls
Copy link

coveralls commented Oct 28, 2020

Pull Request Test Coverage Report for Build 334347503

  • 44 of 45 (97.78%) changed or added relevant lines in 11 files are covered.
  • 10 unchanged lines in 4 files lost coverage.
  • Overall coverage decreased (-0.5%) to 60.095%

Changes Missing Coverage Covered Lines Changed/Added Lines %
packages/visx-xychart/src/components/series/private/BaseBarStack.tsx 5 6 83.33%
Files with Coverage Reduction New Missed Lines %
packages/visx-xychart/src/utils/getScaledValueFactory.ts 1 69.23%
packages/visx-xychart/src/utils/getBarStackRegistryData.ts 2 82.61%
packages/visx-xychart/src/components/series/private/BaseBarGroup.tsx 3 75.83%
packages/visx-xychart/src/components/series/private/BaseBarStack.tsx 4 77.42%
Totals Coverage Status
Change from base Build 263: -0.5%
Covered Lines: 1549
Relevant Lines: 2445

๐Ÿ’› - Coveralls

to: { t: 1 },
reset: true,
});
const tweened = useSpring({ stroke, fill });

Choose a reason for hiding this comment

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

TIL tweened because

Inbetweening or tweening is a key process in all types of animation, including computer animation.

@@ -132,8 +126,8 @@ export default function BaseBarGroup<
const bars = registryEntries.flatMap(({ xAccessor, yAccessor, data, key }) => {
const getLength = (d: Datum) =>
horizontal
? (xScale(xAccessor(d)) ?? 0) - xZeroPosition
: (yScale(yAccessor(d)) ?? 0) - yZeroPosition;
? (xScale(xAccessor(d)) ?? NaN) - xZeroPosition

Choose a reason for hiding this comment

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

nice

@williaster williaster merged commit 68648e2 into master Nov 3, 2020
@williaster williaster deleted the chris--xychart-horizontal-context branch November 3, 2020 22:07
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.

4 participants