Documentation / @finchart/core / index / LinearScale
Class: LinearScale
Defined in: packages/core/src/scale/linear-scale.ts:5
The one-way mapping from data domain to screen coordinates. It's mutable because the domain keeps changing during pan/zoom. Bad input is signaled by throwing, not by returning a Result.
Implements
Constructors
Constructor
new LinearScale(
domainMin?,domainMax?,rangeMin?,rangeMax?):LinearScale
Defined in: packages/core/src/scale/linear-scale.ts:10
Parameters
domainMin?
number
domainMax?
number
rangeMin?
number
rangeMax?
number
Returns
LinearScale
Properties
kind
readonlykind:string="linear"
Defined in: packages/core/src/scale/linear-scale.ts:6
Stable scale kind. Custom scales declare their own kind for declarative pane updates.
Implementation of
Methods
getDomain()
getDomain(): [
number,number]
Defined in: packages/core/src/scale/linear-scale.ts:43
The data domain [min, max].
Returns
[number, number]
Implementation of
getRange()
getRange(): [
number,number]
Defined in: packages/core/src/scale/linear-scale.ts:47
The screen range [start, end] (px).
A reversed range (start > end) is allowed. Screen y increases downward, so the y axis is set to [bottom, top] to put larger values on top — the scale has to hold this inversion so the chart and the axis agree on the same coordinates.
Returns
[number, number]
Implementation of
invert()
invert(
screenValue):number
Defined in: packages/core/src/scale/linear-scale.ts:65
Screen coordinate → data value.
Parameters
screenValue
number
Returns
number
Implementation of
scale()
scale(
value):number
Defined in: packages/core/src/scale/linear-scale.ts:59
A domain — or a range — is two finite numbers, but their difference need not be one: [-MAX_VALUE, MAX_VALUE] is legal for either, its span overflows, and ∞ / ∞ is NaN, a pixel the canvas silently drops. lerp/unlerp take the plain arithmetic wherever it is finite (so an ordinary axis's pixels are bit-for-bit the plain arithmetic's) and the same interpolation at half scale where it is not.
Parameters
value
number
Returns
number
Implementation of
setDomain()
setDomain(
min,max):void
Defined in: packages/core/src/scale/linear-scale.ts:35
This is a chokepoint. Both the y domain and the x domain pass through here without exception (the pane's value domain, value-axis.ts, x-viewport.ts), and an axis reads it only via getDomain(), in the Axis constructor. Refusing a non-finite domain here keeps the tick count finite; the cap in axis.ts is only a backstop.
Checking only min >= max is not enough: -Infinity < Infinity passes it, and that domain makes the axis's tick count Infinity.
Parameters
min
number
max
number
Returns
void
Implementation of
setRange()
setRange(
start,end):void
Defined in: packages/core/src/scale/linear-scale.ts:39
Parameters
start
number
end
number
Returns
void