Similar to threshold scales, but computed cut values based on size of each data. (online demo)
import { Quantize, QuantizeOptions } from '@antv/scale';
const options: QuantizeOptions = {
range: ['a', 'b' ,'c'],
};
const x = new Quantize(options);
x.map(0); // 'a'
x.map(0.2); // 'a'
x.map(0.4); // 'b'
x.map(0.6); // 'b'
x.map(0.8); // 'c'
x.map(1); // 'c'
x.invert('a'); // [undefined, 1 / 3]
x.invert('b'); // [1 / 3, 2 / 3]
x.invert('c'); // [2 / 3, undefined]
x.invert('d'); // [undefined,undefined]
x.getThresholds(); // [1 / 3, 2 / 3]
Key | Description | Type | Default |
---|---|---|---|
domain | Sets the scale’s domain to the specified two-element array of values. The values must be in ascending order. | number[] |
[0, 1] |
range | Sets the scale’s range to the specified array of values. | any[] |
[0.5] |
unknown | Sets the output value of the scale for undefined (or NaN ) input values. |
any |
undefined |
nice | Extends the domain so that it starts and ends on nice round values if it is true. | boolean |
false |
tickCount | Sets approximately count representative values from the scale’s domain. The specified tickCount in options is only a hint: the scale may return more or fewer values depending on the domain. |
number |
5 |
tickMethod | Sets the method for computing representative values from the scale’s domain. | (min: number, max: number, count: number) => number[] |
wilkinson-extended |
# map(x: number): any
Given a value in the input domain, returns the corresponding value in the output range if it is not undefined
(or NaN
), otherwise options.unknown
.
# invert(x: any): (number | undefined)[]
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.
# update(options: QuantizeOptions): void
Update the scale's options and rescale.
# getOptions(): QuantizeOptions
Returns the scale's current options.
# clone(): Quantize
Returns a new quantize scale with the independent and same options as the original one.
# getTicks(): number[]
Returns a series of representative values from the scale’s domain.
# getThresholds(): number[]
Returns the array of computed thresholds within the domain.