1 |
|
2 |
|
3 |
|
4 |
|
5 |
|
6 |
|
7 |
|
8 |
|
9 |
|
10 |
|
11 |
|
12 |
|
13 |
|
14 |
|
15 |
|
16 |
|
17 | export interface HierarchyLink<Datum> {
|
18 | |
19 |
|
20 |
|
21 | source: HierarchyNode<Datum>;
|
22 |
|
23 | |
24 |
|
25 |
|
26 | target: HierarchyNode<Datum>;
|
27 | }
|
28 |
|
29 | export interface HierarchyNode<Datum> {
|
30 | new(data: Datum): this;
|
31 |
|
32 | |
33 |
|
34 |
|
35 | data: Datum;
|
36 |
|
37 | |
38 |
|
39 |
|
40 | readonly depth: number;
|
41 |
|
42 | |
43 |
|
44 |
|
45 | readonly height: number;
|
46 |
|
47 | |
48 |
|
49 |
|
50 | parent: this | null;
|
51 |
|
52 | |
53 |
|
54 |
|
55 | children?: this[] | undefined;
|
56 |
|
57 | |
58 |
|
59 |
|
60 | readonly value?: number | undefined;
|
61 |
|
62 | |
63 |
|
64 |
|
65 | readonly id?: string | undefined;
|
66 |
|
67 | |
68 |
|
69 |
|
70 | ancestors(): this[];
|
71 |
|
72 | |
73 |
|
74 |
|
75 | descendants(): this[];
|
76 |
|
77 | |
78 |
|
79 |
|
80 | leaves(): this[];
|
81 |
|
82 | |
83 |
|
84 |
|
85 |
|
86 | find(filter: (node: this) => boolean): this | undefined;
|
87 |
|
88 | |
89 |
|
90 |
|
91 |
|
92 |
|
93 |
|
94 | path(target: this): this[];
|
95 |
|
96 | |
97 |
|
98 |
|
99 |
|
100 | links(): Array<HierarchyLink<Datum>>;
|
101 |
|
102 | |
103 |
|
104 |
|
105 |
|
106 |
|
107 |
|
108 | sum(value: (d: Datum) => number): this;
|
109 |
|
110 | |
111 |
|
112 |
|
113 |
|
114 | count(): this;
|
115 |
|
116 | |
117 |
|
118 |
|
119 |
|
120 |
|
121 |
|
122 |
|
123 |
|
124 |
|
125 | sort(compare: (a: this, b: this) => number): this;
|
126 |
|
127 | |
128 |
|
129 |
|
130 | [Symbol.iterator](): Iterator<this>;
|
131 |
|
132 | |
133 |
|
134 |
|
135 |
|
136 |
|
137 |
|
138 |
|
139 |
|
140 | each<T = undefined>(func: (this: T, node: this, index: number, thisNode: this) => void, that?: T): this;
|
141 |
|
142 | /**
|
143 | * Invokes the specified function for node and each descendant in post-order traversal,
|
144 | * such that a given node is only visited after all of its descendants have already been visited.
|
145 | *
|
146 | * @param func The specified function is passed the current descendant, the zero-based traversal index, and this node.
|
147 | * @param that If that is specified, it is the this context of the callback.
|
148 | *
|
149 | */
|
150 | eachAfter<T = undefined>(func: (this: T, node: this, index: number, thisNode: this) => void, that?: T): this;
|
151 |
|
152 | /**
|
153 | * Invokes the specified function for node and each descendant in pre-order traversal,
|
154 | * such that a given node is only visited after all of its ancestors have already been visited.
|
155 | *
|
156 | * @param func The specified function is passed the current descendant, the zero-based traversal index, and this node.
|
157 | * @param that If that is specified, it is the this context of the callback.
|
158 | */
|
159 | eachBefore<T = undefined>(func: (this: T, node: this, index: number, thisNode: this) => void, that?: T): this;
|
160 |
|
161 | /**
|
162 | * Return a deep copy of the subtree starting at this node. The returned deep copy shares the same data, however.
|
163 | * The returned node is the root of a new tree; the returned node’s parent is always null and its depth is always zero.
|
164 | */
|
165 | copy(): this;
|
166 | }
|
167 |
|
168 | /**
|
169 | * Constructs a root node from the specified hierarchical data.
|
170 | *
|
171 | * @param data The root specified data.
|
172 | * If *data* is a Map, it is implicitly converted to the entry [undefined, *data*],
|
173 | * and the children accessor instead defaults to `(d) => Array.isArray(d) ? d[1] : null;`.
|
174 | * @param children The specified children accessor function is invoked for each datum, starting with the root data,
|
175 | * and must return an iterable of data representing the children, if any.
|
176 | * If children is not specified, it defaults to: `(d) => d.children`.
|
177 | */
|
178 | export function hierarchy<Datum>(data: Datum, children?: (d: Datum) => (Iterable<Datum> | null | undefined)): HierarchyNode<Datum>;
|
179 |
|
180 | // -----------------------------------------------------------------------
|
181 | // Stratify
|
182 | // -----------------------------------------------------------------------
|
183 |
|
184 | export interface StratifyOperator<Datum> {
|
185 | /**
|
186 | * Generates a new hierarchy from the specified tabular data. Each node in the returned object has a shallow copy of the properties
|
187 | * from the corresponding data object, excluding the following reserved properties: id, parentId, children.
|
188 | *
|
189 | * @param data The root specified data.
|
190 | * @throws Error on missing id, ambiguous id, cycle, multiple roots or no root.
|
191 | */
|
192 | (data: Datum[]): HierarchyNode<Datum>;
|
193 |
|
194 | /**
|
195 | * Returns the current id accessor, which defaults to: `(d) => d.id`.
|
196 | */
|
197 | id(): (d: Datum, i: number, data: Datum[]) => (string | null | '' | undefined);
|
198 | /**
|
199 | * Sets the id accessor to the given function.
|
200 | * The id accessor is invoked for each element in the input data passed to the stratify operator.
|
201 | * The returned string is then used to identify the node's relationships in conjunction with the parent id.
|
202 | * For leaf nodes, the id may be undefined, null or the empty string; otherwise, the id must be unique.
|
203 | *
|
204 | * @param id The id accessor.
|
205 | */
|
206 | id(id: (d: Datum, i: number, data: Datum[]) => (string | null | '' | undefined)): this;
|
207 |
|
208 | /**
|
209 | * Returns the current parent id accessor, which defaults to: `(d) => d.parentId`.
|
210 | */
|
211 | parentId(): (d: Datum, i: number, data: Datum[]) => (string | null | '' | undefined);
|
212 | /**
|
213 | * Sets the parent id accessor to the given function.
|
214 | * The parent id accessor is invoked for each element in the input data passed to the stratify operator.
|
215 | * The returned string is then used to identify the node's relationships in conjunction with the id.
|
216 | * For the root node, the parent id should be undefined, null or the empty string.
|
217 | * There must be exactly one root node in the input data, and no circular relationships.
|
218 | *
|
219 | * @param parentId The parent id accessor.
|
220 | */
|
221 | parentId(parentId: (d: Datum, i: number, data: Datum[]) => (string | null | '' | undefined)): this;
|
222 |
|
223 | /**
|
224 | * Returns the current path accessor, which defaults to undefined.
|
225 | */
|
226 | path(): ((d: Datum, i: number, data: Datum[]) => string) | null | undefined;
|
227 | /**
|
228 | * If path is specified, sets the path accessor to the given function and returns this stratify operator.
|
229 | * Otherwise, returns the current path accessor, which defaults to undefined.
|
230 | * If a path accessor is set, the id and parentId arguments are ignored,
|
231 | * and a unix-like hierarchy is computed on the slash-delimited strings
|
232 | * returned by the path accessor, imputing parent nodes and ids as necessary.
|
233 | *
|
234 | * @param path The path accessor.
|
235 | */
|
236 | path(path: ((d: Datum, i: number, data: Datum[]) => string) | null | undefined): this;
|
237 | }
|
238 |
|
239 | /**
|
240 | * Constructs a new stratify operator with the default settings.
|
241 | */
|
242 | // eslint-disable-next-line no-unnecessary-generics
|
243 | export function stratify<Datum>(): StratifyOperator<Datum>;
|
244 |
|
245 | // -----------------------------------------------------------------------
|
246 | // Cluster
|
247 | // -----------------------------------------------------------------------
|
248 |
|
249 | export interface HierarchyPointLink<Datum> {
|
250 | /**
|
251 | * The source of the link.
|
252 | */
|
253 | source: HierarchyPointNode<Datum>;
|
254 |
|
255 | /**
|
256 | * The target of the link.
|
257 | */
|
258 | target: HierarchyPointNode<Datum>;
|
259 | }
|
260 |
|
261 | export interface HierarchyPointNode<Datum> extends HierarchyNode<Datum> {
|
262 | /**
|
263 | * The x-coordinate of the node.
|
264 | */
|
265 | x: number;
|
266 |
|
267 | /**
|
268 | * The y-coordinate of the node.
|
269 | */
|
270 | y: number;
|
271 |
|
272 | /**
|
273 | * Returns an array of links for this node, where each link is an object that defines source and target properties.
|
274 | * The source of each link is the parent node, and the target is a child node.
|
275 | */
|
276 | links(): Array<HierarchyPointLink<Datum>>;
|
277 | }
|
278 |
|
279 | export interface ClusterLayout<Datum> {
|
280 | /**
|
281 | * Lays out the specified root hierarchy.
|
282 | * You may want to call `root.sort` before passing the hierarchy to the cluster layout.
|
283 | *
|
284 | * @param root The specified root hierarchy.
|
285 | */
|
286 | (root: HierarchyNode<Datum>): HierarchyPointNode<Datum>;
|
287 |
|
288 | /**
|
289 | * Returns the current layout size, which defaults to [1, 1]. A layout size of null indicates that a node size will be used instead.
|
290 | */
|
291 | size(): [number, number] | null;
|
292 | /**
|
293 | * Sets this cluster layout’s size to the specified [width, height] array and returns the cluster layout.
|
294 | * The size represent an arbitrary coordinate system; for example, to produce a radial layout,
|
295 | * a size of [360, radius] corresponds to a breadth of 360° and a depth of radius.
|
296 | *
|
297 | * @param size The specified two-element size array.
|
298 | */
|
299 | size(size: [number, number]): this;
|
300 |
|
301 | /**
|
302 | * Returns the current node size, which defaults to null. A node size of null indicates that a layout size will be used instead.
|
303 | */
|
304 | nodeSize(): [number, number] | null;
|
305 | /**
|
306 | * Sets this cluster layout’s node size to the specified [width, height] array and returns this cluster layout.
|
307 | * When a node size is specified, the root node is always positioned at <0, 0>.
|
308 | *
|
309 | * @param size The specified two-element size array.
|
310 | */
|
311 | nodeSize(size: [number, number]): this;
|
312 |
|
313 | /**
|
314 | * Returns the current separation accessor, which defaults to: `(a, b) => a.parent == b.parent ? 1 : 2`.
|
315 | */
|
316 | separation(): (a: HierarchyPointNode<Datum>, b: HierarchyPointNode<Datum>) => number;
|
317 | /**
|
318 | * Sets the separation accessor to the specified function and returns this cluster layout.
|
319 | * The separation accessor is used to separate neighboring leaves.
|
320 | *
|
321 | * @param separation The separation function is passed two leaves a and b, and must return the desired separation.
|
322 | * The nodes are typically siblings, though the nodes may be more distantly related if the layout decides to place such nodes adjacent.
|
323 | */
|
324 | separation(separation: (a: HierarchyPointNode<Datum>, b: HierarchyPointNode<Datum>) => number): this;
|
325 | }
|
326 |
|
327 | /**
|
328 | * Creates a new cluster layout with default settings.
|
329 | */
|
330 | // eslint-disable-next-line no-unnecessary-generics
|
331 | export function cluster<Datum>(): ClusterLayout<Datum>;
|
332 |
|
333 | // -----------------------------------------------------------------------
|
334 | // Tree
|
335 | // -----------------------------------------------------------------------
|
336 |
|
337 | export interface TreeLayout<Datum> {
|
338 | /**
|
339 | * Lays out the specified root hierarchy.
|
340 | * You may want to call `root.sort` before passing the hierarchy to the tree layout.
|
341 | *
|
342 | * @param root The specified root hierarchy.
|
343 | */
|
344 | (root: HierarchyNode<Datum>): HierarchyPointNode<Datum>;
|
345 |
|
346 | /**
|
347 | * Returns the current layout size, which defaults to [1, 1]. A layout size of null indicates that a node size will be used instead.
|
348 | */
|
349 | size(): [number, number] | null;
|
350 | /**
|
351 | * Sets this tree layout’s size to the specified [width, height] array and returns the tree layout.
|
352 | * The size represent an arbitrary coordinate system; for example, to produce a radial layout,
|
353 | * a size of [360, radius] corresponds to a breadth of 360° and a depth of radius.
|
354 | *
|
355 | * @param size The specified two-element size array.
|
356 | */
|
357 | size(size: [number, number]): this;
|
358 |
|
359 | /**
|
360 | * Returns the current node size, which defaults to null. A node size of null indicates that a layout size will be used instead.
|
361 | */
|
362 | nodeSize(): [number, number] | null;
|
363 | /**
|
364 | * Sets this tree layout’s node size to the specified [width, height] array and returns this tree layout.
|
365 | * When a node size is specified, the root node is always positioned at <0, 0>.
|
366 | *
|
367 | * @param size The specified two-element size array.
|
368 | */
|
369 | nodeSize(size: [number, number]): this;
|
370 |
|
371 | /**
|
372 | * Returns the current separation accessor, which defaults to: `(a, b) => a.parent == b.parent ? 1 : 2`.
|
373 | */
|
374 | separation(): (a: HierarchyPointNode<Datum>, b: HierarchyPointNode<Datum>) => number;
|
375 | /**
|
376 | * Sets the separation accessor to the specified function and returns this tree layout.
|
377 | * The separation accessor is used to separate neighboring nodes.
|
378 | *
|
379 | * @param separation The separation function is passed two nodes a and b, and must return the desired separation.
|
380 | * The nodes are typically siblings, though the nodes may be more distantly related if the layout decides to place such nodes adjacent.
|
381 | */
|
382 | separation(separation: (a: HierarchyPointNode<Datum>, b: HierarchyPointNode<Datum>) => number): this;
|
383 | }
|
384 |
|
385 | /**
|
386 | * Creates a new tree layout with default settings.
|
387 | */
|
388 | // eslint-disable-next-line no-unnecessary-generics
|
389 | export function tree<Datum>(): TreeLayout<Datum>;
|
390 |
|
391 | // -----------------------------------------------------------------------
|
392 | // Treemap
|
393 | // -----------------------------------------------------------------------
|
394 |
|
395 | export interface HierarchyRectangularLink<Datum> {
|
396 | /**
|
397 | * The source of the link.
|
398 | */
|
399 | source: HierarchyRectangularNode<Datum>;
|
400 |
|
401 | /**
|
402 | * The target of the link.
|
403 | */
|
404 | target: HierarchyRectangularNode<Datum>;
|
405 | }
|
406 |
|
407 | export interface HierarchyRectangularNode<Datum> extends HierarchyNode<Datum> {
|
408 | /**
|
409 | * The left edge of the rectangle.
|
410 | */
|
411 | x0: number;
|
412 |
|
413 | /**
|
414 | * The top edge of the rectangle
|
415 | */
|
416 | y0: number;
|
417 |
|
418 | /**
|
419 | * The right edge of the rectangle.
|
420 | */
|
421 | x1: number;
|
422 |
|
423 | /**
|
424 | * The bottom edge of the rectangle.
|
425 | */
|
426 | y1: number;
|
427 |
|
428 | /**
|
429 | * Returns an array of links for this node, where each link is an object that defines source and target properties.
|
430 | * The source of each link is the parent node, and the target is a child node.
|
431 | */
|
432 | links(): Array<HierarchyRectangularLink<Datum>>;
|
433 | }
|
434 |
|
435 | export interface TreemapLayout<Datum> {
|
436 | /**
|
437 | * Lays out the specified root hierarchy.
|
438 | * You must call `root.sum` before passing the hierarchy to the treemap layout.
|
439 | * You probably also want to call `root.sort` to order the hierarchy before computing the layout.
|
440 | *
|
441 | * @param root The specified root hierarchy.
|
442 | */
|
443 | (root: HierarchyNode<Datum>): HierarchyRectangularNode<Datum>;
|
444 |
|
445 | /**
|
446 | * Returns the current tiling method, which defaults to `d3.treemapSquarify` with the golden ratio.
|
447 | */
|
448 | tile(): (node: HierarchyRectangularNode<Datum>, x0: number, y0: number, x1: number, y1: number) => void;
|
449 | /**
|
450 | * Sets the tiling method to the specified function and returns this treemap layout.
|
451 | *
|
452 | * @param tile The specified tiling function.
|
453 | */
|
454 | tile(tile: (node: HierarchyRectangularNode<Datum>, x0: number, y0: number, x1: number, y1: number) => void): this;
|
455 |
|
456 | /**
|
457 | * Returns the current size, which defaults to [1, 1].
|
458 | */
|
459 | size(): [number, number];
|
460 | /**
|
461 | * Sets this treemap layout’s size to the specified [width, height] array and returns this treemap layout.
|
462 | *
|
463 | * @param size The specified two-element size array.
|
464 | */
|
465 | size(size: [number, number]): this;
|
466 |
|
467 | /**
|
468 | * Returns the current rounding state, which defaults to false.
|
469 | */
|
470 | round(): boolean;
|
471 | /**
|
472 | * Enables or disables rounding according to the given boolean and returns this treemap layout.
|
473 | *
|
474 | * @param round The specified boolean flag.
|
475 | */
|
476 | round(round: boolean): this;
|
477 |
|
478 | /**
|
479 | * Returns the current inner padding function.
|
480 | */
|
481 | padding(): (node: HierarchyRectangularNode<Datum>) => number;
|
482 | /**
|
483 | * Sets the inner and outer padding to the specified number and returns this treemap layout.
|
484 | *
|
485 | * @param padding The specified padding value.
|
486 | */
|
487 | padding(padding: number): this;
|
488 | /**
|
489 | * Sets the inner and outer padding to the specified function and returns this treemap layout.
|
490 | *
|
491 | * @param padding The specified padding function.
|
492 | */
|
493 | padding(padding: (node: HierarchyRectangularNode<Datum>) => number): this;
|
494 |
|
495 | /**
|
496 | * Returns the current inner padding function, which defaults to the constant zero.
|
497 | */
|
498 | paddingInner(): (node: HierarchyRectangularNode<Datum>) => number;
|
499 | /**
|
500 | * Sets the inner padding to the specified number and returns this treemap layout.
|
501 | * The inner padding is used to separate a node’s adjacent children.
|
502 | *
|
503 | * @param padding The specified inner padding value.
|
504 | */
|
505 | paddingInner(padding: number): this;
|
506 | /**
|
507 | * Sets the inner padding to the specified function and returns this treemap layout.
|
508 | * The function is invoked for each node with children, being passed the current node.
|
509 | * The inner padding is used to separate a node’s adjacent children.
|
510 | *
|
511 | * @param padding The specified inner padding function.
|
512 | */
|
513 | paddingInner(padding: (node: HierarchyRectangularNode<Datum>) => number): this;
|
514 |
|
515 | /**
|
516 | * Returns the current top padding function.
|
517 | */
|
518 | paddingOuter(): (node: HierarchyRectangularNode<Datum>) => number;
|
519 | /**
|
520 | * Sets the top, right, bottom and left padding to the specified function and returns this treemap layout.
|
521 | *
|
522 | * @param padding The specified padding outer value.
|
523 | */
|
524 | paddingOuter(padding: number): this;
|
525 | /**
|
526 | * Sets the top, right, bottom and left padding to the specified function and returns this treemap layout.
|
527 | *
|
528 | * @param padding The specified padding outer function.
|
529 | */
|
530 | paddingOuter(padding: (node: HierarchyRectangularNode<Datum>) => number): this;
|
531 |
|
532 | /**
|
533 | * Returns the current top padding function, which defaults to the constant zero.
|
534 | */
|
535 | paddingTop(): (node: HierarchyRectangularNode<Datum>) => number;
|
536 | /**
|
537 | * Sets the top padding to the specified number and returns this treemap layout.
|
538 | * The top padding is used to separate the top edge of a node from its children.
|
539 | *
|
540 | * @param padding The specified top padding value.
|
541 | */
|
542 | paddingTop(padding: number): this;
|
543 | /**
|
544 | * Sets the top padding to the specified function and returns this treemap layout.
|
545 | * The function is invoked for each node with children, being passed the current node.
|
546 | * The top padding is used to separate the top edge of a node from its children.
|
547 | *
|
548 | * @param padding The specified top padding function.
|
549 | */
|
550 | paddingTop(padding: (node: HierarchyRectangularNode<Datum>) => number): this;
|
551 |
|
552 | /**
|
553 | * Returns the current right padding function, which defaults to the constant zero.
|
554 | */
|
555 | paddingRight(): (node: HierarchyRectangularNode<Datum>) => number;
|
556 | /**
|
557 | * Sets the right padding to the specified number and returns this treemap layout.
|
558 | * The right padding is used to separate the right edge of a node from its children.
|
559 | *
|
560 | * @param padding The specified right padding value.
|
561 | */
|
562 | paddingRight(padding: number): this;
|
563 | /**
|
564 | * Sets the right padding to the specified function and returns this treemap layout.
|
565 | * The function is invoked for each node with children, being passed the current node.
|
566 | * The right padding is used to separate the right edge of a node from its children.
|
567 | *
|
568 | * @param padding The specified right padding function.
|
569 | */
|
570 | paddingRight(padding: (node: HierarchyRectangularNode<Datum>) => number): this;
|
571 |
|
572 | /**
|
573 | * Returns the current bottom padding function, which defaults to the constant zero.
|
574 | */
|
575 | paddingBottom(): (node: HierarchyRectangularNode<Datum>) => number;
|
576 | /**
|
577 | * Sets the bottom padding to the specified number and returns this treemap layout.
|
578 | * The bottom padding is used to separate the bottom edge of a node from its children.
|
579 | *
|
580 | * @param padding The specified bottom padding value.
|
581 | */
|
582 | paddingBottom(padding: number): this;
|
583 | /**
|
584 | * Sets the bottom padding to the specified function and returns this treemap layout.
|
585 | * The function is invoked for each node with children, being passed the current node.
|
586 | * The bottom padding is used to separate the bottom edge of a node from its children.
|
587 | *
|
588 | * @param padding The specified bottom padding function.
|
589 | */
|
590 | paddingBottom(padding: (node: HierarchyRectangularNode<Datum>) => number): this;
|
591 |
|
592 | /**
|
593 | * Returns the current left padding function, which defaults to the constant zero.
|
594 | */
|
595 | paddingLeft(): (node: HierarchyRectangularNode<Datum>) => number;
|
596 | /**
|
597 | * Sets the left padding to the specified number and returns this treemap layout.
|
598 | * The left padding is used to separate the left edge of a node from its children.
|
599 | *
|
600 | * @param padding The specified left padding value.
|
601 | */
|
602 | paddingLeft(padding: number): this;
|
603 | /**
|
604 | * Sets the left padding to the specified function and returns this treemap layout.
|
605 | * The function is invoked for each node with children, being passed the current node.
|
606 | * The left padding is used to separate the left edge of a node from its children.
|
607 | *
|
608 | * @param padding The specified left padding function.
|
609 | */
|
610 | paddingLeft(padding: (node: HierarchyRectangularNode<Datum>) => number): this;
|
611 | }
|
612 |
|
613 | /**
|
614 | * Creates a new treemap layout with default settings.
|
615 | */
|
616 | // eslint-disable-next-line no-unnecessary-generics
|
617 | export function treemap<Datum>(): TreemapLayout<Datum>;
|
618 |
|
619 | // Tiling functions ------------------------------------------------------
|
620 |
|
621 | /**
|
622 | * Recursively partitions the specified nodes into an approximately-balanced binary tree,
|
623 | * choosing horizontal partitioning for wide rectangles and vertical partitioning for tall rectangles.
|
624 | */
|
625 | export function treemapBinary(node: HierarchyRectangularNode<any>, x0: number, y0: number, x1: number, y1: number): void;
|
626 |
|
627 | /**
|
628 | * Divides the rectangular area specified by x0, y0, x1, y1 horizontally according the value of each of the specified node’s children.
|
629 | * The children are positioned in order, starting with the left edge (x0) of the given rectangle.
|
630 | * If the sum of the children’s values is less than the specified node’s value (i.e., if the specified node has a non-zero internal value),
|
631 | * the remaining empty space will be positioned on the right edge (x1) of the given rectangle.
|
632 | */
|
633 | export function treemapDice(node: HierarchyRectangularNode<any>, x0: number, y0: number, x1: number, y1: number): void;
|
634 |
|
635 | /**
|
636 | * Divides the rectangular area specified by x0, y0, x1, y1 vertically according the value of each of the specified node’s children.
|
637 | * The children are positioned in order, starting with the top edge (y0) of the given rectangle.
|
638 | * If the sum of the children’s values is less than the specified node’s value (i.e., if the specified node has a non-zero internal value),
|
639 | * the remaining empty space will be positioned on the bottom edge (y1) of the given rectangle.
|
640 | */
|
641 | export function treemapSlice(node: HierarchyRectangularNode<any>, x0: number, y0: number, x1: number, y1: number): void;
|
642 |
|
643 | /**
|
644 | * If the specified node has odd depth, delegates to treemapSlice; otherwise delegates to treemapDice.
|
645 | */
|
646 | export function treemapSliceDice(node: HierarchyRectangularNode<any>, x0: number, y0: number, x1: number, y1: number): void;
|
647 |
|
648 | // TODO: Test Factory code
|
649 | export interface RatioSquarifyTilingFactory {
|
650 | (node: HierarchyRectangularNode<any>, x0: number, y0: number, x1: number, y1: number): void;
|
651 |
|
652 | /**
|
653 | * Specifies the desired aspect ratio of the generated rectangles.
|
654 | * Note that the orientation of the generated rectangles (tall or wide) is not implied by the ratio.
|
655 | * Furthermore, the rectangles ratio are not guaranteed to have the exact specified aspect ratio.
|
656 | * If not specified, the aspect ratio defaults to the golden ratio, φ = (1 + sqrt(5)) / 2, per Kong et al.
|
657 | *
|
658 | * @param ratio The specified ratio value greater than or equal to one.
|
659 | */
|
660 | ratio(ratio: number): RatioSquarifyTilingFactory;
|
661 | }
|
662 |
|
663 | /**
|
664 | * Implements the squarified treemap algorithm by Bruls et al., which seeks to produce rectangles of a given aspect ratio.
|
665 | */
|
666 | export const treemapSquarify: RatioSquarifyTilingFactory;
|
667 |
|
668 | /**
|
669 | * Like `d3.treemapSquarify`, except preserves the topology (node adjacencies) of the previous layout computed by `d3.treemapResquarify`,
|
670 | * if there is one and it used the same target aspect ratio. This tiling method is good for animating changes to treemaps because
|
671 | * it only changes node sizes and not their relative positions, thus avoiding distracting shuffling and occlusion.
|
672 | * The downside of a stable update, however, is a suboptimal layout for subsequent updates: only the first layout uses the Bruls et al. squarified algorithm.
|
673 | */
|
674 | export const treemapResquarify: RatioSquarifyTilingFactory;
|
675 |
|
676 | // -----------------------------------------------------------------------
|
677 | // Partition
|
678 | // -----------------------------------------------------------------------
|
679 |
|
680 | export interface PartitionLayout<Datum> {
|
681 | /**
|
682 | * Lays out the specified root hierarchy.
|
683 | * You must call `root.sum` before passing the hierarchy to the partition layout.
|
684 | * You probably also want to call `root.sort` to order the hierarchy before computing the layout.
|
685 | *
|
686 | * @param root The specified root hierarchy.
|
687 | */
|
688 | (root: HierarchyNode<Datum>): HierarchyRectangularNode<Datum>;
|
689 |
|
690 | /**
|
691 | * Returns the current size, which defaults to [1, 1].
|
692 | */
|
693 | size(): [number, number];
|
694 | /**
|
695 | * Sets this partition layout’s size to the specified [width, height] array and returns this partition layout.
|
696 | *
|
697 | * @param size The specified two-element size array.
|
698 | */
|
699 | size(size: [number, number]): this;
|
700 |
|
701 | /**
|
702 | * Returns the current rounding state, which defaults to false.
|
703 | */
|
704 | round(): boolean;
|
705 | /**
|
706 | * Enables or disables rounding according to the given boolean and returns this partition layout.
|
707 | *
|
708 | * @param round The specified boolean flag.
|
709 | */
|
710 | round(round: boolean): this;
|
711 |
|
712 | /**
|
713 | * Returns the current padding, which defaults to zero.
|
714 | */
|
715 | padding(): number;
|
716 | /**
|
717 | * Sets the padding to the specified number and returns this partition layout.
|
718 | * The padding is used to separate a node’s adjacent children.
|
719 | *
|
720 | * @param padding The specified padding value.
|
721 | */
|
722 | padding(padding: number): this;
|
723 | }
|
724 |
|
725 | /**
|
726 | * Creates a new partition layout with the default settings.
|
727 | */
|
728 | // eslint-disable-next-line no-unnecessary-generics
|
729 | export function partition<Datum>(): PartitionLayout<Datum>;
|
730 |
|
731 | // -----------------------------------------------------------------------
|
732 | // Pack
|
733 | // -----------------------------------------------------------------------
|
734 |
|
735 | export interface HierarchyCircularLink<Datum> {
|
736 | /**
|
737 | * The source of the link.
|
738 | */
|
739 | source: HierarchyCircularNode<Datum>;
|
740 |
|
741 | /**
|
742 | * The target of the link.
|
743 | */
|
744 | target: HierarchyCircularNode<Datum>;
|
745 | }
|
746 |
|
747 | export interface HierarchyCircularNode<Datum> extends HierarchyNode<Datum> {
|
748 | /**
|
749 | * The x-coordinate of the circle’s center.
|
750 | */
|
751 | x: number;
|
752 |
|
753 | /**
|
754 | * The y-coordinate of the circle’s center.
|
755 | */
|
756 | y: number;
|
757 |
|
758 | /**
|
759 | * The radius of the circle.
|
760 | */
|
761 | r: number;
|
762 |
|
763 | /**
|
764 | * Returns an array of links for this node, where each link is an object that defines source and target properties.
|
765 | * The source of each link is the parent node, and the target is a child node.
|
766 | */
|
767 | links(): Array<HierarchyCircularLink<Datum>>;
|
768 | }
|
769 |
|
770 | export interface PackLayout<Datum> {
|
771 | /**
|
772 | * Lays out the specified root hierarchy.
|
773 | * You must call `root.sum` before passing the hierarchy to the pack layout.
|
774 | * You probably also want to call `root.sort` to order the hierarchy before computing the layout.
|
775 | *
|
776 | * @param root The specified root hierarchy.
|
777 | */
|
778 | (root: HierarchyNode<Datum>): HierarchyCircularNode<Datum>;
|
779 |
|
780 | /**
|
781 | * Returns the current radius accessor, which defaults to null.
|
782 | */
|
783 | radius(): null | ((node: HierarchyCircularNode<Datum>) => number);
|
784 | /**
|
785 | * Sets the pack layout’s radius accessor to the specified function and returns this pack layout.
|
786 | * If the radius accessor is null, the radius of each leaf circle is derived from the leaf `node.value` (computed by `node.sum`);
|
787 | * the radii are then scaled proportionally to fit the layout size.
|
788 | * If the radius accessor is not null, the radius of each leaf circle is specified exactly by the function.
|
789 | *
|
790 | * @param radius The specified radius accessor.
|
791 | */
|
792 | radius(radius: null | ((node: HierarchyCircularNode<Datum>) => number)): this;
|
793 |
|
794 | /**
|
795 | * Returns the current size, which defaults to [1, 1].
|
796 | */
|
797 | size(): [number, number];
|
798 | /**
|
799 | * Sets this pack layout’s size to the specified [width, height] array and returns this pack layout.
|
800 | *
|
801 | * @param size The specified two-element size array.
|
802 | */
|
803 | size(size: [number, number]): this;
|
804 |
|
805 | /**
|
806 | * Returns the current padding accessor, which defaults to the constant zero.
|
807 | */
|
808 | padding(): (node: HierarchyCircularNode<Datum>) => number;
|
809 | /**
|
810 | * Sets this pack layout’s padding accessor to the specified number and returns this pack layout.
|
811 | * Returns the current padding accessor, which defaults to the constant zero.
|
812 | *
|
813 | * When siblings are packed, tangent siblings will be separated by approximately the specified padding;
|
814 | * the enclosing parent circle will also be separated from its children by approximately the specified padding.
|
815 | * If an explicit radius is not specified, the padding is approximate because a two-pass algorithm
|
816 | * is needed to fit within the layout size: the circles are first packed without padding;
|
817 | * a scaling factor is computed and applied to the specified padding; and lastly the circles are re-packed with padding.
|
818 | *
|
819 | * @param padding The specified padding value.
|
820 | */
|
821 | padding(padding: number): this;
|
822 | /**
|
823 | * Sets this pack layout’s padding accessor to the specified function and returns this pack layout.
|
824 | * Returns the current padding accessor, which defaults to the constant zero.
|
825 | *
|
826 | * When siblings are packed, tangent siblings will be separated by approximately the specified padding;
|
827 | * the enclosing parent circle will also be separated from its children by approximately the specified padding.
|
828 | * If an explicit radius is not specified, the padding is approximate because a two-pass algorithm
|
829 | * is needed to fit within the layout size: the circles are first packed without padding;
|
830 | * a scaling factor is computed and applied to the specified padding; and lastly the circles are re-packed with padding.
|
831 | *
|
832 | * @param padding The specified padding function.
|
833 | */
|
834 | padding(padding: (node: HierarchyCircularNode<Datum>) => number): this;
|
835 | }
|
836 |
|
837 | /**
|
838 | * Creates a new pack layout with the default settings.
|
839 | */
|
840 | // eslint-disable-next-line no-unnecessary-generics
|
841 | export function pack<Datum>(): PackLayout<Datum>;
|
842 |
|
843 | // -----------------------------------------------------------------------
|
844 | // Pack Siblings and Enclosure
|
845 | // -----------------------------------------------------------------------
|
846 |
|
847 | export interface PackRadius {
|
848 | /**
|
849 | * The radius of the circle.
|
850 | */
|
851 | r: number;
|
852 |
|
853 | /**
|
854 | * The x-coordinate of the circle’s center.
|
855 | */
|
856 | x?: number | undefined;
|
857 |
|
858 | /**
|
859 | * The y-coordinate of the circle’s center.
|
860 | */
|
861 | y?: number | undefined;
|
862 | }
|
863 |
|
864 | export interface PackCircle {
|
865 | /**
|
866 | * The radius of the circle.
|
867 | */
|
868 | r: number;
|
869 |
|
870 | /**
|
871 | * The x-coordinate of the circle’s center.
|
872 | */
|
873 | x: number;
|
874 |
|
875 | /**
|
876 | * The y-coordinate of the circle’s center.
|
877 | */
|
878 | y: number;
|
879 | }
|
880 |
|
881 | // TODO: Since packSiblings manipulates the circles array in place, technically the x and y properties
|
882 | // are optional on invocation, but will be created after execution for each entry.
|
883 |
|
884 | /**
|
885 | * Packs the specified array of circles, each of which must have a `circle.r` property specifying the circle’s radius.
|
886 | * The circles are positioned according to the front-chain packing algorithm by Wang et al.
|
887 | *
|
888 | * @param circles The specified array of circles to pack.
|
889 | */
|
890 | export function packSiblings<Datum extends PackRadius>(circles: Datum[]): Array<Datum & PackCircle>;
|
891 |
|
892 | /**
|
893 | * Computes the smallest circle that encloses the specified array of circles, each of which must have
|
894 | * a `circle.r` property specifying the circle’s radius, and `circle.x` and `circle.y` properties specifying the circle’s center.
|
895 | * The enclosing circle is computed using the Matoušek-Sharir-Welzl algorithm. (See also Apollonius’ Problem.)
|
896 | *
|
897 | * @param circles The specified array of circles to pack.
|
898 | */
|
899 | // eslint-disable-next-line no-unnecessary-generics
|
900 | export function packEnclose<Datum extends PackCircle>(circles: Datum[]): PackCircle;
|
901 |
|
\ | No newline at end of file |