Skip to content

TimeScale

Defined in: core/src/scale/time-scale.ts:46

An immutable linear time scale. Pixel values are unrounded floats: rounding to device pixels is the renderer’s job. Dates and durations coming back from pixels are rounded to whole milliseconds; snapping to a step is a separate concern (scale/snap).

Members are plain functions (no this), so they can be passed around unbound. The object is frozen: zooming returns a new scale.

readonly dateToX: (t) => number

Defined in: core/src/scale/time-scale.ts:57

Horizontal position of a date: (t - origin) * pxPerDay / DAY, may be negative.

DateTimeMs

number


readonly direction: ScaleDirection

Defined in: core/src/scale/time-scale.ts:55

Writing direction as configured. 'rtl' currently behaves like 'ltr'.


readonly durationToPx: (ms) => number

Defined in: core/src/scale/time-scale.ts:61

Width in pixels of a fixed duration in milliseconds (sign preserved).

number

number


readonly origin: DateTimeMs

Defined in: core/src/scale/time-scale.ts:51

The date at x = 0. TimeScale.zoom keeps it a whole number of milliseconds (it rounds the shifted origin), so it is an integer whenever the created scale’s origin is.


readonly pxPerDay: number

Defined in: core/src/scale/time-scale.ts:53

Pixels per floating day (24 h).


readonly pxToDuration: (px) => number

Defined in: core/src/scale/time-scale.ts:63

Fixed duration in milliseconds covered by a pixel width, rounded to the nearest ms.

number

number


readonly xToDate: (x) => DateTimeMs

Defined in: core/src/scale/time-scale.ts:59

The date at a horizontal position, rounded to the nearest millisecond.

number

DateTimeMs


readonly zoom: (pxPerDay, anchor) => TimeScale

Defined in: core/src/scale/time-scale.ts:72

A scale with another pxPerDay where the date under anchor.x stays at anchor.x (the origin moves). The new origin is rounded to a whole millisecond, so the anchor date stays within half a millisecond of anchor.x: a sub-pixel shift at any realistic zoom (under 0.06 px at 10 000 px per day). Direction is kept.

number

ZoomAnchor

TimeScale

RangeError for a non-positive or non-finite pxPerDay or a non-finite anchor.x.