forked from airbnb/visx
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
new(xychart): handle rendering + tweening missing values (airbnb#898)
* new(xychart): move horizontal to DataProvider, add utils/isDiscreteScale * deps(xychart): add d3-interpolate-path * deps: update yarn.lock * new(demo/xychart): add missing data + fewer data controls, remove horizontal props * internal(xychart): use d3-interpolate-path to support tweening varying # of points * internal(xychart/useScales): add domain data validation checks * fix(xychart/AnimatedBars): animate from scale baseline, not 0 * new(demo/xychart): add better missing values, and control padding * new(xychart/AnimatedGlyphs): animate opacity * fix(xychart): add better data validation to BaseBarStack, BaseBarGroup, BaseBarSeries * types(xychart): fix * test(xychart): remove horizontal props * types(xychart): add horizontal to mock data context * internal(xychart/useScales): don't unnecessarily filter values for d3 extent * lint(xychart/useScales)
- Loading branch information
1 parent
490045d
commit 68648e2
Showing
21 changed files
with
211 additions
and
108 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
27 changes: 24 additions & 3 deletions
27
packages/visx-xychart/src/components/series/private/AnimatedPath.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,12 +1,33 @@ | ||
import React from 'react'; | ||
import React, { useRef } from 'react'; | ||
import { animated, useSpring } from 'react-spring'; | ||
// @ts-ignore no types | ||
import { interpolatePath } from 'd3-interpolate-path'; | ||
|
||
export default function AnimatedPath({ | ||
d, | ||
stroke, | ||
fill, | ||
...lineProps | ||
}: Omit<React.SVGProps<SVGPathElement>, 'ref'>) { | ||
const tweened = useSpring({ d, stroke, fill }); | ||
return <animated.path d={tweened.d} stroke={tweened.stroke} fill={tweened.fill} {...lineProps} />; | ||
const previousD = useRef(d); | ||
// react-spring cannot interpolate paths which have a differing number of points | ||
// flubber is the "best" at interpolating but assumes closed paths | ||
// d3-interpolate-path is better at interpolating extra/fewer points so we use that | ||
const interpolator = interpolatePath(previousD.current, d); | ||
previousD.current = d; | ||
// @ts-ignore t is not in CSSProperties | ||
const { t } = useSpring({ | ||
from: { t: 0 }, | ||
to: { t: 1 }, | ||
reset: true, | ||
}); | ||
const tweened = useSpring({ stroke, fill }); | ||
return ( | ||
<animated.path | ||
d={t.interpolate(interpolator)} | ||
stroke={tweened.stroke} | ||
fill={tweened.fill} | ||
{...lineProps} | ||
/> | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.