Scale
The Scale class represents a function that maps the values of a data field (domain) to the properties of a visual channel (range). It is recommended that you do not create a scale object directly; instead, use the encode method in the Scene class to get an Encoding object, which contains a Scale object as one of its properties. For example,
let enc = scene.encode(rect.leftSegment, {field: "value", channel: "x"});
let xScale = enc.scale;
A Scale object can be used in multiple encodings. For example, the scale above for encoding rectangle height can be used as an argument for another encoding:
let enc2 = scene.encode(line, {field: "amount", channel: "x", scale: xScale});
Properties
property | explanation | type | default value |
---|---|---|---|
domain | the domain of the scale | Array | |
range | the range of the scale Note: for position encodings: the range is not expressed in screen coordinates, instead, it is in the form of [0, r] where r is the range extentto get the range in actual screen coordinates, use encoding.getScaleRange ;to change the scale range for position encodings, do not directly set this property, set rangeExtent instead | Array | |
rangeExtent | the extent of the scale range | Number | |
isFlipped | whether the scale is flipped | Boolean | |
type | the type of scale | String |
Methods
method | explanation | return type |
---|---|---|
map(d) | convert a domain value into a value in this scale’s range d (Number): a domain value | |
invert(d) | convert a value in this scale’s range into a domain value d (Number): a range value | |
getEncodedChannels() | returns an array of channels this scale encodes | Array |