Skip to content

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 ​

readonly kind: 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 ​

Scale.kind

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 ​

Scale.getDomain


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 ​

Scale.getRange


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.invert


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 (an ordinary axis's pixels are the same bits as before) and the same interpolation at half scale where it is not.

Parameters ​

value ​

number

Returns ​

number

Implementation of ​

Scale.scale


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 (pane.ts:589·1006·1021 · x-viewport.ts, 9 places), and axes only read via getDomain() (axis.ts:52). So unless the scale refuses a non-finite domain, the tick loop in axis.ts can end up infinite.

An earlier version only checked min >= max. -Infinity < Infinity passed that check, and once that domain reached the axis, count became Infinity and the tab died of OOM.

Parameters ​

min ​

number

max ​

number

Returns ​

void

Implementation of ​

Scale.setDomain


setRange() ​

setRange(start, end): void

Defined in: packages/core/src/scale/linear-scale.ts:39

Parameters ​

start ​

number

end ​

number

Returns ​

void

Implementation of ​

Scale.setRange