forked from DefinitelyTyped/DefinitelyTyped
-
Notifications
You must be signed in to change notification settings - Fork 0
/
plottable.d.ts
4119 lines (3967 loc) · 158 KB
/
plottable.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 Plottable v1.4.0
// Project: http://plottablejs.org/
// Definitions by: Plottable Team <https://github.com/palantir/plottable>
// Definitions: https://github.com/borisyankov/DefinitelyTyped
/// <reference path="../d3/d3.d.ts" />
declare module Plottable {
module Utils {
module Math {
/**
* Checks if x is between a and b.
*
* @param {number} x The value to test if in range
* @param {number} a The beginning of the (inclusive) range
* @param {number} b The ending of the (inclusive) range
* @return {boolean} Whether x is in [a, b]
*/
function inRange(x: number, a: number, b: number): boolean;
/**
* Clamps x to the range [min, max].
*
* @param {number} x The value to be clamped.
* @param {number} min The minimum value.
* @param {number} max The maximum value.
* @return {number} A clamped value in the range [min, max].
*/
function clamp(x: number, min: number, max: number): number;
/**
* Applies the accessor, if provided, to each element of `array` and returns the maximum value.
* If no maximum value can be computed, returns defaultValue.
*/
function max<C>(array: C[], defaultValue: C): C;
function max<T, C>(array: T[], accessor: (t?: T, i?: number) => C, defaultValue: C): C;
/**
* Applies the accessor, if provided, to each element of `array` and returns the minimum value.
* If no minimum value can be computed, returns defaultValue.
*/
function min<C>(array: C[], defaultValue: C): C;
function min<T, C>(array: T[], accessor: (t?: T, i?: number) => C, defaultValue: C): C;
/**
* Returns true **only** if x is NaN
*/
function isNaN(n: any): boolean;
/**
* Returns true if the argument is a number, which is not NaN
* Numbers represented as strings do not pass this function
*/
function isValidNumber(n: any): boolean;
/**
* Generates an array of consecutive, strictly increasing numbers
* in the range [start, stop) separeted by step
*/
function range(start: number, stop: number, step?: number): number[];
/**
* Returns the square of the distance between two points
*
* @param {Point} p1
* @param {Point} p2
* @return {number} dist(p1, p2)^2
*/
function distanceSquared(p1: Point, p2: Point): number;
}
}
}
declare module Plottable {
module Utils {
/**
* Shim for ES6 map.
* https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Map
*/
class Map<K, V> {
constructor();
set(key: K, value: V): Map<K, V>;
get(key: K): V;
has(key: K): boolean;
forEach(callbackFn: (value: V, key: K, map: Map<K, V>) => void, thisArg?: any): void;
delete(key: K): boolean;
}
}
}
declare module Plottable {
module Utils {
/**
* Shim for ES6 set.
* https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Set
*/
class Set<T> {
size: number;
constructor();
add(value: T): Set<T>;
delete(value: T): boolean;
has(value: T): boolean;
forEach(callback: (value: T, value2: T, set: Set<T>) => void, thisArg?: any): void;
}
}
}
declare module Plottable {
module Utils {
module DOM {
/**
* Gets the bounding box of an element.
* @param {d3.Selection} element
* @returns {SVGRed} The bounding box.
*/
function elementBBox(element: d3.Selection<any>): SVGRect;
/**
* Screen refresh rate which is assumed to be 60fps
*/
var SCREEN_REFRESH_RATE_MILLISECONDS: number;
/**
* Polyfill for `window.requestAnimationFrame`.
* If the function exists, then we use the function directly.
* Otherwise, we set a timeout on `SCREEN_REFRESH_RATE_MILLISECONDS` and then perform the function.
*
* @param {() => void} callback The callback to call in the next animation frame
*/
function requestAnimationFramePolyfill(callback: () => void): void;
/**
* Calculates the width of the element.
* The width includes the padding and the border on the element's left and right sides.
*
* @param {Element} element The element to query
* @returns {number} The width of the element.
*/
function elementWidth(element: Element): number;
/**
* Calculates the height of the element.
* The height includes the padding the and the border on the element's top and bottom sides.
*
* @param {Element} element The element to query
* @returns {number} The height of the element
*/
function elementHeight(element: Element): number;
/**
* Retrieves the number array representing the translation for the selection
*
* @param {d3.Selection<any>} selection The selection to query
* @returns {[number, number]} The number array representing the translation
*/
function translate(selection: d3.Selection<any>): [number, number];
/**
* Translates the given selection by the input x / y pixel amounts.
*
* @param {d3.Selection<any>} selection The selection to translate
* @param {number} x The amount to translate in the x direction
* @param {number} y The amount to translate in the y direction
* @returns {d3.Selection<any>} The input selection
*/
function translate(selection: d3.Selection<any>, x: number, y: number): d3.Selection<any>;
/**
* Checks if the first ClientRect overlaps the second.
*
* @param {ClientRect} clientRectA The first ClientRect
* @param {ClientRect} clientRectB The second ClientRect
* @returns {boolean} If the ClientRects overlap each other.
*/
function clientRectsOverlap(clientRectA: ClientRect, clientRectB: ClientRect): boolean;
/**
* Returns true if and only if innerClientRect is inside outerClientRect.
*
* @param {ClientRect} innerClientRect The first ClientRect
* @param {ClientRect} outerClientRect The second ClientRect
* @returns {boolean} If and only if the innerClientRect is inside outerClientRect.
*/
function clientRectInside(innerClientRect: ClientRect, outerClientRect: ClientRect): boolean;
/**
* Retrieves the bounding svg of the input element
*
* @param {SVGElement} element The element to query
* @returns {SVGElement} The bounding svg
*/
function boundingSVG(element: SVGElement): SVGElement;
/**
* Generates a ClipPath ID that is unique for this instance of Plottable
*/
function generateUniqueClipPathId(): string;
/**
* Returns true if the supplied coordinates or Ranges intersect or are contained by bbox.
*
* @param {number | Range} xValOrRange The x coordinate or Range to test
* @param {number | Range} yValOrRange The y coordinate or Range to test
* @param {SVGRect} bbox The bbox
* @param {number} tolerance Amount by which to expand bbox, in each dimension, before
* testing intersection
*
* @returns {boolean} True if the supplied coordinates or Ranges intersect or are
* contained by bbox, false otherwise.
*/
function intersectsBBox(xValOrRange: number | Range, yValOrRange: number | Range, bbox: SVGRect, tolerance?: number): boolean;
}
}
}
declare module Plottable {
module Utils {
module Color {
/**
* Return contrast ratio between two colors
* Based on implementation from chroma.js by Gregor Aisch (gka) (licensed under BSD)
* chroma.js may be found here: https://github.com/gka/chroma.js
* License may be found here: https://github.com/gka/chroma.js/blob/master/LICENSE
* see http://www.w3.org/TR/2008/REC-WCAG20-20081211/#contrast-ratiodef
*/
function contrast(a: string, b: string): number;
/**
* Returns a brighter copy of this color. Each channel is multiplied by 0.7 ^ -factor.
* Channel values are capped at the maximum value of 255, and the minimum value of 30.
*/
function lightenColor(color: string, factor: number): string;
/**
* Gets the Hex Code of the color resulting by applying the className CSS class to the
* colorTester selection. Returns null if the tester is transparent.
*
* @param {d3.Selection<void>} colorTester The d3 selection to apply the CSS class to
* @param {string} className The name of the class to be applied
* @return {string} The hex code of the computed color
*/
function colorTest(colorTester: d3.Selection<void>, className: string): string;
}
}
}
declare module Plottable {
module Utils {
module Array {
/**
* Takes two arrays of numbers and adds them together
*
* @param {number[]} aList The first array of numbers
* @param {number[]} bList The second array of numbers
* @return {number[]} An array of numbers where x[i] = aList[i] + bList[i]
*/
function add(aList: number[], bList: number[]): number[];
/**
* Take an array of values, and return the unique values.
* Will work iff ∀ a, b, a.toString() == b.toString() => a == b; will break on Object inputs
*
* @param {T[]} values The values to find uniqueness for
* @return {T[]} The unique values
*/
function uniq<T>(arr: T[]): T[];
/**
* @param {T[][]} a The 2D array that will have its elements joined together.
* @return {T[]} Every array in a, concatenated together in the order they appear.
*/
function flatten<T>(a: T[][]): T[];
/**
* Creates an array of length `count`, filled with value or (if value is a function), value()
*
* @param {T | ((index?: number) => T)} value The value to fill the array with or a value generator (called with index as arg)
* @param {number} count The length of the array to generate
* @return {any[]}
*/
function createFilledArray<T>(value: T | ((index?: number) => T), count: number): T[];
}
}
}
declare module Plottable {
module Utils {
/**
* A set of callbacks which can be all invoked at once.
* Each callback exists at most once in the set (based on reference equality).
* All callbacks should have the same signature.
*/
class CallbackSet<CB extends Function> extends Set<CB> {
callCallbacks(...args: any[]): CallbackSet<CB>;
}
}
}
declare module Plottable {
module Utils {
module Stacking {
type StackedDatum = {
value: number;
offset: number;
};
type StackingResult = Utils.Map<Dataset, Utils.Map<string, StackedDatum>>;
/**
* Computes the StackingResult (value and offset) for each data point in each Dataset.
*
* @param {Dataset[]} datasets The Datasets to be stacked on top of each other in the order of stacking
* @param {Accessor<any>} keyAccessor Accessor for the key of the data
* @param {Accessor<number>} valueAccessor Accessor for the value of the data
* @return {StackingResult} value and offset for each datapoint in each Dataset
*/
function stack(datasets: Dataset[], keyAccessor: Accessor<any>, valueAccessor: Accessor<number>): StackingResult;
/**
* Computes the total extent over all data points in all Datasets, taking stacking into consideration.
*
* @param {StackingResult} stackingResult The value and offset information for each datapoint in each dataset
* @oaram {Accessor<any>} keyAccessor Accessor for the key of the data existent in the stackingResult
* @param {Accessor<boolean>} filter A filter for data to be considered when computing the total extent
* @return {[number, number]} The total extent
*/
function stackedExtent(stackingResult: StackingResult, keyAccessor: Accessor<any>, filter: Accessor<boolean>): number[];
/**
* Normalizes a key used for stacking
*
* @param {any} key The key to be normalized
* @return {string} The stringified key
*/
function normalizeKey(key: any): string;
}
}
}
declare module Plottable {
module Utils {
module Window {
/**
* Print a warning message to the console, if it is available.
*
* @param {string} The warnings to print
*/
function warn(warning: string): void;
/**
* Is like setTimeout, but activates synchronously if time=0
* We special case 0 because of an observed issue where calling setTimeout causes visible flickering.
* We believe this is because when requestAnimationFrame calls into the paint function, as soon as that function finishes
* evaluating, the results are painted to the screen. As a result, if we want something to occur immediately but call setTimeout
* with time=0, then it is pushed to the call stack and rendered in the next frame, so the component that was rendered via
* setTimeout appears out-of-sync with the rest of the plot.
*/
function setTimeout(f: Function, time: number, ...args: any[]): number;
/**
* Sends a deprecation warning to the console. The warning includes the name of the deprecated method,
* version number of the deprecation, and an optional message.
*
* To be used in the first line of a deprecated method.
*
* @param {string} callingMethod The name of the method being deprecated
* @param {string} version The version when the tagged method became obsolete
* @param {string?} message Optional message to be shown with the warning
*/
function deprecated(callingMethod: string, version: string, message?: string): void;
}
}
}
declare module Plottable {
module Utils {
class ClientToSVGTranslator {
/**
* Returns the ClientToSVGTranslator for the <svg> containing elem.
* If one already exists on that <svg>, it will be returned; otherwise, a new one will be created.
*/
static getTranslator(elem: SVGElement): ClientToSVGTranslator;
constructor(svg: SVGElement);
/**
* Computes the position relative to the <svg> in svg-coordinate-space.
*/
computePosition(clientX: number, clientY: number): Point;
/**
* Checks whether event happened inside <svg> element.
*/
insideSVG(e: Event): boolean;
}
}
}
declare module Plottable {
module Configs {
/**
* Specifies if Plottable should show warnings.
*/
var SHOW_WARNINGS: boolean;
}
}
declare module Plottable {
var version: string;
}
declare module Plottable {
type DatasetCallback = (dataset: Dataset) => void;
class Dataset {
/**
* A Dataset contains an array of data and some metadata.
* Changes to the data or metadata will cause anything subscribed to the Dataset to update.
*
* @constructor
* @param {any[]} [data=[]] The data for this Dataset.
* @param {any} [metadata={}] An object containing additional information.
*/
constructor(data?: any[], metadata?: any);
/**
* Adds a callback to be called when the Dataset updates.
*
* @param {DatasetCallback} callback.
* @returns {Dataset} The calling Dataset.
*/
onUpdate(callback: DatasetCallback): Dataset;
/**
* Removes a callback that would be called when the Dataset updates.
*
* @param {DatasetCallback} callback
* @returns {Dataset} The calling Dataset.
*/
offUpdate(callback: DatasetCallback): Dataset;
/**
* Gets the data.
*
* @returns {any[]}
*/
data(): any[];
/**
* Sets the data.
*
* @param {any[]} data
* @returns {Dataset} The calling Dataset.
*/
data(data: any[]): Dataset;
/**
* Gets the metadata.
*
* @returns {any}
*/
metadata(): any;
/**
* Sets the metadata.
*
* @param {any} metadata
* @returns {Dataset} The calling Dataset.
*/
metadata(metadata: any): Dataset;
}
}
declare module Plottable {
module RenderPolicies {
/**
* A policy for rendering Components.
*/
interface RenderPolicy {
render(): any;
}
/**
* Renders Components immediately after they are enqueued.
* Useful for debugging, horrible for performance.
*/
class Immediate implements RenderPolicy {
render(): void;
}
/**
* The default way to render, which only tries to render every frame
* (usually, 1/60th of a second).
*/
class AnimationFrame implements RenderPolicy {
render(): void;
}
/**
* Renders with `setTimeout()`.
* Generally an inferior way to render compared to `requestAnimationFrame`,
* but useful for browsers that don't suppoort `requestAnimationFrame`.
*/
class Timeout implements RenderPolicy {
render(): void;
}
}
}
declare module Plottable {
/**
* The RenderController is responsible for enqueueing and synchronizing
* layout and render calls for Components.
*
* Layout and render calls occur inside an animation callback
* (window.requestAnimationFrame if available).
*
* RenderController.flush() immediately lays out and renders all Components currently enqueued.
*
* To always have immediate rendering (useful for debugging), call
* ```typescript
* Plottable.RenderController.setRenderPolicy(
* new Plottable.RenderPolicies.Immediate()
* );
* ```
*/
module RenderController {
module Policy {
var IMMEDIATE: string;
var ANIMATION_FRAME: string;
var TIMEOUT: string;
}
function renderPolicy(): RenderPolicies.RenderPolicy;
function renderPolicy(renderPolicy: string): void;
/**
* Enqueues the Component for rendering.
*
* @param {Component} component
*/
function registerToRender(component: Component): void;
/**
* Enqueues the Component for layout and rendering.
*
* @param {Component} component
*/
function registerToComputeLayout(component: Component): void;
/**
* Renders all Components waiting to be rendered immediately
* instead of waiting until the next frame.
*
* Useful to call when debugging.
*/
function flush(): void;
}
}
declare module Plottable {
/**
* Accesses a specific datum property.
*/
interface Accessor<T> {
(datum: any, index: number, dataset: Dataset): T;
}
/**
* Retrieves a scaled datum property.
* Essentially passes the result of an Accessor through a Scale.
*/
type Projector = (datum: any, index: number, dataset: Dataset) => any;
/**
* A mapping from attributes ("x", "fill", etc.) to the functions that get
* that information out of the data.
*/
type AttributeToProjector = {
[attr: string]: Projector;
};
/**
* A function that generates attribute values from the datum and index.
* Essentially a Projector with a particular Dataset rolled in.
*/
type AppliedProjector = (datum: any, index: number) => any;
/**
* A mapping from attributes to the AppliedProjectors used to generate them.
*/
type AttributeToAppliedProjector = {
[attr: string]: AppliedProjector;
};
/**
* Space request used during layout negotiation.
*
* @member {number} minWidth The minimum acceptable width given the offered space.
* @member {number} minHeight the minimum acceptable height given the offered space.
*/
type SpaceRequest = {
minWidth: number;
minHeight: number;
};
/**
* Min and max values for a particular property.
*/
type Range = {
min: number;
max: number;
};
/**
* A location in pixel-space.
*/
type Point = {
x: number;
y: number;
};
/**
* The corners of a box.
*/
type Bounds = {
topLeft: Point;
bottomRight: Point;
};
/**
* An object representing a data-backed visual entity inside a Component.
*/
interface Entity<C extends Component> {
datum: any;
position: Point;
selection: d3.Selection<any>;
component: C;
}
}
declare module Plottable {
type Formatter = (d: any) => string;
/**
* This field is deprecated and will be removed in v2.0.0.
*
* The number of milliseconds between midnight one day and the next is
* not a fixed quantity.
*
* Use date.setDate(date.getDate() + number_of_days) instead.
*
*/
var MILLISECONDS_IN_ONE_DAY: number;
module Formatters {
/**
* Creates a formatter for currency values.
*
* @param {number} [precision] The number of decimal places to show (default 2).
* @param {string} [symbol] The currency symbol to use (default "$").
* @param {boolean} [prefix] Whether to prepend or append the currency symbol (default true).
* @param {boolean} [onlyShowUnchanged] Whether to return a value if value changes after formatting (default true).
*
* @returns {Formatter} A formatter for currency values.
*/
function currency(precision?: number, symbol?: string, prefix?: boolean): (d: any) => string;
/**
* Creates a formatter that displays exactly [precision] decimal places.
*
* @param {number} [precision] The number of decimal places to show (default 3).
* @param {boolean} [onlyShowUnchanged] Whether to return a value if value changes after formatting (default true).
*
* @returns {Formatter} A formatter that displays exactly [precision] decimal places.
*/
function fixed(precision?: number): (d: any) => string;
/**
* Creates a formatter that formats numbers to show no more than
* [precision] decimal places. All other values are stringified.
*
* @param {number} [precision] The number of decimal places to show (default 3).
* @param {boolean} [onlyShowUnchanged] Whether to return a value if value changes after formatting (default true).
*
* @returns {Formatter} A formatter for general values.
*/
function general(precision?: number): (d: any) => string;
/**
* Creates a formatter that stringifies its input.
*
* @returns {Formatter} A formatter that stringifies its input.
*/
function identity(): (d: any) => string;
/**
* Creates a formatter for percentage values.
* Multiplies the input by 100 and appends "%".
*
* @param {number} [precision] The number of decimal places to show (default 0).
* @param {boolean} [onlyShowUnchanged] Whether to return a value if value changes after formatting (default true).
*
* @returns {Formatter} A formatter for percentage values.
*/
function percentage(precision?: number): (d: any) => string;
/**
* Creates a formatter for values that displays [precision] significant figures
* and puts SI notation.
*
* @param {number} [precision] The number of significant figures to show (default 3).
*
* @returns {Formatter} A formatter for SI values.
*/
function siSuffix(precision?: number): (d: any) => string;
/**
* Creates a multi time formatter that displays dates.
*
* @returns {Formatter} A formatter for time/date values.
*/
function multiTime(): (d: any) => string;
/**
* Creates a time formatter that displays time/date using given specifier.
*
* List of directives can be found on: https://github.com/mbostock/d3/wiki/Time-Formatting#format
*
* @param {string} [specifier] The specifier for the formatter.
*
* @returns {Formatter} A formatter for time/date values.
*/
function time(specifier: string): Formatter;
/**
* Creates a formatter for relative dates.
*
* @param {number} baseValue The start date (as epoch time) used in computing relative dates (default 0)
* @param {number} increment The unit used in calculating relative date values (default MILLISECONDS_IN_ONE_DAY)
* @param {string} label The label to append to the formatted string (default "")
*
* @returns {Formatter} A formatter for time/date values.
*/
function relativeDate(baseValue?: number, increment?: number, label?: string): (d: any) => string;
}
}
declare module Plottable {
/**
* A SymbolFactory is a function that takes in a symbolSize which is the edge length of the render area
* and returns a string representing the 'd' attribute of the resultant 'path' element
*/
type SymbolFactory = (symbolSize: number) => string;
module SymbolFactories {
function circle(): SymbolFactory;
function square(): SymbolFactory;
function cross(): SymbolFactory;
function diamond(): SymbolFactory;
function triangleUp(): SymbolFactory;
function triangleDown(): SymbolFactory;
}
}
declare module Plottable {
interface ScaleCallback<S extends Scale<any, any>> {
(scale: S): any;
}
module Scales {
/**
* A function that supplies domain values to be included into a Scale.
*
* @param {Scale} scale
* @returns {D[]} An array of values that should be included in the Scale.
*/
interface IncludedValuesProvider<D> {
(scale: Scale<D, any>): D[];
}
/**
* A function that supplies padding exception values for the Scale.
* If one end of the domain is set to an excepted value as a result of autoDomain()-ing,
* that end of the domain will not be padded.
*
* @param {QuantitativeScale} scale
* @returns {D[]} An array of values that should not be padded.
*/
interface PaddingExceptionsProvider<D> {
(scale: QuantitativeScale<D>): D[];
}
}
class Scale<D, R> {
/**
* A Scale is a function (in the mathematical sense) that maps values from a domain to a range.
*
* @constructor
*/
constructor();
/**
* Given an array of potential domain values, computes the extent of those values.
*
* @param {D[]} values
* @returns {D[]} The extent of the input values.
*/
extentOfValues(values: D[]): D[];
protected _getAllIncludedValues(): D[];
protected _getExtent(): D[];
/**
* Adds a callback to be called when the Scale updates.
*
* @param {ScaleCallback} callback.
* @returns {Scale} The calling Scale.
*/
onUpdate(callback: ScaleCallback<Scale<D, R>>): Scale<D, R>;
/**
* Removes a callback that would be called when the Scale updates.
*
* @param {ScaleCallback} callback.
* @returns {Scale} The calling Scale.
*/
offUpdate(callback: ScaleCallback<Scale<D, R>>): Scale<D, R>;
protected _dispatchUpdate(): void;
/**
* Sets the Scale's domain so that it spans the Extents of all its ExtentsProviders.
*
* @returns {Scale} The calling Scale.
*/
autoDomain(): Scale<D, R>;
protected _autoDomainIfAutomaticMode(): void;
/**
* Computes the range value corresponding to a given domain value.
*
* @param {D} value
* @returns {R} The range value corresponding to the supplied domain value.
*/
scale(value: D): R;
/**
* Gets the domain.
*
* @returns {D[]} The current domain.
*/
domain(): D[];
/**
* Sets the domain.
*
* @param {D[]} values
* @returns {Scale} The calling Scale.
*/
domain(values: D[]): Scale<D, R>;
protected _getDomain(): void;
protected _setDomain(values: D[]): void;
protected _setBackingScaleDomain(values: D[]): void;
/**
* Gets the range.
*
* @returns {R[]} The current range.
*/
range(): R[];
/**
* Sets the range.
*
* @param {R[]} values
* @returns {Scale} The calling Scale.
*/
range(values: R[]): Scale<D, R>;
protected _getRange(): void;
protected _setRange(values: R[]): void;
/**
* Adds an IncludedValuesProvider to the Scale.
*
* @param {Scales.IncludedValuesProvider} provider
* @returns {Scale} The calling Scale.
*/
addIncludedValuesProvider(provider: Scales.IncludedValuesProvider<D>): Scale<D, R>;
/**
* Removes the IncludedValuesProvider from the Scale.
*
* @param {Scales.IncludedValuesProvider} provider
* @returns {Scale} The calling Scale.
*/
removeIncludedValuesProvider(provider: Scales.IncludedValuesProvider<D>): Scale<D, R>;
}
}
declare module Plottable {
class QuantitativeScale<D> extends Scale<D, number> {
protected static _DEFAULT_NUM_TICKS: number;
/**
* A QuantitativeScale is a Scale that maps number-like values to numbers.
* It is invertible and continuous.
*
* @constructor
*/
constructor();
autoDomain(): QuantitativeScale<D>;
protected _autoDomainIfAutomaticMode(): void;
protected _getExtent(): D[];
/**
* Adds a padding exception provider.
* If one end of the domain is set to an excepted value as a result of autoDomain()-ing,
* that end of the domain will not be padded.
*
* @param {Scales.PaddingExceptionProvider<D>} provider The provider function.
* @returns {QuantitativeScale} The calling QuantitativeScale.
*/
addPaddingExceptionsProvider(provider: Scales.PaddingExceptionsProvider<D>): QuantitativeScale<D>;
/**
* Removes the padding exception provider.
*
* @param {Scales.PaddingExceptionProvider<D>} provider The provider function.
* @returns {QuantitativeScale} The calling QuantitativeScale.
*/
removePaddingExceptionsProvider(provider: Scales.PaddingExceptionsProvider<D>): QuantitativeScale<D>;
/**
* Gets the padding proportion.
*/
padProportion(): number;
/**
* Sets the padding porportion.
* When autoDomain()-ing, the computed domain will be expanded by this proportion,
* then rounded to human-readable values.
*
* @param {number} padProportion The padding proportion. Passing 0 disables padding.
* @returns {QuantitativeScale} The calling QuantitativeScale.
*/
padProportion(padProportion: number): QuantitativeScale<D>;
protected _expandSingleValueDomain(singleValueDomain: D[]): D[];
/**
* Computes the domain value corresponding to a supplied range value.
*
* @param {number} value: A value from the Scale's range.
* @returns {D} The domain value corresponding to the supplied range value.
*/
invert(value: number): D;
domain(): D[];
domain(values: D[]): QuantitativeScale<D>;
/**
* Gets the lower end of the domain.
*
* @return {D}
*/
domainMin(): D;
/**
* Sets the lower end of the domain.
*
* @return {QuantitativeScale} The calling QuantitativeScale.
*/
domainMin(domainMin: D): QuantitativeScale<D>;
/**
* Gets the upper end of the domain.
*
* @return {D}
*/
domainMax(): D;
/**
* Sets the upper end of the domain.
*
* @return {QuantitativeScale} The calling QuantitativeScale.
*/
domainMax(domainMax: D): QuantitativeScale<D>;
extentOfValues(values: D[]): D[];
protected _setDomain(values: D[]): void;
/**
* Gets the array of tick values generated by the default algorithm.
*/
defaultTicks(): D[];
/**
* Gets an array of tick values spanning the domain.
*
* @returns {D[]}
*/
ticks(): D[];
/**
* Given a domain, expands its domain onto "nice" values, e.g. whole
* numbers.
*/
protected _niceDomain(domain: D[], count?: number): D[];
protected _defaultExtent(): D[];
/**
* Gets the TickGenerator.
*/
tickGenerator(): Scales.TickGenerators.TickGenerator<D>;
/**
* Sets the TickGenerator
*
* @param {TickGenerator} generator
* @return {QuantitativeScale} The calling QuantitativeScale.
*/
tickGenerator(generator: Scales.TickGenerators.TickGenerator<D>): QuantitativeScale<D>;
}
}
declare module Plottable {
module Scales {
class Linear extends QuantitativeScale<number> {
/**
* @constructor
*/
constructor();
protected _defaultExtent(): number[];
protected _expandSingleValueDomain(singleValueDomain: number[]): number[];
scale(value: number): number;
protected _getDomain(): number[];
protected _setBackingScaleDomain(values: number[]): void;
protected _getRange(): number[];
protected _setRange(values: number[]): void;
invert(value: number): number;
defaultTicks(): number[];
protected _niceDomain(domain: number[], count?: number): number[];
}
}
}
declare module Plottable {
module Scales {
class ModifiedLog extends QuantitativeScale<number> {
/**
* A ModifiedLog Scale acts as a regular log scale for large numbers.
* As it approaches 0, it gradually becomes linear.
* Consequently, a ModifiedLog Scale can process 0 and negative numbers.
*
* @constructor
* @param {number} [base=10]
* The base of the log. Must be > 1.
*
* For x <= base, scale(x) = log(x).
*
* For 0 < x < base, scale(x) will become more and more
* linear as it approaches 0.
*
* At x == 0, scale(x) == 0.
*
* For negative values, scale(-x) = -scale(x).
*/
constructor(base?: number);
scale(x: number): number;
invert(x: number): number;
protected _getDomain(): number[];
protected _setDomain(values: number[]): void;
protected _setBackingScaleDomain(values: number[]): void;
ticks(): number[];
protected _niceDomain(domain: number[], count?: number): number[];
protected _defaultExtent(): number[];
protected _expandSingleValueDomain(singleValueDomain: number[]): number[];
protected _getRange(): number[];
protected _setRange(values: number[]): void;
defaultTicks(): number[];