UNPKG

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