UNPKG

67.4 kBTypeScriptView Raw
1// Type definitions for D3JS d3-selection module 2.0
2// Project: https://github.com/d3/d3-selection/, https://d3js.org/d3-selection
3// Definitions by: Tom Wanzek <https://github.com/tomwanzek>
4// Alex Ford <https://github.com/gustavderdrache>
5// Boris Yankov <https://github.com/borisyankov>
6// denisname <https://github.com/denisname>
7// Nathan Bierema <https://github.com/Methuselah96>
8// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
9// TypeScript Version: 2.3
10
11// Last module patch version validated against: 2.0.0
12
13// --------------------------------------------------------------------------
14// Shared Type Definitions and Interfaces
15// --------------------------------------------------------------------------
16
17/**
18 * BaseType serves as an alias for the 'minimal' data type which can be selected
19 * without 'd3-selection' trying to use properties internally which would otherwise not
20 * be supported.
21 */
22export type BaseType = Element | EnterElement | Document | Window | null;
23
24/**
25 * KeyType serves as alias for valid types that d3 supports as key for data binding
26 */
27export type KeyType = string | number;
28
29/**
30 * A helper interface which covers arguments like NodeListOf<T> or HTMLCollectionOf<T>
31 * argument types
32 */
33export interface ArrayLike<T> {
34 length: number;
35 item(index: number): T | null;
36 [index: number]: T;
37}
38
39/**
40 * An interface describing the element type of the Enter Selection group elements
41 * created when invoking selection.enter().
42 */
43export interface EnterElement {
44 ownerDocument: Document;
45 namespaceURI: string;
46 appendChild(newChild: Node): Node;
47 insertBefore(newChild: Node, refChild: Node): Node;
48 querySelector(selectors: string): Element;
49 querySelectorAll(selectors: string): NodeListOf<Element>;
50}
51
52/**
53 * Container element type usable for mouse/touch functions
54 */
55export type ContainerElement = HTMLElement | SVGSVGElement | SVGGElement;
56
57/**
58 * A User interface event (e.g. mouse event, touch or MSGestureEvent) with captured clientX and clientY properties.
59 */
60export interface ClientPointEvent {
61 clientX: number;
62 clientY: number;
63}
64
65/**
66 * Interface for optional parameters map, when dispatching custom events
67 * on a selection
68 */
69export interface CustomEventParameters {
70 /**
71 * If true, the event is dispatched to ancestors in reverse tree order
72 */
73 bubbles: boolean;
74 /**
75 * If true, event.preventDefault is allowed
76 */
77 cancelable: boolean;
78 /**
79 * Any custom data associated with the event
80 */
81 detail: any;
82}
83
84/**
85 * Callback type for selections and transitions
86 */
87export type ValueFn<T extends BaseType, Datum, Result> = (this: T, datum: Datum, index: number, groups: T[] | ArrayLike<T>) => Result;
88
89/**
90 * TransitionLike is a helper interface to represent a quasi-Transition, without specifying the full Transition interface in this file.
91 * For example, wherever d3-zoom allows a Transition to be passed in as an argument, it internally immediately invokes its `selection()`
92 * method to retrieve the underlying Selection object before proceeding.
93 * d3-brush uses a subset of Transition methods internally.
94 * The use of this interface instead of the full imported Transition interface is [referred] to achieve
95 * two things:
96 * (1) the d3-transition module may not be required by a projects use case,
97 * (2) it avoids possible complications from 'module augmentation' from d3-transition to Selection.
98 */
99export interface TransitionLike<GElement extends BaseType, Datum> {
100 selection(): Selection<GElement, Datum, any, any>;
101 on(type: string, listener: null): TransitionLike<GElement, Datum>;
102 on(type: string, listener: ValueFn<GElement, Datum, void>): TransitionLike<GElement, Datum>;
103 tween(name: string, tweenFn: null): TransitionLike<GElement, Datum>;
104 tween(name: string, tweenFn: ValueFn<GElement, Datum, ((t: number) => void)>): TransitionLike<GElement, Datum>;
105}
106
107// --------------------------------------------------------------------------
108// All Selection related interfaces and function
109// --------------------------------------------------------------------------
110
111/**
112 * Select the first element that matches the specified selector string. If no elements match the selector, returns an empty selection.
113 * If multiple elements match the selector, only the first matching element (in document order) will be selected.
114 *
115 * The first generic "GElement" refers to the type of element to be selected. The second generic "OldDatum" refers to the type of the
116 * datum, on the selected element. This is useful when re-selecting an element with a previously set, know datum type.
117 *
118 * @param selector CSS selector string
119 */
120export function select<GElement extends BaseType, OldDatum>(selector: string): Selection<GElement, OldDatum, HTMLElement, any>;
121/**
122 * Select the specified node element.
123 *
124 * The first generic "GElement" refers to the type of element to be selected. The second generic "OldDatum" refers to the type of the
125 * datum, on the selected element. This is useful when re-selecting an element with a previously set, know datum type.
126 *
127 * @param node An element to be selected
128 */
129export function select<GElement extends BaseType, OldDatum>(node: GElement): Selection<GElement, OldDatum, null, undefined>;
130
131/**
132 * Create an empty selection.
133 */
134export function selectAll(): Selection<null, undefined, null, undefined>;
135/**
136 * Create an empty selection.
137 */
138export function selectAll(selector: null): Selection<null, undefined, null, undefined>;
139/**
140 * Create an empty selection.
141 */
142export function selectAll(selector: undefined): Selection<null, undefined, null, undefined>;
143/**
144 * Select all elements that match the specified selector string. The elements will be selected in document order (top-to-bottom).
145 * If no elements in the document match the selector, returns an empty selection.
146 *
147 * The first generic "GElement" refers to the type of element to be selected. The second generic "OldDatum" refers to the type of the
148 * datum, of a selected element. This is useful when re-selecting elements with a previously set, know datum type.
149 *
150 * @param selector CSS selector string
151 */
152export function selectAll<GElement extends BaseType, OldDatum>(selector: string): Selection<GElement, OldDatum, HTMLElement, any>;
153/**
154 * Select the specified array, array-like, or iterable of nodes.
155 * This is useful if you already have a reference to nodes, such as `this.childNodes` within an event listener or a global such as `document.links`.
156 * The nodes may instead be an iterable, or a pseudo-array such as a NodeList.
157 *
158 * The first generic "GElement" refers to the type of element to be selected.
159 * The second generic "OldDatum" refers to the type of the datum, of a selected element.
160 *
161 * @param nodes An array, array-like, or iterable of nodes
162 */
163export function selectAll<GElement extends BaseType, OldDatum>(nodes: GElement[] | ArrayLike<GElement> | Iterable<GElement>): Selection<GElement, OldDatum, null, undefined>;
164
165/**
166 * A D3 Selection of elements.
167 *
168 * The first generic "GElement" refers to the type of the selected element(s).
169 * The second generic "Datum" refers to the type of the datum of a selected element(s).
170 * The third generic "PElement" refers to the type of the parent element(s) in the D3 selection.
171 * The fourth generic "PDatum" refers to the type of the datum of the parent element(s).
172 */
173export interface Selection<GElement extends BaseType, Datum, PElement extends BaseType, PDatum> {
174 // Sub-selection -------------------------
175
176 /**
177 * For each selected element, select the first descendant element that matches the specified selector string.
178 * If no element matches the specified selector for the current element, the element at the current index will
179 * be null in the returned selection. If multiple elements match the selector, only the first matching element
180 * in document order is selected. Selection.select does not affect grouping: it preserves the existing group
181 * structure and indexes, and propagates data (if any) to selected children.
182 *
183 * If the current element has associated data, this data is propagated to the
184 * corresponding selected element.
185 *
186 * The generic represents the type of the descendant element to be selected.
187 *
188 * @param selector CSS selector string
189 */
190 select<DescElement extends BaseType>(selector: string): Selection<DescElement, Datum, PElement, PDatum>;
191 /**
192 * Create an empty sub-selection. Selection.select does not affect grouping: it preserves the existing group
193 * structure and indexes.
194 */
195 select<DescElement extends BaseType>(selector: null): Selection<null, undefined, PElement, PDatum>;
196 /**
197 * For each selected element, select the descendant element returned by the selector function.
198 * If no element is returned by the selector function for the current element, the element at the
199 * current index will be null in the returned selection. Selection.select does not affect grouping:
200 * it preserves the existing group structure and indexes, and propagates data (if any) to selected children.
201 *
202 * If the current element has associated data, this data is propagated to the
203 * corresponding selected element.
204 *
205 * The generic represents the type of the descendant element to be selected.
206 *
207 * @param selector A selector function, which is evaluated for each selected element, in order, being passed the current datum (d),
208 * the current index (i), and the current group (nodes), with this as the current DOM element (nodes[i]).
209 * It must return an element, or null if there is no matching element.
210 */
211 select<DescElement extends BaseType>(selector: ValueFn<GElement, Datum, DescElement>): Selection<DescElement, Datum, PElement, PDatum>;
212
213 /**
214 * Create an empty sub-selection. Selection.selectAll does affect grouping: The elements in the returned
215 * selection are grouped by their corresponding parent node in this selection, the group at the current index will be empty.
216 */
217 selectAll(): Selection<null, undefined, GElement, Datum>;
218 /**
219 * Create an empty sub-selection. Selection.selectAll does affect grouping: The elements in the returned
220 * selection are grouped by their corresponding parent node in this selection, the group at the current index will be empty.
221 */
222 selectAll(selector: null): Selection<null, undefined, GElement, Datum>;
223 /**
224 * Create an empty sub-selection. Selection.selectAll does affect grouping: The elements in the returned
225 * selection are grouped by their corresponding parent node in this selection, the group at the current index will be empty.
226 */
227 selectAll(selector: undefined): Selection<null, undefined, GElement, Datum>;
228 /**
229 * For each selected element, selects the descendant elements that match the specified selector string. The elements in the returned
230 * selection are grouped by their corresponding parent node in this selection. If no element matches the specified selector
231 * for the current element, the group at the current index will be empty. Selection.selectAll does affect grouping: each selected descendant
232 * is grouped by the parent element in the originating selection.
233 *
234 * The selected elements do not inherit data from this selection; use selection.data to propagate data to children.
235 *
236 * The first generic "DescElement" refers to the type of descendant element to be selected. The second generic "OldDatum" refers to the type of the
237 * datum, of a selected element. This is useful when re-selecting elements with a previously set, know datum type.
238 *
239 * @param selector CSS selector string
240 */
241 selectAll<DescElement extends BaseType, OldDatum>(selector: string): Selection<DescElement, OldDatum, GElement, Datum>;
242 /**
243 * For each selected element, selects the descendant elements returned by the selector function. The elements in the returned
244 * selection are grouped by their corresponding parent node in this selection. If no element matches the specified selector
245 * for the current element, the group at the current index will be empty. Selection.selectAll does affect grouping: each selected descendant
246 * is grouped by the parent element in the originating selection.
247 *
248 * The selected elements do not inherit data from this selection; use selection.data to propagate data to children.
249 *
250 * The first generic "DescElement" refers to the type of descendant element to be selected. The second generic "OldDatum" refers to the type of the
251 * datum, of a selected element. This is useful when re-selecting elements with a previously set, know datum type.
252 *
253 * @param selector A selector function which is evaluated for each selected element, in order, being passed the current datum (d),
254 * 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
255 * (or an iterable, or a pseudo-array, such as a NodeList), or the empty array if there are no matching elements.
256 */
257 selectAll<DescElement extends BaseType, OldDatum>(
258 selector: ValueFn<GElement, Datum, DescElement[] | ArrayLike<DescElement> | Iterable<DescElement>>
259 ): Selection<DescElement, OldDatum, GElement, Datum>;
260
261 /**
262 * Filters the selection, returning a new selection that contains only the elements for
263 * which the specified filter is true.
264 *
265 * The returned filtered selection preserves the parents of this selection, but like array.filter,
266 * it does not preserve indexes as some elements may be removed; use selection.select to preserve the index, if needed.
267 *
268 * @param selector A CSS selector string to match when filtering.
269 */
270 filter(selector: string): Selection<GElement, Datum, PElement, PDatum>;
271 /**
272 * Filters the selection, returning a new selection that contains only the elements for
273 * which the specified filter is true.
274 *
275 * The returned filtered selection preserves the parents of this selection, but like array.filter,
276 * it does not preserve indexes as some elements may be removed; use selection.select to preserve the index, if needed.
277 *
278 * The generic refers to the type of element which will be selected after applying the filter, i.e. if the element types
279 * contained in a pre-filter selection are narrowed to a subset as part of the filtering.
280 *
281 * @param selector A CSS selector string to match when filtering.
282 */
283 filter<FilteredElement extends BaseType>(selector: string): Selection<FilteredElement, Datum, PElement, PDatum>;
284 /**
285 * Filter the selection, returning a new selection that contains only the elements for
286 * which the specified filter is true.
287 *
288 * The returned filtered selection preserves the parents of this selection, but like array.filter,
289 * it does not preserve indexes as some elements may be removed; use selection.select to preserve the index, if needed.
290 *
291 * @param selector A value function which is evaluated for each selected element, in order, being passed the current datum (d),
292 * the current index (i), and the current group (nodes), with this as the current DOM element (nodes[i]). This function should return true
293 * for an element to be included, and false otherwise.
294 */
295 filter(selector: ValueFn<GElement, Datum, boolean>): Selection<GElement, Datum, PElement, PDatum>;
296 /**
297 * Filter the selection, returning a new selection that contains only the elements for
298 * which the specified filter is true.
299 *
300 * The returned filtered selection preserves the parents of this selection, but like array.filter,
301 * it does not preserve indexes as some elements may be removed; use selection.select to preserve the index, if needed.
302 *
303 * @param selector A value function which is evaluated for each selected element, in order, being passed the current datum (d),
304 * the current index (i), and the current group (nodes), with this as the current DOM element (nodes[i]). This function should return true
305 * for an element to be included, and false otherwise.
306 */
307 filter<FilteredElement extends BaseType>(selector: ValueFn<GElement, Datum, boolean>): Selection<FilteredElement, Datum, PElement, PDatum>;
308
309 /**
310 * Returns a new selection merging this selection with the specified other selection.
311 * The returned selection has the same number of groups and the same parents as this selection.
312 * Any missing (null) elements in this selection are filled with the corresponding element,
313 * if present (not null), from the specified selection. (If the other selection has additional groups or parents,
314 * they are ignored.)
315 *
316 * This method is commonly used to merge the enter and update selections after a data-join.
317 * After modifying the entering and updating elements separately, you can merge the two selections and
318 * perform operations on both without duplicate code.
319 *
320 * This method is not intended for concatenating arbitrary selections, however: if both this selection
321 * and the specified other selection have (non-null) elements at the same index, this selections element
322 * is returned in the merge and the other selections element is ignored.
323 *
324 * @param other Selection to be merged.
325 */
326 merge(other: Selection<GElement, Datum, PElement, PDatum>): Selection<GElement, Datum, PElement, PDatum>;
327
328 /**
329 * Returns a new selection with the (first) child of each element of the current selection matching the selector.
330 * Selects the first child (if any).
331 *
332 * The generic represents the type of the descendant element to be selected.
333 */
334 selectChild<DescElement extends BaseType>(): Selection<DescElement, Datum, PElement, PDatum>;
335 /**
336 * Returns a new selection with the (first) child of each element of the current selection matching the selector.
337 * Selects the first child that matches (if any).
338 *
339 * The generic represents the type of the descendant element to be selected.
340 *
341 * @param selector CSS selector string
342 */
343 selectChild<DescElement extends BaseType>(selector: string): Selection<DescElement, Datum, PElement, PDatum>;
344 /**
345 * Returns a new selection with the (first) child of each element of the current selection matching the selector.
346 *
347 * The first generic represents the type of the descendant element to be selected.
348 * The second generic represents the type of any of the child elements.
349 *
350 * @param selector A selector function, which is evaluated for each of the children nodes, in order, being passed the child (child), the childs index (i), and the list of children (children);
351 * the method selects the first child for which the selector return truthy, if any.
352 */
353 selectChild<ResultElement extends BaseType, ChildElement extends BaseType>(
354 selector: (child: ChildElement, i: number, children: ChildElement[]) => boolean
355 ): Selection<ResultElement, Datum, PElement, PDatum>;
356
357 /**
358 * Returns a new selection with the children of each element of the current selection matching the selector.
359 * Selects all the children
360 *
361 * The first generic represents the type of the descendant element to be selected.
362 * The second generic refers to the type of the datum of the element to be selected.
363 */
364 selectChildren<DescElement extends BaseType, OldDatum>(): Selection<DescElement, OldDatum, GElement, Datum>;
365 /**
366 * Returns a new selection with the children of each element of the current selection matching the selector.
367 * Selects the children that match (if any)
368 *
369 * The first generic represents the type of the descendant element to be selected.
370 * The second generic refers to the type of the datum of the element to be selected.
371 *
372 * @param selector CSS selector string
373 */
374 selectChildren<DescElement extends BaseType, OldDatum>(
375 selector: string
376 ): Selection<DescElement, OldDatum, GElement, Datum>;
377 /**
378 * Returns a new selection with the children of each element of the current selection matching the selector.
379 *
380 * The first generic represents the type of the descendant element to be selected.
381 * The second generic refers to the type of the datum of the element to be selected.
382 * The third generic represents the type of any of the child elements.
383 *
384 * @param selector A selector function, which is evaluated for each of the children nodes, in order, being passed the child (child), the childs index (i), and the list of children (children);
385 * the method selects the first child for which the selector return truthy, if any.
386 */
387 selectChildren<ResultElement extends BaseType, ResultDatum, ChildElement extends BaseType>(
388 selector: (child: ChildElement, i: number, children: ChildElement[]) => boolean
389 ): Selection<ResultElement, ResultDatum, GElement, Datum>;
390
391 /**
392 * Returns the selection (for symmetry with transition.selection).
393 */
394 selection(): this;
395
396 // Modifying -------------------------------
397
398 /**
399 * Return the current value of the specified attribute for the first (non-null) element in the selection.
400 * This is generally useful only if you know that the selection contains exactly one element.
401 *
402 * @param name Name of the attribute
403 */
404 attr(name: string): string;
405 /**
406 * Clear the attribute with the specified name for the selected elements and returns this selection.
407 *
408 * @param name Name of the attribute
409 * @param value null,to clear the attribute
410 */
411 attr(name: string, value: null): this;
412 /**
413 * Sets the value of the attribute with the specified name for the selected elements and returns this selection.
414 * All elements are given the same attribute value.
415 *
416 * @param name Name of the attribute
417 * @param value Constant value for the attribute
418 */
419 attr(name: string, value: string | number | boolean): this;
420 /**
421 * Sets the value of the attribute with the specified name for the selected elements and returns this selection.
422 * The value for the individual selected elements is determined by the value function.
423 *
424 * @param name Name of the attribute
425 * @param value A value function which is evaluated for each selected element, in order, being passed the current datum (d),
426 * the current index (i), and the current group (nodes), with this as the current DOM element (nodes[i]). A null value will clear the attribute.
427 */
428 attr(name: string, value: ValueFn<GElement, Datum, string | number | boolean | null>): this;
429
430 /**
431 * Returns true if and only if the first (non-null) selected element has the specified classes.
432 * This is generally useful only if you know the selection contains exactly one element.
433 *
434 * @param names A string of space-separated class names.
435 */
436 classed(names: string): boolean;
437 /**
438 * Assigns or unassigns the specified CSS class names on the selected elements by setting
439 * the class attribute or modifying the classList property and returns this selection.
440 * If the constant value is truthy, then all elements are assigned the specified classes; otherwise, the classes are unassigned.
441 *
442 * @param names A string of space-separated class names.
443 * @param value A boolean flag (true = assign / false = unassign)
444 */
445 classed(names: string, value: boolean): this;
446 /**
447 * Assigns or unassigns the specified CSS class names on the selected elements by setting
448 * the class attribute or modifying the classList property and returns this selection.
449 * The assign/unassign status for the individual selected elements is determined by the boolean return
450 * value of the value function.
451 *
452 * @param names A string of space-separated class names.
453 * @param value A value function which is evaluated for each selected element, in order,
454 * being passed the current datum (d), the current index (i), and the current group (nodes), with this as the current DOM element (nodes[i]).
455 * The functions return value is then used to assign or unassign classes on each element.
456 */
457 classed(names: string, value: ValueFn<GElement, Datum, boolean>): this;
458
459 /**
460 * Returns the current value of the specified style property for the first (non-null) element in the selection.
461 * The current value is defined as the elements inline value, if present, and otherwise its computed value.
462 * Accessing the current style value is generally useful only if you know the selection contains exactly one element.
463 *
464 * @param name Name of the style
465 */
466 style(name: string): string;
467 /**
468 * Clear the style with the specified name for the selected elements and returns this selection.
469 *
470 * @param name Name of the style
471 * @param value null,to clear the style
472 */
473 style(name: string, value: null): this;
474 /**
475 * Sets the value of the style with the specified name for the selected elements and returns this selection.
476 * All elements are given the same style value.
477 *
478 * @param name Name of the style
479 * @param value Constant value for the style
480 * @param priority An optional priority flag, either null or the string important (without the exclamation point)
481 */
482 style(name: string, value: string | number | boolean, priority?: null | 'important'): this;
483 /**
484 * Sets the value of the style with the specified name for the selected elements and returns this selection.
485 * The value for the individual selected elements is determined by the value function.
486 *
487 * @param name Name of the style
488 * @param value A value function which is evaluated for each selected element, in order, being passed the current datum (d),
489 * the current index (i), and the current group (nodes), with this as the current DOM element (nodes[i]). A null value will clear the style.
490 * @param priority An optional priority flag, either null or the string important (without the exclamation point)
491 */
492 style(name: string, value: ValueFn<GElement, Datum, string | number | boolean | null>, priority?: null | 'important'): this;
493
494 /**
495 * Return the current value of the specified property for the first (non-null) element in the selection.
496 * This is generally useful only if you know that the selection contains exactly one element.
497 *
498 * @param name Name of the property
499 */
500 property(name: string): any;
501 /**
502 * Look up a local variable on the first node of this selection. Note that this is not equivalent to `local.get(selection.node())` in that it will not look up locals set on the parent node(s).
503 *
504 * @param name The `d3.local` variable to look up.
505 */
506 property<T>(name: Local<T>): T | undefined;
507 /**
508 * Sets the value of the property with the specified name for the selected elements and returns this selection.
509 * The value for the individual selected elements is determined by the value function.
510 *
511 * Some HTML elements have special properties that are not addressable using attributes or styles,
512 * such as a form fields text value and a checkboxs checked boolean. Use this method to get or set these properties.
513 *
514 * @param name Name of the property
515 * @param value A value function which is evaluated for each selected element, in order, being passed the current datum (d),
516 * the current index (i), and the current group (nodes), with this as the current DOM element (nodes[i]). A null value will clear the property.
517 */
518 property(name: string, value: ValueFn<GElement, Datum, any>): this;
519 /**
520 * Clears the property with the specified name for the selected elements and returns this selection.
521 *
522 * @param name Name of the property
523 * @param value null,to clear the property
524 */
525 property(name: string, value: null): this;
526 /**
527 * Sets the value of the property with the specified name for the selected elements and returns this selection.
528 * All elements are given the same property value.
529 *
530 * @param name Name of the property
531 * @param value Constant value for the property
532 */
533 property(name: string, value: any): this;
534 /**
535 * Store a value in a `d3.local` variable.
536 * This is equivalent to `selection.each(function (d, i, g) { name.set(this, value.call(this, d, i, g)); })` but more concise.
537 *
538 * @param name A `d3.local` variable
539 * @param value A callback that returns the value to store
540 */
541 property<T>(name: Local<T>, value: ValueFn<GElement, Datum, T>): this;
542 /**
543 * Store a value in a `d3.local` variable for each node in the selection.
544 * This is equivalent to `selection.each(function () { name.set(this, value); })` but more concise.
545 *
546 * @param name A `d3.local` variable
547 * @param value A callback that returns the value to store
548 */
549 property<T>(name: Local<T>, value: T): this;
550
551 /**
552 * Returns the text content for the first (non-null) element in the selection.
553 * This is generally useful only if you know the selection contains exactly one element.
554 */
555 text(): string;
556 /**
557 * Clear the text content of the selected elements and return the selection.
558 */
559 text(value: null): this;
560 /**
561 * Sets the text content to the specified value on all selected elements, replacing any existing child elements.
562 * All elements are given the same text content.
563 *
564 * @param value Text content value for the elements.
565 */
566 text(value: string | number | boolean): this;
567 /**
568 * Sets the text content to the specified value on all selected elements, replacing any existing child elements.
569 * All elements are given the same text content.
570 *
571 * @param value A value unction which is evaluated for each selected element, in order, being passed the current datum (d),
572 * the current index (i), and the current group (nodes), with this as the current DOM element (nodes[i]).
573 * The functions return value is then used to set each elements text content. A null value will clear the content.
574 */
575 text(value: ValueFn<GElement, Datum, string | number | boolean | null>): this;
576
577 /**
578 * Returns a string representation of the inner HTML for the first (non-null) element in the selection.
579 * This is generally useful only if you know the selection contains exactly one element.
580 */
581 html(): string;
582 /**
583 * Clear the html content of the selected elements and return the selection.
584 */
585 html(value: null): this;
586 /**
587 * Sets the inner HTML to the specified value on all selected elements, replacing any existing child elements.
588 * All elements are given the same inner HTML
589 *
590 * @param value String representation of inner HTML.
591 */
592 html(value: string): this;
593 /**
594 * Sets the inner HTML to the specified value on all selected elements, replacing any existing child elements.
595 * The inner HTML is determined for each individual element using a value function.
596 *
597 * @param value A value function which is evaluated for each selected element, in order, being passed the current
598 * datum (d), the current index (i), and the current group (nodes), with this as the current DOM element (nodes[i]).
599 * The functions return value is then used to set each elements inner HTML. A null value will clear the content.
600 */
601 html(value: ValueFn<GElement, Datum, string | null>): this;
602
603 /**
604 * Appends a new element of this type (tag name) as the last child of each selected element,
605 * or before the next following sibling in the update selection if this is an enter selection.
606 * The latter behavior for enter selections allows you to insert elements into the DOM in an order consistent with the new bound data;
607 * however, note that selection.order may still be required if updating elements change order
608 * (i.e., if the order of new data is inconsistent with old data).
609 *
610 * This method returns a new selection containing the appended elements.
611 * Each new element inherits the data of the current elements, if any.
612 *
613 * @param type A string representing the tag name.
614 */
615 append<K extends keyof ElementTagNameMap>(type: K): Selection<ElementTagNameMap[K], Datum, PElement, PDatum>;
616 /**
617 * Appends a new element of this type (tag name) as the last child of each selected element,
618 * or before the next following sibling in the update selection if this is an enter selection.
619 * The latter behavior for enter selections allows you to insert elements into the DOM in an order consistent with the new bound data;
620 * however, note that selection.order may still be required if updating elements change order
621 * (i.e., if the order of new data is inconsistent with old data).
622 *
623 * This method returns a new selection containing the appended elements.
624 * Each new element inherits the data of the current elements, if any.
625 *
626 * The generic refers to the type of the child element to be appended.
627 *
628 * @param type A string representing the tag name. The specified name may have a namespace prefix, such as svg:text
629 * to specify a text attribute in the SVG namespace. If no namespace is specified, the namespace will be inherited
630 * from the parent element; or, if the name is one of the known prefixes, the corresponding namespace will be used
631 * (for example, svg implies svg:svg)
632 */
633 append<ChildElement extends BaseType>(type: string): Selection<ChildElement, Datum, PElement, PDatum>;
634 /**
635 * Appends a new element of the type provided by the element creator function as the last child of each selected element,
636 * or before the next following sibling in the update selection if this is an enter selection.
637 * The latter behavior for enter selections allows you to insert elements into the DOM in an order consistent with the new bound data;
638 * however, note that selection.order may still be required if updating elements change order
639 * (i.e., if the order of new data is inconsistent with old data).
640 *
641 * This method returns a new selection containing the appended elements.
642 * Each new element inherits the data of the current elements, if any.
643 *
644 * The generic refers to the type of the child element to be appended.
645 *
646 * @param type A creator function which is evaluated for each selected element, in order, being passed the current datum (d),
647 * the current index (i), and the current group (nodes), with this as the current DOM element (nodes[i]). This function should return
648 * an element to be appended. (The function typically creates a new element, but it may instead return an existing element.)
649 */
650 append<ChildElement extends BaseType>(type: ValueFn<GElement, Datum, ChildElement>): Selection<ChildElement, Datum, PElement, PDatum>;
651
652 /**
653 * Inserts a new element of the specified type (tag name) before the first element matching the specified
654 * before selector for each selected element. For example, a before selector :first-child will prepend nodes before the first child.
655 * If before is not specified, it defaults to null. (To append elements in an order consistent with bound data, use selection.append.)
656 *
657 * This method returns a new selection containing the appended elements.
658 * Each new element inherits the data of the current elements, if any.
659 *
660 * The generic refers to the type of the child element to be appended.
661 *
662 * @param type A string representing the tag name for the element type to be inserted.
663 * @param before One of:
664 * * A CSS selector string for the element before which the insertion should occur.
665 * * A child selector function which is evaluated for each selected element, in order, being passed the current datum (d),
666 * the current index (i), and the current group (nodes), with this as the current DOM element (nodes[i]). This function should return the child element
667 * before which the element should be inserted.
668 */
669 insert<K extends keyof ElementTagNameMap>(
670 type: K,
671 before?: string | ValueFn<GElement, Datum, BaseType>
672 ): Selection<ElementTagNameMap[K], Datum, PElement, PDatum>;
673 /**
674 * Inserts a new element of the specified type (tag name) before the first element matching the specified
675 * before selector for each selected element. For example, a before selector :first-child will prepend nodes before the first child.
676 * If before is not specified, it defaults to null. (To append elements in an order consistent with bound data, use selection.append.)
677 *
678 * This method returns a new selection containing the appended elements.
679 * Each new element inherits the data of the current elements, if any.
680 *
681 * The generic refers to the type of the child element to be appended.
682 *
683 * @param type One of:
684 * * A string representing the tag name for the element type to be inserted. The specified name may have a namespace prefix,
685 * such as svg:text to specify a text attribute in the SVG namespace. If no namespace is specified, the namespace will be inherited
686 * from the parent element; or, if the name is one of the known prefixes, the corresponding namespace will be used
687 * (for example, svg implies svg:svg)
688 * * A creator function which is evaluated for each selected element, in order, being passed the current datum (d),
689 * the current index (i), and the current group (nodes), with this as the current DOM element (nodes[i]). This function should return
690 * an element to be inserted. (The function typically creates a new element, but it may instead return an existing element.)
691 * @param before One of:
692 * * A CSS selector string for the element before which the insertion should occur.
693 * * A child selector function which is evaluated for each selected element, in order, being passed the current datum (d),
694 * the current index (i), and the current group (nodes), with this as the current DOM element (nodes[i]). This function should return the child element
695 * before which the element should be inserted.
696 */
697 insert<ChildElement extends BaseType>(
698 type: string | ValueFn<GElement, Datum, ChildElement>,
699 before?: string | ValueFn<GElement, Datum, BaseType>
700 ): Selection<ChildElement, Datum, PElement, PDatum>;
701
702 /**
703 * Removes the selected elements from the document.
704 * Returns this selection (the removed elements) which are now detached from the DOM.
705 */
706 remove(): this;
707
708 /**
709 * Inserts clones of the selected elements immediately following the selected elements and returns a selection of the newly
710 * added clones. If deep is true, the descendant nodes of the selected elements will be cloned as well. Otherwise, only the elements
711 * themselves will be cloned.
712 *
713 * @param deep Perform deep cloning if this flag is set to true.
714 */
715 clone(deep?: boolean): Selection<GElement, Datum, PElement, PDatum>;
716
717 /**
718 * Return a new selection that contains a copy of each group in this selection sorted according
719 * to the compare function. After sorting, re-inserts elements to match the resulting order (per selection.order).
720 *
721 * Note that sorting is not guaranteed to be stable; however, it is guaranteed to have the same
722 * behavior as your browsers built-in sort method on arrays.
723 *
724 * @param comparator An optional comparator function, which defaults to "ascending". The function is passed
725 * two elementsdata a and b to compare. It should return either a negative, positive, or zero value.
726 * If negative, then a should be before b; if positive, then a should be after b; otherwise, a and b are
727 * considered equal and the order is arbitrary.
728 */
729 sort(comparator?: (a: Datum, b: Datum) => number): this;
730
731 /**
732 * Re-insert elements into the document such that the document order of each group matches the selection order.
733 * This is equivalent to calling selection.sort if the data is already sorted, but much faster.
734 */
735 order(): this;
736
737 /**
738 * Re-insert each selected element, in order, as the last child of its parent.
739 */
740 raise(): this;
741
742 /**
743 * Re-insert each selected element, in order, as the first child of its parent.
744 */
745 lower(): this;
746
747 // Data Join ---------------------------------
748
749 /**
750 * Returns the array of data for the selected elements.
751 */
752 data(): Datum[];
753 /**
754 * Joins the specified array of data with the selected elements, returning a new selection that represents
755 * the update selection: the elements successfully bound to data. Also defines the enter and exit selections on
756 * the returned selection, which can be used to add or remove elements to correspond to the new data.
757 *
758 * The data is specified for each group in the selection. If the selection has multiple groups
759 * (such as d3.selectAll followed by selection.selectAll), then data should typically be specified as a function.
760 *
761 * If a key function is not specified, then the first datum in data is assigned to the first selected element,
762 * the second datum to the second selected element, and so on.
763 * A key function may be specified to control which datum is assigned to which element, replacing the default join-by-index,
764 * by computing a string identifier for each datum and element.
765 *
766 * The update and enter selections are returned in data order, while the exit selection preserves the selection
767 * order prior to the join. If a key function is specified, the order of elements in the selection may not match
768 * their order in the document; use selection.order or selection.sort as needed.
769 *
770 * This method cannot be used to clear bound data; use selection.datum instead.
771 *
772 * For details see: {@link https://github.com/d3/d3-selection#joining-data }
773 *
774 * The generic refers to the type of the new datum to be used for the selected elements.
775 *
776 * @param data The specified data is an array or iterable of arbitrary values (e.g., numbers or objects).
777 * @param key An optional key function which is evaluated for each selected element, in order, being passed the
778 * current datum (d), the current index (i), and the current group (nodes), with this as the current DOM element (nodes[i]); the returned string is the elements key.
779 * The key function is then also evaluated for each new datum in data, being passed the current datum (d),
780 * the current index (i), and the groups new data, with this as the groups parent DOM element (nodes[i]); the returned string is the datums key.
781 * The datum for a given key is assigned to the element with the matching key. If multiple elements have the same key,
782 * the duplicate elements are put into the exit selection; if multiple data have the same key, the duplicate data are put into the enter selection.
783 */
784 data<NewDatum>(data: NewDatum[] | Iterable<NewDatum>, key?: ValueFn<GElement | PElement, Datum | NewDatum, KeyType>): Selection<GElement, NewDatum, PElement, PDatum>;
785 /**
786 * Joins the data returned by the specified value function with the selected elements, returning a new selection that it represents
787 * the update selection: the elements successfully bound to data. Also defines the enter and exit selections on
788 * the returned selection, which can be used to add or remove elements to correspond to the new data.
789 *
790 * The data is specified for each group in the selection.
791 *
792 * If a key function is not specified, then the first datum in data is assigned to the first selected element,
793 * the second datum to the second selected element, and so on.
794 * A key function may be specified to control which datum is assigned to which element, replacing the default join-by-index,
795 * by computing a string identifier for each datum and element.
796 *
797 * The update and enter selections are returned in data order, while the exit selection preserves the selection
798 * order prior to the join. If a key function is specified, the order of elements in the selection may not match
799 * their order in the document; use selection.order or selection.sort as needed.
800 *
801 * This method cannot be used to clear bound data; use selection.datum instead.
802 *
803 * For details see: {@link https://github.com/d3/d3-selection#joining-data }
804 *
805 * The generic refers to the type of the new datum to be used for the selected elements.
806 *
807 * @param data A value function which will be evaluated for each group in order, being passed the groups parent datum
808 * (d, which may be undefined), the group index (i), and the selections parent nodes (nodes),
809 * with this as the groups parent element. The function returns an array or iterable of values for each group.
810 * @param key An optional key function which is evaluated for each selected element, in order, being passed the
811 * current datum (d), the current index (i), and the current group (nodes), with this as the current DOM element (nodes[i]); the returned string is the elements key.
812 * The key function is then also evaluated for each new datum in data, being passed the current datum (d),
813 * the current index (i), and the groups new data, with this as the groups parent DOM element (nodes[i]); the returned string is the datums key.
814 * The datum for a given key is assigned to the element with the matching key. If multiple elements have the same key,
815 * the duplicate elements are put into the exit selection; if multiple data have the same key, the duplicate data are put into the enter selection.
816 */
817 data<NewDatum>(data: ValueFn<PElement, PDatum, NewDatum[] | Iterable<NewDatum>>, key?: ValueFn<GElement | PElement, Datum | NewDatum, KeyType>): Selection<GElement, NewDatum, PElement, PDatum>;
818
819 /**
820 * Appends, removes and reorders elements as necessary to match the data that was previously bound by `selection.data`, returning the merged enter and update selection.
821 * This method is a convenient alternative to the more explicit `selection.enter`, `selection.exit`, `selection.append` and `selection.remove`.
822 *
823 * The "matching" logic is determined by the key function passed to `selection.data`.
824 */
825 join<K extends keyof ElementTagNameMap, OldDatum = Datum>(
826 enter: K,
827 update?: (elem: Selection<GElement, Datum, PElement, PDatum>) => Selection<GElement, Datum, PElement, PDatum> | undefined,
828 exit?: (elem: Selection<GElement, OldDatum, PElement, PDatum>) => void
829 ): Selection<GElement | ElementTagNameMap[K], Datum, PElement, PDatum>;
830 /**
831 * Appends, removes and reorders elements as necessary to match the data that was previously bound by `selection.data`, returning the merged enter and update selection.
832 * This method is a convenient alternative to the more explicit `selection.enter`, `selection.exit`, `selection.append` and `selection.remove`.
833 *
834 * The "matching" logic is determined by the key function passed to `selection.data`.
835 */
836 join<ChildElement extends BaseType, OldDatum = Datum>(
837 enter: string,
838 update?: (elem: Selection<GElement, Datum, PElement, PDatum>) => Selection<GElement, Datum, PElement, PDatum> | undefined,
839 exit?: (elem: Selection<GElement, OldDatum, PElement, PDatum>) => void
840 ): Selection<ChildElement | GElement, Datum, PElement, PDatum>;
841 /**
842 * Appends, removes and reorders elements as necessary to match the data that was previously bound by `selection.data`, returning the merged enter and update selection.
843 * This method is a convenient alternative to the more explicit `selection.enter`, `selection.exit`, `selection.append` and `selection.remove`.
844 *
845 * The "matching" logic is determined by the key function passed to `selection.data`.
846 */
847 join<ChildElement extends BaseType, OldDatum = Datum>(
848 enter: (elem: Selection<EnterElement, Datum, PElement, PDatum>) => Selection<ChildElement, Datum, PElement, PDatum>,
849 update?: (elem: Selection<GElement, Datum, PElement, PDatum>) => Selection<GElement, Datum, PElement, PDatum> | undefined,
850 exit?: (elem: Selection<GElement, OldDatum, PElement, PDatum>) => void
851 ): Selection<ChildElement | GElement, Datum, PElement, PDatum>;
852
853 /**
854 * Return the enter selection: placeholder nodes for each datum that had no corresponding DOM element
855 * in the selection. (The enter selection is empty for selections not returned by selection.data.)
856 */
857 enter(): Selection<EnterElement, Datum, PElement, PDatum>;
858
859 /**
860 * Returns the exit selection: existing DOM elements in the selection for which no new datum was found.
861 * (The exit selection is empty for selections not returned by selection.data.)
862 *
863 * IMPORTANT: The generic refers to the type of the old datum associated with the exit selection elements.
864 * Ensure you set the generic to the correct type, if you need to access the data on the exit selection in
865 * follow-up steps, e.g. to set styles as part of an exit transition before removing them.
866 */
867 exit<OldDatum>(): Selection<GElement, OldDatum, PElement, PDatum>;
868
869 /**
870 * Returns the bound datum for the first (non-null) element in the selection.
871 * This is generally useful only if you know the selection contains exactly one element.
872 */
873 datum(): Datum;
874 /**
875 * Delete the bound data for each element in the selection.
876 */
877 datum(value: null): Selection<GElement, undefined, PElement, PDatum>;
878 /**
879 * Sets the elements bound data using the specified value function on all selected elements.
880 * Unlike selection.data, this method does not compute a join and does not affect
881 * indexes or the enter and exit selections.
882 *
883 * The generic refers to the type of the new datum to be used for the selected elements.
884 *
885 * @param value A value function which is evaluated for each selected element, in order,
886 * being passed the current datum (d), the current index (i), and the current group (nodes),
887 * with this as the current DOM element (nodes[i]). The function is then used to set each elements new data.
888 * A null value will delete the bound data.
889 */
890 datum<NewDatum>(value: ValueFn<GElement, Datum, NewDatum>): Selection<GElement, NewDatum, PElement, PDatum>;
891 /**
892 * Sets the elements bound data to the specified value on all selected elements.
893 * Unlike selection.data, this method does not compute a join and does not affect
894 * indexes or the enter and exit selections.
895 *
896 * The generic refers to the type of the new datum to be used for the selected elements.
897 *
898 * @param value A value object to be used as the datum for each element.
899 */
900 datum<NewDatum>(value: NewDatum): Selection<GElement, NewDatum, PElement, PDatum>;
901
902 // Event Handling -------------------
903
904 /**
905 * Return the currently-assigned listener for the specified event typename on the first (non-null) selected element,
906 * if any, If multiple typenames are specified, the first matching listener is returned.
907 *
908 * @param typenames The typenames is a string event type, such as click, mouseover, or submit; any DOM event type supported by your browser may be used.
909 * The type may be optionally followed by a period (.) and a name; the optional name allows multiple callbacks to be registered
910 * to receive events of the same type, such as click.foo and click.bar. To specify multiple typenames, separate typenames with spaces,
911 * such as "input change"" or "click.foo click.bar".
912 */
913 on(typenames: string): ((this: GElement, event: any, d: Datum) => void) | undefined;
914 /**
915 * Remove a listener for the specified event type names. To remove all listeners for a given name,
916 * pass null as the listener and ".foo" as the typename, where foo is the name; to remove all listeners with no name, specify "." as the typename.
917 *
918 * @param typenames The typenames is a string event type, such as click, mouseover, or submit; any DOM event type supported by your browser may be used.
919 * The type may be optionally followed by a period (.) and a name; the optional name allows multiple callbacks to be registered
920 * to receive events of the same type, such as click.foo and click.bar. To specify multiple typenames, separate typenames with spaces,
921 * such as "input change"" or "click.foo click.bar".
922 * @param listener null to indicate removal of listener
923 */
924 on(typenames: string, listener: null): this;
925 /**
926 * Add an event listener for the specified event type names. If an event listener was previously registered for the same typename
927 * on a selected element, the old listener is removed before the new listener is added.
928 *
929 * When a specified event is dispatched on a selected node, the specified listener will be evaluated for each selected element.
930 *
931 * @param typenames The typenames is a string event type, such as click, mouseover, or submit; any DOM event type supported by your browser may be used.
932 * The type may be optionally followed by a period (.) and a name; the optional name allows multiple callbacks to be registered
933 * to receive events of the same type, such as click.foo and click.bar. To specify multiple typenames, separate typenames with spaces,
934 * such as "input change"" or "click.foo click.bar".
935 * @param listener A listener function which will be evaluated for each selected element,
936 * being passed the current event (event) and the current datum (d), with this as the current DOM element (event.currentTarget).
937 * Listeners always see the latest datum for their element.
938 * Note: while you can use event.pageX and event.pageY directly,
939 * it is often convenient to transform the event position to the local coordinate system of that element that received the event using d3.pointer.
940 * @param options An optional options object may specify characteristics about the event listener, such as wehether it is captures or passive; see element.addEventListener.
941 */
942 on(typenames: string, listener: (this: GElement, event: any, d: Datum) => void, options?: any): this;
943
944 /**
945 * Dispatches a custom event of the specified type to each selected element, in order.
946 * An optional parameters map may be specified to set additional properties of the event.
947 *
948 * @param type Name of event to dispatch
949 * @param parameters An optional value map with custom event parameters
950 */
951 dispatch(type: string, parameters?: CustomEventParameters): this;
952 /**
953 * Dispatches a custom event of the specified type to each selected element, in order.
954 * An optional value function returning a parameters map for each element in the selection may be specified to set additional properties of the event.
955 *
956 * @param type Name of event to dispatch
957 * @param parameters A value function which is evaluated for each selected element, in order,
958 * being passed the current datum (d), the current index (i), and the current group (nodes),
959 * with this as the current DOM element (nodes[i]). It must return the parameters map for the current element.
960 */
961 dispatch(type: string, parameters?: ValueFn<GElement, Datum, CustomEventParameters>): this;
962
963 // Control Flow ----------------------
964
965 /**
966 * Invoke the specified function for each selected element, passing in the current datum (d),
967 * the current index (i), and the current group (nodes), with this of the current DOM element (nodes[i]).
968 * 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.
969 *
970 * @param func A function which is invoked for each selected element,
971 * being passed the current datum (d), the current index (i), and the current group (nodes), with this of the current DOM element (nodes[i]).
972 */
973 each(func: ValueFn<GElement, Datum, void>): this;
974
975 /**
976 * Invoke the specified function exactly once, passing in this selection along with any optional arguments.
977 * Returns this selection.
978 *
979 * @param func A function which is passed this selection as the first argument along with any optional arguments.
980 * @param args List of optional arguments to be passed to the callback function.
981 */
982 call(func: (selection: Selection<GElement, Datum, PElement, PDatum>, ...args: any[]) => void, ...args: any[]): this;
983
984 /**
985 * Return true if this selection contains no (non-null) elements.
986 */
987 empty(): boolean;
988
989 /**
990 * Return an array of all (non-null) elements in this selection.
991 */
992 nodes(): GElement[];
993
994 /**
995 * Return the first (non-null) element in this selection. If the selection is empty, returns null.
996 */
997 node(): GElement | null;
998
999 /**
1000 * Returns the total number of elements in this selection.
1001 */
1002 size(): number;
1003
1004 /**
1005 * Returns an iterator over the selected (non-null) elements.
1006 */
1007 [Symbol.iterator](): Iterator<GElement>;
1008}
1009
1010/**
1011 * Selects the root element, document.documentElement. This function can also be used to test for selections
1012 * (instanceof d3.selection) or to extend the selection prototype.
1013 */
1014export type SelectionFn = () => Selection<HTMLElement, any, null, undefined>;
1015
1016/**
1017 * Selects the root element, document.documentElement. This function can also be used to test for selections
1018 * (instanceof d3.selection) or to extend the selection prototype.
1019 */
1020export const selection: SelectionFn;
1021
1022// ---------------------------------------------------------------------------
1023// pointer.js and pointers.js related
1024// ---------------------------------------------------------------------------
1025
1026/**
1027 * Returns a two-element array of numbers [x, y] representing the coordinates of the specified event relative to the specified target.
1028 * event can be a MouseEvent, a PointerEvent, a Touch, or a custom event holding a UIEvent as event.sourceEvent.
1029 *
1030 * If target is not specified, it defaults to the source event’s currentTarget property, if available.
1031 * If the target is an SVG element, the event’s coordinates are transformed using the inverse of the screen coordinate transformation matrix.
1032 * If the target is an HTML element, the event’s coordinates are translated relative to the top-left corner of the target’s bounding client rectangle.
1033 * (As such, the coordinate system can only be translated relative to the client coordinates. See also GeometryUtils.)
1034 * Otherwise, [event.pageX, event.pageY] is returned.
1035 *
1036 * @param event The specified event.
1037 * @param target The target which the coordinates are relative to.
1038 */
1039export function pointer(event: any, target?: any): [number, number];
1040
1041/**
1042 * Returns an array [[x0, y0], [x1, y1]…] of coordinates of the specified event’s pointer locations relative to the specified target.
1043 * For touch events, the returned array of positions corresponds to the event.touches array; for other events, returns a single-element array.
1044 *
1045 * If target is not specified, it defaults to the source event’s currentTarget property, if any.
1046 *
1047 * @param event The specified event.
1048 * @param target The target which the coordinates are relative to.
1049 */
1050export function pointers(event: any, target?: any): Array<[number, number]>;
1051
1052// ---------------------------------------------------------------------------
1053// style
1054// ---------------------------------------------------------------------------
1055
1056/**
1057 * Returns the value of the style property with the specified name for the specified node.
1058 * If the node has an inline style with the specified name, its value is returned; otherwise, the computed property value is returned.
1059 * See also selection.style.
1060 *
1061 * @param node A DOM node (e.g. HTMLElement, SVGElement) for which to retrieve the style property.
1062 * @param name Style property name.
1063 */
1064export function style(node: Element, name: string): string;
1065
1066// ---------------------------------------------------------------------------
1067// local.js related
1068// ---------------------------------------------------------------------------
1069
1070export interface Local<T> {
1071 /**
1072 * Retrieves a local variable stored on the node (or one of its parents).
1073 *
1074 * @param node A node element.
1075 */
1076 get(node: Element): T | undefined;
1077 /**
1078 * Deletes the value associated with the given node. Values stored on ancestors are not affected, meaning that child nodes will still see inherited values.
1079 *
1080 * This function returns true if there was a value stored directly on the node, and false otherwise.
1081 *
1082 * @param node A node element.
1083 */
1084 remove(node: Element): boolean;
1085 /**
1086 * Store a value for this local variable. Calling `.get()` on children of this node will also retrieve the variable's value.
1087 *
1088 * @param node A node element.
1089 * @param value Value to store locally
1090 */
1091 set(node: Element, value: T): Element;
1092 /**
1093 * Obtain a string with the internally assigned property name for the local
1094 * which is used to store the value on a node
1095 */
1096 toString(): string;
1097}
1098
1099/**
1100 * Obtain a new local variable
1101 *
1102 * The generic refers to the type of the variable to store locally.
1103 */
1104export function local<T>(): Local<T>;
1105
1106// ---------------------------------------------------------------------------
1107// namespace.js related
1108// ---------------------------------------------------------------------------
1109
1110/**
1111 * Interface for object literal containing local name with related fully qualified namespace
1112 */
1113export interface NamespaceLocalObject {
1114 /**
1115 * Fully qualified namespace
1116 */
1117 space: string;
1118 /**
1119 * Name of the local to be namespaced.
1120 */
1121 local: string;
1122}
1123
1124/**
1125 * Obtain an object with properties of fully qualified namespace string and
1126 * name of local by parsing a shorthand string "prefix:local". If the prefix
1127 * does not exist in the "namespaces" object provided by d3-selection, then
1128 * the local name is returned as a simple string.
1129 *
1130 * @param prefixedLocal A string composed of the namespace prefix and local
1131 * name separated by colon, e.g. "svg:text".
1132 */
1133export function namespace(prefixedLocal: string): NamespaceLocalObject | string;
1134
1135// ---------------------------------------------------------------------------
1136// namespaces.js related
1137// ---------------------------------------------------------------------------
1138
1139/**
1140 * Interface for maps of namespace prefixes to corresponding fully qualified namespace strings
1141 */
1142export interface NamespaceMap { [prefix: string]: string; }
1143
1144/**
1145 * Map of namespace prefixes to corresponding fully qualified namespace strings
1146 */
1147export const namespaces: NamespaceMap;
1148
1149// ---------------------------------------------------------------------------
1150// window.js related
1151// ---------------------------------------------------------------------------
1152
1153/**
1154 * Returns the owner window for the specified node. If node is a node, returns the owner document’s default view;
1155 * if node is a document, returns its default view; otherwise returns the node.
1156 *
1157 * @param DOMNode A DOM element
1158 */
1159export function window(DOMNode: Window | Document | Element): Window;
1160
1161// ---------------------------------------------------------------------------
1162// creator.js and matcher.js Complex helper closure generating functions
1163// for explicit bound-context dependent use
1164// ---------------------------------------------------------------------------
1165
1166/**
1167 * Given the specified element name, returns a single-element selection containing
1168 * a detached element of the given name in the current document.
1169 *
1170 * @param name tag name of the element to be added.
1171 */
1172export function create<K extends keyof ElementTagNameMap>(name: K): Selection<ElementTagNameMap[K], undefined, null, undefined>;
1173/**
1174 * Given the specified element name, returns a single-element selection containing
1175 * a detached element of the given name in the current document.
1176 *
1177 * @param name Tag name of the element to be added. See "namespace" for details on supported namespace prefixes,
1178 * such as for SVG elements.
1179 */
1180export function create<NewGElement extends Element>(name: string): Selection<NewGElement, undefined, null, undefined>;
1181
1182/**
1183 * Given the specified element name, returns a function which creates an element of the given name,
1184 * assuming that "this" is the parent element.
1185 *
1186 * @param name Tag name of the element to be added.
1187 */
1188export function creator<K extends keyof ElementTagNameMap>(name: K): (this: BaseType) => ElementTagNameMap[K];
1189/**
1190 * Given the specified element name, returns a function which creates an element of the given name,
1191 * assuming that "this" is the parent element.
1192 *
1193 * The generic refers to the type of the new element to be returned by the creator function.
1194 *
1195 * @param name Tag name of the element to be added. See "namespace" for details on supported namespace prefixes,
1196 * such as for SVG elements.
1197 */
1198export function creator<NewGElement extends Element>(name: string): (this: BaseType) => NewGElement;
1199
1200/**
1201 * Given the specified selector, returns a function which returns true if "this" element matches the specified selector.
1202 *
1203 * @param selector A CSS selector string.
1204 */
1205export function matcher(selector: string): (this: BaseType) => boolean;
1206
1207// ----------------------------------------------------------------------------
1208// selector.js and selectorAll.js related functions
1209// ----------------------------------------------------------------------------
1210
1211/**
1212 * Given the specified selector, returns a function which returns the first descendant of "this" element
1213 * that matches the specified selector.
1214 *
1215 * The generic refers to the type of the returned descendant element.
1216 *
1217 * @param selector A CSS selector string.
1218 */
1219export function selector<DescElement extends Element>(selector: string): (this: BaseType) => DescElement;
1220
1221/**
1222 * Given the specified selector, returns a function which returns all descendants of "this" element that match the specified selector.
1223 *
1224 * The generic refers to the type of the returned descendant element.
1225 *
1226 * @param selector A CSS selector string.
1227 */
1228export function selectorAll<DescElement extends Element>(selector: string): (this: BaseType) => NodeListOf<DescElement>;