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});


propertyexplanationtypedefault value
domainthe domain of the scaleArray
rangethe 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 extent
to 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
rangeExtentthe extent of the scale rangeNumber
isFlippedwhether the scale is flippedBoolean
typethe type of scaleString


methodexplanationreturn 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 encodesArray