UNPKG

38.9 kBTypeScriptView Raw
1// Last module patch version validated against: 3.0.1
2
3import { ArrayLike, BaseType, Selection, ValueFn } from "d3-selection";
4
5/**
6 * Extend interface 'Selection' by declaration merging with 'd3-selection'
7 */
8declare module "d3-selection" {
9 /**
10 * A D3 Selection of elements.
11 *
12 * The first generic "GElement" refers to the type of the selected element(s).
13 * The second generic "Datum" refers to the type of the datum of a selected element(s).
14 * The third generic "PElement" refers to the type of the parent element(s) in the D3 selection.
15 * The fourth generic "PDatum" refers to the type of the datum of the parent element(s).
16 */
17 interface Selection<GElement extends BaseType, Datum, PElement extends BaseType, PDatum> {
18 /**
19 * Interrupts the active transition of the specified name on the selected elements, and cancels any pending transitions with the specified name, if any.
20 * If a name is not specified, null is used.
21 *
22 * IMPORTANT: Interrupting a transition on an element has no effect on any transitions on any descendant elements.
23 * For example, an axis transition consists of multiple independent, synchronized transitions on the descendants of the axis G element
24 * (the tick lines, the tick labels, the domain path, etc.). To interrupt the axis transition, you must therefore interrupt the descendants.
25 *
26 * @param name Name of the transition.
27 */
28 interrupt(name?: string): this;
29 /**
30 * Returns a new transition on the given selection with the specified name. If a name is not specified, null is used.
31 * The new transition is only exclusive with other transitions of the same name.
32 *
33 * @param name Name of the transition.
34 */
35 transition(name?: string): Transition<GElement, Datum, PElement, PDatum>;
36 /**
37 * Returns a new transition on the given selection.
38 *
39 * When using a transition instance, the returned transition has the same id and name as the specified transition.
40 * If a transition with the same id already exists on a selected element, the existing transition is returned for that element.
41 * Otherwise, the timing of the returned transition is inherited from the existing transition of the same id on the nearest ancestor of each selected element.
42 * Thus, this method can be used to synchronize a transition across multiple selections,
43 * or to re-select a transition for specific elements and modify its configuration.
44 *
45 * If the specified transition is not found on a selected node or its ancestors (such as if the transition already ended),
46 * the default timing parameters are used; however, in a future release, this will likely be changed to throw an error.
47 *
48 * @param transition A transition instance.
49 */
50 transition(transition: Transition<BaseType, any, any, any>): Transition<GElement, Datum, PElement, PDatum>;
51 }
52}
53
54/**
55 * Return the active transition on the specified node with the specified name, if any.
56 * If no name is specified, null is used. Returns null if there is no such active transition on the specified node.
57 * This method is useful for creating chained transitions.
58 *
59 * The first generic "GElement" refers to the type of element on which the returned active transition was defined. The second generic "Datum" refers to the type of the
60 * datum, of a selected element on which the transition is defined. The third generic refers to the type of the parent elements in the returned Transition.
61 * The fourth generic refers to the type of the datum defined on the parent elements in the returned Transition.
62 *
63 * @param node Element for which the active transition should be returned.
64 * @param name Name of the transition.
65 */
66// eslint-disable-next-line @definitelytyped/no-unnecessary-generics
67export function active<GElement extends BaseType, Datum, PElement extends BaseType, PDatum>(
68 node: GElement,
69 name?: string,
70): Transition<GElement, Datum, PElement, PDatum> | null;
71
72/**
73 * Interrupts the active transition of the specified name on the specified node, and cancels any pending transitions with the specified name, if any.
74 * If a name is not specified, null is used.
75 *
76 * @param node Element for which the transition should be interrupted.
77 * @param name Name of the transition to be interrupted. If a name is not specified, null is used.
78 */
79export function interrupt(node: BaseType, name?: string): void;
80
81/**
82 * A D3 Transition.
83 *
84 * The first generic "GElement" refers to the type of the selected element(s) in the Transition.
85 * The second generic "Datum" refers to the type of the datum of a selected element(s) in the Transition.
86 * The third generic "PElement" refers to the type of the parent element(s) in the D3 selection in the Transition.
87 * The fourth generic "PDatum" refers to the type of the datum of the parent element(s) in the Transition.
88 */
89export interface Transition<GElement extends BaseType, Datum, PElement extends BaseType, PDatum> {
90 // Sub-selection -------------------------
91
92 /**
93 * For each selected element, select the first descendant element that matches the specified selector string, if any,
94 * and returns a transition on the resulting selection. The new transition has the same id, name and timing as this transition;
95 * however, if a transition with the same id already exists on a selected element,
96 * the existing transition is returned for that element.
97 *
98 * The generic represents the type of the descendant element to be selected.
99 *
100 * @param selector CSS selector string
101 */
102 // eslint-disable-next-line @definitelytyped/no-unnecessary-generics
103 select<DescElement extends BaseType>(selector: string): Transition<DescElement, Datum, PElement, PDatum>;
104 /**
105 * For each selected element, select the descendant element returned by the selector function, if any,
106 * and returns a transition on the resulting selection. The new transition has the same id, name and timing as this transition;
107 * however, if a transition with the same id already exists on a selected element,
108 * the existing transition is returned for that element.
109 *
110 * The generic represents the type of the descendant element to be selected.
111 *
112 * @param selector A selector function, which is evaluated for each selected element, in order, being passed the current datum (d),
113 * the current index (i), and the current group (nodes), with this as the current DOM element (nodes[i]).
114 * It must return an element, or null if there is no matching element.
115 */
116 select<DescElement extends BaseType>(
117 selector: ValueFn<GElement, Datum, DescElement>,
118 ): Transition<DescElement, Datum, PElement, PDatum>;
119
120 /**
121 * For each selected element, select all descendant elements that match the specified selector string, if any,
122 * and returns a transition on the resulting selection. The new transition has the same id, name and timing as this transition;
123 * however, if a transition with the same id already exists on a selected element, the existing transition is returned for that element.
124 *
125 * The first generic "DescElement" refers to the type of descendant element to be selected. The second generic "OldDatum" refers to the type of the
126 * datum, of a selected element. This is useful when re-selecting elements with a previously set, know datum type.
127 *
128 * @param selector CSS selector string
129 */
130 // eslint-disable-next-line @definitelytyped/no-unnecessary-generics
131 selectAll<DescElement extends BaseType, OldDatum>(
132 selector: string,
133 ): Transition<DescElement, OldDatum, GElement, Datum>;
134 /**
135 * For each selected element, select all descendant elements returned by the selector function, if any,
136 * and returns a transition on the resulting selection. The new transition has the same id, name and timing as this transition;
137 * however, if a transition with the same id already exists on a selected element, the existing transition is returned for that element.
138 *
139 * The first generic "DescElement" refers to the type of descendant element to be selected. The second generic "OldDatum" refers to the type of the
140 * datum, of a selected element. This is useful when re-selecting elements with a previously set, know datum type.
141 *
142 * @param selector A selector function which is evaluated for each selected element, in order, being passed the current datum (d),
143 * the current index (i), and the current group (nodes), with this as the current DOM element (nodes[i]). It must return an array of elements
144 * (or a pseudo-array, such as a NodeList), or the empty array if there are no matching elements.
145 */
146 // eslint-disable-next-line @definitelytyped/no-unnecessary-generics
147 selectAll<DescElement extends BaseType, OldDatum>(
148 selector: ValueFn<GElement, Datum, DescElement[] | ArrayLike<DescElement>>,
149 ): Transition<DescElement, OldDatum, GElement, Datum>;
150
151 /**
152 * For each selected element, selects the first child element that matches the specified selector string, if any, and returns a transition on the resulting selection.
153 * The selector may be specified either as a selector string or a function.
154 * If a function, it is evaluated for each selected element, in order, being passed the current datum (d),
155 * the current index (i), and the current group (nodes), with this as the current DOM element.
156 * The new transition has the same id, name and timing as this transition;
157 * however, if a transition with the same id already exists on a selected element, the existing transition is returned for that element.
158 * This method is equivalent to deriving the selection for this transition via transition.selection,
159 * creating a subselection via selection.selectChild, and then creating a new transition via selection.transition.
160 */
161 // eslint-disable-next-line @definitelytyped/no-unnecessary-generics
162 selectChild<DescElement extends BaseType, OldDatum>(
163 selector?: string | ValueFn<GElement, Datum, DescElement>,
164 ): Transition<DescElement, OldDatum, GElement, Datum>;
165
166 /**
167 * For each selected element, selects all children that match the specified selector string, if any, and returns a transition on the resulting selection.
168 * The selector may be specified either as a selector string or a function.
169 * If a function, it is evaluated for each selected element, in order, being passed the current datum (d),
170 * the current index (i), and the current group (nodes), with this as the current DOM element.
171 * The new transition has the same id, name and timing as this transition;
172 * however, if a transition with the same id already exists on a selected element, the existing transition is returned for that element.
173 * This method is equivalent to deriving the selection for this transition via transition.selection,
174 * creating a subselection via selection.selectChildren, and then creating a new transition via selection.transition.
175 */
176 // eslint-disable-next-line @definitelytyped/no-unnecessary-generics
177 selectChildren<DescElement extends BaseType, OldDatum>(
178 selector?: string | ValueFn<GElement, Datum, DescElement>,
179 ): Transition<DescElement, OldDatum, GElement, Datum>;
180
181 /**
182 * Return the selection corresponding to this transition.
183 */
184 selection(): Selection<GElement, Datum, PElement, PDatum>;
185
186 /**
187 * Returns a new transition on the same selected elements as this transition, scheduled to start when this transition ends.
188 * The new transition inherits a reference time equal to this transition’s time plus its delay and duration.
189 * The new transition also inherits this transition’s name, duration, and easing.
190 * This method can be used to schedule a sequence of chained transitions.
191 *
192 * A delay configured for the new transition will be relative to the previous transition.
193 */
194 transition(): Transition<GElement, Datum, PElement, PDatum>;
195
196 // Modifying -------------------------------
197
198 /**
199 * For each selected element, assigns the attribute tween for the attribute with the specified name to the specified target value.
200 * The starting value of the tween is the attribute’s value when the transition starts.
201 * If the target value is null, the attribute is removed when the transition starts.
202 */
203 attr(name: string, value: null | string | number | boolean): this;
204 /**
205 * For each selected element, assigns the attribute tween for the attribute with the specified name to the specified target value.
206 * The starting value of the tween is the attribute’s value when the transition starts.
207 * The target value is return value of the value function evaluated for the selected element.
208 *
209 * An interpolator is chosen based on the type of the target value, using the following algorithm:
210 * 1.) If value is a number, use interpolateNumber.
211 * 2.) If value is a color or a string coercible to a color, use interpolateRgb.
212 * 3.) Use interpolateString.
213 *
214 * To apply a different interpolator, use transition.attrTween.
215 *
216 * @param name Name of the attribute.
217 * @param value A value function which is evaluated for each selected element, in order, being passed the current datum (d),
218 * the current index (i), and the current group (nodes), with this as the current DOM element (nodes[i]).
219 * A null value will clear the attribute at the start of the transition.
220 */
221 attr(name: string, value: ValueFn<GElement, Datum, string | number | boolean | null>): this;
222
223 /**
224 * Return the current interpolator factory for attribute with the specified name, or undefined if no such tween exists.
225 *
226 * @param name Name of attribute.
227 */
228 attrTween(name: string): ValueFn<GElement, Datum, (this: GElement, t: number) => string> | undefined;
229 /**
230 * Remove the previously-assigned attribute tween of the specified name, if any.
231 *
232 * @param name Name of attribute.
233 * @param factory Use null to remove previously-assigned attribute tween.
234 */
235 attrTween(name: string, factory: null): this;
236 /**
237 * Assign the attribute tween for the attribute with the specified name to the specified interpolator factory.
238 * An interpolator factory is a function that returns an interpolator; when the transition starts, the factory is evaluated for each selected element.
239 * The returned interpolator will then be invoked for each frame of the transition, in order,
240 * being passed the eased time t, typically in the range [0, 1]. Lastly, the return value of the interpolator will be used to set the attribute value.
241 * The interpolator must return a string.
242 *
243 * @param name Name of attribute.
244 * @param factory An interpolator factory which is evaluated for each selected element, in order, being passed the current datum (d),
245 * the current index (i), and the current group (nodes), with this as the current DOM element (nodes[i]). The interpolator factory returns a string interpolator,
246 * which takes as its argument eased time t, typically in the range [0, 1] and returns the interpolated string.
247 */
248 attrTween(name: string, factory: ValueFn<GElement, Datum, (this: GElement, t: number) => string>): this;
249
250 /**
251 * For each selected element, the style with the specified name will be cleared at the start of the transition.
252 *
253 * @param name Name of the style.
254 * @param value Use null to clear the style.
255 */
256 style(name: string, value: null): this;
257 /**
258 * For each selected element, assigns the style tween for the style with the specified name to the specified target value with the
259 * specified priority.
260 * The starting value of the tween is the style’s inline value if present, and otherwise its computed value.
261 * The target value is the specified constant value for all elements.
262 *
263 * An interpolator is chosen based on the type of the target value, using the following algorithm:
264 * 1.) If value is a number, use interpolateNumber.
265 * 2.) If value is a color or a string coercible to a color, use interpolateRgb.
266 * 3.) Use interpolateString.
267 *
268 * To apply a different interpolator, use transition.attrTween.
269 *
270 * @param name Name of the style.
271 * @param value Target value for the style.
272 * @param priority An optional priority flag, either null or the string important (without the exclamation point)
273 */
274 style(name: string, value: string | number | boolean, priority?: null | "important"): this;
275 /**
276 * For each selected element, assigns the style tween for the style with the specified name to the specified target value with the
277 * specified priority.
278 * The starting value of the tween is the style's inline value if present, and otherwise its computed value.
279 * The target value is return value of the value function evaluated for the selected element.
280 *
281 * An interpolator is chosen based on the type of the target value, using the following algorithm:
282 * 1.) If value is a number, use interpolateNumber.
283 * 2.) If value is a color or a string coercible to a color, use interpolateRgb.
284 * 3.) Use interpolateString.
285 *
286 * To apply a different interpolator, use transition.attrTween.
287 *
288 * @param name Name of the style.
289 * @param value A value function which is evaluated for each selected element, in order, being passed the current datum (d),
290 * the current index (i), and the current group (nodes), with this as the current DOM element (nodes[i]).
291 * A null value will clear the style at the start of the transition.
292 * @param priority An optional priority flag, either null or the string important (without the exclamation point)
293 */
294 style(
295 name: string,
296 value: ValueFn<GElement, Datum, string | number | boolean | null>,
297 priority?: null | "important",
298 ): this;
299
300 /**
301 * Return the current interpolator factory for style with the specified name, or undefined if no such tween exists.
302 *
303 * @param name Name of style.
304 */
305 styleTween(name: string): ValueFn<GElement, Datum, (this: GElement, t: number) => string> | undefined;
306 /**
307 * Remove the previously-assigned style tween of the specified name, if any.
308 *
309 * @param name Name of style.
310 * @param factory Use null to remove previously-assigned style tween.
311 */
312 styleTween(name: string, factory: null): this;
313 /**
314 * Assign the style tween for the style with the specified name to the specified interpolator factory.
315 * An interpolator factory is a function that returns an interpolator; when the transition starts, the factory is evaluated for each selected element.
316 * The returned interpolator will then be invoked for each frame of the transition, in order,
317 * being passed the eased time t, typically in the range [0, 1]. Lastly, the return value of the interpolator will be used to set the style value.
318 * The interpolator must return a string.
319 *
320 * @param name Name of style.
321 * @param factory An interpolator factory which is evaluated for each selected element, in order, being passed the current datum (d),
322 * the current index (i), and the current group (nodes), with this as the current DOM element (nodes[i]). The interpolator factory returns a string interpolator,
323 * which takes as its argument eased time t, typically in the range [0, 1] and returns the interpolated string.
324 * @param priority An optional priority flag, either null or the string important (without the exclamation point)
325 */
326 styleTween(
327 name: string,
328 factory: ValueFn<GElement, Datum, (this: GElement, t: number) => string>,
329 priority?: null | "important",
330 ): this;
331
332 /**
333 * For each selected element, sets the text content to the specified target value when the transition starts.
334 * A null value will clear the content.
335 */
336 text(value: null | string | number | boolean): this;
337 /**
338 * For each selected element, sets the text content returned by the value function for each selected element when the transition starts.
339 *
340 * To interpolate text rather than to set it on start, use transition.textTween (for example) or append a replacement element and cross-fade opacity (for example).
341 * Text is not interpolated by default because it is usually undesirable.
342 *
343 * @param value A value function which is evaluated for each selected element, in order, being passed the current datum (d),
344 * the current index (i), and the current group (nodes), with this as the current DOM element (nodes[i]).
345 * A null value will clear the text content at the start of the transition.
346 */
347 text(value: ValueFn<GElement, Datum, string | number | boolean>): this;
348
349 /**
350 * Returns the current interpolator factory for text, or undefined if no such tween exists.
351 */
352 textTween(): ValueFn<GElement, Datum, (this: GElement, t: number) => string> | undefined;
353 /**
354 * Removes the previously-assigned text tween, if any
355 *
356 * @param factory Use null to remove previously-assigned text tween.
357 */
358 textTween(factory: null): this;
359 /**
360 * Assigns the text tween to the specified interpolator factory.
361 * An interpolator factory is a function that returns an interpolator; when the transition starts, the factory is evaluated for each selected element,
362 * in order, being passed the current datum d and index i, with the this context as the current DOM element.
363 * The returned interpolator will then be invoked for each frame of the transition, in order, being passed the eased time t, typically in the range [0, 1].
364 * Lastly, the return value of the interpolator will be used to set the text.
365 * The interpolator must return a string.
366 *
367 * @param factory An interpolator factory is a function that returns an interpolator; when the transition starts, the factory is evaluated for each selected element,
368 * in order, being passed the current datum d and index i, with the this context as the current DOM element.
369 * The returned interpolator will then be invoked for each frame of the transition, in order, being passed the eased time t, typically in the range [0, 1].
370 * Lastly, the return value of the interpolator will be used to set the text.
371 * The interpolator must return a string.
372 */
373 textTween(factory: ValueFn<GElement, Datum, (this: GElement, t: number) => string>): this;
374
375 /**
376 * For each selected element, removes the element when the transition ends, as long as the element has no other active or pending transitions.
377 * If the element has other active or pending transitions, does nothing.
378 */
379 remove(): this;
380
381 /**
382 * Returns the tween with the specified name, or undefined, if no tween was previously assigned to
383 * that name.
384 *
385 * @param name Name of tween.
386 */
387 tween(name: string): ValueFn<GElement, Datum, (this: GElement, t: number) => void> | undefined;
388 /**
389 * Removes the tween with the specified name, if a tween was previously assigned to
390 * that name.
391 *
392 * @param name Name of tween.
393 * @param tweenFn Use null to remove a previously-assigned tween.
394 */
395 tween(name: string, tweenFn: null): this;
396 /**
397 * For each selected element, assigns the tween with the specified name with the specified value function.
398 * The value must be specified as a function that returns a function.
399 * When the transition starts, the value function is evaluated for each selected element.
400 * The returned function is then invoked for each frame of the transition, in order,
401 * being passed the eased time t, typically in the range [0, 1].
402 *
403 * @param name Name of tween.
404 * @param tweenFn A tween function which is evaluated for each selected element, in order, being passed the current datum (d),
405 * the current index (i), and the current group (nodes), with this as the current DOM element (nodes[i]). The tween function returns a function
406 * which takes as its argument eased time t, typically in the range [0, 1] and performs the tweening activities for each transition frame.
407 */
408 tween(name: string, tweenFn: ValueFn<GElement, Datum, (this: GElement, t: number) => void>): this;
409
410 /**
411 * Returns a new transition merging this transition with the specified other transition,
412 * which must have the same id as this transition. The returned transition has the same number of groups,
413 * the same parents, the same name and the same id as this transition.
414 * Any missing (null) elements in this transition are filled with the corresponding element, if present (not null), from the other transition.
415 *
416 * @param other The transition to be merged.
417 */
418 merge(other: Transition<GElement, Datum, PElement, PDatum>): Transition<GElement, Datum, PElement, PDatum>;
419
420 /**
421 * For each selected element, selects only the elements that match the specified filter, and returns a transition on the resulting selection.
422 *
423 * The new transition has the same id, name and timing as this transition; however, if a transition with the same id already exists on a selected element,
424 * the existing transition is returned for that element.
425 *
426 * @param filter A CSS selector string.
427 */
428 filter(filter: string): Transition<GElement, Datum, PElement, PDatum>;
429 /**
430 * For each selected element, selects only the elements that match the specified filter, and returns a transition on the resulting selection.
431 *
432 * The new transition has the same id, name and timing as this transition; however, if a transition with the same id already exists on a selected element,
433 * the existing transition is returned for that element.
434 *
435 * The generic refers to the type of element which will be selected after applying the filter, i.e. if the element types
436 * contained in a pre-filter selection are narrowed to a subset as part of the filtering.
437 *
438 * @param filter A CSS selector string.
439 */
440 // eslint-disable-next-line @definitelytyped/no-unnecessary-generics
441 filter<FilteredElement extends BaseType>(filter: string): Transition<FilteredElement, Datum, PElement, PDatum>;
442 /**
443 * For each selected element, selects only the elements that match the specified filter, and returns a transition on the resulting selection.
444 *
445 * The new transition has the same id, name and timing as this transition; however, if a transition with the same id already exists on a selected element,
446 * the existing transition is returned for that element.
447 *
448 * @param filter A filter function which is evaluated for each selected element, in order, being passed the current datum (d),
449 * the current index (i), and the current group (nodes), with this as the current DOM element (nodes[i]). The filter function returns a boolean indicating,
450 * whether the selected element matches.
451 */
452 filter(filter: ValueFn<GElement, Datum, boolean>): Transition<GElement, Datum, PElement, PDatum>;
453 /**
454 * For each selected element, selects only the elements that match the specified filter, and returns a transition on the resulting selection.
455 *
456 * The new transition has the same id, name and timing as this transition; however, if a transition with the same id already exists on a selected element,
457 * the existing transition is returned for that element.
458 *
459 * The generic refers to the type of element which will be selected after applying the filter, i.e. if the element types
460 * contained in a pre-filter selection are narrowed to a subset as part of the filtering.
461 *
462 * @param filter A filter function which is evaluated for each selected element, in order, being passed the current datum (d),
463 * the current index (i), and the current group (nodes), with this as the current DOM element (nodes[i]). The filter function returns a boolean indicating,
464 * whether the selected element matches.
465 */
466 // eslint-disable-next-line @definitelytyped/no-unnecessary-generics
467 filter<FilteredElement extends BaseType>(
468 filter: ValueFn<GElement, Datum, boolean>,
469 ): Transition<FilteredElement, Datum, PElement, PDatum>;
470
471 // Event Handling -------------------
472
473 /**
474 * Return the currently-assigned listener for the specified event typename on the first (non-null) selected element, if any.
475 * If multiple typenames are specified, the first matching listener is returned.
476 *
477 * @param typenames The typenames is one of the following string event types: start (when the transition starts), end (when the transition ends),
478 * interrupt (when the transition is interrupted), cancel(when the transition is cancelled).
479 * Note that these are not native DOM events. The type may be optionally followed by a period (.) and a name;
480 * the optional name allows multiple callbacks to be registered to receive events of the same type, such as "start.foo"" and "start.bar".
481 * To specify multiple typenames, separate typenames with spaces, such as "interrupt end"" or "start.foo start.bar".
482 */
483 on(typenames: string): ValueFn<GElement, Datum, void> | undefined;
484 /**
485 * Remove all listeners for a given name.
486 *
487 * @param typenames Name of the event type for which the listener should be removed. To remove all listeners for a given name use ".foo"
488 * as the typename, where foo is the name; to remove all listeners with no name, specify "." as the typename.
489 * @param listener Use null to remove listeners.
490 */
491 on(typenames: string, listener: null): this;
492 /**
493 * Add a listener to each selected element for the specified event typenames.
494 *
495 * When a specified transition event is dispatched on a selected node, the specified listener will be invoked for each transitioning element.
496 * Listeners always see the latest datum for their element, but the index is a property of the selection and is fixed when the listener is assigned;
497 * to update the index, re-assign the listener.
498 *
499 * @param typenames The typenames is one of the following string event types: start (when the transition starts), end (when the transition ends),
500 * interrupt (when the transition is interrupted), cancel(when the transition is cancelled).
501 * Note that these are not native DOM events. The type may be optionally followed by a period (.) and a name;
502 * the optional name allows multiple callbacks to be registered to receive events of the same type, such as "start.foo"" and "start.bar".
503 * To specify multiple typenames, separate typenames with spaces, such as "interrupt end"" or "start.foo start.bar".
504 * @param listener A listener function which will be evaluated for each selected element, being passed the current datum (d), the current index (i),
505 * and the current group (nodes), with this as the current DOM element (nodes[i]). Listeners always see the latest datum for their element,
506 * but the index is a property of the selection and is fixed when the listener is assigned; to update the index, re-assign the listener.
507 */
508 on(typenames: string, listener: ValueFn<GElement, Datum, void>): this;
509
510 /**
511 * Returns a promise that resolves when every selected element finishes transitioning. If any element’s transition is cancelled or interrupted, the promise rejects.
512 */
513 end(): Promise<void>;
514
515 // Control Flow ----------------------
516
517 /**
518 * Invoke the specified function for each selected element, passing the current datum (d),
519 * the current index (i), and the current group (nodes), with this of the current DOM element (nodes[i]).
520 * This method can be used to invoke arbitrary code for each selected element, and is useful for creating a context to access parent and child data simultaneously.
521 *
522 * @param func A function which is invoked for each selected element,
523 * being passed the current datum (d), the current index (i), and the current group (nodes), with this of the current DOM element (nodes[i]).
524 */
525 each(func: ValueFn<GElement, Datum, void>): this;
526
527 /**
528 * Invoke the specified function exactly once, passing in this transition along with any optional arguments.
529 * Returns this transition.
530 *
531 * @param func A function which is passed this transition as the first argument along with any optional arguments.
532 * @param args List of optional arguments to be passed to the callback function.
533 */
534 call(
535 func: (transition: Transition<GElement, Datum, PElement, PDatum>, ...args: any[]) => any,
536 ...args: any[]
537 ): this;
538
539 /**
540 * Return true if this transition contains no (non-null) elements.
541 */
542 empty(): boolean;
543
544 /**
545 * Return the first (non-null) element in this transition. If the transition is empty, returns null.
546 */
547 node(): GElement | null;
548
549 /**
550 * Return an array of all (non-null) elements in this transition.
551 */
552 nodes(): GElement[];
553
554 /**
555 * Returns the total number of elements in this transition.
556 */
557 size(): number;
558
559 // Transition Configuration ----------------------
560
561 /**
562 * Returns the current value of the delay for the first (non-null) element in the transition.
563 * This is generally useful only if you know that the transition contains exactly one element.
564 */
565 delay(): number;
566 /**
567 * For each selected element, sets the transition delay to the specified value in milliseconds.
568 * If a delay is not specified, it defaults to zero.
569 *
570 * @param milliseconds Number of milliseconds for the delay.
571 */
572 delay(milliseconds: number): this;
573 /**
574 * For each selected element, sets the transition delay to the value in milliseconds returned by the
575 * value function.
576 *
577 * @param milliseconds A value function which is evaluated for each selected element, being passed the current datum (d),
578 * the current index (i), and the current group (nodes), with this of the current DOM element (nodes[i]). The return value is a number
579 * specifying the delay in milliseconds.
580 */
581 delay(milliseconds: ValueFn<GElement, Datum, number>): this;
582
583 /**
584 * Returns the current value of the duration for the first (non-null) element in the transition.
585 * This is generally useful only if you know that the transition contains exactly one element.
586 */
587 duration(): number;
588 /**
589 * For each selected element, sets the transition duration to the specified value in milliseconds.
590 * If a duration is not specified, it defaults to 250ms.
591 *
592 * @param duration Number of milliseconds for the duration.
593 */
594 duration(milliseconds: number): this;
595 /**
596 * For each selected element, sets the transition duration to the value in milliseconds returned by the
597 * value function.
598 *
599 * @param milliseconds A value function which is evaluated for each selected element, being passed the current datum (d),
600 * the current index (i), and the current group (nodes), with this of the current DOM element (nodes[i]). The return value is a number
601 * specifying the duration in milliseconds.
602 */
603 duration(milliseconds: ValueFn<GElement, Datum, number>): this;
604
605 /**
606 * Returns the current easing function for the first (non-null) element in the transition.
607 * This is generally useful only if you know that the transition contains exactly one element.
608 */
609 ease(): (normalizedTime: number) => number;
610 /**
611 * Specifies the transition easing function for all selected elements. The value must be specified as a function.
612 * The easing function is invoked for each frame of the animation, being passed the normalized time t in the range [0, 1];
613 * it must then return the eased time tʹ which is typically also in the range [0, 1].
614 * A good easing function should return 0 if t = 0 and 1 if t = 1. If an easing function is not specified,
615 * it defaults to d3.easeCubic.
616 *
617 * @param easingFn An easing function which is passed the normalized time t in the range [0, 1];
618 * it must then return the eased time tʹ which is typically also in the range [0, 1].
619 * A good easing function should return 0 if t = 0 and 1 if t = 1.
620 */
621 ease(easingFn: (normalizedTime: number) => number): this;
622
623 /**
624 * Specifies a factory for the transition easing function.
625 *
626 * @param factory The factory must be a function.
627 * It is invoked for each node of the selection, being passed the current datum (d), the current index (i), and the current group (nodes), with this as the current DOM element.
628 * It must return an easing function.
629 */
630 easeVarying(factory: ValueFn<GElement, Datum, (normalizedTime: number) => number>): this;
631}
632
633/**
634 * Represents the union of the Selection and Transition types for any usages that operate on both.
635 * Typically used for functions which take in either a selection or transition and set or update attributes.
636 */
637export type SelectionOrTransition<GElement extends BaseType, Datum, PElement extends BaseType, PDatum> =
638 | Selection<GElement, Datum, PElement, PDatum>
639 | Transition<GElement, Datum, PElement, PDatum>;
640
641/**
642 * Returns a new transition with the specified name. If a name is not specified, null is used.
643 * The new transition is only exclusive with other transitions of the same name.
644 *
645 * The generic "OldDatum" refers to the type of a previously-set datum of the selected element in the Transition.
646 *
647 * @param name Name of the transition.
648 */
649// eslint-disable-next-line @definitelytyped/no-unnecessary-generics
650export function transition<OldDatum>(name?: string): Transition<BaseType, OldDatum, null, undefined>;
651
652/**
653 * Returns a new transition from an existing transition.
654 *
655 * When using a transition instance, the returned transition has the same id and name as the specified transition.
656 *
657 * The generic "OldDatum" refers to the type of a previously-set datum of the selected element in the Transition.
658 *
659 * @param transition A transition instance.
660 */
661// eslint-disable-next-line @definitelytyped/no-unnecessary-generics
662export function transition<OldDatum>(
663 transition: Transition<BaseType, any, BaseType, any>,
664): Transition<BaseType, OldDatum, null, undefined>;