Skip to content

Commit 1494170

Browse files
committedSep 1, 2021
feat(sankey): update stories to use new storybook format
1 parent b57d8b0 commit 1494170

File tree

1 file changed

+58
-34
lines changed

1 file changed

+58
-34
lines changed
 
+58-34
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,14 @@
1-
import { storiesOf } from '@storybook/react'
1+
import { Meta } from '@storybook/react'
22
import { generateSankeyData, randColor } from '@nivo/generators'
33
import { SankeyNodeMinimal } from 'd3-sankey'
44
// @ts-ignore
55
import { Sankey } from '../src'
6+
import { PropsWithChildren } from 'react'
7+
8+
export default {
9+
component: Sankey,
10+
title: 'Sankey',
11+
} as Meta
612

713
const sankeyData = generateSankeyData({ nodeCount: 11, maxIterations: 2 })
814
const commonProperties = {
@@ -13,41 +19,25 @@ const commonProperties = {
1319
colors: { scheme: 'category10' as const },
1420
}
1521

16-
const stories = storiesOf('Sankey', module)
17-
18-
stories.add('default', () => <Sankey {...commonProperties} />)
22+
export const Defaut = () => <Sankey {...commonProperties} />
1923

20-
stories.add('custom align (end)', () => <Sankey {...commonProperties} align="end" />)
24+
export const CustomAlign = () => <Sankey {...commonProperties} align="end" />
2125

22-
stories.add('outside labels', () => <Sankey {...commonProperties} labelPosition="outside" />)
26+
export const OutsideLabels = () => <Sankey {...commonProperties} labelPosition="outside" />
2327

24-
stories.add('vertical labels', () => (
28+
export const VerticalLabels = () => (
2529
<Sankey {...commonProperties} labelOrientation="vertical" labelPadding={20} />
26-
))
30+
)
2731

28-
stories.add('contracting links', () => <Sankey {...commonProperties} linkContract={10} />)
32+
export const ContractingLinks = () => <Sankey {...commonProperties} linkContract={10} />
2933

30-
stories.add('click listener (console)', () => (
34+
export const ClickHandler = () => (
3135
<Sankey {...commonProperties} onClick={(data, event) => console.log({ data, event })} />
32-
))
36+
)
3337

34-
stories.add('label formatter', () => (
35-
<Sankey {...commonProperties} label={node => `${node.id} 😁`} />
36-
))
37-
38-
stories.add('custom tooltip', () => (
39-
<Sankey
40-
{...commonProperties}
41-
nodeTooltip={({ node }) => <span>Custom tooltip for node: {node.label}</span>}
42-
linkTooltip={({ link }) => (
43-
<span>
44-
Custom tooltip for link: {link.source.label} to {link.target.label}
45-
</span>
46-
)}
47-
/>
48-
))
38+
export const CustomLabel = () => <Sankey {...commonProperties} label={node => `${node.id} 😁`} />
4939

50-
stories.add('with formatted values', () => (
40+
export const FormattedValues = () => (
5141
<Sankey
5242
{...commonProperties}
5343
valueFormat={value =>
@@ -56,7 +46,40 @@ stories.add('with formatted values', () => (
5646
})} ₽`
5747
}
5848
/>
59-
))
49+
)
50+
51+
const CustomTooltipContainer = ({ children }: PropsWithChildren<any>) => (
52+
<div
53+
style={{
54+
padding: 9,
55+
background: '#eeeeee',
56+
borderRadius: '2px',
57+
border: '1px solid #aaaaaa',
58+
}}
59+
>
60+
{children}
61+
</div>
62+
)
63+
64+
export const CustomTooltips = () => (
65+
<Sankey
66+
{...commonProperties}
67+
nodeTooltip={({ node }) => (
68+
<CustomTooltipContainer>
69+
Custom tooltip for node:
70+
<br />
71+
<strong>{node.label}</strong>
72+
</CustomTooltipContainer>
73+
)}
74+
linkTooltip={({ link }) => (
75+
<CustomTooltipContainer>
76+
Custom tooltip for link:
77+
<br />
78+
<strong>{link.source.label}</strong> to <strong>{link.target.label}</strong>
79+
</CustomTooltipContainer>
80+
)}
81+
/>
82+
)
6083

6184
const dataWithRandLinkColors = (data: typeof sankeyData) => ({
6285
nodes: data.nodes.map(node => ({
@@ -70,14 +93,14 @@ const dataWithRandLinkColors = (data: typeof sankeyData) => ({
7093
})),
7194
})
7295

73-
stories.add('with custom node & link coloring', () => (
96+
export const CustomNodeAndLinkColors = () => (
7497
<Sankey
7598
{...commonProperties}
7699
data={dataWithRandLinkColors(sankeyData)}
77100
enableLinkGradient={true}
78101
colors={node => node.nodeColor}
79102
/>
80-
))
103+
)
81104

82105
const minNodeValueOnTop = (
83106
nodeA: SankeyNodeMinimal<any, any>,
@@ -88,11 +111,12 @@ const minNodeValueOnTop = (
88111
return 0
89112
}
90113

91-
stories.add('with reverse sort ordering (min node value on top)', () => (
114+
// min node value on top
115+
export const WithReverseSortOrdering = () => (
92116
<Sankey {...commonProperties} sort={minNodeValueOnTop} />
93-
))
117+
)
94118

95-
stories.add('sort links by input', () => (
119+
export const SortLinksByInput = () => (
96120
<Sankey
97121
{...commonProperties}
98122
data={{
@@ -117,4 +141,4 @@ stories.add('sort links by input', () => (
117141
sort="input"
118142
enableLinkGradient
119143
/>
120-
))
144+
)

0 commit comments

Comments
 (0)
Please sign in to comment.