From 0cea9606b231693b9710d78971da249f0d7bdc2f Mon Sep 17 00:00:00 2001 From: Kenan Date: Wed, 7 Feb 2024 11:36:58 +0000 Subject: [PATCH] add victory-animation story --- stories/victory-animation.stories.tsx | 98 +++++++++++++++++++++++++++ 1 file changed, 98 insertions(+) create mode 100644 stories/victory-animation.stories.tsx diff --git a/stories/victory-animation.stories.tsx b/stories/victory-animation.stories.tsx new file mode 100644 index 000000000..447eda8db --- /dev/null +++ b/stories/victory-animation.stories.tsx @@ -0,0 +1,98 @@ +import { Meta } from "@storybook/react"; +import React, { useEffect } from "react"; + +import { VictoryPie } from "../packages/victory-pie"; +import { VictoryAnimation, VictoryLabel } from "../packages/victory-core"; +import { storyContainer } from "./decorators"; + +const meta: Meta = { + title: "Victory Charts/SVG Container/VictoryAnimation", + component: VictoryAnimation, + tags: ["autodocs"], + decorators: [storyContainer], +}; + +export default meta; + +const ANIMATION_DATA = [ + [ + { x: 1, y: 0 }, + { x: 2, y: 100 }, + ], + [ + { x: 1, y: 25 }, + { x: 2, y: 75 }, + ], + [ + { x: 1, y: 50 }, + { x: 2, y: 50 }, + ], + [ + { x: 1, y: 75 }, + { x: 2, y: 25 }, + ], + [ + { x: 1, y: 100 }, + { x: 2, y: 0 }, + ], +]; + +const AnimationDemo = () => { + const [data, setData] = React.useState(ANIMATION_DATA[0]); + const [percent, setPercent] = React.useState(0); + + useEffect(() => { + const interval = setInterval(() => { + const nextIndex = + (ANIMATION_DATA.indexOf(data) + 1) % ANIMATION_DATA.length; + setData(ANIMATION_DATA[nextIndex]); + setPercent(ANIMATION_DATA[nextIndex][0].y); + }, 2000); + + // clean up interval on unmount + return () => clearInterval(interval); + }, [percent]); + + return ( +
+ + null} + style={{ + data: { + fill: ({ datum }) => { + const color = datum.y > 30 ? "green" : "red"; + return datum.x === 1 ? color : "transparent"; + }, + }, + }} + /> + + {(newProps) => { + return ( + + ); + }} + + +
+ ); +}; + +export const DefaultRendering = () => { + return ; +};