UNPKG

131 kBTypeScriptView Raw
1// Type definitions for D3JS d3-scale module 4.0
2// Project: https://github.com/d3/d3-scale/, https://d3js.org/d3-scale
3// Definitions by: Tom Wanzek <https://github.com/tomwanzek>
4// Alex Ford <https://github.com/gustavderdrache>
5// Boris Yankov <https://github.com/borisyankov>
6// denisname <https://github.com/denisname>
7// rulonder <https://github.com/rulonder>
8// Nathan Bierema <https://github.com/Methuselah96>
9// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
10
11// Last module patch version validated against: 4.0.0
12
13import { CountableTimeInterval, TimeInterval } from 'd3-time';
14
15// -------------------------------------------------------------------------------
16// Shared Types and Interfaces
17// -------------------------------------------------------------------------------
18
19/**
20 * An Interpolator factory returns an interpolator function.
21 *
22 * The first generic corresponds to the data type of the interpolation boundaries.
23 * The second generic corresponds to the data type of the return type of the interpolator.
24 */
25export interface InterpolatorFactory<T, U> {
26 /**
27 * Construct a new interpolator function, based on the provided interpolation boundaries.
28 *
29 * @param a Start boundary of the interpolation interval.
30 * @param b End boundary of the interpolation interval.
31 */
32 (a: T, b: T): (t: number) => U;
33}
34
35export type NumberValue = number | { valueOf(): number };
36
37export type UnknownReturnType<Unknown, DefaultUnknown> = [Unknown] extends [never] ? DefaultUnknown : Unknown;
38
39/**
40 * A helper interface for a continuous scale defined over a numeric domain.
41 */
42export interface ScaleContinuousNumeric<Range, Output, Unknown = never> {
43 /**
44 * Given a value from the domain, returns the corresponding value from the range, subject to interpolation, if any.
45 *
46 * If the given value is outside the domain, and clamping is not enabled, the mapping may be extrapolated such that the returned value is outside the range.
47 *
48 * Note: The interpolation function applied by the scale may change the output type from the range type as part of the interpolation.
49 *
50 * @param value A numeric value from the domain.
51 */
52 (value: NumberValue): Output | Unknown;
53
54 /**
55 * Given a value from the range, returns the corresponding value from the domain. Inversion is useful for interaction,
56 * say to determine the data value corresponding to the position of the mouse.
57 *
58 * If the given value is outside the range, and clamping is not enabled, the mapping may be extrapolated such that the returned value is outside the domain.
59 *
60 * IMPORTANT: This method is only supported if the range is numeric. If the range is not numeric, returns NaN.
61 *
62 * For a valid value y in the range, continuous(continuous.invert(y)) approximately equals y;
63 * similarly, for a valid value x in the domain, continuous.invert(continuous(x)) approximately equals x.
64 * The scale and its inverse may not be exact due to the limitations of floating point precision.
65 *
66 * @param value A numeric value from the range.
67 */
68 invert(value: NumberValue): number;
69
70 /**
71 * Returns a copy of the scale’s current domain.
72 */
73 domain(): number[];
74 /**
75 * Sets the scale’s domain to the specified array of numbers. The array must contain two or more elements.
76 * If the elements in the given array are not numbers, they will be coerced to numbers
77 *
78 * Although continuous scales typically have two values each in their domain and range, specifying more than two values produces a piecewise scale.
79 *
80 * Internally, a piecewise scale performs a binary search for the range interpolator corresponding to the given domain value.
81 * Thus, the domain must be in ascending or descending order. If the domain and range have different lengths N and M, only the first min(N,M) elements in each are observed.
82 *
83 * @param domain Array of numeric domain values.
84 */
85 domain(domain: Iterable<NumberValue>): this;
86
87 /**
88 * Returns a copy of the scale’s current range.
89 */
90 range(): Range[];
91 /**
92 * Sets the scale’s range to the specified array of values.
93 *
94 * The array must contain two or more elements. Unlike the domain, elements in the given array need not be numbers;
95 * any value that is supported by the underlying interpolator will work, though note that numeric ranges are required for invert.
96 *
97 * @param range Array of range values.
98 */
99 range(range: Iterable<Range>): this;
100
101 /**
102 * Sets the scale’s range to the specified array of values while also setting the scale’s interpolator to interpolateRound.
103 *
104 * The rounding interpolator is sometimes useful for avoiding antialiasing artifacts,
105 * though also consider the shape-rendering “crispEdges” styles. Note that this interpolator can only be used with numeric ranges.
106 *
107 * The array must contain two or more elements. Unlike the domain, elements in the given array need not be numbers;
108 * any value that is supported by the underlying interpolator will work, though note that numeric ranges are required for invert.
109 *
110 * @param range Array of range values.
111 */
112 rangeRound(range: Iterable<NumberValue>): this;
113
114 /**
115 * Returns whether or not the scale currently clamps values to within the range.
116 */
117 clamp(): boolean;
118 /**
119 * Enables or disables clamping, respectively. If clamping is disabled and the scale is passed a value outside the domain,
120 * the scale may return a value outside the range through extrapolation.
121 *
122 * If clamping is enabled, the return value of the scale is always within the scale’s range. Clamping similarly applies to the "invert" method.
123 *
124 * @param clamp A flag to enable (true) or disable (false) clamping.
125 */
126 clamp(clamp: boolean): this;
127
128 /**
129 * Returns approximately count representative values from the scale’s domain.
130 *
131 * If count is not specified, it defaults to 10.
132 *
133 * The returned tick values are uniformly spaced, have human-readable values (such as multiples of powers of 10),
134 * and are guaranteed to be within the extent of the domain. Ticks are often used to display reference lines, or tick marks, in conjunction with the visualized data.
135 * The specified count is only a hint; the scale may return more or fewer values depending on the domain. See also d3-array’s ticks.
136 *
137 * @param count Optional approximate number of ticks to be returned. If count is not specified, it defaults to 10.
138 */
139 ticks(count?: number): number[];
140
141 /**
142 * Returns a number format function suitable for displaying a tick value, automatically computing the appropriate precision based on the fixed interval between tick values.
143 * The specified count should have the same value as the count that is used to generate the tick values.
144 *
145 * @param count Approximate number of ticks to be used when calculating precision for the number format function.
146 * @param specifier An optional valid format specifier string which allows a custom format where the precision of the format is automatically set by the scale as appropriate for the tick interval.
147 * If specifier uses the format type "s", the scale will return a SI-prefix format based on the largest value in the domain.
148 * If the specifier already specifies a precision, this method is equivalent to locale.format.
149 */
150 tickFormat(count?: number, specifier?: string): (d: NumberValue) => string;
151
152 /**
153 * Extends the domain so that it starts and ends on nice round values.
154 * This method typically modifies the scale’s domain, and may only extend the bounds to the nearest round value.
155 * An optional tick count argument allows greater control over the step size used to extend the bounds,
156 * guaranteeing that the returned ticks will exactly cover the domain.
157 * Nicing is useful if the domain is computed from data, say using extent, and may be irregular.
158 * For example, for a domain of [0.201479…, 0.996679…], a nice domain might be [0.2, 1.0].
159 * If the domain has more than two values, nicing the domain only affects the first and last value.
160 *
161 * Nicing a scale only modifies the current domain; it does not automatically nice domains that are subsequently set using continuous.domain.
162 * You must re-nice the scale after setting the new domain, if desired.
163 *
164 * @param count An optional number of ticks expected to be used.
165 */
166 nice(count?: number): this;
167
168 /**
169 * Returns an exact copy of this scale. Changes to this scale will not affect the returned scale, and vice versa.
170 */
171 copy(): this;
172}
173
174/**
175 * Returns a number format function suitable for displaying a tick value,
176 * automatically computing the appropriate precision based on the fixed interval between tick values, as determined by d3.tickStep.
177 *
178 * @param start Start
179 * @param stop Stop
180 * @param count Approximate number of ticks to be used when calculating precision for the number format function.
181 * @param specifier An optional specifier allows a custom format where the precision of the format is automatically set by the scale as appropriate for the tick interval.
182 * If specifier uses the format type s, the scale will return a SI-prefix format based on the larger absolute value of start and stop.
183 * If the specifier already specifies a precision, this method is equivalent to locale.format.
184 */
185export function tickFormat(start: number, stop: number, count: number, specifier?: string): (d: NumberValue) => string;
186
187// -------------------------------------------------------------------------------
188// Linear Scale Factory
189// -------------------------------------------------------------------------------
190
191/**
192 * A linear continuous scale defined over a numeric domain.
193 *
194 * Continuous scales map a continuous, quantitative input domain to a continuous output range.
195 * Each range value y can be expressed as a function of the domain value x: y = mx + b.
196 *
197 * If the range is also numeric, the mapping may be inverted.
198 *
199 * Note that the data types of the range and output of the scale must be compatible with the interpolator applied by the scale.
200 *
201 * The first generic corresponds to the data type of the range elements.
202 *
203 * The second generic corresponds to the data type of the output elements generated by the scale.
204 *
205 * The third generic corresponds to the data type of the unknown value.
206 *
207 * If range element and output element type differ, the interpolator factory used with the scale must match this behavior and
208 * convert the interpolated range element to a corresponding output element.
209 */
210export interface ScaleLinear<Range, Output, Unknown = never> extends ScaleContinuousNumeric<Range, Output, Unknown> {
211 /**
212 * Returns the scale’s current interpolator factory, which defaults to interpolate.
213 */
214 interpolate(): InterpolatorFactory<any, any>;
215
216 /**
217 * Sets the scale’s range interpolator factory. This interpolator factory is used to create interpolators for each adjacent pair of values from the range;
218 * these interpolators then map a normalized domain parameter t in [0, 1] to the corresponding value in the range.
219 *
220 * Note: the default interpolator may reuse return values. For example, if the range values are objects, then the value interpolator always returns the same object, modifying it in-place.
221 * If the scale is used to set an attribute or style, this is typically acceptable (and desirable for performance);
222 * however, if you need to store the scale’s return value, you must specify your own interpolator or make a copy as appropriate.
223 *
224 * As part of the interpolation process the interpolated value from the range may be converted to a corresponding output value.
225 *
226 * @param interpolate An interpolation factory. The generics for Range and Output of the scale must correspond to the interpolation factory applied to the scale.
227 */
228 interpolate(interpolate: InterpolatorFactory<Range, Output>): this;
229 /**
230 * Sets the scale’s range interpolator factory. This interpolator factory is used to create interpolators for each adjacent pair of values from the range;
231 * these interpolators then map a normalized domain parameter t in [0, 1] to the corresponding value in the range.
232 *
233 * Note: the default interpolator may reuse return values. For example, if the range values are objects, then the value interpolator always returns the same object, modifying it in-place.
234 * If the scale is used to set an attribute or style, this is typically acceptable (and desirable for performance);
235 * however, if you need to store the scale’s return value, you must specify your own interpolator or make a copy as appropriate.
236 *
237 * As part of the interpolation process the interpolated value from the range may be converted to a corresponding output value.
238 *
239 * The generic "NewOutput" can be used to change the scale to have a different output element type corresponding to the new interpolation factory.
240 *
241 * @param interpolate An interpolation factory. The generics for Range and Output of the scale must correspond to the interpolation factory applied to the scale.
242 */
243 interpolate<NewOutput>(interpolate: InterpolatorFactory<Range, NewOutput>): ScaleLinear<Range, NewOutput, Unknown>;
244
245 /**
246 * Returns the current unknown value, which defaults to undefined.
247 */
248 unknown(): UnknownReturnType<Unknown, undefined>;
249 /**
250 * Sets the output value of the scale for undefined (or NaN) input values and returns this scale.
251 *
252 * @param value The output value of the scale for undefined (or NaN) input values.
253 */
254 unknown<NewUnknown>(value: NewUnknown): ScaleLinear<Range, Output, NewUnknown>;
255}
256
257/**
258 * Constructs a new continuous scale with the specified range, the default interpolator and clamping disabled.
259 * The domain defaults to [0, 1].
260 * If range is not specified, it defaults to [0, 1].
261 *
262 * The first generic corresponds to the data type of the range elements.
263 * The second generic corresponds to the data type of the output elements generated by the scale.
264 * The third generic corresponds to the data type of the unknown value.
265 *
266 * If range element and output element type differ, the interpolator factory used with the scale must match this behavior and
267 * convert the interpolated range element to a corresponding output element.
268 *
269 * The range must be set in accordance with the range element type.
270 *
271 * The interpolator factory may be set using the interpolate(...) method of the scale.
272 *
273 * @param range Array of range values.
274 */
275export function scaleLinear<Range = number, Output = Range, Unknown = never>(
276 range?: Iterable<Range>
277// tslint:disable-next-line:no-unnecessary-generics
278): ScaleLinear<Range, Output, Unknown>;
279/**
280 * Constructs a new continuous scale with the specified domain and range, the default interpolator and clamping disabled.
281 *
282 * The first generic corresponds to the data type of the range elements.
283 * The second generic corresponds to the data type of the output elements generated by the scale.
284 * The third generic corresponds to the data type of the unknown value.
285 *
286 * If range element and output element type differ, the interpolator factory used with the scale must match this behavior and
287 * convert the interpolated range element to a corresponding output element.
288 *
289 * The range must be set in accordance with the range element type.
290 *
291 * The interpolator factory may be set using the interpolate(...) method of the scale.
292 *
293 * @param domain Array of numeric domain values.
294 * @param range Array of range values.
295 */
296export function scaleLinear<Range, Output = Range, Unknown = never>(
297 domain: Iterable<NumberValue>,
298 range: Iterable<Range>
299// tslint:disable-next-line:no-unnecessary-generics
300): ScaleLinear<Range, Output, Unknown>;
301
302// -------------------------------------------------------------------------------
303// Power Scale Factories
304// -------------------------------------------------------------------------------
305
306/**
307 * A continuous power scale defined over a numeric domain.
308 *
309 * Continuous scales map a continuous, quantitative input domain to a continuous output range.
310 *
311 * Each range value y can be expressed as a function of the domain value x: y = mx^k + b, where k is the exponent value.
312 * Power scales also support negative domain values, in which case the input value and the resulting output value are multiplied by -1.
313 *
314 * If the range is also numeric, the mapping may be inverted.
315 *
316 * Note that the data types of the range and output of the scale must be compatible with the interpolator applied by the scale.
317 *
318 * The first generic corresponds to the data type of the range elements.
319 *
320 * The second generic corresponds to the data type of the output elements generated by the scale.
321 *
322 * The third generic corresponds to the data type of the unknown value.
323 *
324 * If range element and output element type differ, the interpolator factory used with the scale must match this behavior and
325 * convert the interpolated range element to a corresponding output element.
326 */
327export interface ScalePower<Range, Output, Unknown = never> extends ScaleContinuousNumeric<Range, Output, Unknown> {
328 /**
329 * Returns the scale’s current interpolator factory, which defaults to interpolate.
330 */
331 interpolate(): InterpolatorFactory<any, any>;
332
333 /**
334 * Sets the scale’s range interpolator factory. This interpolator factory is used to create interpolators for each adjacent pair of values from the range;
335 * these interpolators then map a normalized domain parameter t in [0, 1] to the corresponding value in the range.
336 *
337 * Note: the default interpolator may reuse return values. For example, if the range values are objects, then the value interpolator always returns the same object, modifying it in-place.
338 * If the scale is used to set an attribute or style, this is typically acceptable (and desirable for performance);
339 * however, if you need to store the scale’s return value, you must specify your own interpolator or make a copy as appropriate.
340 *
341 * As part of the interpolation process the interpolated value from the range may be converted to a corresponding output value.
342 *
343 * @param interpolate An interpolation factory. The generics for Range and Output of the scale must correspond to the interpolation factory applied to the scale.
344 */
345 interpolate(interpolate: InterpolatorFactory<Range, Output>): this;
346 /**
347 * Sets the scale’s range interpolator factory. This interpolator factory is used to create interpolators for each adjacent pair of values from the range;
348 * these interpolators then map a normalized domain parameter t in [0, 1] to the corresponding value in the range.
349 *
350 * Note: the default interpolator may reuse return values. For example, if the range values are objects, then the value interpolator always returns the same object, modifying it in-place.
351 * If the scale is used to set an attribute or style, this is typically acceptable (and desirable for performance);
352 * however, if you need to store the scale’s return value, you must specify your own interpolator or make a copy as appropriate.
353 *
354 * As part of the interpolation process the interpolated value from the range may be converted to a corresponding output value.
355 *
356 * The generic "NewOutput" can be used to change the scale to have a different output element type corresponding to the new interpolation factory.
357 *
358 * @param interpolate An interpolation factory. The generics for Range and Output of the scale must correspond to the interpolation factory applied to the scale.
359 */
360 interpolate<NewOutput>(interpolate: InterpolatorFactory<Range, NewOutput>): ScalePower<Range, NewOutput, Unknown>;
361
362 /**
363 * If exponent is not specified, returns the current exponent, which defaults to 1.
364 * (Note that this is effectively a linear scale until you set a different exponent.)
365 */
366 exponent(): number;
367 /**
368 * Sets the current exponent to the given numeric value.
369 * (Note that this is effectively a linear scale until you set a different exponent.)
370 */
371 exponent(exponent: number): this;
372
373 /**
374 * Returns the current unknown value, which defaults to undefined.
375 */
376 unknown(): UnknownReturnType<Unknown, undefined>;
377 /**
378 * Sets the output value of the scale for undefined (or NaN) input values and returns this scale.
379 *
380 * @param value The output value of the scale for undefined (or NaN) input values.
381 */
382 unknown<NewUnknown>(value: NewUnknown): ScalePower<Range, Output, NewUnknown>;
383}
384
385/**
386 * Constructs a new continuous scale with the specified range, the exponent 1, the default interpolator and clamping disabled.
387 * The domain defaults to [0, 1].
388 * If range is not specified, it defaults to [0, 1].
389 * (Note that this is effectively a linear scale until you set a different exponent.)
390 *
391 * The first generic corresponds to the data type of the range elements.
392 * The second generic corresponds to the data type of the output elements generated by the scale.
393 * The third generic corresponds to the data type of the unknown value.
394 *
395 * If range element and output element type differ, the interpolator factory used with the scale must match this behavior and
396 * convert the interpolated range element to a corresponding output element.
397 *
398 * The range must be set in accordance with the range element type.
399 *
400 * The interpolator factory may be set using the interpolate(...) method of the scale.
401 *
402 * @param range Array of range values.
403 */
404export function scalePow<Range = number, Output = Range, Unknown = never>(
405 range?: Iterable<Range>
406// tslint:disable-next-line:no-unnecessary-generics
407): ScalePower<Range, Output, Unknown>;
408/**
409 * Constructs a new continuous scale with the specified domain and range, the exponent 1, the default interpolator and clamping disabled.
410 * (Note that this is effectively a linear scale until you set a different exponent.)
411 *
412 * The first generic corresponds to the data type of the range elements.
413 * The second generic corresponds to the data type of the output elements generated by the scale.
414 * The third generic corresponds to the data type of the unknown value.
415 *
416 * If range element and output element type differ, the interpolator factory used with the scale must match this behavior and
417 * convert the interpolated range element to a corresponding output element.
418 *
419 * The range must be set in accordance with the range element type.
420 *
421 * The interpolator factory may be set using the interpolate(...) method of the scale.
422 *
423 * @param domain Array of numeric domain values.
424 * @param range Array of range values.
425 */
426export function scalePow<Range, Output = Range, Unknown = never>(
427 domain: Iterable<NumberValue>,
428 range: Iterable<Range>
429// tslint:disable-next-line:no-unnecessary-generics
430): ScalePower<Range, Output, Unknown>;
431
432/**
433 * Constructs a new continuous power scale with the specified range, the exponent 0.5, the default interpolator and clamping disabled.
434 * The domain defaults to [0, 1].
435 * If range is not specified, it defaults to [0, 1].
436 * This is a convenience method equivalent to d3.scalePow().exponent(0.5).
437 *
438 * The first generic corresponds to the data type of the range elements.
439 * The second generic corresponds to the data type of the output elements generated by the scale.
440 * The third generic corresponds to the data type of the unknown value.
441 *
442 * If range element and output element type differ, the interpolator factory used with the scale must match this behavior and
443 * convert the interpolated range element to a corresponding output element.
444 *
445 * The range must be set in accordance with the range element type.
446 *
447 * The interpolator factory may be set using the interpolate(...) method of the scale.
448 *
449 * @param range Array of range values.
450 */
451export function scaleSqrt<Range = number, Output = Range, Unknown = never>(
452 range?: Iterable<Range>
453// tslint:disable-next-line:no-unnecessary-generics
454): ScalePower<Range, Output, Unknown>;
455/**
456 * Constructs a new continuous power scale with the specified domain and range, the exponent 0.5, the default interpolator and clamping disabled.
457 * This is a convenience method equivalent to d3.scalePow().exponent(0.5).
458 *
459 * The first generic corresponds to the data type of the range elements.
460 * The second generic corresponds to the data type of the output elements generated by the scale.
461 * The third generic corresponds to the data type of the unknown value.
462 *
463 * If range element and output element type differ, the interpolator factory used with the scale must match this behavior and
464 * convert the interpolated range element to a corresponding output element.
465 *
466 * The range must be set in accordance with the range element type.
467 *
468 * The interpolator factory may be set using the interpolate(...) method of the scale.
469 *
470 * @param domain Array of numeric domain values.
471 * @param range Array of range values.
472 */
473export function scaleSqrt<Range, Output = Range, Unknown = never>(
474 domain: Iterable<NumberValue>,
475 range: Iterable<Range>
476// tslint:disable-next-line:no-unnecessary-generics
477): ScalePower<Range, Output, Unknown>;
478
479// -------------------------------------------------------------------------------
480// Logarithmic Scale Factory
481// -------------------------------------------------------------------------------
482
483/**
484 * A continuous logarithmic scale defined over a numeric domain.
485 *
486 * Continuous scales map a continuous, quantitative input domain to a continuous output range.
487 *
488 * The mapping to the range value y can be expressed as a function of the domain value x: y = m log(x) + b.
489 *
490 * As log(0) = -∞, a log scale domain must be strictly-positive or strictly-negative; the domain must not include or cross zero.
491 * A log scale with a positive domain has a well-defined behavior for positive values, and a log scale with a negative domain has a well-defined behavior for negative values.
492 * (For a negative domain, input and output values are implicitly multiplied by -1.)
493 * The behavior of the scale is undefined if you pass a negative value to a log scale with a positive domain or vice versa.
494 *
495 * If the range is also numeric, the mapping may be inverted.
496 *
497 * Note that the data types of the range and output of the scale must be compatible with the interpolator applied by the scale.
498 *
499 * The first generic corresponds to the data type of the range elements.
500 *
501 * The second generic corresponds to the data type of the output elements generated by the scale.
502 *
503 * The third generic corresponds to the data type of the unknown value.
504 *
505 * If range element and output element type differ, the interpolator factory used with the scale must match this behavior and
506 * convert the interpolated range element to a corresponding output element.
507 */
508export interface ScaleLogarithmic<Range, Output, Unknown = never>
509 extends ScaleContinuousNumeric<Range, Output, Unknown> {
510 /**
511 * Returns a copy of the scale’s current domain.
512 */
513 domain(): number[];
514 /**
515 * Sets the scale’s domain to the specified array of numbers. The array must contain two or more elements.
516 * If the elements in the given array are not numbers, they will be coerced to numbers
517 *
518 * As log(0) = -∞, a log scale domain must be strictly-positive or strictly-negative; the domain must not include or cross zero.
519 * A log scale with a positive domain has a well-defined behavior for positive values, and a log scale with a negative domain has a well-defined behavior for negative values.
520 * (For a negative domain, input and output values are implicitly multiplied by -1.)
521 * The behavior of the scale is undefined if you pass a negative value to a log scale with a positive domain or vice versa.
522 *
523 * Although continuous scales typically have two values each in their domain and range, specifying more than two values produces a piecewise scale.
524 *
525 * Internally, a piecewise scale performs a binary search for the range interpolator corresponding to the given domain value.
526 * Thus, the domain must be in ascending or descending order. If the domain and range have different lengths N and M, only the first min(N,M) elements in each are observed.
527 *
528 * @param domain Array of numeric domain values.
529 */
530 domain(domain: Iterable<NumberValue>): this;
531
532 /**
533 * Returns the scale’s current interpolator factory, which defaults to interpolate.
534 */
535 interpolate(): InterpolatorFactory<any, any>;
536
537 /**
538 * Sets the scale’s range interpolator factory. This interpolator factory is used to create interpolators for each adjacent pair of values from the range;
539 * these interpolators then map a normalized domain parameter t in [0, 1] to the corresponding value in the range.
540 *
541 * Note: the default interpolator may reuse return values. For example, if the range values are objects, then the value interpolator always returns the same object, modifying it in-place.
542 * If the scale is used to set an attribute or style, this is typically acceptable (and desirable for performance);
543 * however, if you need to store the scale’s return value, you must specify your own interpolator or make a copy as appropriate.
544 *
545 * As part of the interpolation process the interpolated value from the range may be converted to a corresponding output value.
546 *
547 * @param interpolate An interpolation factory. The generics for Range and Output of the scale must correspond to the interpolation factory applied to the scale.
548 */
549 interpolate(interpolate: InterpolatorFactory<Range, Output>): this;
550 /**
551 * Sets the scale’s range interpolator factory. This interpolator factory is used to create interpolators for each adjacent pair of values from the range;
552 * these interpolators then map a normalized domain parameter t in [0, 1] to the corresponding value in the range.
553 *
554 * Note: the default interpolator may reuse return values. For example, if the range values are objects, then the value interpolator always returns the same object, modifying it in-place.
555 * If the scale is used to set an attribute or style, this is typically acceptable (and desirable for performance);
556 * however, if you need to store the scale’s return value, you must specify your own interpolator or make a copy as appropriate.
557 *
558 * As part of the interpolation process the interpolated value from the range may be converted to a corresponding output value.
559 *
560 * The generic "NewOutput" can be used to change the scale to have a different output element type corresponding to the new interpolation factory.
561 *
562 * @param interpolate An interpolation factory. The generics for Range and Output of the scale must correspond to the interpolation factory applied to the scale.
563 */
564 interpolate<NewOutput>(
565 interpolate: InterpolatorFactory<Range, NewOutput>
566 ): ScaleLogarithmic<Range, NewOutput, Unknown>;
567
568 /**
569 * Returns approximately count representative values from the scale’s domain.
570 *
571 * If count is not specified, it defaults to 10.
572 *
573 * If the base is an integer, the returned ticks are uniformly spaced within each integer power of base; otherwise, one tick per power of base is returned.
574 * The returned ticks are guaranteed to be within the extent of the domain. If the orders of magnitude in the domain is greater than count, then at most one tick per power is returned.
575 * Otherwise, the tick values are unfiltered, but note that you can use log.tickFormat to filter the display of tick labels.
576 *
577 * @param count Optional approximate number of ticks to be returned. If count is not specified, it defaults to 10.
578 */
579 ticks(count?: number): number[];
580
581 /**
582 * Returns a number format function suitable for displaying a tick value, automatically computing the appropriate precision based on the fixed interval between tick values.
583 *
584 * The specified count typically has the same value as the count that is used to generate the tick values.
585 * If there are too many ticks, the formatter may return the empty string for some of the tick labels;
586 * however, note that the ticks are still shown.
587 * To disable filtering, specify a count of Infinity. When specifying a count, you may also provide a format specifier or format function.
588 * For example, to get a tick formatter that will display 20 ticks of a currency, say log.tickFormat(20, "$,f").
589 * If the specifier does not have a defined precision, the precision will be set automatically by the scale, returning the appropriate format.
590 * This provides a convenient way of specifying a format whose precision will be automatically set by the scale.
591 *
592 * @param count Approximate number of ticks to be used when calculating precision for the number format function.
593 * @param specifier An optional valid format specifier string which allows a custom format where the precision of the format is automatically set by the scale as appropriate for the tick interval.
594 * For example, to get a tick formatter that will display 20 ticks of a currency, say log.tickFormat(20, "$,f").
595 * If the specifier does not have a defined precision, the precision will be set automatically by the scale, returning the appropriate format.
596 * This provides a convenient way of specifying a format whose precision will be automatically set by the scale.
597 */
598 tickFormat(count?: number, specifier?: string): (d: NumberValue) => string;
599
600 /**
601 * Extends the domain to integer powers of base. For example, for a domain of [0.201479…, 0.996679…], and base 10, the nice domain is [0.1, 1].
602 * If the domain has more than two values, nicing the domain only affects the first and last value.
603 *
604 * Nicing a scale only modifies the current domain; it does not automatically nice domains that are subsequently set using continuous.domain.
605 * You must re-nice the scale after setting the new domain, if desired.
606 */
607 nice(): this;
608
609 /**
610 * Returns the current base, which defaults to 10.
611 */
612 base(): number;
613 /**
614 * Sets the base for this logarithmic scale to the specified value.
615 */
616 base(base: number): this;
617
618 /**
619 * Returns the current unknown value, which defaults to undefined.
620 */
621 unknown(): UnknownReturnType<Unknown, undefined>;
622 /**
623 * Sets the output value of the scale for undefined (or NaN) input values and returns this scale.
624 *
625 * @param value The output value of the scale for undefined (or NaN) input values.
626 */
627 unknown<NewUnknown>(value: NewUnknown): ScaleLogarithmic<Range, Output, NewUnknown>;
628}
629
630/**
631 * Constructs a new continuous scale with the specified range, the base 10, the default interpolator and clamping disabled.
632 * The domain defaults to [1, 10].
633 * If range is not specified, it defaults to [0, 1].
634 *
635 * The first generic corresponds to the data type of the range elements.
636 * The second generic corresponds to the data type of the output elements generated by the scale.
637 * The third generic corresponds to the data type of the unknown value.
638 *
639 * If range element and output element type differ, the interpolator factory used with the scale must match this behavior and
640 * convert the interpolated range element to a corresponding output element.
641 *
642 * The range must be set in accordance with the range element type.
643 *
644 * The interpolator factory may be set using the interpolate(...) method of the scale.
645 *
646 * @param range Array of range values.
647 */
648export function scaleLog<Range = number, Output = Range, Unknown = never>(
649 range?: Iterable<Range>
650// tslint:disable-next-line:no-unnecessary-generics
651): ScaleLogarithmic<Range, Output, Unknown>;
652/**
653 * Constructs a new continuous scale with the specified domain and range, the base 10, the default interpolator and clamping disabled.
654 *
655 * The first generic corresponds to the data type of the range elements.
656 * The second generic corresponds to the data type of the output elements generated by the scale.
657 * The third generic corresponds to the data type of the unknown value.
658 *
659 * If range element and output element type differ, the interpolator factory used with the scale must match this behavior and
660 * convert the interpolated range element to a corresponding output element.
661 *
662 * The range must be set in accordance with the range element type.
663 *
664 * The interpolator factory may be set using the interpolate(...) method of the scale.
665 *
666 * @param domain Array of numeric domain values.
667 * @param range Array of range values.
668 */
669export function scaleLog<Range, Output = Range, Unknown = never>(
670 domain: Iterable<NumberValue>,
671 range: Iterable<Range>
672// tslint:disable-next-line:no-unnecessary-generics
673): ScaleLogarithmic<Range, Output, Unknown>;
674
675// -------------------------------------------------------------------------------
676// Symlog Scale Factory
677// -------------------------------------------------------------------------------
678
679/**
680 * A bi-symmetric log transformation for wide-range data by Webber scale defined over a numeric domain.
681 *
682 * Continuous scales map a continuous, quantitative input domain to a continuous output range.
683 *
684 * See “A bi-symmetric log transformation for wide-range data” by Webber for more
685 *
686 * If the range is also numeric, the mapping may be inverted.
687 *
688 * Note that the data types of the range and output of the scale must be compatible with the interpolator applied by the scale.
689 *
690 * The first generic corresponds to the data type of the range elements.
691 *
692 * The second generic corresponds to the data type of the output elements generated by the scale.
693 *
694 * The third generic corresponds to the data type of the unknown value.
695 *
696 * If range element and output element type differ, the interpolator factory used with the scale must match this behavior and
697 * convert the interpolated range element to a corresponding output element.
698 */
699export interface ScaleSymLog<Range, Output, Unknown = never> extends ScaleContinuousNumeric<Range, Output, Unknown> {
700 /**
701 * Returns a number format function suitable for displaying a tick value, automatically computing the appropriate precision based on the fixed interval between tick values.
702 *
703 * The specified count typically has the same value as the count that is used to generate the tick values.
704 * If there are too many ticks, the formatter may return the empty string for some of the tick labels;
705 * however, note that the ticks are still shown.
706 * To disable filtering, specify a count of Infinity. When specifying a count, you may also provide a format specifier or format function.
707 * For example, to get a tick formatter that will display 20 ticks of a currency, say log.tickFormat(20, "$,f").
708 * If the specifier does not have a defined precision, the precision will be set automatically by the scale, returning the appropriate format.
709 * This provides a convenient way of specifying a format whose precision will be automatically set by the scale.
710 *
711 * @param count Approximate number of ticks to be used when calculating precision for the number format function.
712 * @param specifier An optional valid format specifier string which allows a custom format where the precision of the format is automatically set by the scale as appropriate for the tick interval.
713 * For example, to get a tick formatter that will display 20 ticks of a currency, say log.tickFormat(20, "$,f").
714 * If the specifier does not have a defined precision, the precision will be set automatically by the scale, returning the appropriate format.
715 * This provides a convenient way of specifying a format whose precision will be automatically set by the scale.
716 */
717 tickFormat(count?: number, specifier?: string): (d: NumberValue) => string;
718 /**
719 * Returns the current constant, which defaults to 1.
720 */
721 constant(): number;
722 /**
723 * Sets the symlog constant to the specified number and returns this scale;
724 * otherwise returns the current value of the symlog constant, which defaults to 1. See “A bi-symmetric log transformation for wide-range data” by Webber for more.
725 */
726 constant(constant: number): this;
727
728 /**
729 * Returns the current unknown value, which defaults to undefined.
730 */
731 unknown(): UnknownReturnType<Unknown, undefined>;
732 /**
733 * Sets the output value of the scale for undefined (or NaN) input values and returns this scale.
734 *
735 * @param value The output value of the scale for undefined (or NaN) input values.
736 */
737 unknown<NewUnknown>(value: NewUnknown): ScaleSymLog<Range, Output, NewUnknown>;
738}
739
740/**
741 * Constructs a new continuous scale with the specified range, the constant 1, the default interpolator and clamping disabled.
742 * The domain defaults to [0, 1].
743 * If range is not specified, it defaults to [0, 1].
744 *
745 * The first generic corresponds to the data type of the range elements.
746 * The second generic corresponds to the data type of the output elements generated by the scale.
747 * The third generic corresponds to the data type of the unknown value.
748 *
749 * If range element and output element type differ, the interpolator factory used with the scale must match this behavior and
750 * convert the interpolated range element to a corresponding output element.
751 *
752 * The range must be set in accordance with the range element type.
753 *
754 * The interpolator factory may be set using the interpolate(...) method of the scale.
755 *
756 * @param range Array of range values.
757 */
758export function scaleSymlog<Range = number, Output = Range, Unknown = never>(
759 range?: Iterable<Range>
760// tslint:disable-next-line:no-unnecessary-generics
761): ScaleSymLog<Range, Output, Unknown>;
762/**
763 * Constructs a new continuous scale with the specified domain and range, the constant 1, the default interpolator and clamping disabled.
764 *
765 * The first generic corresponds to the data type of the range elements.
766 * The second generic corresponds to the data type of the output elements generated by the scale.
767 * The third generic corresponds to the data type of the unknown value.
768 *
769 * If range element and output element type differ, the interpolator factory used with the scale must match this behavior and
770 * convert the interpolated range element to a corresponding output element.
771 *
772 * The range must be set in accordance with the range element type.
773 *
774 * The interpolator factory may be set using the interpolate(...) method of the scale.
775 *
776 * @param domain Array of numeric domain values.
777 * @param range Array of range values.
778 */
779export function scaleSymlog<Range, Output = Range, Unknown = never>(
780 domain: Iterable<NumberValue>,
781 range: Iterable<Range>
782// tslint:disable-next-line:no-unnecessary-generics
783): ScaleSymLog<Range, Output, Unknown>;
784
785// -------------------------------------------------------------------------------
786// Identity Scale Factory
787// -------------------------------------------------------------------------------
788
789/**
790 * Identity scales are a special case of linear scales where the domain and range are identical; the scale and its invert method are thus the identity function.
791 * These scales are occasionally useful when working with pixel coordinates, say in conjunction with an axis.
792 *
793 * The generic corresponds to the data type of the unknown value.
794 */
795export interface ScaleIdentity<Unknown = never> {
796 /**
797 * Given a value from the domain, returns the corresponding value from the range, subject to interpolation, if any.
798 *
799 * If the given value is outside the domain, and clamping is not enabled, the mapping may be extrapolated such that the returned value is outside the range.
800 *
801 * Note: The interpolation function applied by the scale may change the output type from the range type as part of the interpolation.
802 *
803 * @param value A numeric value from the domain.
804 */
805 (value: NumberValue): number | Unknown;
806
807 /**
808 * Given a value from the range, returns the corresponding value from the domain. Inversion is useful for interaction,
809 * say to determine the data value corresponding to the position of the mouse.
810 *
811 * If the given value is outside the range, and clamping is not enabled, the mapping may be extrapolated such that the returned value is outside the domain.
812 *
813 * IMPORTANT: This method is only supported if the range is numeric. If the range is not numeric, returns NaN.
814 *
815 * For a valid value y in the range, continuous(continuous.invert(y)) approximately equals y;
816 * similarly, for a valid value x in the domain, continuous.invert(continuous(x)) approximately equals x.
817 * The scale and its inverse may not be exact due to the limitations of floating point precision.
818 *
819 * @param value A numeric value from the range.
820 */
821 invert(value: NumberValue): number;
822
823 /**
824 * Returns a copy of the scale’s current domain.
825 */
826 domain(): number[];
827 /**
828 * Sets the scale’s domain to the specified array of numbers. The array must contain two or more elements.
829 * If the elements in the given array are not numbers, they will be coerced to numbers
830 *
831 * Although continuous scales typically have two values each in their domain and range, specifying more than two values produces a piecewise scale.
832 *
833 * Internally, a piecewise scale performs a binary search for the range interpolator corresponding to the given domain value.
834 * Thus, the domain must be in ascending or descending order. If the domain and range have different lengths N and M, only the first min(N,M) elements in each are observed.
835 *
836 * @param domain Array of numeric domain values.
837 */
838 domain(domain: Iterable<NumberValue>): this;
839
840 /**
841 * Returns a copy of the scale’s current range.
842 */
843 range(): number[];
844 /**
845 * Sets the scale’s range to the specified array of values.
846 *
847 * The array must contain two or more elements. Unlike the domain, elements in the given array need not be numbers;
848 * any value that is supported by the underlying interpolator will work, though note that numeric ranges are required for invert.
849 *
850 * @param range Array of range values.
851 */
852 range(range: Iterable<NumberValue>): this;
853
854 /**
855 * Returns approximately count representative values from the scale’s domain.
856 *
857 * If count is not specified, it defaults to 10.
858 *
859 * The returned tick values are uniformly spaced, have human-readable values (such as multiples of powers of 10),
860 * and are guaranteed to be within the extent of the domain. Ticks are often used to display reference lines, or tick marks, in conjunction with the visualized data.
861 * The specified count is only a hint; the scale may return more or fewer values depending on the domain. See also d3-array’s ticks.
862 *
863 * @param count Optional approximate number of ticks to be returned. If count is not specified, it defaults to 10.
864 */
865 ticks(count?: number): number[];
866
867 /**
868 * Returns a number format function suitable for displaying a tick value, automatically computing the appropriate precision based on the fixed interval between tick values.
869 * The specified count should have the same value as the count that is used to generate the tick values.
870 *
871 * @param count Approximate number of ticks to be used when calculating precision for the number format function.
872 * @param specifier An optional valid format specifier string which allows a custom format where the precision of the format is automatically set by the scale as appropriate for the tick interval.
873 * If specifier uses the format type "s", the scale will return a SI-prefix format based on the largest value in the domain.
874 * If the specifier already specifies a precision, this method is equivalent to locale.format.
875 */
876 tickFormat(count?: number, specifier?: string): (d: NumberValue) => string;
877
878 /**
879 * Extends the domain so that it starts and ends on nice round values.
880 * This method typically modifies the scale’s domain, and may only extend the bounds to the nearest round value.
881 * An optional tick count argument allows greater control over the step size used to extend the bounds,
882 * guaranteeing that the returned ticks will exactly cover the domain.
883 * Nicing is useful if the domain is computed from data, say using extent, and may be irregular.
884 * For example, for a domain of [0.201479…, 0.996679…], a nice domain might be [0.2, 1.0].
885 * If the domain has more than two values, nicing the domain only affects the first and last value.
886 *
887 * Nicing a scale only modifies the current domain; it does not automatically nice domains that are subsequently set using continuous.domain.
888 * You must re-nice the scale after setting the new domain, if desired.
889 *
890 * @param count An optional number of ticks expected to be used.
891 */
892 nice(count?: number): this;
893
894 /**
895 * Returns an exact copy of this scale. Changes to this scale will not affect the returned scale, and vice versa.
896 */
897 copy(): this;
898
899 /**
900 * Returns the current unknown value, which defaults to undefined.
901 */
902 unknown(): UnknownReturnType<Unknown, undefined>;
903 /**
904 * Sets the output value of the scale for undefined (or NaN) input values and returns this scale.
905 *
906 * @param value The output value of the scale for undefined (or NaN) input values.
907 */
908 unknown<NewUnknown>(value: NewUnknown): ScaleIdentity<NewUnknown>;
909}
910
911/**
912 * Constructs a new identity scale with the specified domain and range.
913 * If range is not specified, it defaults to [0, 1].
914 *
915 * The generic corresponds to the data type of the unknown value.
916 *
917 * @param range Array of range values.
918 */
919// tslint:disable-next-line:no-unnecessary-generics
920export function scaleIdentity<Unknown = never>(range?: Iterable<NumberValue>): ScaleIdentity<Unknown>;
921
922// -------------------------------------------------------------------------------
923// Radial Scale Factory
924// -------------------------------------------------------------------------------
925
926export interface ScaleRadial<Range, Output, Unknown = never> extends ScaleContinuousNumeric<Range, Output, Unknown> {
927 /**
928 * Returns the current unknown value, which defaults to undefined.
929 */
930 unknown(): UnknownReturnType<Unknown, undefined>;
931 /**
932 * Sets the output value of the scale for undefined (or NaN) input values and returns this scale.
933 *
934 * @param value The output value of the scale for undefined (or NaN) input values.
935 */
936 unknown<NewUnknown>(value: NewUnknown): ScaleRadial<Range, Output, NewUnknown>;
937}
938
939/**
940 * Constructs a new radial scale with the specified range.
941 * The domain defaults to [0, 1].
942 *
943 * The first generic corresponds to the data type of the range elements.
944 * The second generic corresponds to the data type of the unknown value.
945 *
946 * The range must be set in accordance with the range element type.
947 *
948 * @param range Iterable of range values.
949 */
950export function scaleRadial<Range = number, Unknown = never>(
951 range?: Iterable<Range>
952// tslint:disable-next-line:no-unnecessary-generics
953): ScaleRadial<Range, Range, Unknown>;
954/**
955 * Constructs a new radial scale with the specified domain and range.
956 *
957 * The first generic corresponds to the data type of the range elements.
958 * The second generic corresponds to the data type of the unknown value.
959 *
960 * The range must be set in accordance with the range element type.
961 *
962 * @param domain Iterable of numeric domain values.
963 * @param range Iterable of range values.
964 */
965export function scaleRadial<Range, Unknown = never>(
966 domain: Iterable<NumberValue>,
967 range: Iterable<Range>
968// tslint:disable-next-line:no-unnecessary-generics
969): ScaleRadial<Range, Range, Unknown>;
970
971// -------------------------------------------------------------------------------
972// Time Scale Factories
973// -------------------------------------------------------------------------------
974
975/**
976 * A linear scale defined over a temporal domain.
977 *
978 * Time scales implement ticks based on calendar intervals, taking the pain out of generating axes for temporal domains.
979 *
980 * If the range is numeric, the mapping may be inverted to return a date.
981 *
982 * Note that the data types of the range and output of the scale must be compatible with the interpolator applied by the scale.
983 *
984 * The first generic corresponds to the data type of the range elements.
985 *
986 * The second generic corresponds to the data type of the output elements generated by the scale.
987 *
988 * The third generic corresponds to the data type of the unknown value.
989 *
990 * If range element and output element type differ, the interpolator factory used with the scale must match this behavior and
991 * convert the interpolated range element to a corresponding output element.
992 */
993export interface ScaleTime<Range, Output, Unknown = never> {
994 /**
995 * Given a value from the domain, returns the corresponding value from the range, subject to interpolation, if any.
996 *
997 * If the given value is outside the domain, and clamping is not enabled, the mapping may be extrapolated such that the returned value is outside the range.
998 *
999 * Note: The interpolation function applied by the scale may change the output type from the range type as part of the interpolation.
1000 *
1001 * @param value A temporal value from the domain. If the value is not a Date, it will be coerced to Date.
1002 */
1003 (value: Date | NumberValue): Output | Unknown;
1004
1005 /**
1006 * Given a value from the range, returns the corresponding value from the domain. Inversion is useful for interaction,
1007 * say to determine the data value corresponding to the position of the mouse.
1008 *
1009 * If the given value is outside the range, and clamping is not enabled, the mapping may be extrapolated such that the returned value is outside the domain.
1010 *
1011 * IMPORTANT: This method is only supported if the range is numeric. If the range is not numeric, returns Invalid Date.
1012 *
1013 * For a valid value y in the range, time(time.invert(y)) equals y; similarly, for a valid value x in the domain, time.invert(time(x)) equals x.
1014 * The invert method is useful for interaction, say to determine the value in the domain that corresponds to the pixel location under the mouse.
1015 *
1016 * @param value A numeric value from the range.
1017 */
1018 invert(value: NumberValue): Date;
1019
1020 /**
1021 * Returns a copy of the scale’s current domain.
1022 */
1023 domain(): Date[];
1024
1025 /**
1026 * Sets the scale’s domain to the specified array of temporal domain values. The array must contain two or more elements.
1027 * If the elements in the given array are not dates, they will be coerced to dates.
1028 *
1029 * Although continuous scales typically have two values each in their domain and range, specifying more than two values produces a piecewise scale.
1030 *
1031 * Internally, a piecewise scale performs a binary search for the range interpolator corresponding to the given domain value.
1032 * Thus, the domain must be in ascending or descending order. If the domain and range have different lengths N and M, only the first min(N,M) elements in each are observed.
1033 *
1034 * @param domain Array of temporal domain values. Numeric values will be coerced to dates.
1035 */
1036 domain(domain: Iterable<Date | NumberValue>): this;
1037
1038 /**
1039 * Returns a copy of the scale’s current range.
1040 */
1041 range(): Range[];
1042 /**
1043 * Sets the scale’s range to the specified array of values.
1044 *
1045 * The array must contain two or more elements. Unlike the domain, elements in the given array need not be temporal domain values;
1046 * any value that is supported by the underlying interpolator will work, though note that numeric ranges are required for invert.
1047 *
1048 * @param range Array of range values.
1049 */
1050 range(range: Iterable<Range>): this;
1051
1052 /**
1053 * Sets the scale’s range to the specified array of values while also setting the scale’s interpolator to interpolateRound.
1054 *
1055 * The rounding interpolator is sometimes useful for avoiding antialiasing artifacts,
1056 * though also consider the shape-rendering “crispEdges” styles. Note that this interpolator can only be used with numeric ranges.
1057 *
1058 * The array must contain two or more elements. Unlike the domain, elements in the given array need not be temporal domain values;
1059 * any value that is supported by the underlying interpolator will work, though note that numeric ranges are required for invert.
1060 *
1061 * @param range Array of range values.
1062 */
1063 rangeRound(range: Iterable<NumberValue>): this;
1064
1065 /**
1066 * Returns whether or not the scale currently clamps values to within the range.
1067 */
1068 clamp(): boolean;
1069 /**
1070 * Enables or disables clamping, respectively. If clamping is disabled and the scale is passed a value outside the domain,
1071 * the scale may return a value outside the range through extrapolation.
1072 *
1073 * If clamping is enabled, the return value of the scale is always within the scale’s range. Clamping similarly applies to the "invert" method.
1074 *
1075 * @param clamp A flag to enable (true) or disable (false) clamping.
1076 */
1077 clamp(clamp: boolean): this;
1078
1079 /**
1080 * Returns the scale’s current interpolator factory, which defaults to interpolate.
1081 */
1082 interpolate(): InterpolatorFactory<any, any>;
1083
1084 /**
1085 * Sets the scale’s range interpolator factory. This interpolator factory is used to create interpolators for each adjacent pair of values from the range;
1086 * these interpolators then map a normalized domain parameter t in [0, 1] to the corresponding value in the range.
1087 *
1088 * Note: the default interpolator may reuse return values. For example, if the range values are objects, then the value interpolator always returns the same object, modifying it in-place.
1089 * If the scale is used to set an attribute or style, this is typically acceptable (and desirable for performance);
1090 * however, if you need to store the scale’s return value, you must specify your own interpolator or make a copy as appropriate.
1091 *
1092 * As part of the interpolation process the interpolated value from the range may be converted to a corresponding output value.
1093 *
1094 * @param interpolate An interpolation factory. The generics for Range and Output of the scale must correspond to the interpolation factory applied to the scale.
1095 */
1096 interpolate(interpolate: InterpolatorFactory<Range, Output>): this;
1097 /**
1098 * Sets the scale’s range interpolator factory. This interpolator factory is used to create interpolators for each adjacent pair of values from the range;
1099 * these interpolators then map a normalized domain parameter t in [0, 1] to the corresponding value in the range.
1100 *
1101 * Note: the default interpolator may reuse return values. For example, if the range values are objects, then the value interpolator always returns the same object, modifying it in-place.
1102 * If the scale is used to set an attribute or style, this is typically acceptable (and desirable for performance);
1103 * however, if you need to store the scale’s return value, you must specify your own interpolator or make a copy as appropriate.
1104 *
1105 * As part of the interpolation process the interpolated value from the range may be converted to a corresponding output value.
1106 *
1107 * The generic "NewOutput" can be used to change the scale to have a different output element type corresponding to the new interpolation factory.
1108 *
1109 * @param interpolate An interpolation factory. The generics for Range and Output of the scale must correspond to the interpolation factory applied to the scale.
1110 */
1111 interpolate<NewOutput>(interpolate: InterpolatorFactory<Range, NewOutput>): ScaleTime<Range, NewOutput, Unknown>;
1112
1113 /**
1114 * Returns representative dates from the scale’s domain. The returned tick values are uniformly-spaced (mostly),
1115 * have sensible values (such as every day at midnight), and are guaranteed to be within the extent of the domain.
1116 * Ticks are often used to display reference lines, or tick marks, in conjunction with the visualized data.
1117 *
1118 * An optional count may be specified to affect how many ticks are generated. If count is not specified, it defaults to 10.
1119 * The specified count is only a hint; the scale may return more or fewer values depending on the domain.
1120 *
1121 * @param count Expected number of ticks.
1122 */
1123 ticks(count?: number): Date[];
1124 /**
1125 * Returns representative dates from the scale’s domain. The returned tick values are uniformly-spaced (mostly),
1126 * have sensible values (such as every day at midnight), and are guaranteed to be within the extent of the domain.
1127 * Ticks are often used to display reference lines, or tick marks, in conjunction with the visualized data.
1128 *
1129 * The specified time interval controls the ticks generated and returned. To prune the generated ticks for a given time interval,
1130 * use interval.every(...) or interval.filter(...).
1131 *
1132 * @param interval A time interval to specify the expected ticks.
1133 */
1134 ticks(interval: TimeInterval): Date[];
1135
1136 /**
1137 * Returns a time format function suitable for displaying tick values.
1138 *
1139 * The default multi-scale time format chooses a human-readable representation based on the specified date as follows:
1140 *
1141 * - %Y - for year boundaries, such as 2011.
1142 * - %B - for month boundaries, such as February.
1143 * - %b %d - for week boundaries, such as Feb 06.
1144 * - %a %d - for day boundaries, such as Mon 07.
1145 * - %I %p - for hour boundaries, such as 01 AM.
1146 * - %I:%M - for minute boundaries, such as 01:23.
1147 * - :%S - for second boundaries, such as :45.
1148 * - .%L - milliseconds for all other times, such as .012.
1149 *
1150 * Although somewhat unusual, this default behavior has the benefit of providing both local and global context:
1151 * for example, formatting a sequence of ticks as [11 PM, Mon 07, 01 AM] reveals information about hours, dates, and day simultaneously,
1152 * rather than just the hours [11 PM, 12 AM, 01 AM].
1153 *
1154 * The specified count is currently ignored, but is accepted for consistency with other scales such as continuous.tickFormat.
1155 *
1156 * @param count Expected number of ticks. (Currently ignored)
1157 * @param specifier An optional valid date format specifier string (see d3-time-format).
1158 */
1159 tickFormat(count?: number, specifier?: string): (d: Date) => string;
1160 /**
1161 * Returns a time format function suitable for displaying tick values.
1162 *
1163 * The specified time interval is currently ignored, but is accepted for consistency with other scales such as continuous.tickFormat.
1164 *
1165 * @param interval A time interval to specify the expected ticks. (Currently ignored)
1166 * @param specifier An optional valid date format specifier string (see d3-time-format).
1167 */
1168 tickFormat(interval: TimeInterval, specifier?: string): (d: Date) => string;
1169
1170 /**
1171 * Extends the domain so that it starts and ends on nice round values.
1172 * This method typically modifies the scale’s domain, and may only extend the bounds to the nearest round value.
1173 *
1174 * An optional count argument allows greater control over the step size used to extend the bounds, guaranteeing that the returned ticks will exactly cover the domain.
1175 *
1176 * Nicing is useful if the domain is computed from data, say using extent, and may be irregular.
1177 * For example, for a domain of [2009-07-13T00:02, 2009-07-13T23:48], the nice domain is [2009-07-13, 2009-07-14].
1178 * If the domain has more than two values, nicing the domain only affects the first and last value.
1179 *
1180 * @param count Expected number of ticks.
1181 */
1182 nice(count?: number): this;
1183 /**
1184 * Extends the domain so that it starts and ends on nice round values.
1185 * This method typically modifies the scale’s domain, and may only extend the bounds to the nearest round value.
1186 *
1187 * A time interval may be specified to explicitly set the ticks.
1188 * If an interval is specified, an optional step may also be specified to skip some ticks.
1189 * For example, time.nice(d3.timeSecond.every(10)) will extend the domain to an even ten seconds (0, 10, 20, etc.).
1190 * See time.ticks and interval.every for further detail.
1191 *
1192 * Nicing is useful if the domain is computed from data, say using extent, and may be irregular.
1193 * For example, for a domain of [2009-07-13T00:02, 2009-07-13T23:48], the nice domain is [2009-07-13, 2009-07-14].
1194 * If the domain has more than two values, nicing the domain only affects the first and last value.
1195 *
1196 * @param interval A time interval to specify the expected ticks.
1197 */
1198 nice(interval: CountableTimeInterval): this;
1199
1200 /**
1201 * Returns an exact copy of this scale. Changes to this scale will not affect the returned scale, and vice versa.
1202 */
1203 copy(): this;
1204
1205 /**
1206 * Returns the current unknown value, which defaults to undefined.
1207 */
1208 unknown(): UnknownReturnType<Unknown, undefined>;
1209 /**
1210 * Sets the output value of the scale for undefined (or NaN) input values and returns this scale.
1211 *
1212 * @param value The output value of the scale for undefined (or NaN) input values.
1213 */
1214 unknown<NewUnknown>(value: NewUnknown): ScaleTime<Range, Output, NewUnknown>;
1215}
1216
1217/**
1218 * Constructs a new time scale with the specified range, the default interpolator and clamping disabled.
1219 * The domain defaults to [2000-01-01, 2000-01-02].
1220 * If range is not specified, it defaults to [0, 1].
1221 *
1222 * The first generic corresponds to the data type of the range elements.
1223 * The second generic corresponds to the data type of the output elements generated by the scale.
1224 * The third generic corresponds to the data type of the unknown value.
1225 *
1226 * If range element and output element type differ, the interpolator factory used with the scale must match this behavior and
1227 * convert the interpolated range element to a corresponding output element.
1228 *
1229 * The range must be set in accordance with the range element type.
1230 *
1231 * The interpolator factory may be set using the interpolate(...) method of the scale.
1232 *
1233 * @param range Array of range values.
1234 */
1235export function scaleTime<Range = number, Output = Range, Unknown = never>(
1236 range?: Iterable<Range>
1237// tslint:disable-next-line:no-unnecessary-generics
1238): ScaleTime<Range, Output, Unknown>;
1239/**
1240 * Constructs a new time scale with the specified domain and range, the default interpolator and clamping disabled.
1241 *
1242 * The first generic corresponds to the data type of the range elements.
1243 * The second generic corresponds to the data type of the output elements generated by the scale.
1244 * The third generic corresponds to the data type of the unknown value.
1245 *
1246 * If range element and output element type differ, the interpolator factory used with the scale must match this behavior and
1247 * convert the interpolated range element to a corresponding output element.
1248 *
1249 * The range must be set in accordance with the range element type.
1250 *
1251 * The interpolator factory may be set using the interpolate(...) method of the scale.
1252 *
1253 * @param domain Array of temporal domain values. Numeric values will be coerced to dates.
1254 * @param range Array of range values.
1255 */
1256export function scaleTime<Range, Output = Range, Unknown = never>(
1257 domain: Iterable<Date | NumberValue>,
1258 range: Iterable<Range>
1259// tslint:disable-next-line:no-unnecessary-generics
1260): ScaleTime<Range, Output, Unknown>;
1261
1262/**
1263 * Constructs a new time scale using Coordinated Universal Time (UTC) with the specified range, the default interpolator and clamping disabled.
1264 * The domain defaults to [2000-01-01, 2000-01-02].
1265 * If range is not specified, it defaults to [0, 1].
1266 *
1267 * The first generic corresponds to the data type of the range elements.
1268 * The second generic corresponds to the data type of the output elements generated by the scale.
1269 * The third generic corresponds to the data type of the unknown value.
1270 *
1271 * If range element and output element type differ, the interpolator factory used with the scale must match this behavior and
1272 * convert the interpolated range element to a corresponding output element.
1273 *
1274 * The range must be set in accordance with the range element type.
1275 *
1276 * The interpolator factory may be set using the interpolate(...) method of the scale.
1277 *
1278 * @param range Array of range values.
1279 */
1280export function scaleUtc<Range = number, Output = Range, Unknown = never>(
1281 range?: Iterable<Range>
1282// tslint:disable-next-line:no-unnecessary-generics
1283): ScaleTime<Range, Output, Unknown>;
1284/**
1285 * Constructs a new time scale using Coordinated Universal Time (UTC) with the specified domain and range, the default interpolator and clamping disabled.
1286 *
1287 * The first generic corresponds to the data type of the range elements.
1288 * The second generic corresponds to the data type of the output elements generated by the scale.
1289 * The third generic corresponds to the data type of the unknown value.
1290 *
1291 * If range element and output element type differ, the interpolator factory used with the scale must match this behavior and
1292 * convert the interpolated range element to a corresponding output element.
1293 *
1294 * The range must be set in accordance with the range element type.
1295 *
1296 * The interpolator factory may be set using the interpolate(...) method of the scale.
1297 *
1298 * @param domain Array of temporal domain values. Numeric values will be coerced to dates.
1299 * @param range Array of range values.
1300 */
1301export function scaleUtc<Range, Output = Range, Unknown = never>(
1302 domain: Iterable<NumberValue>,
1303 range: Iterable<Range>
1304// tslint:disable-next-line:no-unnecessary-generics
1305): ScaleTime<Range, Output, Unknown>;
1306
1307// -------------------------------------------------------------------------------
1308// Sequential Scale Factory
1309// -------------------------------------------------------------------------------
1310
1311/**
1312 * Sequential scales are similar to continuous scales in that they map a continuous, numeric input domain to a continuous output range.
1313 * However, unlike continuous scales, the input domain and output range of a sequential scale always has exactly two elements,
1314 * and the output range is typically specified as an interpolator rather than an array of values.
1315 * These scales do not expose invert and interpolate methods.
1316 *
1317 * The first generic corresponds to the data type of the output of the interpolator underlying the scale.
1318 *
1319 * The second generic corresponds to the data type of the unknown value.
1320 */
1321export interface ScaleSequentialBase<Output, Unknown = never> {
1322 /**
1323 * Given a value from the domain, returns the corresponding value from the output range, subject to interpolation.
1324 *
1325 * If the given value is outside the domain, and clamping is not enabled, the mapping may be extrapolated such that the returned value is outside the range.
1326 *
1327 * @param value A numeric value from the domain.
1328 */
1329 (value: NumberValue): Output | Unknown;
1330
1331 /**
1332 * Returns a copy of the scale’s current domain.
1333 */
1334 domain(): [number, number];
1335 /**
1336 * Sets the scale’s domain to the specified array of numbers. The array must contain exactly two elements.
1337 * If the elements in the given array are not numbers, they will be coerced to numbers
1338 *
1339 * @param domain A two-element array of numeric domain values.
1340 */
1341 domain(domain: Iterable<NumberValue>): this;
1342
1343 /**
1344 * Returns whether or not the scale currently clamps values to within the range.
1345 */
1346 clamp(): boolean;
1347 /**
1348 * Enables or disables clamping, respectively. If clamping is disabled and the scale is passed a value outside the domain,
1349 * the scale may return a value outside the range through extrapolation.
1350 *
1351 * If clamping is enabled, the return value of the scale is always within the scale’s range. Clamping similarly applies to the "invert" method.
1352 *
1353 * @param clamp A flag to enable (true) or disable (false) clamping.
1354 */
1355 clamp(clamp: boolean): this;
1356
1357 /**
1358 * See continuous.range.
1359 */
1360 range(): () => [Output, Output];
1361 /**
1362 * See continuous.range.
1363 * The given two-element array is converted to an interpolator function using d3.interpolate.
1364 *
1365 * @param range Range values.
1366 */
1367 range(range: Iterable<Output>): this;
1368
1369 /**
1370 * See continuous.rangeRound.
1371 * If range is specified, implicitly uses d3.interpolateRound as the interpolator.
1372 *
1373 * @param range Range values.
1374 */
1375 rangeRound(range: Iterable<NumberValue>): this;
1376
1377 /**
1378 * Returns an exact copy of this scale. Changes to this scale will not affect the returned scale, and vice versa.
1379 */
1380 copy(): this;
1381}
1382
1383export interface ScaleSequential<Output, Unknown = never> extends ScaleSequentialBase<Output, Unknown> {
1384 /**
1385 * Returns the current interpolator underlying the scale.
1386 */
1387 interpolator(): (t: number) => Output;
1388 /**
1389 * Sets the scale’s interpolator to the specified function.
1390 *
1391 * @param interpolator An interpolator function mapping a value from the [0, 1] interval to an output value.
1392 */
1393 interpolator(interpolator: (t: number) => Output): this;
1394 /**
1395 * Sets the scale’s interpolator to the specified function.
1396 *
1397 * The generic corresponds to a the new output type of the scale. The output type of the scale is determined by the output type of the interpolator function.
1398 *
1399 * @param interpolator An interpolator function mapping a value from the [0, 1] interval to an output value.
1400 */
1401 interpolator<NewOutput>(interpolator: (t: number) => NewOutput): ScaleSequential<NewOutput, Unknown>;
1402
1403 /**
1404 * Returns the current unknown value, which defaults to undefined.
1405 */
1406 unknown(): UnknownReturnType<Unknown, undefined>;
1407 /**
1408 * Sets the output value of the scale for undefined (or NaN) input values and returns this scale.
1409 *
1410 * @param value The output value of the scale for undefined (or NaN) input values.
1411 */
1412 unknown<NewUnknown>(value: NewUnknown): ScaleSequential<Output, NewUnknown>;
1413}
1414
1415/**
1416 * Constructs a new sequential scale with the specified interpolator function or array.
1417 * The domain defaults to [0, 1].
1418 * If interpolator is not specified, it defaults to the identity function.
1419 * When the scale is applied, the interpolator will be invoked with a value typically in the range [0, 1], where 0 represents the minimum value and 1 represents the maximum value.
1420 *
1421 * If interpolator is an array, it represents the scales two-element output range and is converted to an interpolator function using d3.interpolate.
1422 *
1423 * The first generic corresponds to the data type of the output of the interpolator underlying the scale.
1424 * The second generic corresponds to the data type of the unknown value.
1425 *
1426 * @param interpolator The interpolator function or array to be used with the scale.
1427 */
1428export function scaleSequential<Output = number, Unknown = never>(
1429 interpolator?: ((t: number) => Output) | Iterable<Output>
1430// tslint:disable-next-line:no-unnecessary-generics
1431): ScaleSequential<Output, Unknown>;
1432/**
1433 * Constructs a new sequential scale with the specified domain and interpolator function or array.
1434 * When the scale is applied, the interpolator will be invoked with a value typically in the range [0, 1], where 0 represents the minimum value and 1 represents the maximum value.
1435 *
1436 * If interpolator is an array, it represents the scales two-element output range and is converted to an interpolator function using d3.interpolate.
1437 *
1438 * The first generic corresponds to the data type of the output of the interpolator underlying the scale.
1439 * The second generic corresponds to the data type of the unknown value.
1440 *
1441 * @param domain A two-element array of numeric domain values.
1442 * @param interpolator The interpolator function or array to be used with the scale.
1443 */
1444export function scaleSequential<Output, Unknown = never>(
1445 domain: Iterable<NumberValue>,
1446 interpolator: ((t: number) => Output) | Iterable<Output>
1447// tslint:disable-next-line:no-unnecessary-generics
1448): ScaleSequential<Output, Unknown>;
1449
1450/**
1451 * A sequential scale with a logarithmic transform, analogous to a log scale.
1452 *
1453 * The first generic corresponds to the data type of the output of the interpolator underlying the scale.
1454 * The second generic corresponds to the data type of the unknown value.
1455 *
1456 * @param interpolator The interpolator function to be used with the scale.
1457 */
1458export function scaleSequentialLog<Output = number, Unknown = never>(
1459 interpolator?: (t: number) => Output
1460// tslint:disable-next-line:no-unnecessary-generics
1461): ScaleSequential<Output, Unknown>;
1462/**
1463 * A sequential scale with a logarithmic transform, analogous to a log scale.
1464 *
1465 * The first generic corresponds to the data type of the output of the interpolator underlying the scale.
1466 * The second generic corresponds to the data type of the unknown value.
1467 *
1468 * @param domain A two-element array of numeric domain values.
1469 * @param interpolator The interpolator function to be used with the scale.
1470 */
1471export function scaleSequentialLog<Output, Unknown = never>(
1472 domain: Iterable<NumberValue>,
1473 interpolator: (t: number) => Output
1474// tslint:disable-next-line:no-unnecessary-generics
1475): ScaleSequential<Output, Unknown>;
1476
1477/**
1478 * A sequential scale with a exponential transform, analogous to a power scale.
1479 *
1480 * The first generic corresponds to the data type of the output of the interpolator underlying the scale.
1481 * The second generic corresponds to the data type of the unknown value.
1482 *
1483 * @param interpolator The interpolator function to be used with the scale.
1484 */
1485export function scaleSequentialPow<Output = number, Unknown = never>(
1486 interpolator?: (t: number) => Output
1487// tslint:disable-next-line:no-unnecessary-generics
1488): ScaleSequential<Output, Unknown>;
1489/**
1490 * A sequential scale with a exponential transform, analogous to a power scale.
1491 *
1492 * The first generic corresponds to the data type of the output of the interpolator underlying the scale.
1493 * The second generic corresponds to the data type of the unknown value.
1494 *
1495 * @param domain A two-element array of numeric domain values.
1496 * @param interpolator The interpolator function to be used with the scale.
1497 */
1498export function scaleSequentialPow<Output, Unknown = never>(
1499 domain: Iterable<NumberValue>,
1500 interpolator: (t: number) => Output
1501// tslint:disable-next-line:no-unnecessary-generics
1502): ScaleSequential<Output, Unknown>;
1503
1504/**
1505 * A sequential scale with a square-root transform, analogous to a d3.scaleSqrt.
1506 *
1507 * The first generic corresponds to the data type of the output of the interpolator underlying the scale.
1508 * The second third generic corresponds to the data type of the unknown value.
1509 *
1510 * @param interpolator The interpolator function to be used with the scale.
1511 */
1512export function scaleSequentialSqrt<Output = number, Unknown = never>(
1513 interpolator?: (t: number) => Output
1514// tslint:disable-next-line:no-unnecessary-generics
1515): ScaleSequential<Output, Unknown>;
1516/**
1517 * A sequential scale with a square-root transform, analogous to a d3.scaleSqrt.
1518 *
1519 * The first generic corresponds to the data type of the output of the interpolator underlying the scale.
1520 * The second generic corresponds to the data type of the unknown value.
1521 *
1522 * @param domain A two-element array of numeric domain values.
1523 * @param interpolator The interpolator function to be used with the scale.
1524 */
1525export function scaleSequentialSqrt<Output, Unknown = never>(
1526 domain: Iterable<NumberValue>,
1527 interpolator: (t: number) => Output
1528// tslint:disable-next-line:no-unnecessary-generics
1529): ScaleSequential<Output, Unknown>;
1530
1531/**
1532 * A sequential scale with a symmetric logarithmic transform, analogous to a symlog scale.
1533 *
1534 * The first generic corresponds to the data type of the output of the interpolator underlying the scale.
1535 * The second generic corresponds to the data type of the unknown value.
1536 *
1537 * @param interpolator The interpolator function to be used with the scale.
1538 */
1539export function scaleSequentialSymlog<Output = number, Unknown = never>(
1540 interpolator?: (t: number) => Output
1541// tslint:disable-next-line:no-unnecessary-generics
1542): ScaleSequential<Output, Unknown>;
1543/**
1544 * A sequential scale with a symmetric logarithmic transform, analogous to a symlog scale.
1545 *
1546 * The first generic corresponds to the data type of the output of the interpolator underlying the scale.
1547 * The second generic corresponds to the data type of the unknown value.
1548 *
1549 * @param domain A two-element array of numeric domain values.
1550 * @param interpolator The interpolator function to be used with the scale.
1551 */
1552export function scaleSequentialSymlog<Output, Unknown = never>(
1553 domain: Iterable<NumberValue>,
1554 interpolator: (t: number) => Output
1555// tslint:disable-next-line:no-unnecessary-generics
1556): ScaleSequential<Output, Unknown>;
1557
1558export interface ScaleSequentialQuantile<Output, Unknown = never> extends ScaleSequentialBase<Output, Unknown> {
1559 /**
1560 * Returns an array of n + 1 quantiles.
1561 * For example, if n = 4, returns an array of five numbers: the minimum value, the first quartile, the median, the third quartile, and the maximum.
1562 */
1563 quantiles(): number[];
1564
1565 /**
1566 * Returns the current interpolator underlying the scale.
1567 */
1568 interpolator(): (t: number) => Output;
1569 /**
1570 * Sets the scale’s interpolator to the specified function.
1571 *
1572 * @param interpolator An interpolator function mapping a value from the [0, 1] interval to an output value.
1573 */
1574 interpolator(interpolator: (t: number) => Output): this;
1575 /**
1576 * Sets the scale’s interpolator to the specified function.
1577 *
1578 * The generic corresponds to a the new output type of the scale. The output type of the scale is determined by the output type of the interpolator function.
1579 *
1580 * @param interpolator An interpolator function mapping a value from the [0, 1] interval to an output value.
1581 */
1582 interpolator<NewOutput>(interpolator: (t: number) => NewOutput): ScaleSequentialQuantile<NewOutput, Unknown>;
1583
1584 /**
1585 * Returns the current unknown value, which defaults to undefined.
1586 */
1587 unknown(): UnknownReturnType<Unknown, undefined>;
1588 /**
1589 * Sets the output value of the scale for undefined (or NaN) input values and returns this scale.
1590 *
1591 * @param value The output value of the scale for undefined (or NaN) input values.
1592 */
1593 unknown<NewUnknown>(value: NewUnknown): ScaleSequentialQuantile<Output, NewUnknown>;
1594}
1595
1596/**
1597 * A sequential scale using a p-quantile transform, analogous to a quantile scale.
1598 *
1599 * The first generic corresponds to the data type of the output of the interpolator underlying the scale.
1600 * The second generic corresponds to the data type of the unknown value.
1601 *
1602 * @param interpolator The interpolator function to be used with the scale.
1603 */
1604export function scaleSequentialQuantile<Output = number, Unknown = never>(
1605 interpolator?: (t: number) => Output
1606// tslint:disable-next-line:no-unnecessary-generics
1607): ScaleSequentialQuantile<Output, Unknown>;
1608/**
1609 * A sequential scale using a p-quantile transform, analogous to a quantile scale.
1610 *
1611 * The first generic corresponds to the data type of the output of the interpolator underlying the scale.
1612 * The second generic corresponds to the data type of the unknown value.
1613 *
1614 * @param domain A two-element array of numeric domain values.
1615 * @param interpolator The interpolator function to be used with the scale.
1616 */
1617export function scaleSequentialQuantile<Output, Unknown = never>(
1618 domain: Iterable<NumberValue>,
1619 interpolator: (t: number) => Output
1620// tslint:disable-next-line:no-unnecessary-generics
1621): ScaleSequentialQuantile<Output, Unknown>;
1622
1623// -------------------------------------------------------------------------------
1624// Diverging Scale Factory
1625// -------------------------------------------------------------------------------
1626
1627/**
1628 * Diverging scales, like sequential scales, are similar to continuous scales in that they map a continuous, numeric input domain to a continuous output range.
1629 * However, unlike continuous scales, the input domain and output range of a diverging scale always has exactly three elements,
1630 * and the output range is typically specified as an interpolator rather than an array of values.
1631 * These scales do not expose invert and interpolate methods.
1632 *
1633 * The first generic corresponds to the data type of the interpolator return type.
1634 *
1635 * The second generic corresponds to the data type of the unknown value.
1636 */
1637export interface ScaleDiverging<Output, Unknown = never> {
1638 /**
1639 * Given a value from the domain, returns the corresponding value subject to interpolation.
1640 *
1641 * If the given value is outside the domain, and clamping is not enabled, the mapping may be extrapolated such that the returned value is outside the range.
1642 *
1643 * @param value A numeric value from the domain.
1644 */
1645 (value: NumberValue): Output | Unknown;
1646
1647 /**
1648 * Returns a copy of the scales current domain.
1649 */
1650 domain(): [number, number, number];
1651 /**
1652 * Sets the scales domain to the specified array of numbers.
1653 * The domain must be numeric and must contain exactly three values. The default domain is [0, 0.5, 1].
1654 * If the elements in the given array are not numbers, they will be coerced to numbers
1655 *
1656 * @param domain Array of three numeric domain values.
1657 */
1658 domain(domain: Iterable<NumberValue>): this;
1659
1660 /**
1661 * Returns whether or not the scale currently clamps values to within the range.
1662 */
1663 clamp(): boolean;
1664 /**
1665 * Enables or disables clamping, respectively. If clamping is disabled and the scale is passed a value outside the domain,
1666 * the scale may return a value outside the range through extrapolation.
1667 *
1668 * If clamping is enabled, the return value of the scale is always within the interpolator scales range.
1669 *
1670 * @param clamp A flag to enable (true) or disable (false) clamping.
1671 */
1672 clamp(clamp: boolean): this;
1673
1674 /**
1675 * Returns the scales current interpolator.
1676 */
1677 interpolator(): (t: number) => Output;
1678 /**
1679 * Sets the scale’s interpolator to the specified function.
1680 *
1681 * @param interpolator The scale’s interpolator.
1682 */
1683 interpolator(interpolator?: (t: number) => Output): this;
1684
1685 /**
1686 * See continuous.range.
1687 */
1688 range(): () => [Output, Output, Output];
1689 /**
1690 * See continuous.range.
1691 * The given two-element array is converted to an interpolator function using d3.interpolate and d3.piecewise.
1692 *
1693 * @param range Range values.
1694 */
1695 range(range: Iterable<Output>): this;
1696
1697 /**
1698 * See continuous.rangeRound.
1699 * If range is specified, implicitly uses d3.interpolateRound as the interpolator.
1700 *
1701 * @param range Range values.
1702 */
1703 rangeRound(range: Iterable<NumberValue>): this;
1704
1705 /**
1706 * Returns an exact copy of this scale. Changes to this scale will not affect the returned scale, and vice versa.
1707 */
1708 copy(): this;
1709
1710 /**
1711 * Returns the current unknown value, which defaults to undefined.
1712 */
1713 unknown(): UnknownReturnType<Unknown, undefined>;
1714 /**
1715 * Sets the output value of the scale for undefined (or NaN) input values and returns this scale.
1716 *
1717 * @param value The output value of the scale for undefined (or NaN) input values.
1718 */
1719 unknown<NewUnknown>(value: NewUnknown): ScaleDiverging<Output, NewUnknown>;
1720}
1721
1722/**
1723 * Constructs a new diverging scale with the specified interpolator function or array.
1724 * The domain defaults to [0, 0.5, 1].
1725 * If interpolator is not specified, it defaults to the identity function.
1726 * When the scale is applied, the interpolator will be invoked with a value typically in the range [0, 1],
1727 * where 0 represents the extreme negative value, 0.5 represents the neutral value, and 1 represents the extreme positive value.
1728 *
1729 * If interpolator is an array, it represents the scale’s three-element output range and is converted to an interpolator function using d3.interpolate and d3.piecewise.
1730 *
1731 * The first generic corresponds to the data type of the interpolator return type.
1732 * The second generic corresponds to the data type of the unknown value.
1733 *
1734 * @param interpolator The scale’s interpolator function or array.
1735 */
1736export function scaleDiverging<Output = number, Unknown = never>(
1737 interpolator?: ((t: number) => Output) | Iterable<Output>
1738// tslint:disable-next-line:no-unnecessary-generics
1739): ScaleDiverging<Output, Unknown>;
1740/**
1741 * Constructs a new diverging scale with the specified domain and interpolator function or array.
1742 * When the scale is applied, the interpolator will be invoked with a value typically in the range [0, 1],
1743 * where 0 represents the extreme negative value, 0.5 represents the neutral value, and 1 represents the extreme positive value.
1744 *
1745 * If interpolator is an array, it represents the scale’s three-element output range and is converted to an interpolator function using d3.interpolate and d3.piecewise.
1746 *
1747 * The first generic corresponds to the data type of the interpolator return type.
1748 * The second generic corresponds to the data type of the unknown value.
1749 *
1750 * @param domain Array of three numeric domain values.
1751 * @param interpolator The scale’s interpolator function or array.
1752 */
1753export function scaleDiverging<Output, Unknown = never>(
1754 domain: Iterable<NumberValue>,
1755 interpolator: ((t: number) => Output) | Iterable<Output>
1756// tslint:disable-next-line:no-unnecessary-generics
1757): ScaleDiverging<Output, Unknown>;
1758
1759/**
1760 * A diverging scale with a logarithmic transform, analogous to a log scale.
1761 *
1762 * The first generic corresponds to the data type of the interpolator return type.
1763 * The second generic corresponds to the data type of the unknown value.
1764 *
1765 * @param interpolator The scale’s interpolator.
1766 */
1767export function scaleDivergingLog<Output = number, Unknown = never>(
1768 interpolator?: (t: number) => Output
1769// tslint:disable-next-line:no-unnecessary-generics
1770): ScaleDiverging<Output, Unknown>;
1771/**
1772 * A diverging scale with a logarithmic transform, analogous to a log scale.
1773 *
1774 * The first generic corresponds to the data type of the interpolator return type.
1775 * The second generic corresponds to the data type of the unknown value.
1776 *
1777 * @param domain Array of three numeric domain values.
1778 * @param interpolator The scale’s interpolator.
1779 */
1780export function scaleDivergingLog<Output, Unknown = never>(
1781 domain: Iterable<NumberValue>,
1782 interpolator: (t: number) => Output
1783// tslint:disable-next-line:no-unnecessary-generics
1784): ScaleDiverging<Output, Unknown>;
1785
1786/**
1787 * A diverging scale with a exponential transform, analogous to a power scale.
1788 *
1789 * The first generic corresponds to the data type of the interpolator return type.
1790 * The second generic corresponds to the data type of the unknown value.
1791 *
1792 * @param interpolator The scale’s interpolator.
1793 */
1794export function scaleDivergingPow<Output = number, Unknown = never>(
1795 interpolator?: (t: number) => Output
1796// tslint:disable-next-line:no-unnecessary-generics
1797): ScaleDiverging<Output, Unknown>;
1798/**
1799 * A diverging scale with a exponential transform, analogous to a power scale.
1800 *
1801 * The first generic corresponds to the data type of the interpolator return type.
1802 * The second generic corresponds to the data type of the unknown value.
1803 *
1804 * @param domain Array of three numeric domain values.
1805 * @param interpolator The scale’s interpolator.
1806 */
1807export function scaleDivergingPow<Output, Unknown = never>(
1808 domain: Iterable<NumberValue>,
1809 interpolator: (t: number) => Output
1810// tslint:disable-next-line:no-unnecessary-generics
1811): ScaleDiverging<Output, Unknown>;
1812
1813/**
1814 * A diverging scale with a square-root transform, analogous to a d3.scaleSqrt.
1815 *
1816 * The first generic corresponds to the data type of the interpolator return type.
1817 * The second generic corresponds to the data type of the unknown value.
1818 *
1819 * @param interpolator The scale’s interpolator.
1820 */
1821export function scaleDivergingSqrt<Output = number, Unknown = never>(
1822 interpolator?: (t: number) => Output
1823// tslint:disable-next-line:no-unnecessary-generics
1824): ScaleDiverging<Output, Unknown>;
1825/**
1826 * A diverging scale with a square-root transform, analogous to a d3.scaleSqrt.
1827 *
1828 * The first generic corresponds to the data type of the interpolator return type.
1829 * The second generic corresponds to the data type of the unknown value.
1830 *
1831 * @param domain Array of three numeric domain values.
1832 * @param interpolator The scale’s interpolator.
1833 */
1834export function scaleDivergingSqrt<Output, Unknown = never>(
1835 domain: Iterable<NumberValue>,
1836 interpolator: (t: number) => Output
1837// tslint:disable-next-line:no-unnecessary-generics
1838): ScaleDiverging<Output, Unknown>;
1839
1840/**
1841 * A diverging scale with a symmetric logarithmic transform, analogous to a symlog scale.
1842 *
1843 * The first generic corresponds to the data type of the interpolator return type.
1844 * The second generic corresponds to the data type of the unknown value.
1845 *
1846 * @param interpolator The scale’s interpolator.
1847 */
1848export function scaleDivergingSymlog<Output = number, Unknown = never>(
1849 interpolator?: (t: number) => Output
1850// tslint:disable-next-line:no-unnecessary-generics
1851): ScaleDiverging<Output, Unknown>;
1852/**
1853 * A diverging scale with a symmetric logarithmic transform, analogous to a symlog scale.
1854 *
1855 * The first generic corresponds to the data type of the interpolator return type.
1856 * The second generic corresponds to the data type of the unknown value.
1857 *
1858 * @param domain Array of three numeric domain values.
1859 * @param interpolator The scale’s interpolator.
1860 */
1861export function scaleDivergingSymlog<Output, Unknown = never>(
1862 domain: Iterable<NumberValue>,
1863 interpolator: (t: number) => Output
1864// tslint:disable-next-line:no-unnecessary-generics
1865): ScaleDiverging<Output, Unknown>;
1866
1867// -------------------------------------------------------------------------------
1868// Quantize Scale Factory
1869// -------------------------------------------------------------------------------
1870
1871/**
1872 * Quantize scales are similar to linear scales, except they use a discrete rather than continuous range.
1873 * The continuous input domain is divided into uniform segments based on the number of values in (i.e., the cardinality of) the output range.
1874 *
1875 * Each range value y can be expressed as a quantized linear function of the domain value x: y = m round(x) + b.
1876 *
1877 * The first generic corresponds to the data type of the range elements.
1878 *
1879 * The second generic corresponds to the data type of the unknown value.
1880 */
1881export interface ScaleQuantize<Range, Unknown = never> {
1882 /**
1883 * Given a value in the input domain, returns the corresponding value in the output range.
1884 */
1885 (value: NumberValue): Range | Unknown;
1886 /**
1887 * Returns the extent of values in the domain [x0, x1] for the corresponding value in the range: the inverse of quantize.
1888 * This method is useful for interaction, say to determine the value in the domain that corresponds to the pixel location under the mouse.
1889 *
1890 * If an invalid range value is entered, returns [NaN, NaN].
1891 *
1892 * @param value A value from the range.
1893 */
1894 invertExtent(value: Range): [number, number];
1895
1896 /**
1897 * Returns the scale’s current domain.
1898 */
1899 domain(): [number, number];
1900
1901 /**
1902 * Sets the scale’s domain to the specified two-element array of numbers.
1903 * If the elements in the given array are not numbers, they will be coerced to numbers.
1904 *
1905 * @param domain A two-element array of numeric values defining the domain.
1906 */
1907 domain(domain: Iterable<NumberValue>): this;
1908
1909 /**
1910 * Returns the scale’s current range.
1911 */
1912 range(): Range[];
1913 /**
1914 * Sets the scale’s range to the specified array of values. The array may contain any number of discrete values.
1915 *
1916 * @param range Array of range values.
1917 */
1918 range(range: Iterable<Range>): this;
1919
1920 /**
1921 * Returns approximately count representative values from the scale’s domain.
1922 *
1923 * If count is not specified, it defaults to 10.
1924 *
1925 * The returned tick values are uniformly spaced, have human-readable values (such as multiples of powers of 10),
1926 * and are guaranteed to be within the extent of the domain. Ticks are often used to display reference lines, or tick marks, in conjunction with the visualized data.
1927 * The specified count is only a hint; the scale may return more or fewer values depending on the domain. See also d3-array’s ticks.
1928 *
1929 * @param count Optional approximate number of ticks to be returned. If count is not specified, it defaults to 10.
1930 */
1931 ticks(count?: number): number[];
1932
1933 /**
1934 * Returns a number format function suitable for displaying a tick value, automatically computing the appropriate precision based on the fixed interval between tick values.
1935 * The specified count should have the same value as the count that is used to generate the tick values.
1936 *
1937 * @param count Approximate number of ticks to be used when calculating precision for the number format function.
1938 * @param specifier An optional valid format specifier string which allows a custom format where the precision of the format is automatically set by the scale as appropriate for the tick interval.
1939 * If specifier uses the format type "s", the scale will return a SI-prefix format based on the largest value in the domain.
1940 * If the specifier already specifies a precision, this method is equivalent to locale.format.
1941 */
1942 tickFormat(count?: number, specifier?: string): (d: NumberValue) => string;
1943
1944 /**
1945 * Extends the domain so that it starts and ends on nice round values.
1946 * This method typically modifies the scale’s domain, and may only extend the bounds to the nearest round value.
1947 *
1948 * Nicing is useful if the domain is computed from data, say using extent, and may be irregular.
1949 * For example, for a domain of [0.201479…, 0.996679…], a nice domain might be [0.2, 1.0].
1950 *
1951 * Nicing a scale only modifies the current domain; it does not automatically nice domains that are subsequently set using continuous.domain.
1952 * You must re-nice the scale after setting the new domain, if desired.
1953 *
1954 * @param count An optional number of ticks expected to be used.
1955 */
1956 nice(count?: number): this;
1957
1958 /**
1959 * Returns the current unknown value, which defaults to undefined.
1960 */
1961 unknown(): UnknownReturnType<Unknown, undefined>;
1962 /**
1963 * Sets the output value of the scale for undefined (or NaN) input values and returns this scale.
1964 *
1965 * @param value The output value of the scale for undefined (or NaN) input values.
1966 */
1967 unknown<NewUnknown>(value: NewUnknown): ScaleQuantize<Range, NewUnknown>;
1968
1969 /**
1970 * Returns the array of computed thresholds within the domain.
1971 */
1972 thresholds(): number[];
1973
1974 /**
1975 * Returns an exact copy of this scale. Changes to this scale will not affect the returned scale, and vice versa.
1976 */
1977 copy(): this;
1978}
1979
1980/**
1981 * Constructs a new quantize scale with the specified range.
1982 * The domain defaults to [0, 1].
1983 * If range is not specified, it defaults to [0, 1].
1984 * Thus, the default quantize scale is equivalent to the Math.round function.
1985 *
1986 * The range must be set corresponding to the type of the range elements.
1987 *
1988 * The first generic corresponds to the data type of the range elements.
1989 * The second generic corresponds to the data type of the unknown value.
1990 *
1991 * @param range Array of range values.
1992 */
1993// tslint:disable-next-line:no-unnecessary-generics
1994export function scaleQuantize<Range = number, Unknown = never>(range?: Iterable<Range>): ScaleQuantize<Range, Unknown>;
1995/**
1996 * Constructs a new quantize scale with the specified domain and range.
1997 * Thus, the default quantize scale is equivalent to the Math.round function.
1998 *
1999 * The range must be set corresponding to the type of the range elements.
2000 *
2001 * The first generic corresponds to the data type of the range elements.
2002 * The second generic corresponds to the data type of the unknown value.
2003 *
2004 * @param domain A two-element array of numeric values defining the domain.
2005 * @param range Array of range values.
2006 */
2007export function scaleQuantize<Range, Unknown = never>(
2008 domain: Iterable<NumberValue>,
2009 range: Iterable<Range>
2010// tslint:disable-next-line:no-unnecessary-generics
2011): ScaleQuantize<Range, Unknown>;
2012
2013// -------------------------------------------------------------------------------
2014// Quantile Scale Factory
2015// -------------------------------------------------------------------------------
2016
2017/**
2018 * Quantile scales map a sampled input domain to a discrete range.
2019 * The domain is considered continuous and thus the scale will accept any reasonable input value;
2020 * however, the domain is specified as a discrete set of sample values.
2021 * The number of values in (the cardinality of) the output range determines the number of quantiles that will be computed from the domain.
2022 * To compute the quantiles, the domain is sorted, and treated as a population of discrete values; see d3-array’s quantile.
2023 *
2024 * The first generic corresponds to the data type of range elements.
2025 *
2026 * The second generic corresponds to the data type of the unknown value.
2027 */
2028export interface ScaleQuantile<Range, Unknown = never> {
2029 /**
2030 * Given a value in the input domain, returns the corresponding value in the output range.
2031 *
2032 * @param value A numeric value in the input domain.
2033 */
2034 (value: NumberValue): Range | Unknown;
2035
2036 /**
2037 * Returns the extent of values in the domain [x0, x1] for the corresponding value in the range: the inverse of quantile.
2038 * This method is useful for interaction, say to determine the value in the domain that corresponds to the pixel location under the mouse.
2039 *
2040 * @param value A value from the range.
2041 */
2042 invertExtent(value: Range): [number, number];
2043
2044 /**
2045 * Returns the scale’s current domain.
2046 */
2047 domain(): number[];
2048 /**
2049 * Sets the domain of the quantile scale to the specified set of discrete numeric values.
2050 * The array must not be empty, and must contain at least one numeric value; NaN, null and undefined values are ignored and not considered part of the sample population.
2051 *
2052 * If the elements in the given array are not numbers, they will be coerced to numbers. A copy of the input array is sorted and stored internally.
2053 *
2054 * @param domain Array of domain values.
2055 */
2056 domain(domain: Iterable<NumberValue | null | undefined>): this;
2057
2058 /**
2059 * Returns the current range.
2060 */
2061 range(): Range[];
2062 /**
2063 * Sets the discrete values in the range. The array must not be empty.
2064 * The number of values in (the cardinality, or length, of) the range array determines the number of quantiles that are computed.
2065 *
2066 * For example, to compute quartiles, range must be an array of four elements such as [0, 1, 2, 3].
2067 *
2068 * @param range Array of range values.
2069 */
2070 range(range: Iterable<Range>): this;
2071
2072 /**
2073 * Returns the quantile thresholds. If the range contains n discrete values, the returned array will contain n - 1 thresholds.
2074 * Values less than the first threshold are considered in the first quantile;
2075 * values greater than or equal to the first threshold but less than the second threshold are in the second quantile, and so on.
2076 * Internally, the thresholds array is used with bisect to find the output quantile associated with the given input value.
2077 */
2078 quantiles(): number[];
2079
2080 /**
2081 * Returns an exact copy of this scale. Changes to this scale will not affect the returned scale, and vice versa.
2082 */
2083 copy(): this;
2084
2085 /**
2086 * Returns the current unknown value, which defaults to undefined.
2087 */
2088 unknown(): UnknownReturnType<Unknown, undefined>;
2089 /**
2090 * Sets the output value of the scale for undefined (or NaN) input values and returns this scale.
2091 *
2092 * @param value The output value of the scale for undefined (or NaN) input values.
2093 */
2094 unknown<NewUnknown>(value: NewUnknown): ScaleQuantile<Range, NewUnknown>;
2095}
2096
2097/**
2098 * Constructs a new quantile scale with the specified range.
2099 * The domain defaults to the empty array.
2100 * If range is not specified, it defaults to the empty array.
2101 * The quantile scale is invalid until both a domain and range are specified.
2102 *
2103 * The first generic corresponds to the data type of range elements.
2104 * The second generic corresponds to the data type of the unknown value.
2105 *
2106 * @param range Array of range values.
2107 */
2108// tslint:disable-next-line:no-unnecessary-generics
2109export function scaleQuantile<Range = number, Unknown = never>(range?: Iterable<Range>): ScaleQuantile<Range, Unknown>;
2110/**
2111 * Constructs a new quantile scale with the specified domain and range.
2112 * The quantile scale is invalid until both a domain and range are specified.
2113 *
2114 * The first generic corresponds to the data type of range elements.
2115 * The second generic corresponds to the data type of the unknown value.
2116 *
2117 * @param domain Array of domain values.
2118 * @param range Array of range values.
2119 */
2120export function scaleQuantile<Range, Unknown = never>(
2121 domain: Iterable<NumberValue | null | undefined>,
2122 range: Iterable<Range>
2123// tslint:disable-next-line:no-unnecessary-generics
2124): ScaleQuantile<Range, Unknown>;
2125
2126// -------------------------------------------------------------------------------
2127// Threshold Scale Factory
2128// -------------------------------------------------------------------------------
2129
2130/**
2131 * Threshold scales are similar to quantize scales, except they allow you to map arbitrary subsets of the domain to discrete values in the range.
2132 * The input domain is still continuous, and divided into slices based on a set of threshold values.
2133 *
2134 * If the number of values in the scale’s range is N+1, the number of values in the scale’s domain must be N.
2135 * If there are fewer than N elements in the domain, the additional values in the range are ignored.
2136 * If there are more than N elements in the domain, the scale may return undefined for some inputs.
2137 *
2138 * The first generic corresponds to the data type of domain values.
2139 * The second generic corresponds to the data type of range values.
2140 * The third generic corresponds to the data type of the unknown value.
2141 */
2142export interface ScaleThreshold<Domain extends number | string | Date, Range, Unknown = never> {
2143 /**
2144 * Given a value in the input domain, returns the corresponding value in the output range.
2145 *
2146 * @param value A domain value.
2147 */
2148 (value: Domain): Range | Unknown;
2149
2150 /**
2151 * Returns the extent of values in the domain [x0, x1] for the corresponding value in the range, representing the inverse mapping from range to domain.
2152 * This method is useful for interaction, say to determine the value in the domain that corresponds to the pixel location under the mouse.
2153 *
2154 * @param value A range value.
2155 */
2156 invertExtent(value: Range): [Domain | undefined, Domain | undefined];
2157
2158 /**
2159 * Returns the scale’s current domain.
2160 */
2161 domain(): Domain[];
2162 /**
2163 * Sets the scale’s domain to the specified array of values. The values must be in sorted ascending order, or the behavior of the scale is undefined.
2164 * The values are typically numbers, but any naturally ordered values (such as strings) will work; a threshold scale can be used to encode any type that is ordered.
2165 * If the number of values in the scale’s range is N+1, the number of values in the scale’s domain must be N.
2166 * If there are fewer than N elements in the domain, the additional values in the range are ignored.
2167 * If there are more than N elements in the domain, the scale may return undefined for some inputs.
2168 *
2169 * @param domain Array of domain values.
2170 */
2171 domain(domain: Iterable<Domain>): this;
2172
2173 /**
2174 * Returns the scale’s current range.
2175 */
2176 range(): Range[];
2177 /**
2178 * Sets the scale’s range to the specified array of values. If the number of values in the scale’s domain is N, the number of values in the scale’s range must be N+1.
2179 * If there are fewer than N+1 elements in the range, the scale may return undefined for some inputs.
2180 * If there are more than N+1 elements in the range, the additional values are ignored.
2181 *
2182 * @param range Array of range values.
2183 */
2184 range(range: Iterable<Range>): this;
2185
2186 /**
2187 * Returns an exact copy of this scale. Changes to this scale will not affect the returned scale, and vice versa.
2188 */
2189 copy(): this;
2190
2191 /**
2192 * Returns the current unknown value, which defaults to undefined.
2193 */
2194 unknown(): UnknownReturnType<Unknown, undefined>;
2195 /**
2196 * Sets the output value of the scale for undefined (or NaN) input values and returns this scale.
2197 *
2198 * @param value The output value of the scale for undefined (or NaN) input values.
2199 */
2200 unknown<NewUnknown>(value: NewUnknown): ScaleThreshold<Domain, Range, NewUnknown>;
2201}
2202
2203/**
2204 * Constructs a new threshold scale with the specified range.
2205 * The domain defaults to [0.5].
2206 * If range is not specified, it defaults to [0, 1].
2207 * Thus, the default threshold scale is equivalent to the Math.round function for numbers; for example threshold(0.49) returns 0, and threshold(0.51) returns 1.
2208 *
2209 * The first generic corresponds to the data type of domain values.
2210 * The second generic corresponds to the data type of range values.
2211 * The third generic corresponds to the data type of the unknown value.
2212 *
2213 * @param range Array of range values.
2214 */
2215export function scaleThreshold<Domain extends number | string | Date = number, Range = number, Unknown = never>(
2216 range?: Iterable<Range>,
2217// tslint:disable-next-line:no-unnecessary-generics
2218): ScaleThreshold<Domain, Range, Unknown>;
2219/**
2220 * Constructs a new threshold scale with the specified domain and range.
2221 * Thus, the default threshold scale is equivalent to the Math.round function for numbers; for example threshold(0.49) returns 0, and threshold(0.51) returns 1.
2222 *
2223 * The first generic corresponds to the data type of domain values.
2224 * The second generic corresponds to the data type of range values.
2225 * The third generic corresponds to the data type of the unknown value.
2226 *
2227 * @param domain Array of domain values.
2228 * @param range Array of range values.
2229 */
2230export function scaleThreshold<Domain extends number | string | Date, Range, Unknown = never>(
2231 domain: Iterable<Domain>,
2232 range: Iterable<Range>,
2233// tslint:disable-next-line:no-unnecessary-generics
2234): ScaleThreshold<Domain, Range, Unknown>;
2235
2236// -------------------------------------------------------------------------------
2237// Ordinal Scale Factory
2238// -------------------------------------------------------------------------------
2239
2240/**
2241 * Unlike continuous scales, ordinal scales have a discrete domain and range. For example, an ordinal scale might map a set of named categories to a set of colors,
2242 * or determine the horizontal positions of columns in a column chart.
2243 *
2244 * The first element in the domain will be mapped to the first element in range, the second domain value to the second range value, and so on.
2245 * If there are fewer elements in the range than in the domain, the scale will reuse values from the start of the range.
2246 *
2247 * The first generic corresponds to the data type of domain values.
2248 * The second generic corresponds to the data type of range values.
2249 * The third generic corresponds to the data type of the unknown value.
2250 */
2251export interface ScaleOrdinal<Domain extends { toString(): string }, Range, Unknown = never> {
2252 /**
2253 * Given a value in the input domain, returns the corresponding value in the output range.
2254 * If the given value is not in the scale’s domain, returns the unknown; or, if the unknown value is implicit (the default),
2255 * then the value is implicitly added to the domain and the next-available value in the range is assigned to value,
2256 * such that this and subsequent invocations of the scale given the same input value return the same output value.
2257 *
2258 * @param x A value from the domain.
2259 */
2260 (x: Domain): Range | Unknown;
2261
2262 /**
2263 * Returns the scale's current domain.
2264 */
2265 domain(): Domain[];
2266 /**
2267 * Sets the domain to the specified array of values.
2268 *
2269 * The first element in domain will be mapped to the first element in the range,
2270 * the second domain value to the second range value, and so on.
2271 *
2272 * Domain values are stored internally in a map from stringified value to index; the resulting index is then used to retrieve a value from the range.
2273 * Thus, an ordinal scale’s values must be coercible to a string, and the stringified version of the domain value uniquely identifies the corresponding range value.
2274 *
2275 * Setting the domain on an ordinal scale is optional if the unknown value is implicit (the default).
2276 * In this case, the domain will be inferred implicitly from usage by assigning each unique value passed to the scale a new value from the range.
2277 * Note that an explicit domain is recommended to ensure deterministic behavior, as inferring the domain from usage will be dependent on ordering.
2278 *
2279 * @param domain Array of domain values.
2280 */
2281 domain(domain: Iterable<Domain>): this;
2282
2283 /**
2284 * Returns the scale's current range.
2285 */
2286 range(): Range[];
2287 /**
2288 * Sets the range of the ordinal scale to the specified array of values.
2289 *
2290 * The first element in the domain will be mapped to the first element in range, the second domain value to the second range value, and so on.
2291 *
2292 * If there are fewer elements in the range than in the domain, the scale will reuse values from the start of the range.
2293 *
2294 * @param range Array of range values.
2295 */
2296 range(range: Iterable<Range>): this;
2297
2298 /**
2299 * Returns the current unknown value, which defaults to "implicit".
2300 */
2301 unknown(): UnknownReturnType<Unknown, { name: 'implicit' }>;
2302 /**
2303 * Sets the output value of the scale for unknown input values and returns this scale.
2304 * The implicit value enables implicit domain construction. scaleImplicit can be used as a convenience to set the implicit value.
2305 *
2306 * @param value Unknown value to be used or scaleImplicit to set implicit scale generation.
2307 */
2308 unknown<NewUnknown>(
2309 value: NewUnknown
2310 ): NewUnknown extends { name: "implicit" }
2311 ? ScaleOrdinal<Domain, Range>
2312 : ScaleOrdinal<Domain, Range, NewUnknown>;
2313
2314 /**
2315 * Returns an exact copy of this ordinal scale. Changes to this scale will not affect the returned scale, and vice versa.
2316 */
2317 copy(): this;
2318}
2319
2320/**
2321 * Constructs a new ordinal scale with the specified range.
2322 * The domain defaults to the empty array.
2323 * If range is not specified, it defaults to the empty array; an ordinal scale always returns undefined until a non-empty range is defined.
2324 *
2325 * The generic corresponds to the data type of range elements.
2326 *
2327 * @param range An optional array of range values to initialize the scale with.
2328 */
2329export function scaleOrdinal<Range>(range?: Iterable<Range>): ScaleOrdinal<string, Range>;
2330/**
2331 * Constructs a new ordinal scale with the specified range.
2332 * The domain defaults to the empty array.
2333 * If range is not specified, it defaults to the empty array; an ordinal scale always returns undefined until a non-empty range is defined.
2334 *
2335 * The first generic corresponds to the data type of domain elements.
2336 * The second generic corresponds to the data type of range elements.
2337 * The third generic corresponds to the data type of the unknown value.
2338 *
2339 * @param range An optional array of range values to initialize the scale with.
2340 */
2341export function scaleOrdinal<Domain extends { toString(): string }, Range, Unknown = never>(
2342 range?: Iterable<Range>,
2343// tslint:disable-next-line:no-unnecessary-generics
2344): ScaleOrdinal<Domain, Range, Unknown>;
2345/**
2346 * Constructs a new ordinal scale with the specified domain and range.
2347 *
2348 * The first generic corresponds to the data type of domain elements.
2349 * The second generic corresponds to the data type of range elements.
2350 * The third generic corresponds to the data type of the unknown value.
2351 *
2352 * @param domain Array of domain values.
2353 * @param range An optional array of range values to initialize the scale with.
2354 */
2355export function scaleOrdinal<Domain extends { toString(): string }, Range, Unknown = never>(
2356 domain: Iterable<Domain>,
2357 range: Iterable<Range>,
2358// tslint:disable-next-line:no-unnecessary-generics
2359): ScaleOrdinal<Domain, Range, Unknown>;
2360
2361/**
2362 * A special value for ordinal.unknown that enables implicit domain construction: unknown values are implicitly added to the domain.
2363 */
2364export const scaleImplicit: { name: 'implicit' };
2365
2366// -------------------------------------------------------------------------------
2367// Band Scale Factory
2368// -------------------------------------------------------------------------------
2369
2370/**
2371 * Band scales are like ordinal scales except the output range is continuous and numeric.
2372 * Discrete output values are automatically computed by the scale by dividing the continuous range into uniform bands.
2373 * Band scales are typically used for bar charts with an ordinal or categorical dimension.
2374 * The unknown value of a band scale is effectively undefined: they do not allow implicit domain construction.
2375 *
2376 * The generic corresponds to the data type of domain elements.
2377 */
2378export interface ScaleBand<Domain extends { toString(): string }> {
2379 /**
2380 * Given a value in the input domain, returns the start of the corresponding band derived from the output range.
2381 * If the given value is not in the scale’s domain, returns undefined.
2382 *
2383 * @param x A value from the domain.
2384 */
2385 (x: Domain): number | undefined;
2386
2387 /**
2388 * Returns to scale's current domain
2389 */
2390 domain(): Domain[];
2391 /**
2392 * Sets the domain to the specified array of values. The first element in domain will be mapped to the first band, the second domain value to the second band, and so on.
2393 * Domain values are stored internally in a map from stringified value to index; the resulting index is then used to determine the band.
2394 * Thus, a band scale’s values must be coercible to a string, and the stringified version of the domain value uniquely identifies the corresponding band.
2395 *
2396 * @param domain Array of domain values.
2397 */
2398 domain(domain: Iterable<Domain>): this;
2399
2400 /**
2401 * Returns the scale’s current range, which defaults to [0, 1].
2402 */
2403 range(): [number, number];
2404 /**
2405 * Sets the scale’s range to the specified two-element array of numbers. If the elements in the given array are not numbers, they will be coerced to numbers.
2406 * The default range is [0, 1].
2407 *
2408 * @param range A two-element array of numeric values.
2409 */
2410 range(range: Iterable<NumberValue>): this;
2411
2412 /**
2413 * Sets the scale’s range to the specified two-element array of numbers while also enabling rounding.
2414 * If the elements in the given array are not numbers, they will be coerced to numbers.
2415 *
2416 * Rounding is sometimes useful for avoiding antialiasing artifacts, though also consider the shape-rendering “crispEdges” styles.
2417 *
2418 * @param range A two-element array of numeric values.
2419 */
2420 rangeRound(range: Iterable<NumberValue>): this;
2421
2422 /**
2423 * Returns the current rounding status for the scale: enabled (= true) or disabled (= false).
2424 */
2425 round(): boolean;
2426 /**
2427 * Enables or disables rounding accordingly. If rounding is enabled, the start and stop of each band will be integers.
2428 * Rounding is sometimes useful for avoiding antialiasing artifacts, though also consider the shape-rendering “crispEdges” styles.
2429 * Note that if the width of the domain is not a multiple of the cardinality of the range, there may be leftover unused space, even without padding!
2430 * Use band.align to specify how the leftover space is distributed.
2431 *
2432 * @param round Enable rounding (= true), disable rounding (= false).
2433 */
2434 round(round: boolean): this;
2435
2436 /**
2437 * Returns the current inner padding which defaults to 0.
2438 */
2439 paddingInner(): number;
2440 /**
2441 * Sets the inner padding to the specified value which must be in the range [0, 1].
2442 * The inner padding determines the ratio of the range that is reserved for blank space between bands.
2443 *
2444 * The default setting is 0.
2445 *
2446 * @param padding Value for inner padding in [0, 1] interval.
2447 */
2448 paddingInner(padding: number): this;
2449
2450 /**
2451 * Returns the current outer padding which defaults to 0.
2452 */
2453 paddingOuter(): number;
2454 /**
2455 * Sets the outer padding to the specified value which must be in the range [0, 1].
2456 * The outer padding determines the ratio of the range that is reserved for blank space before the first band and after the last band.
2457 *
2458 * The default setting is 0.
2459 *
2460 * @param padding Value for outer padding in [0, 1] interval.
2461 */
2462 paddingOuter(padding: number): this;
2463
2464 /**
2465 * Returns the inner padding.
2466 */
2467 padding(): number;
2468 /**
2469 * A convenience method for setting the inner and outer padding to the same padding value.
2470 *
2471 * @param padding Value for inner and outer padding in [0, 1] interval.
2472 */
2473 padding(padding: number): this;
2474
2475 /**
2476 * Returns the current alignment which defaults to 0.5.
2477 */
2478 align(): number;
2479 /**
2480 * Sets the alignment to the specified value which must be in the range [0, 1].
2481 *
2482 * The default is 0.5.
2483 *
2484 * The alignment determines how any leftover unused space in the range is distributed.
2485 * A value of 0.5 indicates that the outer patter should be equally distributed before the first band and after the last band;
2486 * i.e., the bands should be centered within the range. A value of 0 or 1 may be used to shift the bands to one side, say to position them adjacent to an axis.
2487 *
2488 * @param align Value for alignment setting in [0, 1] interval.
2489 */
2490 align(align: number): this;
2491
2492 /**
2493 * Returns the width of each band.
2494 */
2495 bandwidth(): number;
2496
2497 /**
2498 * Returns the distance between the starts of adjacent bands.
2499 */
2500 step(): number;
2501
2502 /**
2503 * Returns an exact copy of this scale. Changes to this scale will not affect the returned scale, and vice versa.
2504 */
2505 copy(): this;
2506}
2507
2508/**
2509 * Constructs a new band scale with the specified range, no padding, no rounding and center alignment.
2510 * The domain defaults to the empty domain.
2511 * If range is not specified, it defaults to the unit range [0, 1].
2512 *
2513 * The generic corresponds to the data type of domain elements.
2514 *
2515 * @param range A two-element array of numeric values.
2516 */
2517export function scaleBand<Domain extends { toString(): string } = string>(
2518 range?: Iterable<NumberValue>
2519// tslint:disable-next-line:no-unnecessary-generics
2520): ScaleBand<Domain>;
2521/**
2522 * Constructs a new band scale with the specified domain and range, no padding, no rounding and center alignment.
2523 *
2524 * The generic corresponds to the data type of domain elements.
2525 *
2526 * @param domain Array of domain values.
2527 * @param range A two-element array of numeric values.
2528 */
2529export function scaleBand<Domain extends { toString(): string }>(
2530 domain: Iterable<Domain>,
2531 range: Iterable<NumberValue>
2532): ScaleBand<Domain>;
2533
2534// -------------------------------------------------------------------------------
2535// Point Scale Factory
2536// -------------------------------------------------------------------------------
2537
2538/**
2539 * Point scales are a variant of band scales with the bandwidth fixed to zero.
2540 * Point scales are typically used for scatterplots with an ordinal or categorical dimension.
2541 * The unknown value of a point scale is always undefined: they do not allow implicit domain construction.
2542 *
2543 * The generic corresponds to the data type of domain elements.
2544 */
2545export interface ScalePoint<Domain extends { toString(): string }> {
2546 /**
2547 * Given a value in the input domain, returns the corresponding point derived from the output range.
2548 * If the given value is not in the scale’s domain, returns undefined.
2549 *
2550 * @param x A value from the domain.
2551 */
2552 (x: Domain): number | undefined;
2553
2554 /**
2555 * Returns the scale's current domain.
2556 */
2557 domain(): Domain[];
2558 /**
2559 * Sets the domain to the specified array of values. The first element in domain will be mapped to the first point, the second domain value to the second point, and so on.
2560 * Domain values are stored internally in a map from stringified value to index; the resulting index is then used to determine the point.
2561 * Thus, a point scale’s values must be coercible to a string, and the stringified version of the domain value uniquely identifies the corresponding point.
2562 *
2563 * @param domain Array of domain values.
2564 */
2565 domain(domain: Iterable<Domain>): this;
2566
2567 /**
2568 * Returns the scale’s current range, which defaults to [0, 1].
2569 */
2570 range(): [number, number];
2571 /**
2572 * Sets the scale’s range to the specified two-element array of numbers.
2573 * If the elements in the given array are not numbers, they will be coerced to numbers.
2574 * The default range is [0, 1].
2575 *
2576 * @param range A two-element array of numeric values.
2577 */
2578 range(range: Iterable<NumberValue>): this;
2579
2580 /**
2581 * Sets the scale’s range to the specified two-element array of numbers while also enabling rounding.
2582 * If the elements in the given array are not numbers, they will be coerced to numbers.
2583 *
2584 * Rounding is sometimes useful for avoiding antialiasing artifacts, though also consider the shape-rendering “crispEdges” styles.
2585 *
2586 * @param range A two-element array of numeric values.
2587 */
2588 rangeRound(range: Iterable<NumberValue>): this;
2589
2590 /**
2591 * Returns the current rounding status for the scale: enabled (= true) or disabled (= false).
2592 */
2593 round(): boolean;
2594 /**
2595 * Enables or disables rounding accordingly. If rounding is enabled, the position of each point will be integers.
2596 * Rounding is sometimes useful for avoiding antialiasing artifacts, though also consider the shape-rendering “crispEdges” styles.
2597 * Note that if the width of the domain is not a multiple of the cardinality of the range, there may be leftover unused space, even without padding!
2598 * Use point.align to specify how the leftover space is distributed.
2599 *
2600 * @param round Enable rounding (= true), disable rounding (= false).
2601 */
2602 round(round: boolean): this;
2603
2604 /**
2605 * Returns the current outer padding which defaults to 0.
2606 * The outer padding determines the ratio of the range that is reserved for blank space
2607 * before the first point and after the last point.
2608 *
2609 */
2610 padding(): number;
2611 /**
2612 * Sets the outer padding to the specified value which must be in the range [0, 1].
2613 * The outer padding determines the ratio of the range that is reserved for blank space
2614 * before the first point and after the last point.
2615 *
2616 * The default is 0.
2617 *
2618 * @param padding Value for outer padding in [0, 1] interval.
2619 */
2620 padding(padding: number): this;
2621
2622 /**
2623 * Returns the current alignment which defaults to 0.5.
2624 */
2625 align(): number;
2626 /**
2627 * Sets the alignment to the specified value which must be in the range [0, 1].
2628 *
2629 * The alignment determines how any leftover unused space in the range is distributed.
2630 * A value of 0.5 indicates that the leftover space should be equally distributed before the first point and after the last point;
2631 * i.e., the points should be centered within the range. A value of 0 or 1 may be used to shift the points to one side, say to position them adjacent to an axis.
2632 *
2633 * The default value is 0.5.
2634 *
2635 * @param align Value for alignment setting in [0, 1] interval.
2636 */
2637 align(align: number): this;
2638
2639 /**
2640 * Return 0.
2641 */
2642 bandwidth(): number;
2643
2644 /**
2645 * Returns the distance between the starts of adjacent points.
2646 */
2647 step(): number;
2648
2649 /**
2650 * Returns an exact copy of this scale. Changes to this scale will not affect the returned scale, and vice versa.
2651 */
2652 copy(): this;
2653}
2654
2655/**
2656 * Constructs a new point scale with the specified range, no padding, no rounding and center alignment.
2657 * The domain defaults to the empty domain.
2658 * If range is not specified, it defaults to the unit range [0, 1].
2659 *
2660 * The generic corresponds to the data type of domain elements.
2661 *
2662 * @param range A two-element array of numeric values.
2663 */
2664export function scalePoint<Domain extends { toString(): string } = string>(
2665 range?: Iterable<NumberValue>
2666// tslint:disable-next-line:no-unnecessary-generics
2667): ScalePoint<Domain>;
2668/**
2669 * Constructs a new point scale with the specified domain and range, no padding, no rounding and center alignment.
2670 * The domain defaults to the empty domain.
2671 *
2672 * The generic corresponds to the data type of domain elements.
2673 *
2674 * @param domain Array of domain values.
2675 * @param range A two-element array of numeric values.
2676 */
2677export function scalePoint<Domain extends { toString(): string }>(
2678 domain: Iterable<Domain>,
2679 range: Iterable<NumberValue>
2680): ScalePoint<Domain>;