forked from DefinitelyTyped/DefinitelyTyped
-
Notifications
You must be signed in to change notification settings - Fork 0
/
d3.d.ts
3318 lines (2567 loc) · 127 KB
/
d3.d.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
// Type definitions for d3JS
// Project: http://d3js.org/
// Definitions by: Alex Ford <https://github.com/gustavderdrache>, Boris Yankov <https://github.com/borisyankov>
// Definitions: https://github.com/borisyankov/DefinitelyTyped
declare module d3 {
/**
* The current version of D3.js.
*/
export var version: string;
/**
* Find the first element that matches the given selector string.
*/
export function select(selector: string): Selection<any>;
/**
* Create a selection from the given node reference.
*/
export function select(node: EventTarget): Selection<any>;
/**
* Find all elements that match the given selector string.
*/
export function selectAll(selector: string): Selection<any>;
/**
* Create a selection from the given list of nodes.
*/
export function selectAll(nodes: EventTarget[]): Selection<any>;
/**
* Returns the root selection (as if by d3.select(document.documentElement)). This function may be used for 'instanceof' tests, and extending its prototype will add properties to all selections.
*/
export function selection(): Selection<any>;
module selection {
export var prototype: Selection<any>;
/**
* Selections are grouped into arrays of nodes, with the parent tracked in the 'parentNode' property.
*/
interface Group extends Array<EventTarget> {
parentNode: EventTarget;
}
interface Update<Datum> {
/**
* Retrieve a grouped selection.
*/
[index: number]: Group;
/**
* The number of groups in this selection.
*/
length: number;
/**
* Retrieve the value of the given attribute for the first node in the selection.
*
* @param name The attribute name to query. May be prefixed (see d3.ns.prefix).
*/
attr(name: string): string;
/**
* For all nodes, set the attribute to the specified constant value. Use null to remove.
*
* @param name The attribute name, optionally prefixed.
* @param value The attribute value to use. Note that this is coerced to a string automatically.
*/
attr(name: string, value: Primitive): Update<Datum>;
/**
* Derive an attribute value for each node in the selection based on bound data.
*
* @param name The attribute name, optionally prefixed.
* @param value The function of the datum (the bound data item), index (the position in the subgrouping), and outer index (overall position in nested selections) which computes the attribute value. If the function returns null, the attribute is removed.
*/
attr(name: string, value: (datum: Datum, index: number, outerIndex: number) => Primitive): Update<Datum>;
/**
* Set multiple properties at once using an Object. D3 iterates over all enumerable properties and either sets or computes the attribute's value based on the corresponding entry in the Object.
*
* @param obj A key-value mapping corresponding to attributes and values. If the value is a simple string or number, it is taken as a constant. Otherwise, it is a function that derives the attribute value.
*/
attr(obj: { [key: string]: Primitive | ((datum: Datum, index: number, outerIndex: number) => Primitive) }): Update<Datum>;
/**
* Returns true if the first node in this selection has the given class list. If multiple classes are specified (i.e., "foo bar"), then returns true only if all classes match.
*
* @param name The class list to query.
*/
classed(name: string): boolean;
/**
* Adds (or removes) the given class list.
*
* @param name The class list to toggle. Spaces separate class names: "foo bar" is a list of two classes.
* @param value If true, add the classes. If false, remove them.
*/
classed(name: string, value: boolean): Update<Datum>;
/**
* Determine if the given class list should be toggled for each node in the selection.
*
* @param name The class list. Spaces separate multiple class names.
* @param value The function to run for each node. Should return true to add the class to the node, or false to remove it.
*/
classed(name: string, value: (datum: Datum, index: number, outerIndex: number) => boolean): Update<Datum>;
/**
* Set or derive classes for multiple class lists at once.
*
* @param obj An Object mapping class lists to values that are either plain booleans or functions that return booleans.
*/
classed(obj: { [key: string]: boolean | ((datum: Datum, index: number, outerIndex: number) => boolean) }): Update<Datum>;
/**
* Retrieve the computed style value for the first node in the selection.
* @param name The CSS property name to query
*/
style(name: string): string;
/**
* Set a style property for all nodes in the selection.
* @param name the CSS property name
* @param value the property value
* @param priority if specified, either null or the string "important" (no exclamation mark)
*/
style(name: string, value: Primitive, priority?: string): Update<Datum>;
/**
* Derive a property value for each node in the selection.
* @param name the CSS property name
* @param value the function to derive the value
* @param priority if specified, either null or the string "important" (no exclamation mark)
*/
style(name: string, value: (datum: Datum, index: number, outerIndex: number) => Primitive, priority?: string): Update<Datum>;
/**
* Set a large number of CSS properties from an object.
*
* @param obj an Object whose keys correspond to CSS property names and values are either constants or functions that derive property values
* @param priority if specified, either null or the string "important" (no exclamation mark)
*/
style(obj: { [key: string]: Primitive | ((datum: Datum, index: number, outerIndex: number) => Primitive) }, priority?: string): Update<Datum>;
/**
* Retrieve an arbitrary node property such as the 'checked' property of checkboxes, or the 'value' of text boxes.
*
* @param name the node's property to retrieve
*/
property(name: string): any;
/**
* For each node, set the property value. Internally, this sets the node property directly (e.g., node[name] = value), so take care not to mutate special properties like __proto__.
*
* @param name the property name
* @param value the property value
*/
property(name: string, value: any): Update<Datum>;
/**
* For each node, derive the property value. Internally, this sets the node property directly (e.g., node[name] = value), so take care not to mutate special properties like __proto__.
*
* @param name the property name
* @param value the function used to derive the property's value
*/
property(name: string, value: (datum: Datum, index: number, outerIndex: number) => any): Update<Datum>;
/**
* Set multiple node properties. Caveats apply: take care not to mutate special properties like __proto__.
*
* @param obj an Object whose keys correspond to node properties and values are either constants or functions that will compute a value.
*/
property(obj: { [key: string]: any | ((datum: Datum, index: number, outerIndex: number) => any) }): Update<Datum>;
/**
* Retrieve the textContent of the first node in the selection.
*/
text(): string;
/**
* Set the textContent of each node in the selection.
* @param value the text to use for all nodes
*/
text(value: Primitive): Update<Datum>;
/**
* Compute the textContent of each node in the selection.
* @param value the function which will compute the text
*/
text(value: (datum: Datum, index: number, outerIndex: number) => Primitive): Update<Datum>;
/**
* Retrieve the HTML content of the first node in the selection. Uses 'innerHTML' internally and will not work with SVG or other elements without a polyfill.
*/
html(): string;
/**
* Set the HTML content of every node in the selection. Uses 'innerHTML' internally and thus will not work with SVG or other elements without a polyfill.
* @param value the HTML content to use.
*/
html(value: string): Selection<Datum>;
/**
* Compute the HTML content for each node in the selection. Uses 'innerHTML' internally and thus will not work with SVG or other elements without a polyfill.
* @param value the function to compute HTML content
*/
html(value: (datum: Datum, index: number, outerIndex: number) => string): Selection<Datum>;
/**
* Appends a new child to each node in the selection. This child will inherit the parent's data (if available). Returns a fresh selection consisting of the newly-appended children.
*
* @param name the element name to append. May be prefixed (see d3.ns.prefix).
*/
append(name: string): Selection<Datum>;
/**
* Appends a new child to each node in the selection by computing a new node. This child will inherit the parent's data (if available). Returns a fresh selection consisting of the newly-appended children.
*
* @param name the function to compute a new element
*/
append(name: (datum: Datum, index: number, outerIndex: number) => EventTarget): Update<Datum>;
/**
* Inserts a new child to each node in the selection. This child will inherit its parent's data (if available). Returns a fresh selection consisting of the newly-inserted children.
* @param name the element name to append. May be prefixed (see d3.ns.prefix).
* @param before the selector to determine position (e.g., ":first-child")
*/
insert(name: string, before: string): Update<Datum>;
/**
* Inserts a new child to each node in the selection. This child will inherit its parent's data (if available). Returns a fresh selection consisting of the newly-inserted children.
* @param name the element name to append. May be prefixed (see d3.ns.prefix).
* @param before a function to determine the node to use as the next sibling
*/
insert(name: string, before: (datum: Datum, index: number, outerIndex: number) => EventTarget): Update<Datum>;
/**
* Inserts a new child to the end of each node in the selection by computing a new node. This child will inherit its parent's data (if available). Returns a fresh selection consisting of the newly-inserted children.
* @param name the function to compute a new child
* @param before the selector to determine position (e.g., ":first-child")
*/
insert(name: (datum: Datum, index: number, outerIndex: number) => EventTarget, before: string): Update<Datum>;
/**
* Inserts a new child to the end of each node in the selection by computing a new node. This child will inherit its parent's data (if available). Returns a fresh selection consisting of the newly-inserted children.
* @param name the function to compute a new child
* @param before a function to determine the node to use as the next sibling
*/
insert(name: (datum: Datum, index: number, outerIndex: number) => EventTarget, before: (datum: Datum, index: number, outerIndex: number) => EventTarget): Update<Datum>;
/**
* Removes the elements from the DOM. They are in a detached state and may be re-added (though there is currently no dedicated API for doing so).
*/
remove(): Update<Datum>;
/**
* Retrieves the data bound to the first group in this selection.
*/
data(): Datum[];
/**
* Binds data to this selection.
* @param data the array of data to bind to this selection
* @param key the optional function to determine the unique key for each piece of data. When unspecified, uses the index of the element.
*/
data<NewDatum>(data: NewDatum[], key?: (datum: NewDatum, index: number, outerIndex: number) => string): Update<NewDatum>;
/**
* Derives data to bind to this selection.
* @param data the function to derive data. Must return an array.
* @param key the optional function to determine the unique key for each data item. When unspecified, uses the index of the element.
*/
data<NewDatum>(data: (datum: Datum, index: number, outerIndex: number) => NewDatum[], key?: (datum: NewDatum, index: number, outerIndex: number) => string): Update<NewDatum>;
/**
* Filters the selection, returning only those nodes that match the given CSS selector.
* @param selector the CSS selector
*/
filter(selector: string): Update<Datum>;
/**
* Filters the selection, returning only those nodes for which the given function returned true.
* @param selector the filter function
*/
filter(selector: (datum: Datum, index: number, outerIndex: number) => boolean): Update<Datum>;
/**
* Return the data item bound to the first element in the selection.
*/
datum(): Datum;
/**
* Set the data item for each node in the selection.
* @param value the constant element to use for each node
*/
datum<NewDatum>(value: NewDatum): Update<NewDatum>;
/**
* Derive the data item for each node in the selection. Useful for situations such as the HTML5 'dataset' attribute.
* @param value the function to compute data for each node
*/
datum<NewDatum>(value: (datum: Datum, index: number, outerIndex: number) => NewDatum): Update<NewDatum>;
/**
* Reorders nodes in the selection based on the given comparator. Nodes are re-inserted into the document once sorted.
* @param comparator the comparison function, which defaults to d3.ascending
*/
sort(comparator?: (a: Datum, b: Datum) => number): Update<Datum>;
/**
* Reorders nodes in the document to match the selection order. More efficient than calling sort() if the selection is already ordered.
*/
order(): Update<Datum>;
/**
* Returns the listener (if any) for the given event.
* @param type the type of event to load the listener for. May have a namespace (e.g., ".foo") at the end.
*/
on(type: string): (datum: Datum, index: number, outerIndex: number) => any;
/**
* Adds a listener for the specified event. If one was already registered, it is removed before the new listener is added. The return value of the listener function is ignored.
* @param type the of event to listen to. May have a namespace (e.g., ".foo") at the end.
* @param listener an event listener function, or null to unregister
* @param capture sets the DOM useCapture flag
*/
on(type: string, listener: (datum: Datum, index: number, outerIndex: number) => any, capture?: boolean): Update<Datum>;
/**
* Begins a new transition. Interrupts any active transitions of the same name.
* @param name the transition name (defaults to "")
*/
transition(name?: string): Transition<Datum>;
/**
* Interrupts the active transition of the provided name. Does not cancel scheduled transitions.
* @param name the transition name (defaults to "")
*/
interrupt(name?: string): Update<Datum>;
/**
* Creates a subselection by finding the first descendent matching the selector string. Bound data is inherited.
* @param selector the CSS selector to match against
*/
select(selector: string): Update<Datum>;
/**
* Creates a subselection by using a function to find descendent elements. Bound data is inherited.
* @param selector the function to find matching descendants
*/
select(selector: (datum: Datum, index: number, outerIndex: number) => EventTarget): Update<Datum>;
/**
* Creates a subselection by finding all descendents that match the given selector. Bound data is not inherited.
* @param selector the CSS selector to match against
*/
selectAll(selector: string): Update<Datum>;
/**
* Creates a subselection by using a function to find descendent elements. Bound data is not inherited.
* @param selector the function to find matching descendents
*/
selectAll(selector: (datum: Datum, index: number, outerIndex: number) => Array<EventTarget> | NodeList): Update<any>;
/**
* Invoke the given function for each element in the selection. The return value of the function is ignored.
* @param func the function to invoke
*/
each(func: (datum: Datum, index: number, outerIndex: number) => any): Update<Datum>;
/**
* Call a function on the selection. sel.call(foo) is equivalent to foo(sel).
* @param func the function to call on the selection
* @param args any optional args
*/
call(func: (sel: Update<Datum>, ...args: any[]) => any, ...args: any[]): Update<Datum>;
/**
* Returns true if the current selection is empty.
*/
empty(): boolean;
/**
* Returns the first non-null element in the selection, or null otherwise.
*/
node(): Node;
/**
* Returns the total number of elements in the selection.
*/
size(): number;
/**
* Returns the placeholder nodes for each data element for which no corresponding DOM element was found.
*/
enter(): Enter<Datum>;
/**
* Returns a selection for those DOM nodes for which no new data element was found.
*/
exit(): Selection<Datum>;
}
interface Enter<Datum> {
append(name: string): Selection<Datum>;
append(name: (datum: Datum, index: number, outerIndex: number) => EventTarget): Selection<Datum>;
insert(name: string, before?: string): Selection<Datum>;
insert(name: string, before: (datum: Datum, index: number, outerIndex: number) => EventTarget): Selection<Datum>;
insert(name: (datum: Datum, index: number, outerIndex: number) => EventTarget, before?: string): Selection<Datum>;
insert(name: (datum: Datum, index: number, outerIndex: number) => EventTarget, before: (datum: Datum, index: number, outerIndex: number) => EventTarget): Selection<Datum>;
select(name: (datum: Datum, index: number, outerIndex: number) => EventTarget): Selection<Datum>;
call(func: (selection: Enter<Datum>, ...args: any[]) => any, ...args: any[]): Enter<Datum>;
}
}
/**
* Administrivia: JavaScript primitive types, or "things that toString() predictably".
*/
export type Primitive = number | string | boolean;
/**
* Administrivia: anything with a valueOf(): number method is comparable, so we allow it in numeric operations
*/
interface Numeric {
valueOf(): number;
}
/**
* A grouped array of nodes.
* @param Datum the data bound to this selection.
*/
interface Selection<Datum> {
/**
* Retrieve a grouped selection.
*/
[index: number]: selection.Group;
/**
* The number of groups in this selection.
*/
length: number;
/**
* Retrieve the value of the given attribute for the first node in the selection.
*
* @param name The attribute name to query. May be prefixed (see d3.ns.prefix).
*/
attr(name: string): string;
/**
* For all nodes, set the attribute to the specified constant value. Use null to remove.
*
* @param name The attribute name, optionally prefixed.
* @param value The attribute value to use. Note that this is coerced to a string automatically.
*/
attr(name: string, value: Primitive): Selection<Datum>;
/**
* Derive an attribute value for each node in the selection based on bound data.
*
* @param name The attribute name, optionally prefixed.
* @param value The function of the datum (the bound data item), index (the position in the subgrouping), and outer index (overall position in nested selections) which computes the attribute value. If the function returns null, the attribute is removed.
*/
attr(name: string, value: (datum: Datum, index: number, outerIndex: number) => Primitive): Selection<Datum>;
/**
* Set multiple properties at once using an Object. D3 iterates over all enumerable properties and either sets or computes the attribute's value based on the corresponding entry in the Object.
*
* @param obj A key-value mapping corresponding to attributes and values. If the value is a simple string or number, it is taken as a constant. Otherwise, it is a function that derives the attribute value.
*/
attr(obj: { [key: string]: Primitive | ((datum: Datum, index: number, outerIndex: number) => Primitive) }): Selection<Datum>;
/**
* Returns true if the first node in this selection has the given class list. If multiple classes are specified (i.e., "foo bar"), then returns true only if all classes match.
*
* @param name The class list to query.
*/
classed(name: string): boolean;
/**
* Adds (or removes) the given class list.
*
* @param name The class list to toggle. Spaces separate class names: "foo bar" is a list of two classes.
* @param value If true, add the classes. If false, remove them.
*/
classed(name: string, value: boolean): Selection<Datum>;
/**
* Determine if the given class list should be toggled for each node in the selection.
*
* @param name The class list. Spaces separate multiple class names.
* @param value The function to run for each node. Should return true to add the class to the node, or false to remove it.
*/
classed(name: string, value: (datum: Datum, index: number, outerIndex: number) => boolean): Selection<Datum>;
/**
* Set or derive classes for multiple class lists at once.
*
* @param obj An Object mapping class lists to values that are either plain booleans or functions that return booleans.
*/
classed(obj: { [key: string]: boolean | ((datum: Datum, index: number, outerIndex: number) => boolean) }): Selection<Datum>;
/**
* Retrieve the computed style value for the first node in the selection.
* @param name The CSS property name to query
*/
style(name: string): string;
/**
* Set a style property for all nodes in the selection.
* @param name the CSS property name
* @param value the property value
* @param priority if specified, either null or the string "important" (no exclamation mark)
*/
style(name: string, value: Primitive, priority?: string): Selection<Datum>;
/**
* Derive a property value for each node in the selection.
* @param name the CSS property name
* @param value the function to derive the value
* @param priority if specified, either null or the string "important" (no exclamation mark)
*/
style(name: string, value: (datum: Datum, index: number, outerIndex: number) => Primitive, priority?: string): Selection<Datum>;
/**
* Set a large number of CSS properties from an object.
*
* @param obj an Object whose keys correspond to CSS property names and values are either constants or functions that derive property values
* @param priority if specified, either null or the string "important" (no exclamation mark)
*/
style(obj: { [key: string]: Primitive | ((datum: Datum, index: number, outerIndex: number) => Primitive) }, priority?: string): Selection<Datum>;
/**
* Retrieve an arbitrary node property such as the 'checked' property of checkboxes, or the 'value' of text boxes.
*
* @param name the node's property to retrieve
*/
property(name: string): any;
/**
* For each node, set the property value. Internally, this sets the node property directly (e.g., node[name] = value), so take care not to mutate special properties like __proto__.
*
* @param name the property name
* @param value the property value
*/
property(name: string, value: any): Selection<Datum>;
/**
* For each node, derive the property value. Internally, this sets the node property directly (e.g., node[name] = value), so take care not to mutate special properties like __proto__.
*
* @param name the property name
* @param value the function used to derive the property's value
*/
property(name: string, value: (datum: Datum, index: number, outerIndex: number) => any): Selection<Datum>;
/**
* Set multiple node properties. Caveats apply: take care not to mutate special properties like __proto__.
*
* @param obj an Object whose keys correspond to node properties and values are either constants or functions that will compute a value.
*/
property(obj: { [key: string]: any | ((datum: Datum, index: number, innerInder: number) => any) }): Selection<Datum>;
/**
* Retrieve the textContent of the first node in the selection.
*/
text(): string;
/**
* Set the textContent of each node in the selection.
* @param value the text to use for all nodes
*/
text(value: Primitive): Selection<Datum>;
/**
* Compute the textContent of each node in the selection.
* @param value the function which will compute the text
*/
text(value: (datum: Datum, index: number, outerIndex: number) => Primitive): Selection<Datum>;
/**
* Retrieve the HTML content of the first node in the selection. Uses 'innerHTML' internally and will not work with SVG or other elements without a polyfill.
*/
html(): string;
/**
* Set the HTML content of every node in the selection. Uses 'innerHTML' internally and thus will not work with SVG or other elements without a polyfill.
* @param value the HTML content to use.
*/
html(value: string): Selection<Datum>;
/**
* Compute the HTML content for each node in the selection. Uses 'innerHTML' internally and thus will not work with SVG or other elements without a polyfill.
* @param value the function to compute HTML content
*/
html(value: (datum: Datum, index: number, outerIndex: number) => string): Selection<Datum>;
/**
* Appends a new child to each node in the selection. This child will inherit the parent's data (if available). Returns a fresh selection consisting of the newly-appended children.
*
* @param name the element name to append. May be prefixed (see d3.ns.prefix).
*/
append(name: string): Selection<Datum>;
/**
* Appends a new child to each node in the selection by computing a new node. This child will inherit the parent's data (if available). Returns a fresh selection consisting of the newly-appended children.
*
* @param name the function to compute a new element
*/
append(name: (datum: Datum, index: number, outerIndex: number) => EventTarget): Selection<Datum>;
/**
* Inserts a new child to each node in the selection. This child will inherit its parent's data (if available). Returns a fresh selection consisting of the newly-inserted children.
* @param name the element name to append. May be prefixed (see d3.ns.prefix).
* @param before the selector to determine position (e.g., ":first-child")
*/
insert(name: string, before: string): Selection<Datum>;
/**
* Inserts a new child to each node in the selection. This child will inherit its parent's data (if available). Returns a fresh selection consisting of the newly-inserted children.
* @param name the element name to append. May be prefixed (see d3.ns.prefix).
* @param before a function to determine the node to use as the next sibling
*/
insert(name: string, before: (datum: Datum, index: number, outerIndex: number) => EventTarget): Selection<Datum>;
/**
* Inserts a new child to the end of each node in the selection by computing a new node. This child will inherit its parent's data (if available). Returns a fresh selection consisting of the newly-inserted children.
* @param name the function to compute a new child
* @param before the selector to determine position (e.g., ":first-child")
*/
insert(name: (datum: Datum, index: number, outerIndex: number) => EventTarget, before: string): Selection<Datum>;
/**
* Inserts a new child to the end of each node in the selection by computing a new node. This child will inherit its parent's data (if available). Returns a fresh selection consisting of the newly-inserted children.
* @param name the function to compute a new child
* @param before a function to determine the node to use as the next sibling
*/
insert(name: (datum: Datum, index: number, outerIndex: number) => EventTarget, before: (datum: Datum, index: number, outerIndex: number) => EventTarget): Selection<Datum>;
/**
* Removes the elements from the DOM. They are in a detached state and may be re-added (though there is currently no dedicated API for doing so).
*/
remove(): Selection<Datum>;
/**
* Retrieves the data bound to the first group in this selection.
*/
data(): Datum[];
/**
* Binds data to this selection.
* @param data the array of data to bind to this selection
* @param key the optional function to determine the unique key for each piece of data. When unspecified, uses the index of the element.
*/
data<NewDatum>(data: NewDatum[], key?: (datum: NewDatum, index: number, outerIndex: number) => string): selection.Update<NewDatum>;
/**
* Derives data to bind to this selection.
* @param data the function to derive data. Must return an array.
* @param key the optional function to determine the unique key for each data item. When unspecified, uses the index of the element.
*/
data<NewDatum>(data: (datum: Datum, index: number, outerIndex: number) => NewDatum[], key?: (datum: NewDatum, index: number, outerIndex: number) => string): selection.Update<NewDatum>;
/**
* Filters the selection, returning only those nodes that match the given CSS selector.
* @param selector the CSS selector
*/
filter(selector: string): Selection<Datum>;
/**
* Filters the selection, returning only those nodes for which the given function returned true.
* @param selector the filter function
*/
filter(selector: (datum: Datum, index: number, outerIndex: number) => boolean): Selection<Datum>;
/**
* Return the data item bound to the first element in the selection.
*/
datum(): Datum;
/**
* Derive the data item for each node in the selection. Useful for situations such as the HTML5 'dataset' attribute.
* @param value the function to compute data for each node
*/
datum<NewDatum>(value: (datum: Datum, index: number, outerIndex: number) => NewDatum): Selection<NewDatum>;
/**
* Set the data item for each node in the selection.
* @param value the constant element to use for each node
*/
datum<NewDatum>(value: NewDatum): Selection<NewDatum>;
/**
* Reorders nodes in the selection based on the given comparator. Nodes are re-inserted into the document once sorted.
* @param comparator the comparison function, which defaults to d3.ascending
*/
sort(comparator?: (a: Datum, b: Datum) => number): Selection<Datum>;
/**
* Reorders nodes in the document to match the selection order. More efficient than calling sort() if the selection is already ordered.
*/
order(): Selection<Datum>;
/**
* Returns the listener (if any) for the given event.
* @param type the type of event to load the listener for. May have a namespace (e.g., ".foo") at the end.
*/
on(type: string): (datum: Datum, index: number, outerIndex: number) => any;
/**
* Adds a listener for the specified event. If one was already registered, it is removed before the new listener is added. The return value of the listener function is ignored.
* @param type the of event to listen to. May have a namespace (e.g., ".foo") at the end.
* @param listener an event listener function, or null to unregister
* @param capture sets the DOM useCapture flag
*/
on(type: string, listener: (datum: Datum, index: number, outerIndex: number) => any, capture?: boolean): Selection<Datum>;
/**
* Begins a new transition. Interrupts any active transitions of the same name.
* @param name the transition name (defaults to "")
*/
transition(name?: string): Transition<Datum>;
/**
* Interrupts the active transition of the provided name. Does not cancel scheduled transitions.
* @param name the transition name (defaults to "")
*/
interrupt(name?: string): Selection<Datum>;
/**
* Creates a subselection by finding the first descendent matching the selector string. Bound data is inherited.
* @param selector the CSS selector to match against
*/
select(selector: string): Selection<Datum>;
/**
* Creates a subselection by using a function to find descendent elements. Bound data is inherited.
* @param selector the function to find matching descendants
*/
select(selector: (datum: Datum, index: number, outerIndex: number) => EventTarget): Selection<Datum>;
/**
* Creates a subselection by finding all descendents that match the given selector. Bound data is not inherited.
* @param selector the CSS selector to match against
*/
selectAll(selector: string): Selection<any>;
/**
* Creates a subselection by finding all descendants that match the given selector. Bound data is not inherited.
*
* Use this overload when data-binding a subselection (that is, sel.selectAll('.foo').data(d => ...)). The type will carry over.
*/
selectAll<T>(selector: string): Selection<T>;
/**
* Creates a subselection by using a function to find descendent elements. Bound data is not inherited.
* @param selector the function to find matching descendents
*/
selectAll(selector: (datum: Datum, index: number, outerIndex: number) => Array<EventTarget> | NodeList): Selection<any>;
/**
* Creates a subselection by using a function to find descendent elements. Bound data is not inherited.
*
* Use this overload when data-binding a subselection (that is, sel.selectAll('.foo').data(d => ...)). The type will carry over.
* @param selector the function to find matching descendents
*/
selectAll<T>(selector: (datum: Datum, index: number, outerIndex: number) => Array<EventTarget> | NodeList): Selection<T>;
/**
* Invoke the given function for each element in the selection. The return value of the function is ignored.
* @param func the function to invoke
*/
each(func: (datum: Datum, index: number, outerIndex: number) => any): Selection<Datum>;
/**
* Call a function on the selection. sel.call(foo) is equivalent to foo(sel).
* @param func the function to call on the selection
* @param args any optional args
*/
call(func: (sel: Selection<Datum>, ...args: any[]) => any, ...args: any[]): Selection<Datum>;
/**
* Returns true if the current selection is empty.
*/
empty(): boolean;
/**
* Returns the first non-null element in the selection, or null otherwise.
*/
node(): Node;
/**
* Returns the total number of elements in the selection.
*/
size(): number;
}
export function transition(): Transition<any>;
module transition {
export var prototype: Transition<any>;
}
interface Transition<Datum> {
transition(): Transition<Datum>;
delay(): number;
delay(delay: number): Transition<Datum>;
delay(delay: (datum: Datum, index: number, outerIndex: number) => number): Transition<Datum>;
duration(): number;
duration(duration: number): Transition<Datum>;
duration(duration: (datum: Datum, index: number, outerIndex: number) => number): Transition<Datum>;
ease(): (t: number) => number;
ease(value: string, ...args: any[]): Transition<Datum>;
ease(value: (t: number) => number): Transition<Datum>;
attr(name: string, value: Primitive): Transition<Datum>;
attr(name: string, value: (datum: Datum, index: number, outerIndex: number) => Primitive): Transition<Datum>;
attr(obj: { [key: string]: Primitive | ((datum: Datum, index: number, outerIndex: number) => Primitive) }): Transition<Datum>;
attrTween(name: string, tween: (datum: Datum, index: number, attr: string) => (t: number) => Primitive): Transition<Datum>;
style(name: string, value: Primitive, priority?: string): Transition<Datum>;
style(name: string, value: (datum: Datum, index: number, outerIndex: number) => Primitive, priority?: string): Transition<Datum>;
style(obj: { [key: string]: Primitive | ((datum: Datum, index: number, outerIndex: number) => Primitive) }, priority?: string): Transition<Datum>;
styleTween(name: string, tween: (datum: Datum, index: number, attr: string) => (t: number) => Primitive, priority?: string): Transition<Datum>;
text(value: Primitive): Transition<Datum>;
text(value: (datum: Datum, index: number, outerIndex: number) => Primitive): Transition<Datum>;
tween(name: string, factory: () => (t: number) => any): Transition<Datum>;
remove(): Transition<Datum>;
select(selector: string): Transition<Datum>;
select(selector: (d: Datum, i: number) => EventTarget): Transition<Datum>;
selectAll(selector: string): Transition<any>;
selectAll(selector: (d: Datum, i: number) => EventTarget[]): Transition<any>;
filter(selector: string): Transition<Datum>;
filter(selector: (d: Datum, i: number) => boolean): Transition<Datum>;
each(type: string, listener: (d: Datum, i: number) => any): Transition<Datum>;
each(listener: (d: Datum, i: number) => any): Transition<Datum>;
call(func: (transition: Transition<Datum>, ...args: any[]) => any, ...args: any[]): Transition<Datum>;
empty(): boolean;
node(): Node;
size(): number;
}
export function ease(type: 'linear'): (t: number) => number;
export function ease(type: 'linear-in'): (t: number) => number;
export function ease(type: 'linear-out'): (t: number) => number;
export function ease(type: 'linear-in-out'): (t: number) => number;
export function ease(type: 'linear-out-in'): (t: number) => number;
export function ease(type: 'poly', k: number): (t: number) => number;
export function ease(type: 'poly-in', k: number): (t: number) => number;
export function ease(type: 'poly-out', k: number): (t: number) => number;
export function ease(type: 'poly-in-out', k: number): (t: number) => number;
export function ease(type: 'poly-out-in', k: number): (t: number) => number;
export function ease(type: 'quad'): (t: number) => number;
export function ease(type: 'quad-in'): (t: number) => number;
export function ease(type: 'quad-out'): (t: number) => number;
export function ease(type: 'quad-in-out'): (t: number) => number;
export function ease(type: 'quad-out-in'): (t: number) => number;
export function ease(type: 'cubic'): (t: number) => number;
export function ease(type: 'cubic-in'): (t: number) => number;
export function ease(type: 'cubic-out'): (t: number) => number;
export function ease(type: 'cubic-in-out'): (t: number) => number;
export function ease(type: 'cubic-out-in'): (t: number) => number;
export function ease(type: 'sin'): (t: number) => number;
export function ease(type: 'sin-in'): (t: number) => number;
export function ease(type: 'sin-out'): (t: number) => number;
export function ease(type: 'sin-in-out'): (t: number) => number;
export function ease(type: 'sin-out-in'): (t: number) => number;
export function ease(type: 'circle'): (t: number) => number;
export function ease(type: 'circle-in'): (t: number) => number;
export function ease(type: 'circle-out'): (t: number) => number;
export function ease(type: 'circle-in-out'): (t: number) => number;
export function ease(type: 'circle-out-in'): (t: number) => number;
export function ease(type: 'elastic', a?: number, b?: number): (t: number) => number;
export function ease(type: 'elastic-in', a?: number, b?: number): (t: number) => number;
export function ease(type: 'elastic-out', a?: number, b?: number): (t: number) => number;
export function ease(type: 'elastic-in-out', a?: number, b?: number): (t: number) => number;
export function ease(type: 'elastic-out-in', a?: number, b?: number): (t: number) => number;
export function ease(type: 'back', s: number): (t: number) => number;
export function ease(type: 'back-in', s: number): (t: number) => number;
export function ease(type: 'back-out', s: number): (t: number) => number;
export function ease(type: 'back-in-out', s: number): (t: number) => number;
export function ease(type: 'back-out-in', s: number): (t: number) => number;
export function ease(type: 'bounce'): (t: number) => number;
export function ease(type: 'bounce-in'): (t: number) => number;
export function ease(type: 'bounce-out'): (t: number) => number;
export function ease(type: 'bounce-in-out'): (t: number) => number;
export function ease(type: 'bounce-out-in'): (t: number) => number;
export function ease(type: string, ...args: any[]): (t: number) => number;
export function timer(func: () => any, delay?: number, time?: number): void;
module timer {
export function flush(): void;
}
interface BaseEvent {
type: string;
sourceEvent?: Event;
}
/**
* Define a D3-specific ZoomEvent per https://github.com/mbostock/d3/wiki/Zoom-Behavior#event
*/
interface ZoomEvent extends BaseEvent {
scale: number;
translate: [number, number];
}
/**
* Define a D3-specific DragEvent per https://github.com/mbostock/d3/wiki/Drag-Behavior#on
*/
interface DragEvent extends BaseEvent {
x: number;
y: number;
dx: number;
dy: number;
}
/**
* The current event's value. Use this variable in a handler registered with `selection.on`.
*/
export var event: Event | BaseEvent;
/**
* Returns the x and y coordinates of the mouse relative to the provided container element, using d3.event for the mouse's position on the page.
* @param container the container element (e.g. an SVG <g> element)
*/
export function mouse(container: EventTarget): [number, number];
/**
* Given a container element and a touch identifier, determine the x and y coordinates of the touch.
* @param container the container element (e.g., an SVG <svg> element)
* @param identifier the given touch identifier
*/
export function touch(container: EventTarget, identifer: number): [number, number];
/**
* Given a container element, a list of touches, and a touch identifier, determine the x and y coordinates of the touch.
* @param container the container element (e.g., an SVG <svg> element)
* @param identifier the given touch identifier
*/
export function touch(container: EventTarget, touches: TouchList, identifer: number): [number, number];
/**
* Given a container element and an optional list of touches, return the position of every touch relative to the container.
* @param container the container element
* @param touches an optional list of touches (defaults to d3.event.touches)
*/
export function touches(container: EventTarget, touches?: TouchList): Array<[number, number]>;
// NB. this is limited to primitive values due to D3's use of the <, >, and >= operators. Results get weird for object instances.
/**
* Compares two primitive values for sorting (in ascending order).
*/
export function ascending(a: Primitive, b: Primitive): number;
/**
* Compares two primitive values for sorting (in ascending order).
*/
export function descending(a: Primitive, b: Primitive): number;
/**
* Return the minimum value in the array using natural order.
*/
export function min(array: number[]): number;
/**
* Return the minimum value in the array using natural order.
*/
export function min(array: string[]): string;
/**
* Return the minimum value in the array using natural order.