import { useState } from 'react'; import chroma from 'chroma-js'; import { Sankey } from 'reaviz'; import { SankeyNode } from 'reaviz'; import { SankeyLink } from 'reaviz'; import { sankeyNodes, sankeyLinks, simpleSankeyNodes, simpleSankeyLinks } from 'reaviz-data-utils'; import { SankeyLabel } from 'reaviz'; const colorScheme = chroma .scale([ '2b908f', '90ee7e', 'f45b5b', '7798BF', 'aaeeee', 'ff0066', 'eeaaee', '55BF3B', 'DF5353', '7798BF', 'aaeeee' ]) .mode('lch') .colors(sankeyNodes.length); const onNodeClick = (title: string) => window.alert(`${title} is clicked`); export default { tags: ['snapshot'], title: 'Charts/Sankey Plot', component: Sankey, subcomponents: { SankeyNode, SankeyLink, SankeyLabel } }; export const Simple = () => ( ( } onClick={() => onNodeClick(node.title)} /> ))} links={simpleSankeyLinks.map((link, i) => ( ))} /> ); export const LabelsInsideContainer = () => (
( } onClick={() => onNodeClick(node.title)} /> ))} links={simpleSankeyLinks.map((link, i) => ( ))} />
); export const FitLongLabels = () => (
( } onClick={() => onNodeClick(node.title)} /> ))} links={simpleSankeyLinks.map((link, i) => ( ))} />
); export const Filtering = () => ; export const Multilevels = () => ( ( ))} links={sankeyLinks.map((link, i) => ( ))} /> ); export const Autosize = () => (
( ))} links={sankeyLinks.map((link, i) => ( ))} />
); export const Justification = () => ( ( ))} links={sankeyLinks.map((link, i) => ( ))} /> ); const DemoStory = () => { const [filtered, setFiltered] = useState(false); const [state, setState] = useState({ nodes: [...simpleSankeyNodes], links: [...simpleSankeyLinks] }); const onClick = (node) => { const { links } = state; if (filtered) { setFiltered(false); setState({ nodes: simpleSankeyNodes, links: simpleSankeyLinks }); } else { setFiltered(true); setState({ nodes: [ node, ...links .filter((n) => n.source === node.id) .map((n) => simpleSankeyNodes.find((nn) => nn.id === n.target)) ], links: links.filter((l) => l.source === node.id) }); } }; return ( ( onClick(node)} /> ))} links={state.links.map((link, i) => ( ))} /> ); };