Skip to content

charton API


charton API / @chart-on/core / index / PriceScale

Class: PriceScale ​

Defined in: packages/core/src/scales.ts:465

Vertical scale. min/max live in coordinate space: price for normal/percent, log10(price) for log. Use minPrice/maxPrice for prices.

Constructors ​

Constructor ​

new PriceScale(options): PriceScale

Defined in: packages/core/src/scales.ts:514

Parameters ​

options ​

PriceScaleOptions

Returns ​

PriceScale

Properties ​

autoMargins ​

autoMargins: [number, number]

Defined in: packages/core/src/scales.ts:474

The margins (top, bottom) the chart sizes each frame, used for the null sides.


autoScale ​

autoScale: boolean = true

Defined in: packages/core/src/scales.ts:469


autoscaleRule ​

autoscaleRule: AutoscaleRule | null = null

Defined in: packages/core/src/scales.ts:502

Adjustments to the fitted data range; see AutoscaleRule.


barRatio ​

barRatio: number | null = null

Defined in: packages/core/src/scales.ts:507

Coordinate units per bar width while the price-to-bar ratio is locked (NaN: lock at the current ratio on the next applyBarRatio); null when unlocked.


bounds ​

bounds: { high?: number; low?: number; } | null = null

Defined in: packages/core/src/scales.ts:498

Prices the visible range must stay within (viewport bounds); either end may be missing.


fixedRange ​

fixedRange: { max: number; min: number; } | null = null

Defined in: packages/core/src/scales.ts:500

While autoscale is on, show exactly this price range instead of fitting the data.


height ​

height: number = 0

Defined in: packages/core/src/scales.ts:466


id ​

readonly id: string

Defined in: packages/core/src/scales.ts:478


invert ​

invert: boolean = false

Defined in: packages/core/src/scales.ts:477

Higher prices lower down.


link: PriceScale | null = null

Defined in: packages/core/src/scales.ts:489

Scale this one follows (e.g. a compared symbol's scale linked to the main one): it takes the same mode, and in percent and indexed modes both fit one shared percent range, so their lines compare directly.


marginBottom ​

marginBottom: number | null

Defined in: packages/core/src/scales.ts:472


marginTop ​

marginTop: number | null

Defined in: packages/core/src/scales.ts:471

Fractions of the height left empty above/below the data; null for a side the chart sizes.


max ​

max: number = 1

Defined in: packages/core/src/scales.ts:468


min ​

min: number = 0

Defined in: packages/core/src/scales.ts:467


mode ​

mode: PriceScaleMode = 'normal'

Defined in: packages/core/src/scales.ts:475


noPositiveData ​

noPositiveData: boolean = false

Defined in: packages/core/src/scales.ts:496

Log mode with visible data but none of it above zero (set by the chart). Autoscale then keeps the last range.


percentBase ​

percentBase: number = 1

Defined in: packages/core/src/scales.ts:481

Reference price for percent and indexed modes, resolved each frame from percentFrom.


percentFrom ​

percentFrom: PercentBase = 'firstVisible'

Defined in: packages/core/src/scales.ts:483

Where percentBase comes from (the percentBase setting); a linked scale follows its root's.


side ​

side: PriceScaleSide

Defined in: packages/core/src/scales.ts:479


smooth ​

smooth: boolean = false

Defined in: packages/core/src/scales.ts:491

Ease autoscale changes instead of jumping (set by the chart).

Accessors ​

isLog ​

Get Signature ​

get isLog(): boolean

Defined in: packages/core/src/scales.ts:521

Returns ​

boolean


maxPrice ​

Get Signature ​

get maxPrice(): number

Defined in: packages/core/src/scales.ts:539

Returns ​

number


minPrice ​

Get Signature ​

get minPrice(): number

Defined in: packages/core/src/scales.ts:535

Returns ​

number

Methods ​

applyBarRatio() ​

applyBarRatio(barSpacing): void

Defined in: packages/core/src/scales.ts:734

With a locked ratio, set the span for barSpacing around the current centre, so zooming time scales prices too and angles stay put.

Parameters ​

barSpacing ​

number

Returns ​

void


applyRule() ​

applyRule(r): void

Defined in: packages/core/src/scales.ts:641

Apply autoscaleRule to a price range fitted from the data, in place. Without a rule, or for a fixed range (which wins), r is left as it is.

Parameters ​

r ​

[number, number]

Returns ​

void


fit() ​

fit(lo, hi): void

Defined in: packages/core/src/scales.ts:607

Fit [lo, hi] (prices) including margins; no-op in manual mode. In log mode bounds at or below zero cannot be shown: a non-positive hi keeps the current range, and a non-positive lo fits around hi alone.

Parameters ​

lo ​

number

hi ​

number

Returns ​

void


follow() ​

follow(root): void

Defined in: packages/core/src/scales.ts:724

Show the same percent range as root shows, exactly (a linked scale whose root is not fitting the data: manual, fixed or ratio-locked).

Parameters ​

root ​

PriceScale

Returns ​

void


fromCoord() ​

fromCoord(coord): number

Defined in: packages/core/src/scales.ts:531

Coordinate space → price.

Parameters ​

coord ​

number

Returns ​

number


fromIndexed() ​

fromIndexed(value): number

Defined in: packages/core/src/scales.ts:598

Parameters ​

value ​

number

Returns ​

number


fromPercent() ​

fromPercent(pct): number

Defined in: packages/core/src/scales.ts:589

Parameters ​

pct ​

number

Returns ​

number


inBounds() ​

inBounds(min, max): [number, number]

Defined in: packages/core/src/scales.ts:680

The range min to max (coordinates) moved inside bounds: slid in without changing its span, or the whole band when the span is wider.

Parameters ​

min ​

number

max ​

number

Returns ​

[number, number]


keepInBounds() ​

keepInBounds(): void

Defined in: packages/core/src/scales.ts:692

Keep the visible range inside bounds.

Returns ​

void


lockRatio() ​

lockRatio(ratio): void

Defined in: packages/core/src/scales.ts:715

Lock the price-to-bar ratio at ratio, or at the current one with NaN; null unlocks.

Parameters ​

ratio ​

number | null

Returns ​

void


pan() ​

pan(dy): void

Defined in: packages/core/src/scales.ts:782

Positive dy drags content down; switches to manual mode.

Parameters ​

dy ​

number

Returns ​

void


priceToY() ​

priceToY(price): number

Defined in: packages/core/src/scales.ts:563

Parameters ​

price ​

number

Returns ​

number


setMode() ​

setMode(mode): void

Defined in: packages/core/src/scales.ts:543

Parameters ​

mode ​

PriceScaleMode

Returns ​

void


setRange() ​

setRange(lo, hi, animate?): void

Defined in: packages/core/src/scales.ts:700

Show prices lo to hi exactly and switch to manual mode, easing there with animate. A locked price-to-bar ratio is taken again from the new range.

Parameters ​

lo ​

number

hi ​

number

animate? ​

boolean = false

Returns ​

void


step() ​

step(dt): boolean

Defined in: packages/core/src/scales.ts:750

Ease towards the last fit target, or a setRange target; true while still moving.

Parameters ​

dt ​

number

Returns ​

boolean


toCoord() ​

toCoord(price): number

Defined in: packages/core/src/scales.ts:526

Price → coordinate space.

Parameters ​

price ​

number

Returns ​

number


toIndexed() ​

toIndexed(price): number

Defined in: packages/core/src/scales.ts:594

price indexed to 100 at percentBase.

Parameters ​

price ​

number

Returns ​

number


toPercent() ​

toPercent(price): number

Defined in: packages/core/src/scales.ts:585

Percent change of price against percentBase.

Parameters ​

price ​

number

Returns ​

number


yToPrice() ​

yToPrice(y): number

Defined in: packages/core/src/scales.ts:568

Parameters ​

y ​

number

Returns ​

number


yTransform() ​

yTransform(): [number, number]

Defined in: packages/core/src/scales.ts:579

Affine coefficients so that y = coord(price) * scale + offset.

Returns ​

[number, number]


zoom() ​

zoom(factor, anchorY?): void

Defined in: packages/core/src/scales.ts:771

Scale around the price at anchorY; switches to manual mode, and a locked ratio follows.

Parameters ​

factor ​

number

anchorY? ​

number = ...

Returns ​

void