1 |
|
2 |
|
3 |
|
4 |
|
5 |
|
6 |
|
7 |
|
8 |
|
9 |
|
10 |
|
11 |
|
12 |
|
13 |
|
14 |
|
15 |
|
16 |
|
17 |
|
18 |
|
19 |
|
20 |
|
21 |
|
22 | export type BaseType = Element | EnterElement | Document | Window | null;
|
23 |
|
24 |
|
25 |
|
26 |
|
27 | export type KeyType = string | number;
|
28 |
|
29 |
|
30 |
|
31 |
|
32 |
|
33 | export interface ArrayLike<T> {
|
34 | length: number;
|
35 | item(index: number): T | null;
|
36 | [index: number]: T;
|
37 | }
|
38 |
|
39 |
|
40 |
|
41 |
|
42 |
|
43 | export 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 |
|
54 |
|
55 | export type ContainerElement = HTMLElement | SVGSVGElement | SVGGElement;
|
56 |
|
57 |
|
58 |
|
59 |
|
60 | export interface ClientPointEvent {
|
61 | clientX: number;
|
62 | clientY: number;
|
63 | }
|
64 |
|
65 |
|
66 |
|
67 |
|
68 |
|
69 | export interface CustomEventParameters {
|
70 | |
71 |
|
72 |
|
73 | bubbles: boolean;
|
74 | |
75 |
|
76 |
|
77 | cancelable: boolean;
|
78 | |
79 |
|
80 |
|
81 | detail: any;
|
82 | }
|
83 |
|
84 |
|
85 |
|
86 |
|
87 | export type ValueFn<T extends BaseType, Datum, Result> = (this: T, datum: Datum, index: number, groups: T[] | ArrayLike<T>) => Result;
|
88 |
|
89 |
|
90 |
|
91 |
|
92 |
|
93 |
|
94 |
|
95 |
|
96 |
|
97 |
|
98 |
|
99 | export 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 | */
|
120 | export 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 | */
|
129 | export function select<GElement extends BaseType, OldDatum>(node: GElement): Selection<GElement, OldDatum, null, undefined>;
|
130 |
|
131 | /**
|
132 | * Create an empty selection.
|
133 | */
|
134 | export function selectAll(): Selection<null, undefined, null, undefined>;
|
135 | /**
|
136 | * Create an empty selection.
|
137 | */
|
138 | export function selectAll(selector: null): Selection<null, undefined, null, undefined>;
|
139 | /**
|
140 | * Create an empty selection.
|
141 | */
|
142 | export 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 | */
|
152 | export 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 | */
|
163 | export 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 | */
|
173 | export 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 selection’s element
|
322 | * is returned in the merge and the other selection’s 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 child’s 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 child’s 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 function’s 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 element’s 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 field’s text value and a checkbox’s 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 function’s return value is then used to set each element’s 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 function’s return value is then used to set each element’s 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 browser’s built-in sort method on arrays.
|
723 | *
|
724 | * @param comparator An optional comparator function, which defaults to "ascending". The function is passed
|
725 | * two elements’ data 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 element’s 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 group’s new data, with this as the group’s parent DOM element (nodes[i]); the returned string is the datum’s 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 group’s parent datum
|
808 | * (d, which may be undefined), the group index (i), and the selection’s parent nodes (nodes),
|
809 | * with this as the group’s 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 element’s 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 group’s new data, with this as the group’s parent DOM element (nodes[i]); the returned string is the datum’s 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 element’s 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 element’s 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 element’s 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 | */
|
1014 | export type SelectionFn = () => Selection<HTMLElement, any, null, undefined>;
|
1015 |
|
1016 |
|
1017 |
|
1018 |
|
1019 |
|
1020 | export const selection: SelectionFn;
|
1021 |
|
1022 |
|
1023 |
|
1024 |
|
1025 |
|
1026 |
|
1027 |
|
1028 |
|
1029 |
|
1030 |
|
1031 |
|
1032 |
|
1033 |
|
1034 |
|
1035 |
|
1036 |
|
1037 |
|
1038 |
|
1039 | export function pointer(event: any, target?: any): [number, number];
|
1040 |
|
1041 |
|
1042 |
|
1043 |
|
1044 |
|
1045 |
|
1046 |
|
1047 |
|
1048 |
|
1049 |
|
1050 | export function pointers(event: any, target?: any): Array<[number, number]>;
|
1051 |
|
1052 |
|
1053 |
|
1054 |
|
1055 |
|
1056 |
|
1057 |
|
1058 |
|
1059 |
|
1060 |
|
1061 |
|
1062 |
|
1063 |
|
1064 | export function style(node: Element, name: string): string;
|
1065 |
|
1066 |
|
1067 |
|
1068 |
|
1069 |
|
1070 | export interface Local<T> {
|
1071 | |
1072 |
|
1073 |
|
1074 |
|
1075 |
|
1076 | get(node: Element): T | undefined;
|
1077 | |
1078 |
|
1079 |
|
1080 |
|
1081 |
|
1082 |
|
1083 |
|
1084 | remove(node: Element): boolean;
|
1085 | |
1086 |
|
1087 |
|
1088 |
|
1089 |
|
1090 |
|
1091 | set(node: Element, value: T): Element;
|
1092 | |
1093 |
|
1094 |
|
1095 |
|
1096 | toString(): string;
|
1097 | }
|
1098 |
|
1099 |
|
1100 |
|
1101 |
|
1102 |
|
1103 |
|
1104 | export function local<T>(): Local<T>;
|
1105 |
|
1106 |
|
1107 |
|
1108 |
|
1109 |
|
1110 |
|
1111 |
|
1112 |
|
1113 | export interface NamespaceLocalObject {
|
1114 | |
1115 |
|
1116 |
|
1117 | space: string;
|
1118 | |
1119 |
|
1120 |
|
1121 | local: string;
|
1122 | }
|
1123 |
|
1124 |
|
1125 |
|
1126 |
|
1127 |
|
1128 |
|
1129 |
|
1130 |
|
1131 |
|
1132 |
|
1133 | export function namespace(prefixedLocal: string): NamespaceLocalObject | string;
|
1134 |
|
1135 |
|
1136 |
|
1137 |
|
1138 |
|
1139 |
|
1140 |
|
1141 |
|
1142 | export interface NamespaceMap { [prefix: string]: string; }
|
1143 |
|
1144 |
|
1145 |
|
1146 |
|
1147 | export const namespaces: NamespaceMap;
|
1148 |
|
1149 |
|
1150 |
|
1151 |
|
1152 |
|
1153 |
|
1154 |
|
1155 |
|
1156 |
|
1157 |
|
1158 |
|
1159 | export function window(DOMNode: Window | Document | Element): Window;
|
1160 |
|
1161 |
|
1162 |
|
1163 |
|
1164 |
|
1165 |
|
1166 |
|
1167 |
|
1168 |
|
1169 |
|
1170 |
|
1171 |
|
1172 | export function create<K extends keyof ElementTagNameMap>(name: K): Selection<ElementTagNameMap[K], undefined, null, undefined>;
|
1173 |
|
1174 |
|
1175 |
|
1176 |
|
1177 |
|
1178 |
|
1179 |
|
1180 | export function create<NewGElement extends Element>(name: string): Selection<NewGElement, undefined, null, undefined>;
|
1181 |
|
1182 |
|
1183 |
|
1184 |
|
1185 |
|
1186 |
|
1187 |
|
1188 | export function creator<K extends keyof ElementTagNameMap>(name: K): (this: BaseType) => ElementTagNameMap[K];
|
1189 |
|
1190 |
|
1191 |
|
1192 |
|
1193 |
|
1194 |
|
1195 |
|
1196 |
|
1197 |
|
1198 | export function creator<NewGElement extends Element>(name: string): (this: BaseType) => NewGElement;
|
1199 |
|
1200 |
|
1201 |
|
1202 |
|
1203 |
|
1204 |
|
1205 | export function matcher(selector: string): (this: BaseType) => boolean;
|
1206 |
|
1207 |
|
1208 |
|
1209 |
|
1210 |
|
1211 |
|
1212 |
|
1213 |
|
1214 |
|
1215 |
|
1216 |
|
1217 |
|
1218 |
|
1219 | export function selector<DescElement extends Element>(selector: string): (this: BaseType) => DescElement;
|
1220 |
|
1221 |
|
1222 |
|
1223 |
|
1224 |
|
1225 |
|
1226 |
|
1227 |
|
1228 | export function selectorAll<DescElement extends Element>(selector: string): (this: BaseType) => NodeListOf<DescElement>;
|