1
1
import { AriaAttributes , FunctionComponent , MouseEvent , MouseEventHandler } from 'react'
2
+ import { SpringValues } from '@react-spring/web'
2
3
import {
3
4
Box ,
4
5
Dimensions ,
5
6
Theme ,
6
7
ValueFormat ,
7
8
PropertyAccessor ,
8
9
ModernMotionProps ,
10
+ SvgDefsAndFill ,
9
11
} from '@nivo/core'
10
- import { InheritedColorConfig , OrdinalColorScaleConfig } from '@nivo/colors'
11
- import { SpringValues } from '@react-spring/web'
12
-
13
- export interface TreeMapDatum {
14
- children : TreeMapDatum [ ]
15
- }
12
+ import { InheritedColorConfig , OrdinalColorScaleConfig , DatumIdentityAccessor } from '@nivo/colors'
13
+ import { TileType } from './tiling'
16
14
17
15
export interface DefaultTreeMapDatum {
18
16
id : string
19
- value : string
20
- children : DefaultTreeMapDatum [ ]
17
+ value ?: number
18
+ children ? : DefaultTreeMapDatum [ ]
21
19
}
22
20
23
- export interface ComputedNode < Datum extends TreeMapDatum > {
21
+ export interface ComputedNode < Datum extends object > {
24
22
id : string
25
23
path : string
26
24
pathComponents : string [ ]
@@ -49,12 +47,12 @@ export interface ComputedNode<Datum extends TreeMapDatum> {
49
47
parentLabelRotation : number
50
48
}
51
49
52
- export type ComputedNodeWithoutStyles < Datum extends TreeMapDatum > = Omit <
50
+ export type ComputedNodeWithoutStyles < Datum extends object > = Omit <
53
51
ComputedNode < Datum > ,
54
52
'color' | 'opacity' | 'borderColor' | 'labelTextColor' | 'parentLabelTextColor'
55
53
>
56
54
57
- export interface ComputedNodeWithHandlers < Datum extends TreeMapDatum > extends ComputedNode < Datum > {
55
+ export interface ComputedNodeWithHandlers < Datum extends object > extends ComputedNode < Datum > {
58
56
onMouseEnter ?: MouseEventHandler
59
57
onMouseMove ?: MouseEventHandler
60
58
onMouseLeave ?: MouseEventHandler
@@ -77,52 +75,50 @@ export type NodeAnimatedProps = {
77
75
parentLabelOpacity : number
78
76
}
79
77
80
- export interface NodeProps < Datum extends TreeMapDatum > {
78
+ export interface NodeProps < Datum extends object > {
81
79
node : ComputedNodeWithHandlers < Datum >
82
80
animatedProps : SpringValues < NodeAnimatedProps >
83
81
borderWidth : TreeMapCommonProps < Datum > [ 'borderWidth' ]
84
82
enableLabel : TreeMapCommonProps < Datum > [ 'enableLabel' ]
85
83
labelSkipSize : TreeMapCommonProps < Datum > [ 'labelSkipSize' ]
86
84
enableParentLabel : TreeMapCommonProps < Datum > [ 'enableParentLabel' ]
87
85
}
88
- export type NodeComponent < Datum extends TreeMapDatum > = FunctionComponent < NodeProps < Datum > >
86
+ export type NodeComponent < Datum extends object > = FunctionComponent < NodeProps < Datum > >
89
87
90
- export type TreeMapTile = 'binary' | 'squarify' | 'slice' | 'dice' | 'sliceDice' | 'resquarify'
91
-
92
- export interface TooltipProps < Datum extends TreeMapDatum > {
88
+ export interface TooltipProps < Datum extends object > {
93
89
node : ComputedNode < Datum >
94
90
}
95
- export type TooltipComponent < Datum extends TreeMapDatum > = FunctionComponent < TooltipProps < Datum > >
91
+ export type TooltipComponent < Datum extends object > = FunctionComponent < TooltipProps < Datum > >
96
92
97
93
export type LayerId = 'nodes'
98
94
99
- export interface CustomLayerProps < Datum extends TreeMapDatum > {
95
+ export interface CustomLayerProps < Datum extends object > {
100
96
nodes : ComputedNode < Datum > [ ]
101
97
}
102
- export type CustomSvgLayer < Datum extends TreeMapDatum > = FunctionComponent < CustomLayerProps < Datum > >
103
- export type CustomHtmlLayer < Datum extends TreeMapDatum > = FunctionComponent < CustomLayerProps < Datum > >
104
- export type CustomCanvasLayer < Datum extends TreeMapDatum > = (
98
+ export type CustomSvgLayer < Datum extends object > = FunctionComponent < CustomLayerProps < Datum > >
99
+ export type CustomHtmlLayer < Datum extends object > = FunctionComponent < CustomLayerProps < Datum > >
100
+ export type CustomCanvasLayer < Datum extends object > = (
105
101
ctx : CanvasRenderingContext2D ,
106
102
props : CustomLayerProps < Datum >
107
103
) => void
108
104
109
- export type NodeMouseEventHandler < Datum extends TreeMapDatum > = (
105
+ export type NodeMouseEventHandler < Datum extends object > = (
110
106
node : ComputedNode < Datum > ,
111
107
event : MouseEvent
112
108
) => void
113
109
114
- export interface TreeMapDataProps < Datum extends TreeMapDatum > {
110
+ export interface TreeMapDataProps < Datum extends object > {
115
111
data : Datum
116
112
}
117
113
118
- export type TreeMapCommonProps < Datum extends TreeMapDatum > = {
114
+ export type TreeMapCommonProps < Datum extends object > = {
119
115
margin : Box
120
116
121
117
identity : PropertyAccessor < Datum , string >
122
118
value : PropertyAccessor < Datum , number >
123
119
valueFormat : ValueFormat < number >
124
120
125
- tile : TreeMapTile
121
+ tile : TileType
126
122
leavesOnly : boolean
127
123
innerPadding : number
128
124
outerPadding : number
@@ -131,19 +127,27 @@ export type TreeMapCommonProps<Datum extends TreeMapDatum> = {
131
127
label : PropertyAccessor < Omit < ComputedNodeWithoutStyles < Datum > , 'label' | 'parentLabel' > , string >
132
128
labelFormat : ValueFormat < number >
133
129
labelSkipSize : number
134
- labelTextColor : InheritedColorConfig < any >
130
+ labelTextColor : InheritedColorConfig <
131
+ ComputedNodeWithoutStyles < Datum > & {
132
+ color : ComputedNode < Datum > [ 'color' ]
133
+ }
134
+ >
135
135
orientLabel : boolean
136
136
137
137
enableParentLabel : boolean
138
138
parentLabel : PropertyAccessor < Omit < ComputedNodeWithoutStyles < Datum > , 'parentLabel' > , string >
139
139
parentLabelSize : number
140
140
parentLabelPosition : 'top' | 'right' | 'bottom' | 'left'
141
141
parentLabelPadding : number
142
- parentLabelTextColor : InheritedColorConfig < any >
142
+ parentLabelTextColor : InheritedColorConfig <
143
+ ComputedNodeWithoutStyles < Datum > & {
144
+ color : ComputedNode < Datum > [ 'color' ]
145
+ }
146
+ >
143
147
144
148
theme : Theme
145
149
colors : OrdinalColorScaleConfig < ComputedNodeWithoutStyles < Datum > >
146
- colorBy : any //colorPropertyAccessorPropType.isRequired,
150
+ colorBy : string | DatumIdentityAccessor < ComputedNodeWithoutStyles < Datum > >
147
151
nodeOpacity : number
148
152
borderWidth : number
149
153
borderColor : InheritedColorConfig <
@@ -153,6 +157,10 @@ export type TreeMapCommonProps<Datum extends TreeMapDatum> = {
153
157
>
154
158
155
159
isInteractive : boolean
160
+ onMouseEnter : NodeMouseEventHandler < Datum >
161
+ onMouseMove : NodeMouseEventHandler < Datum >
162
+ onMouseLeave : NodeMouseEventHandler < Datum >
163
+ onClick : NodeMouseEventHandler < Datum >
156
164
tooltip : TooltipComponent < Datum >
157
165
158
166
renderWrapper : boolean
@@ -163,36 +171,36 @@ export type TreeMapCommonProps<Datum extends TreeMapDatum> = {
163
171
ariaDescribedBy : AriaAttributes [ 'aria-describedby' ]
164
172
} & ModernMotionProps
165
173
166
- export type TreeMapSvgProps < Datum extends TreeMapDatum > = Partial < TreeMapCommonProps < Datum > > &
174
+ export type TreeMapSvgProps < Datum extends object > = Partial < TreeMapCommonProps < Datum > > &
167
175
TreeMapDataProps < Datum > &
168
- Dimensions & {
176
+ Dimensions &
177
+ SvgDefsAndFill < ComputedNode < Datum > > & {
169
178
nodeComponent ?: NodeComponent < Datum >
170
179
layers ?: ( LayerId | CustomSvgLayer < Datum > ) [ ]
171
- defs ?: any [ ]
172
- fill ?: any [ ]
173
- onMouseEnter ?: NodeMouseEventHandler < Datum >
174
- onMouseMove ?: NodeMouseEventHandler < Datum >
175
- onMouseLeave ?: NodeMouseEventHandler < Datum >
176
- onClick ?: NodeMouseEventHandler < Datum >
177
180
}
178
181
179
- export type TreeMapHtmlProps < Datum extends TreeMapDatum > = Partial < TreeMapCommonProps < Datum > > &
182
+ export type TreeMapHtmlProps < Datum extends object > = Partial < TreeMapCommonProps < Datum > > &
180
183
TreeMapDataProps < Datum > &
181
184
Dimensions & {
182
185
nodeComponent ?: NodeComponent < Datum >
183
186
layers ?: ( LayerId | CustomHtmlLayer < Datum > ) [ ]
184
- pixelRatio ?: number
185
- onMouseEnter ?: NodeMouseEventHandler < Datum >
186
- onMouseMove ?: NodeMouseEventHandler < Datum >
187
- onMouseLeave ?: NodeMouseEventHandler < Datum >
188
- onClick ?: NodeMouseEventHandler < Datum >
189
187
}
190
188
191
- export type TreeMapCanvasProps < Datum extends TreeMapDatum > = Partial < TreeMapCommonProps < Datum > > &
189
+ export type TreeMapCanvasProps < Datum extends object > = Partial <
190
+ Omit <
191
+ TreeMapCommonProps < Datum > ,
192
+ | 'enableParentLabel'
193
+ | 'parentLabel'
194
+ | 'parentLabelSize'
195
+ | 'parentLabelPosition'
196
+ | 'parentLabelPadding'
197
+ | 'parentLabelTextColor'
198
+ | 'onMouseEnter'
199
+ | 'onMouseLeave'
200
+ >
201
+ > &
192
202
TreeMapDataProps < Datum > &
193
203
Dimensions & {
194
204
layers ?: ( LayerId | CustomCanvasLayer < Datum > ) [ ]
195
205
pixelRatio ?: number
196
- onMouseMove ?: NodeMouseEventHandler < Datum >
197
- onClick ?: NodeMouseEventHandler < Datum >
198
206
}
0 commit comments