Skip to content

Latest commit

 

History

History
58 lines (38 loc) · 2.05 KB

threshold.md

File metadata and controls

58 lines (38 loc) · 2.05 KB

Threshold

Divide continuous domain into slices based on specified cut values and map value in each slice to corresponding discrete values in the range. (online demo)

Usage

import { Threshold, ThresholdOptions } from '@antv/scale';

const options: ThresholdOptions = {
  domain: [1 / 3, 2 / 3],
  range: ['a', 'b', 'c'],
};

const x = new Identity(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]

Options

Key Description Type Default
domain Sets the scale’s domain to the specified array of values. The values must be in ascending order and will divide the domain into slices based on them. number[] [0.5]
range Sets the scale’s range to the specified array of values. any[] [0, 1]
unknown Sets the output value of the scale for undefined (or NaN) input values. any undefined

Methods

# map(x: number): any

Returns the input value itself 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: ThresholdOptions): void

Updates the scale's options and rescale.

# getOptions(): ThresholdOptions

Returns the scale's current options.

# clone(): Threshold

Returns a new threshold scale with the independent and same options as the original one.