UNPKG

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