1 |
|
2 |
|
3 |
|
4 |
|
5 |
|
6 |
|
7 |
|
8 |
|
9 |
|
10 |
|
11 |
|
12 |
|
13 |
|
14 |
|
15 |
|
16 |
|
17 |
|
18 |
|
19 |
|
20 |
|
21 |
|
22 |
|
23 |
|
24 |
|
25 |
|
26 |
|
27 |
|
28 | export interface SimulationNodeDatum {
|
29 | |
30 |
|
31 |
|
32 | index?: number | undefined;
|
33 | |
34 |
|
35 |
|
36 | x?: number | undefined;
|
37 | |
38 |
|
39 |
|
40 | y?: number | undefined;
|
41 | |
42 |
|
43 |
|
44 | vx?: number | undefined;
|
45 | |
46 |
|
47 |
|
48 | vy?: number | undefined;
|
49 | |
50 |
|
51 |
|
52 | fx?: number | null | undefined;
|
53 | |
54 |
|
55 |
|
56 | fy?: number | null | undefined;
|
57 | }
|
58 |
|
59 |
|
60 |
|
61 |
|
62 |
|
63 |
|
64 |
|
65 |
|
66 |
|
67 |
|
68 |
|
69 |
|
70 | export interface SimulationLinkDatum<NodeDatum extends SimulationNodeDatum> {
|
71 | |
72 |
|
73 |
|
74 |
|
75 |
|
76 |
|
77 |
|
78 | source: NodeDatum | string | number;
|
79 | |
80 |
|
81 |
|
82 |
|
83 |
|
84 |
|
85 |
|
86 | target: NodeDatum | string | number;
|
87 | |
88 |
|
89 |
|
90 | index?: number | undefined;
|
91 | }
|
92 |
|
93 |
|
94 |
|
95 |
|
96 |
|
97 |
|
98 |
|
99 |
|
100 | export interface Simulation<NodeDatum extends SimulationNodeDatum, LinkDatum extends SimulationLinkDatum<NodeDatum> | undefined> {
|
101 | |
102 |
|
103 |
|
104 |
|
105 |
|
106 | restart(): this;
|
107 |
|
108 | |
109 |
|
110 |
|
111 |
|
112 | stop(): this;
|
113 |
|
114 | |
115 |
|
116 |
|
117 |
|
118 |
|
119 |
|
120 |
|
121 |
|
122 |
|
123 |
|
124 | tick(iterations?: number): this;
|
125 |
|
126 | |
127 |
|
128 |
|
129 | nodes(): NodeDatum[];
|
130 | |
131 |
|
132 |
|
133 |
|
134 |
|
135 |
|
136 |
|
137 |
|
138 |
|
139 |
|
140 |
|
141 |
|
142 |
|
143 |
|
144 |
|
145 |
|
146 |
|
147 |
|
148 |
|
149 |
|
150 |
|
151 |
|
152 |
|
153 |
|
154 |
|
155 |
|
156 |
|
157 | nodes(nodesData: NodeDatum[]): this;
|
158 |
|
159 | |
160 |
|
161 |
|
162 |
|
163 |
|
164 |
|
165 |
|
166 | alpha(): number;
|
167 | |
168 |
|
169 |
|
170 |
|
171 |
|
172 |
|
173 |
|
174 |
|
175 |
|
176 |
|
177 | alpha(alpha: number): this;
|
178 |
|
179 | |
180 |
|
181 |
|
182 | alphaMin(): number;
|
183 | |
184 |
|
185 |
|
186 |
|
187 |
|
188 |
|
189 |
|
190 | alphaMin(min: number): this;
|
191 |
|
192 | |
193 |
|
194 |
|
195 | alphaDecay(): number;
|
196 | |
197 |
|
198 |
|
199 |
|
200 |
|
201 |
|
202 |
|
203 |
|
204 |
|
205 |
|
206 |
|
207 |
|
208 |
|
209 | alphaDecay(decay: number): this;
|
210 |
|
211 | |
212 |
|
213 |
|
214 | alphaTarget(): number;
|
215 | |
216 |
|
217 |
|
218 |
|
219 |
|
220 |
|
221 | alphaTarget(target: number): this;
|
222 |
|
223 | |
224 |
|
225 |
|
226 | velocityDecay(): number;
|
227 | |
228 |
|
229 |
|
230 |
|
231 |
|
232 |
|
233 |
|
234 |
|
235 |
|
236 |
|
237 | velocityDecay(decay: number): this;
|
238 |
|
239 | |
240 |
|
241 |
|
242 |
|
243 |
|
244 |
|
245 |
|
246 |
|
247 |
|
248 |
|
249 | force<F extends Force<NodeDatum, LinkDatum>>(name: string): F | undefined;
|
250 | |
251 |
|
252 |
|
253 |
|
254 | force(name: string, force: null | Force<NodeDatum, LinkDatum>): this;
|
255 |
|
256 | |
257 |
|
258 |
|
259 |
|
260 |
|
261 |
|
262 |
|
263 |
|
264 |
|
265 | find(x: number, y: number, radius?: number): NodeDatum | undefined;
|
266 |
|
267 | |
268 |
|
269 |
|
270 |
|
271 | randomSource(): () => number;
|
272 | |
273 |
|
274 |
|
275 |
|
276 |
|
277 | randomSource(source: () => number): this;
|
278 |
|
279 | |
280 |
|
281 |
|
282 |
|
283 |
|
284 |
|
285 |
|
286 |
|
287 | on(typenames: 'tick' | 'end' | string): ((this: Simulation<NodeDatum, LinkDatum>) => void) | undefined;
|
288 | /**
|
289 | * Sets the event listener for the specified typenames and returns this simulation.
|
290 | * If an event listener was already registered for the same type and name, the existing listener is removed before the new listener is added.
|
291 | * If listener is null, removes the current event listeners for the specified typenames, if any.
|
292 | * When a specified event is dispatched, each listener will be invoked with the this context as the simulation.
|
293 | */
|
294 | on(typenames: 'tick' | 'end' | string, listener: null | ((this: this) => void)): this;
|
295 | }
|
296 |
|
297 | /**
|
298 | * Create a new simulation with the specified array of nodes and no forces.
|
299 | * If nodes is not specified, it defaults to the empty array.
|
300 | * The simulator starts automatically; use simulation.on to listen for tick events as the simulation runs.
|
301 | * If you wish to run the simulation manually instead, call simulation.stop, and then call simulation.tick as desired.
|
302 | *
|
303 | * Use this signature, when creating a simulation WITHOUT link force(s).
|
304 | *
|
305 | * The generic refers to the type of the data for a node.
|
306 | *
|
307 | * @param nodesData Optional array of nodes data, defaults to empty array.
|
308 | */
|
309 | export function forceSimulation<NodeDatum extends SimulationNodeDatum>(nodesData?: NodeDatum[]): Simulation<NodeDatum, undefined>;
|
310 | /**
|
311 | * Create a new simulation with the specified array of nodes and no forces.
|
312 | * If nodes is not specified, it defaults to the empty array.
|
313 | * The simulator starts automatically; use simulation.on to listen for tick events as the simulation runs.
|
314 | * If you wish to run the simulation manually instead, call simulation.stop, and then call simulation.tick as desired.
|
315 | *
|
316 | * Use this signature, when creating a simulation WITH link force(s).
|
317 | *
|
318 | * The first generic refers to the type of data for a node.
|
319 | * The second generic refers to the type of data for a link.
|
320 | *
|
321 | * @param nodesData Optional array of nodes data, defaults to empty array.
|
322 | */
|
323 | // eslint-disable-next-line no-unnecessary-generics
|
324 | export function forceSimulation<NodeDatum extends SimulationNodeDatum, LinkDatum extends SimulationLinkDatum<NodeDatum>>(nodesData?: NodeDatum[]): Simulation<NodeDatum, LinkDatum>;
|
325 |
|
326 | // ----------------------------------------------------------------------
|
327 | // Forces
|
328 | // ----------------------------------------------------------------------
|
329 |
|
330 | /**
|
331 | * A force is simply a function that modifies nodes’ positions or velocities; in this context, a force can apply a classical physical force such as electrical charge or gravity,
|
332 | * or it can resolve a geometric constraint, such as keeping nodes within a bounding box or keeping linked nodes a fixed distance apart.
|
333 | *
|
334 | * Forces typically read the node’s current position [x,y] and then add to (or subtract from) the node’s velocity [vx,vy].
|
335 | * However, forces may also “peek ahead” to the anticipated next position of the node, [x + vx,y + vy]; this is necessary for resolving geometric constraints through iterative relaxation.
|
336 | * Forces may also modify the position directly, which is sometimes useful to avoid adding energy to the simulation, such as when recentering the simulation in the viewport.
|
337 | *
|
338 | * Forces may optionally implement force.initialize to receive the simulation’s array of nodes.
|
339 | */
|
340 | export interface Force<NodeDatum extends SimulationNodeDatum, LinkDatum extends SimulationLinkDatum<NodeDatum> | undefined> {
|
341 | /**
|
342 | * Apply this force, optionally observing the specified alpha.
|
343 | * Typically, the force is applied to the array of nodes previously passed to force.initialize,
|
344 | * however, some forces may apply to a subset of nodes, or behave differently.
|
345 | * For example, d3.forceLink applies to the source and target of each link.
|
346 | */
|
347 | (alpha: number): void;
|
348 | /**
|
349 | * Supplies the array of nodes and random source to this force. This method is called when a force is bound to a simulation via simulation.force
|
350 | * and when the simulation’s nodes change via simulation.nodes.
|
351 | *
|
352 | * A force may perform necessary work during initialization, such as evaluating per-node parameters, to avoid repeatedly performing work during each application of the force.
|
353 | */
|
354 | initialize?(nodes: NodeDatum[], random: () => number): void;
|
355 | }
|
356 |
|
357 | // Centering ------------------------------------------------------------
|
358 |
|
359 | /**
|
360 | * The centering force translates nodes uniformly so that the mean position of all nodes
|
361 | * (the center of mass if all nodes have equal weight) is at the given position [x,y].
|
362 | * This force modifies the positions of nodes on each application; it does not modify velocities,
|
363 | * as doing so would typically cause the nodes to overshoot and oscillate around the desired center.
|
364 | * This force helps keeps nodes in the center of the viewport, and unlike the positioning force,
|
365 | * it does not distort their relative positions.
|
366 | *
|
367 | * The generic refers to the type of data for a node.
|
368 | */
|
369 | export interface ForceCenter<NodeDatum extends SimulationNodeDatum> extends Force<NodeDatum, any> {
|
370 | /**
|
371 | * Supplies the array of nodes and random source to this force. This method is called when a force is bound to a simulation via simulation.force
|
372 | * and when the simulation’s nodes change via simulation.nodes.
|
373 | *
|
374 | * A force may perform necessary work during initialization, such as evaluating per-node parameters, to avoid repeatedly performing work during each application of the force.
|
375 | */
|
376 | initialize(nodes: NodeDatum[], random: () => number): void;
|
377 |
|
378 | /**
|
379 | * Return the current x-coordinate of the centering position, which defaults to zero.
|
380 | */
|
381 | x(): number;
|
382 | /**
|
383 | * Set the x-coordinate of the centering position.
|
384 | *
|
385 | * @param x x-coordinate.
|
386 | */
|
387 | x(x: number): this;
|
388 |
|
389 | /**
|
390 | * Return the current y-coordinate of the centering position, which defaults to zero.
|
391 | */
|
392 | y(): number;
|
393 | /**
|
394 | * Set the y-coordinate of the centering position.
|
395 | *
|
396 | * @param y y-coordinate.
|
397 | */
|
398 | y(y: number): this;
|
399 |
|
400 | /**
|
401 | * Returns the force’s current strength, which defaults to 1.
|
402 | */
|
403 | strength(): number;
|
404 |
|
405 | /**
|
406 | * Sets the centering force’s strength.
|
407 | * A reduced strength of e.g. 0.05 softens the movements on interactive graphs in which new nodes enter or exit the graph.
|
408 | * @param strength The centering force's strength.
|
409 | */
|
410 | strength(strength: number): this;
|
411 | }
|
412 |
|
413 | /**
|
414 | * Create a new centering force with the specified x- and y- coordinates.
|
415 | * If x and y are not specified, they default to [0,0].
|
416 | *
|
417 | * The centering force translates nodes uniformly so that the mean position of all nodes
|
418 | * (the center of mass if all nodes have equal weight) is at the given position [x,y].
|
419 | * This force modifies the positions of nodes on each application; it does not modify velocities,
|
420 | * as doing so would typically cause the nodes to overshoot and oscillate around the desired center.
|
421 | * This force helps keeps nodes in the center of the viewport, and unlike the positioning force,
|
422 | * it does not distort their relative positions.
|
423 | *
|
424 | * The generic refers to the type of data for a node.
|
425 | *
|
426 | * @param x An optional x-coordinate for the centering position, defaults to 0.
|
427 | * @param y An optional y-coordinate for the centering position, defaults to 0.
|
428 | */
|
429 | // eslint-disable-next-line no-unnecessary-generics
|
430 | export function forceCenter<NodeDatum extends SimulationNodeDatum>(x?: number, y?: number): ForceCenter<NodeDatum>;
|
431 |
|
432 | // Collision ------------------------------------------------------------
|
433 |
|
434 | /**
|
435 | * The collision force treats nodes as circles with a given radius, rather than points, and prevents nodes from overlapping.
|
436 | * More formally, two nodes a and b are separated so that the distance between a and b is at least radius(a) + radius(b).
|
437 | * To reduce jitter, this is by default a “soft” constraint with a configurable strength and iteration count.
|
438 | *
|
439 | * The generic refers to the type of data for a node.
|
440 | */
|
441 | export interface ForceCollide<NodeDatum extends SimulationNodeDatum> extends Force<NodeDatum, any> {
|
442 | /**
|
443 | * Supplies the array of nodes and random source to this force. This method is called when a force is bound to a simulation via simulation.force
|
444 | * and when the simulation’s nodes change via simulation.nodes.
|
445 | *
|
446 | * A force may perform necessary work during initialization, such as evaluating per-node parameters, to avoid repeatedly performing work during each application of the force.
|
447 | */
|
448 | initialize(nodes: NodeDatum[], random: () => number): void;
|
449 |
|
450 | /**
|
451 | * Returns the current radius accessor function.
|
452 | */
|
453 | radius(): (node: NodeDatum, i: number, nodes: NodeDatum[]) => number;
|
454 | |
455 |
|
456 |
|
457 |
|
458 |
|
459 |
|
460 | radius(radius: number | ((node: NodeDatum, i: number, nodes: NodeDatum[]) => number)): this;
|
461 |
|
462 | /**
|
463 | * Return the current strength, which defaults to 1.
|
464 | */
|
465 | strength(): number;
|
466 | /**
|
467 | * Set the force strength to the specified number in the range [0,1] and return this force.
|
468 | * The default strength is 0.7.
|
469 | *
|
470 | * Overlapping nodes are resolved through iterative relaxation.
|
471 | * For each node, the other nodes that are anticipated to overlap at the next tick (using the anticipated positions [x + vx,y + vy]) are determined;
|
472 | * the node’s velocity is then modified to push the node out of each overlapping node.
|
473 | * The change in velocity is dampened by the force’s strength such that the resolution of simultaneous overlaps can be blended together to find a stable solution.
|
474 | *
|
475 | * @param strength Strength.
|
476 | */
|
477 | strength(strength: number): this;
|
478 |
|
479 | /**
|
480 | * Return the current iteration count which defaults to 1.
|
481 | */
|
482 | iterations(): number;
|
483 | /**
|
484 | * Sets the number of iterations per application to the specified number and return this force.
|
485 | *
|
486 | * Increasing the number of iterations greatly increases the rigidity of the constraint and avoids partial overlap of nodes,
|
487 | * but also increases the runtime cost to evaluate the force.
|
488 | *
|
489 | * @param iterations Number of iterations.
|
490 | */
|
491 | iterations(iterations: number): this;
|
492 | }
|
493 |
|
494 | /**
|
495 | * Creates a new circle collision force with the specified radius.
|
496 | * If radius is not specified, it defaults to the constant one for all nodes.
|
497 | */
|
498 | export function forceCollide<NodeDatum extends SimulationNodeDatum>(radius?: number | ((node: NodeDatum, i: number, nodes: NodeDatum[]) => number)): ForceCollide<NodeDatum>;
|
499 |
|
500 | // Link ----------------------------------------------------------------
|
501 |
|
502 | /**
|
503 | * The link force pushes linked nodes together or apart according to the desired link distance.
|
504 | * The strength of the force is proportional to the difference between the linked nodes’ distance and the target distance, similar to a spring force.
|
505 | *
|
506 | * The first generic refers to the type of data for a node.
|
507 | * The second generic refers to the type of data for a link.
|
508 | */
|
509 | export interface ForceLink<NodeDatum extends SimulationNodeDatum, LinkDatum extends SimulationLinkDatum<NodeDatum>> extends Force<NodeDatum, LinkDatum> {
|
510 | /**
|
511 | * Supplies the array of nodes and random source to this force. This method is called when a force is bound to a simulation via simulation.force
|
512 | * and when the simulation’s nodes change via simulation.nodes.
|
513 | *
|
514 | * A force may perform necessary work during initialization, such as evaluating per-node parameters, to avoid repeatedly performing work during each application of the force.
|
515 | */
|
516 | initialize(nodes: NodeDatum[], random: () => number): void;
|
517 |
|
518 | /**
|
519 | * Return the current array of links, which defaults to the empty array.
|
520 | *
|
521 | */
|
522 | links(): LinkDatum[];
|
523 | /**
|
524 | * Set the array of links associated with this force, recompute the distance and strength parameters for each link, and return this force.
|
525 | *
|
526 | * Each link is an object with the following properties:
|
527 | * * source - the link’s source node; see simulation.nodes
|
528 | * * target - the link’s target node; see simulation.nodes
|
529 | * * index - the zero-based index into links, assigned by this method
|
530 | *
|
531 | * For convenience, a link’s source and target properties may be initialized using numeric or string identifiers rather than object references; see link.id.
|
532 | * When the link force is initialized (or re-initialized, as when the nodes or links change), any link.source or link.target property which is not an object
|
533 | * is replaced by an object reference to the corresponding node with the given identifier.
|
534 | * If the specified array of links is modified, such as when links are added to or removed from the simulation,
|
535 | * this method must be called again with the new (or changed) array to notify the force of the change;
|
536 | * the force does not make a defensive copy of the specified array.
|
537 | *
|
538 | * @param links An array of link data.
|
539 | */
|
540 | links(links: LinkDatum[]): this;
|
541 |
|
542 | /**
|
543 | * Return the current node id accessor, which defaults to the numeric node.index.
|
544 | */
|
545 | id(): (node: NodeDatum, i: number, nodesData: NodeDatum[]) => (string | number);
|
546 | |
547 |
|
548 |
|
549 |
|
550 |
|
551 |
|
552 |
|
553 |
|
554 |
|
555 |
|
556 |
|
557 |
|
558 |
|
559 | id(id: (node: NodeDatum, i: number, nodesData: NodeDatum[]) => (string | number)): this;
|
560 |
|
561 | |
562 |
|
563 |
|
564 | distance(): (link: LinkDatum, i: number, links: LinkDatum[]) => number;
|
565 | |
566 |
|
567 |
|
568 |
|
569 |
|
570 |
|
571 | distance(distance: number | ((link: LinkDatum, i: number, links: LinkDatum[]) => number)): this;
|
572 |
|
573 | /**
|
574 | * Return the current strength accessor.
|
575 | * For details regarding the default behavior see: {@link https://github.com/d3/d3-force#link_strength}
|
576 | */
|
577 | strength(): (link: LinkDatum, i: number, links: LinkDatum[]) => number;
|
578 | |
579 |
|
580 |
|
581 |
|
582 |
|
583 |
|
584 | strength(strength: number | ((link: LinkDatum, i: number, links: LinkDatum[]) => number)): this;
|
585 |
|
586 | /**
|
587 | * Return the current iteration count which defaults to 1.
|
588 | */
|
589 | iterations(): number;
|
590 | /**
|
591 | * Sets the number of iterations per application to the specified number and return this force.
|
592 | *
|
593 | * Increasing the number of iterations greatly increases the rigidity of the constraint and is useful for complex structures such as lattices,
|
594 | * but also increases the runtime cost to evaluate the force.
|
595 | *
|
596 | * @param iterations Number of iterations.
|
597 | */
|
598 | iterations(iterations: number): this;
|
599 | }
|
600 |
|
601 | /**
|
602 | * Creates a new link force with the specified links and default parameters.
|
603 | * If links is not specified, it defaults to the empty array.
|
604 | */
|
605 | export function forceLink<NodeDatum extends SimulationNodeDatum, LinksDatum extends SimulationLinkDatum<NodeDatum>>(links?: LinksDatum[]): ForceLink<NodeDatum, LinksDatum>;
|
606 |
|
607 | // Many Body ----------------------------------------------------------------
|
608 |
|
609 | /**
|
610 | * The many-body (or n-body) force applies mutually amongst all nodes. It can be used to simulate gravity (attraction) if the strength is positive,
|
611 | * or electrostatic charge (repulsion) if the strength is negative. This implementation uses quadtrees and the Barnes–Hut approximation to greatly
|
612 | * improve performance; the accuracy can be customized using the theta parameter.
|
613 | *
|
614 | * Unlike links, which only affect two linked nodes, the charge force is global: every node affects every other node, even if they are on disconnected subgraphs.
|
615 | *
|
616 | * The generic refers to the type of data for a node.
|
617 | */
|
618 | export interface ForceManyBody<NodeDatum extends SimulationNodeDatum> extends Force<NodeDatum, any> {
|
619 | /**
|
620 | * Supplies the array of nodes and random source to this force. This method is called when a force is bound to a simulation via simulation.force
|
621 | * and when the simulation’s nodes change via simulation.nodes.
|
622 | *
|
623 | * A force may perform necessary work during initialization, such as evaluating per-node parameters, to avoid repeatedly performing work during each application of the force.
|
624 | */
|
625 | initialize(nodes: NodeDatum[], random: () => number): void;
|
626 |
|
627 | /**
|
628 | * Return the current strength accessor.
|
629 | *
|
630 | * For details regarding the default behavior see: {@link https://github.com/d3/d3-force#manyBody_strength}
|
631 | */
|
632 | strength(): (d: NodeDatum, i: number, data: NodeDatum[]) => number;
|
633 | |
634 |
|
635 |
|
636 |
|
637 |
|
638 |
|
639 |
|
640 | strength(strength: number | ((d: NodeDatum, i: number, data: NodeDatum[]) => number)): this;
|
641 |
|
642 | /**
|
643 | * Return the current value of the Barnes–Hut approximation criterion , which defaults to 0.9
|
644 | */
|
645 | theta(): number;
|
646 | /**
|
647 | * Set the Barnes–Hut approximation criterion to the specified number and returns this force.
|
648 | *
|
649 | * To accelerate computation, this force implements the Barnes–Hut approximation which takes O(n log n) per application
|
650 | * where n is the number of nodes. For each application, a quadtree stores the current node positions;
|
651 | * then for each node, the combined force of all other nodes on the given node is computed.
|
652 | * For a cluster of nodes that is far away, the charge force can be approximated by treating the cluster as a single, larger node.
|
653 | * The theta parameter determines the accuracy of the approximation:
|
654 | * if the ratio w / l of the width w of the quadtree cell to the distance l from the node to the cell’s center of mass is less than theta,
|
655 | * all nodes in the given cell are treated as a single node rather than individually.
|
656 | *
|
657 | * The default value is 0.9.
|
658 | *
|
659 | * @param theta Value for the theta parameter.
|
660 | */
|
661 | theta(theta: number): this;
|
662 |
|
663 | /**
|
664 | * Returns the current minimum distance over which this force is considered, which defaults to 1.
|
665 | */
|
666 | distanceMin(): number;
|
667 | /**
|
668 | * Sets the minimum distance between nodes over which this force is considered.
|
669 | *
|
670 | * A minimum distance establishes an upper bound on the strength of the force between two nearby nodes, avoiding instability.
|
671 | * In particular, it avoids an infinitely-strong force if two nodes are exactly coincident; in this case, the direction of the force is random.
|
672 | *
|
673 | * The default value is 1.
|
674 | *
|
675 | * @param distance The minimum distance between nodes over which this force is considered.
|
676 | */
|
677 | distanceMin(distance: number): this;
|
678 |
|
679 | /**
|
680 | * Returns the current maximum distance over which this force is considered, which defaults to infinity.
|
681 | */
|
682 | distanceMax(): number;
|
683 | /**
|
684 | * Sets the maximum distance between nodes over which this force is considered.
|
685 | *
|
686 | * Specifying a finite maximum distance improves performance and produces a more localized layout.
|
687 | *
|
688 | * The default value is infinity.
|
689 | *
|
690 | * @param distance The maximum distance between nodes over which this force is considered.
|
691 | */
|
692 | distanceMax(distance: number): this;
|
693 | }
|
694 |
|
695 | /**
|
696 | * Creates a new many-body force with the default parameters.
|
697 | *
|
698 | * The many-body (or n-body) force applies mutually amongst all nodes. It can be used to simulate gravity (attraction) if the strength is positive,
|
699 | * or electrostatic charge (repulsion) if the strength is negative. This implementation uses quadtrees and the Barnes–Hut approximation to greatly
|
700 | * improve performance; the accuracy can be customized using the theta parameter.
|
701 | *
|
702 | * Unlike links, which only affect two linked nodes, the charge force is global: every node affects every other node, even if they are on disconnected subgraphs.
|
703 | *
|
704 | * The generic refers to the type of data for a node.
|
705 | */
|
706 | // eslint-disable-next-line no-unnecessary-generics
|
707 | export function forceManyBody<NodeDatum extends SimulationNodeDatum>(): ForceManyBody<NodeDatum>;
|
708 |
|
709 | // Positioning ----------------------------------------------------------------
|
710 |
|
711 | /**
|
712 | * The x-positioning force pushes nodes towards a desired position along the given dimension with a configurable strength.
|
713 | * The strength of the force is proportional to the one-dimensional distance between the node’s position and the target position.
|
714 | * While this force can be used to position individual nodes, it is intended primarily for global forces that apply to all (or most) nodes.
|
715 | *
|
716 | * The generic refers to the type of data for a node.
|
717 | */
|
718 | export interface ForceX<NodeDatum extends SimulationNodeDatum> extends Force<NodeDatum, any> {
|
719 | /**
|
720 | * Supplies the array of nodes and random source to this force. This method is called when a force is bound to a simulation via simulation.force
|
721 | * and when the simulation’s nodes change via simulation.nodes.
|
722 | *
|
723 | * A force may perform necessary work during initialization, such as evaluating per-node parameters, to avoid repeatedly performing work during each application of the force.
|
724 | */
|
725 | initialize(nodes: NodeDatum[], random: () => number): void;
|
726 |
|
727 | /**
|
728 | * Returns the current strength accessor, which defaults to a constant strength for all nodes of 0.1.
|
729 | */
|
730 | strength(): (d: NodeDatum, i: number, data: NodeDatum[]) => number;
|
731 | |
732 |
|
733 |
|
734 |
|
735 |
|
736 |
|
737 |
|
738 |
|
739 |
|
740 |
|
741 | strength(strength: number | ((d: NodeDatum, i: number, data: NodeDatum[]) => number)): this;
|
742 |
|
743 | /**
|
744 | * Return the current x-accessor, which defaults to a function returning 0 for all nodes.
|
745 | */
|
746 | x(): (d: NodeDatum, i: number, data: NodeDatum[]) => number;
|
747 | |
748 |
|
749 |
|
750 |
|
751 |
|
752 |
|
753 | x(x: number | ((d: NodeDatum, i: number, data: NodeDatum[]) => number)): this;
|
754 | }
|
755 |
|
756 | /**
|
757 | * Creates a new positioning force along the x-axis towards the given position x.
|
758 | * If x is not specified, it defaults to 0.
|
759 | */
|
760 | export function forceX<NodeDatum extends SimulationNodeDatum>(x?: number | ((d: NodeDatum, i: number, data: NodeDatum[]) => number)): ForceX<NodeDatum>;
|
761 |
|
762 | /**
|
763 | * The y-positioning force pushes nodes towards a desired position along the given dimension with a configurable strength.
|
764 | * The strength of the force is proportional to the one-dimensional distance between the node’s position and the target position.
|
765 | * While this force can be used to position individual nodes, it is intended primarily for global forces that apply to all (or most) nodes.
|
766 | *
|
767 | * The generic refers to the type of data for a node.
|
768 | */
|
769 | export interface ForceY<NodeDatum extends SimulationNodeDatum> extends Force<NodeDatum, any> {
|
770 | /**
|
771 | * Supplies the array of nodes and random source to this force. This method is called when a force is bound to a simulation via simulation.force
|
772 | * and when the simulation’s nodes change via simulation.nodes.
|
773 | *
|
774 | * A force may perform necessary work during initialization, such as evaluating per-node parameters, to avoid repeatedly performing work during each application of the force.
|
775 | */
|
776 | initialize(nodes: NodeDatum[], random: () => number): void;
|
777 |
|
778 | /**
|
779 | * Returns the current strength accessor, which defaults to a constant strength for all nodes of 0.1.
|
780 | */
|
781 | strength(): (d: NodeDatum, i: number, data: NodeDatum[]) => number;
|
782 | |
783 |
|
784 |
|
785 |
|
786 |
|
787 |
|
788 |
|
789 |
|
790 |
|
791 |
|
792 | strength(strength: number | ((d: NodeDatum, i: number, data: NodeDatum[]) => number)): this;
|
793 |
|
794 | /**
|
795 | * Return the current y-accessor, which defaults to a function returning 0 for all nodes.
|
796 | */
|
797 | y(): (d: NodeDatum, i: number, data: NodeDatum[]) => number;
|
798 | |
799 |
|
800 |
|
801 |
|
802 |
|
803 |
|
804 | y(y: number | ((d: NodeDatum, i: number, data: NodeDatum[]) => number)): this;
|
805 | }
|
806 |
|
807 | /**
|
808 | * Creates a new positioning force along the y-axis towards the given position y.
|
809 | * If y is not specified, it defaults to 0.
|
810 | */
|
811 | export function forceY<NodeDatum extends SimulationNodeDatum>(y?: number | ((d: NodeDatum, i: number, data: NodeDatum[]) => number)): ForceY<NodeDatum>;
|
812 |
|
813 | /**
|
814 | * The radial force is similar to the x- and y-positioning forces, except it pushes nodes towards the closest point on a given circle.
|
815 | * The circle is of the specified radius centered at ⟨x,y⟩. If x and y are not specified, they default to ⟨0,0⟩.
|
816 | * The strength of the force is proportional to the one-dimensional distance between the node’s position and the target position.
|
817 | * While this force can be used to position individual nodes, it is intended primarily for global forces that apply to all (or most) nodes.
|
818 | *
|
819 | * The generic refers to the type of data for a node.
|
820 | */
|
821 | export interface ForceRadial<NodeDatum extends SimulationNodeDatum> extends Force<NodeDatum, any> {
|
822 | /**
|
823 | * Assigns the array of nodes and random source to this force. This method is called when a force is bound to a simulation via simulation.force
|
824 | * and when the simulation’s nodes change via simulation.nodes.
|
825 | *
|
826 | * A force may perform necessary work during initialization, such as evaluating per-node parameters, to avoid repeatedly performing work during each application of the force.
|
827 | */
|
828 | initialize(nodes: NodeDatum[], random: () => number): void;
|
829 |
|
830 | /**
|
831 | * Returns the current strength accessor, which defaults to a constant strength for all nodes of 0.1.
|
832 | */
|
833 | strength(): (d: NodeDatum, i: number, data: NodeDatum[]) => number;
|
834 | |
835 |
|
836 |
|
837 |
|
838 |
|
839 |
|
840 |
|
841 |
|
842 |
|
843 |
|
844 | strength(strength: number | ((d: NodeDatum, i: number, data: NodeDatum[]) => number)): this;
|
845 |
|
846 | /**
|
847 | * Return the current radius accessor for the circle.
|
848 | */
|
849 | radius(): (d: NodeDatum, i: number, data: NodeDatum[]) => number;
|
850 | |
851 |
|
852 |
|
853 |
|
854 |
|
855 |
|
856 | radius(radius: number | ((d: NodeDatum, i: number, data: NodeDatum[]) => number)): this;
|
857 |
|
858 | /**
|
859 | * Return the current x-accessor for the circle center, which defaults to a function returning 0 for all nodes.
|
860 | */
|
861 | x(): (d: NodeDatum, i: number, data: NodeDatum[]) => number;
|
862 | |
863 |
|
864 |
|
865 | x(x: number | ((d: NodeDatum, i: number, data: NodeDatum[]) => number)): this;
|
866 |
|
867 | /**
|
868 | * Return the current y-accessor for the circle center, which defaults to a function returning 0 for all nodes.
|
869 | */
|
870 | y(): (d: NodeDatum, i: number, data: NodeDatum[]) => number;
|
871 | |
872 |
|
873 |
|
874 | y(y: number | ((d: NodeDatum, i: number, data: NodeDatum[]) => number)): this;
|
875 | }
|
876 |
|
877 | /**
|
878 | * Create a new radial positioning force towards a circle of the specified radius centered at ⟨x,y⟩.
|
879 | * If x and y are not specified, they default to ⟨0,0⟩.
|
880 | *
|
881 | * The strength of the force is proportional to the one-dimensional distance between the node’s position and the target position.
|
882 | * While this force can be used to position individual nodes, it is intended primarily for global forces that apply to all (or most) nodes.
|
883 | *
|
884 | * The generic refers to the type of data for a node.
|
885 | */
|
886 | export function forceRadial<NodeDatum extends SimulationNodeDatum>(radius: number | ((d: NodeDatum, i: number, data: NodeDatum[]) => number),
|
887 | x?: number | ((d: NodeDatum, i: number, data: NodeDatum[]) => number), y?: number | ((d: NodeDatum, i: number, data: NodeDatum[]) => number)): ForceRadial<NodeDatum>;
|
888 |
|
\ | No newline at end of file |