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