-
Notifications
You must be signed in to change notification settings - Fork 286
Expand file tree
/
Copy pathtypes.ts
More file actions
331 lines (295 loc) · 9.72 KB
/
types.ts
File metadata and controls
331 lines (295 loc) · 9.72 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
import { HierarchyPointNode } from 'd3-hierarchy';
import { SyntheticEvent } from 'react';
import {
Orientation,
PathClassFunction,
PathFunction,
PathFunctionOption,
Point,
RawNodeDatum,
RenderCustomNodeElementFn,
TreeNodeDatum,
} from '../types/common.js';
export type TreeNodeEventCallback = (
node: HierarchyPointNode<TreeNodeDatum>,
event: SyntheticEvent
) => any;
export type TreeLinkEventCallback = (
sourceNode: HierarchyPointNode<TreeNodeDatum>,
targetNode: HierarchyPointNode<TreeNodeDatum>,
event: SyntheticEvent
) => any;
/**
* Props accepted by the `Tree` component.
*
* {@link Tree.defaultProps | Default Props}
*/
export interface TreeProps {
/**
* The root node object, in which child nodes (also of type `RawNodeDatum`)
* are recursively defined in the `children` key.
*
* `react-d3-tree` will automatically attach a unique `id` attribute to each node in the DOM,
* as well as `data-source-id` & `data-target-id` attributes to each link connecting two nodes.
*/
data: RawNodeDatum[] | RawNodeDatum;
/**
* Custom render function that will be used for every node in the tree.
*
* The function is passed `CustomNodeElementProps` as its first argument.
* `react-d3-tree` expects the function to return a `ReactElement`.
*
* See the `RenderCustomNodeElementFn` type for more details.
*
* {@link Tree.defaultProps.renderCustomNodeElement | Default value}
*/
renderCustomNodeElement?: RenderCustomNodeElementFn;
/**
* Called when a node is clicked.
*
* {@link Tree.defaultProps.onNodeClick | Default value}
*/
onNodeClick?: TreeNodeEventCallback;
/**
* Called when mouse enters the space belonging to a node.
*
* {@link Tree.defaultProps.onNodeMouseOver | Default value}
*/
onNodeMouseOver?: TreeNodeEventCallback;
/**
* Called when mouse leaves the space belonging to a node.
*
* {@link Tree.defaultProps.onNodeMouseOut | Default value}
*/
onNodeMouseOut?: TreeNodeEventCallback;
/**
* Called when a link is clicked.
*
* {@link Tree.defaultProps.onLinkClick | Default value}
*/
onLinkClick?: TreeLinkEventCallback;
/**
* Called when mouse enters the space belonging to a link.
*
* {@link Tree.defaultProps.onLinkMouseOver | Default value}
*/
onLinkMouseOver?: TreeLinkEventCallback;
/**
* Called when mouse leaves the space belonging to a link.
*
* {@link Tree.defaultProps.onLinkMouseOut | Default value}
*/
onLinkMouseOut?: TreeLinkEventCallback;
/**
* Called when the inner D3 component updates. That is - on every zoom or translate event,
* or when tree branches are toggled.
*
* {@link Tree.defaultProps.onUpdate | Default value}
*/
onUpdate?: (target: { node: TreeNodeDatum | null; zoom: number; translate: Point }) => any;
/**
* Determines along which axis the tree is oriented.
*
* `horizontal` - Tree expands along x-axis (left-to-right).
*
* `vertical` - Tree expands along y-axis (top-to-bottom).
*
* Additionally, passing a negative value to {@link TreeProps.depthFactor | depthFactor} will
* invert the tree's direction (i.e. right-to-left, bottom-to-top).
*
* {@link Tree.defaultProps.orientation | Default value}
*/
orientation?: Orientation;
/**
* Translates the graph along the x/y axis by the specified amount of pixels.
*
* By default, the graph will render in the top-left corner of the SVG canvas.
*
* {@link Tree.defaultProps.translate | Default value}
*/
translate?: Point;
/**
* Enables the centering of nodes on click by providing the dimensions of the tree container,
* e.g. via {@link https://developer.mozilla.org/en-US/docs/Web/API/Element/getBoundingClientRect | `getBoundingClientRect()`}.
*
* If dimensions are given: node will center on click. If not, node will not center on click.
*/
dimensions?: {
width: number;
height: number;
};
/**
* Sets the time (in milliseconds) for the transition to center a node once clicked.
*
* {@link Tree.defaultProps.centeringTransitionDuration | Default value}
*/
centeringTransitionDuration?: number;
/**
* The draw function (or `d`) used to render `path`/`link` elements. Accepts a predefined
* `PathFunctionOption` or a user-defined `PathFunction`.
*
* See the `PathFunction` type for more information.
*
* For details on draw functions, see: https://developer.mozilla.org/en-US/docs/Web/SVG/Attribute/d
*
* {@link Tree.defaultProps.pathFunc | Default value}
*/
pathFunc?: PathFunctionOption | PathFunction;
/**
* Allows for additional className(s) to be passed to links.
*
* Each link calls `pathClassFunc` with its own `TreeLinkDatum` and the tree's current `orientation`.
* Expects a `className` string to be returned.
*
* See the `PathClassFunction` type for more information.
*
* {@link Tree.defaultProps.pathClassFunc | Default value}
*/
pathClassFunc?: PathClassFunction;
/**
* Determines the spacing between parent & child nodes.
*
* **Tip: Negative values invert the tree's direction.**
*
* `node.y = node.depth * depthFactor`
*
* Example: `depthFactor: 0` renders all nodes on the same height (since node.y === 0 for all).
*
* {@link Tree.defaultProps.depthFactor | Default value}
*/
depthFactor?: number;
/**
* Determines whether the tree's nodes can collapse/expand.
*
* {@link Tree.defaultProps.collapsible | Default value}
*/
collapsible?: boolean;
/**
* Sets the maximum node depth to which the tree is expanded on its initial render.
*
* By default, the tree renders to full depth.
*
* {@link Tree.defaultProps.initialDepth | Default value}
*/
initialDepth?: number;
/**
* Toggles ability to zoom in/out on the Tree by scaling it according to `scaleExtent`.
*
* {@link Tree.defaultProps.zoomable | Default value}
*/
zoomable?: boolean;
/**
* Toggles ability to drag the Tree.
*
* {@link Tree.defaultProps.draggable | Default value}
*/
draggable?: boolean;
/**
* A floating point number to set the initial zoom level. It is constrained by `scaleExtent`.
*
* {@link Tree.defaultProps.zoom | Default value}
*/
zoom?: number;
/**
* Sets the minimum/maximum extent to which the tree can be scaled if `zoomable` is true.
*
* {@link Tree.defaultProps.scaleExtent | Default value}
*/
scaleExtent?: {
min?: number;
max?: number;
};
/**
* Set the maximum distance that the mouse can move between mousedown and mouseup that will trigger
* a subsequent click event. If at any point between mousedown and mouseup the mouse is greater than or equal to
* distance from its position on mousedown, the click event following mouseup will be suppressed.
*
* {@link Tree.defaultProps.clickDistance | Default value}
*/
clickDistance?: number;
/**
* The amount of space each node element occupies.
*
* {@link Tree.defaultProps.nodeSize | Default value}
*/
nodeSize?: {
x: number;
y: number;
};
/**
* Sets separation between neighboring nodes, differentiating between siblings (same parent node)
* and non-siblings.
*
* {@link Tree.defaultProps.separation | Default value}
*/
separation?: {
siblings?: number;
nonSiblings?: number;
};
/**
* If a node is currently being expanded, all other nodes at the same depth will be collapsed.
*
* {@link Tree.defaultProps.shouldCollapseNeighborNodes | Default value}
*/
shouldCollapseNeighborNodes?: boolean;
/**
* Allows for additional className(s) to be passed to the `svg` element wrapping the tree.
*
* {@link Tree.defaultProps.svgClassName | Default value}
*/
svgClassName?: string;
/**
* Allows for additional className(s) to be passed to the root node.
*
* {@link Tree.defaultProps.rootNodeClassName | Default value}
*/
rootNodeClassName?: string;
/**
* Allows for additional className(s) to be passed to all branch nodes (nodes with children).
*
* {@link Tree.defaultProps.branchNodeClassName | Default value}
*/
branchNodeClassName?: string;
/**
* Allows for additional className(s) to be passed to all leaf nodes (nodes without children).
*
* {@link Tree.defaultProps.leafNodeClassName | Default value}
*/
leafNodeClassName?: string;
/**
* Enables/disables legacy transitions using `react-transition-group`.
*
* **Note:** This flag is considered legacy and **usage is discouraged for large trees**,
* as responsiveness may suffer.
*
* `enableLegacyTransitions` will be deprecated once a suitable
* replacement for transitions has been found.
*
* {@link Tree.defaultProps.enableLegacyTransitions | Default value}
*/
enableLegacyTransitions?: boolean;
/**
* Sets the animation duration (in milliseconds) of each expansion/collapse of a tree node.
* Requires `enableLegacyTransition` to be `true`.
*
* {@link Tree.defaultProps.transitionDuration | Default value}
*/
transitionDuration?: number;
/**
* Disables drag/pan/zoom D3 events when hovering over a node.
* Useful for cases where D3 events interfere when interacting with inputs or other interactive elements on a node.
*
* **Tip:** Holding the `Shift` key while hovering over a node re-enables the D3 events.
*
* {@link Tree.defaultProps.hasInteractiveNodes | Default value}
*/
hasInteractiveNodes?: boolean;
/**
* Indicates the tree being represented by the data. If the dataKey changes, then we should re-render the tree.
* If the data changes but the dataKey keeps being the same, then it's a change (like adding children to a node) for the same tree,
* so we shouldn't re-render the tree.
*
* {@link Tree.defaultProps.dataKey | Default value}
*/
dataKey?: string;
}