1
1
import { storiesOf } from '@storybook/react'
2
2
import { generateChordData } from '@nivo/generators'
3
3
import { TableTooltip , BasicTooltip , Chip } from '@nivo/tooltip'
4
- import { Chord } from '../src'
4
+ // @ts -ignore
5
+ import { Chord , ArcDatum , ArcTooltipComponentProps , RibbonTooltipComponentProps } from '../src'
6
+
7
+ const generateData = ( size : number ) => {
8
+ const { matrix, keys } = generateChordData ( { size } )
9
+
10
+ return { data : matrix , keys }
11
+ }
5
12
6
13
const commonProperties = {
7
14
width : 900 ,
8
15
height : 500 ,
9
16
margin : { top : 60 , right : 80 , bottom : 60 , left : 80 } ,
10
- ...generateChordData ( { size : 7 } ) ,
17
+ ...generateData ( 7 ) ,
11
18
xPadding : 0.2 ,
12
19
}
13
20
@@ -17,9 +24,9 @@ stories.add('default', () => <Chord {...commonProperties} />)
17
24
18
25
stories . add ( 'radial labels' , ( ) => < Chord { ...commonProperties } labelRotation = { - 90 } /> )
19
26
20
- const customLabel = d => `${ d . id } [${ d . value } ]`
27
+ const customLabel = ( arc : Omit < ArcDatum , 'label' | 'color' > ) => `${ arc . id } [${ arc . value } ]`
21
28
stories . add ( 'custom labels text' , ( ) => (
22
- < Chord { ...commonProperties } { ...generateChordData ( { size : 5 } ) } label = { customLabel } />
29
+ < Chord { ...commonProperties } { ...generateData ( 5 ) } label = { customLabel } />
23
30
) )
24
31
25
32
stories . add ( 'angle padding' , ( ) => (
@@ -43,7 +50,7 @@ stories.add('alternative colors', () => (
43
50
stories . add ( 'putting labels inside arcs' , ( ) => (
44
51
< Chord
45
52
{ ...commonProperties }
46
- { ...generateChordData ( { size : 5 } ) }
53
+ { ...generateData ( 5 ) }
47
54
padAngle = { 0.02 }
48
55
innerRadiusRatio = { 0.8 }
49
56
innerRadiusOffset = { 0.02 }
@@ -55,7 +62,7 @@ stories.add('putting labels inside arcs', () => (
55
62
stories . add ( 'with formatted values' , ( ) => (
56
63
< Chord
57
64
{ ...commonProperties }
58
- { ...generateChordData ( { size : 5 } ) }
65
+ { ...generateData ( 5 ) }
59
66
valueFormat = { value =>
60
67
`${ Number ( value ) . toLocaleString ( 'ru-RU' , {
61
68
minimumFractionDigits : 2 ,
@@ -64,7 +71,7 @@ stories.add('with formatted values', () => (
64
71
/>
65
72
) )
66
73
67
- const ArcTooltip = ( { arc } ) => (
74
+ const ArcTooltip = ( { arc } : ArcTooltipComponentProps ) => (
68
75
< BasicTooltip
69
76
id = { `Custom arc tooltip, ${ arc . label } ` }
70
77
value = { arc . formattedValue }
@@ -73,7 +80,7 @@ const ArcTooltip = ({ arc }) => (
73
80
/>
74
81
)
75
82
76
- const RibbonTooltip = ( { ribbon } ) => (
83
+ const RibbonTooltip = ( { ribbon } : RibbonTooltipComponentProps ) => (
77
84
< TableTooltip
78
85
rows = { [
79
86
[
@@ -95,7 +102,7 @@ const RibbonTooltip = ({ ribbon }) => (
95
102
stories . add ( 'custom tooltips' , ( ) => (
96
103
< Chord
97
104
{ ...commonProperties }
98
- { ...generateChordData ( { size : 5 } ) }
105
+ { ...generateData ( 5 ) }
99
106
arcTooltip = { ArcTooltip }
100
107
ribbonTooltip = { RibbonTooltip }
101
108
/>
0 commit comments