UNPKG

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