Scale interface
The base interface that all scale implementations must follow.The type of scale:
"linear", "log", "time", or "categorical"The input data range. For numeric scales, this is
[number, number]. For categorical scales, this is string[]The output pixel range as
[start, end]Methods
Converts a data value to pixel coordinates
Converts pixel coordinates back to data values
LinearScale
Maps numeric values to pixels using linear interpolation.Constructor
The minimum and maximum data values
The minimum and maximum pixel coordinates
Example
LogScale
Maps numeric values to pixels using logarithmic scaling, useful for data that spans multiple orders of magnitude.Constructor
The minimum and maximum data values (must be positive)
The minimum and maximum pixel coordinates
Example
CategoricalScale
Maps categorical (string) values to evenly-spaced positions on the axis.Constructor
Array of category labels
The minimum and maximum pixel coordinates
Properties
Controls spacing between categories
Example
Notes
- Categories are automatically centered within their bands
- The
toPixelsmethod accepts either a category string or a numeric index - Returns empty string from
invertif pixels are outside the range