Skip to main content

TimeScale

Struct TimeScale 

Source
pub struct TimeScale { /* private fields */ }
Expand description

Time-scale coordinate engine – pure logic, no UI dependencies.

Manages the horizontal mapping between logical bar indices and pixel positions. The chart widget reads from TimeScale to lay out candles and writes back scroll/zoom deltas from user interaction.

§Coordinate model

The rightmost data point (the latest bar) is the anchor. The right_offset field shifts the anchor away from the right edge of the chart to leave whitespace for price labels and visual breathing room.

  bar index:  0  1  2  3  4  5  6  7  8  ·  ·
              │  │  │  │  │  │  │  │  │        │
              ◄──────── visible ──────────►     │
              ◄──────────── width ─────────────►
                                         ↑
                                    right_offset

Implementations§

Source§

impl TimeScale

Source

pub fn new() -> Self

Create new TimeScale with default settings

Source

pub fn apply_options( &mut self, bar_spacing: f32, min_bar_spacing: f32, max_bar_spacing: f32, fix_left_edge: bool, fix_right_edge: bool, right_offset_bars: f32, right_offset_pixels: Option<f32>, )

Apply options coming from TimeScaleOptions Note: this does not own TimeScaleOptions to avoid a dependency cycle. Non-finite spacing retains the current spacing, clamped to the new bounds. Non-finite right offsets retain their previous values.

Source

pub fn set_width(&mut self, width: f32)

Set the width of the chart area (must be called when chart resizes). Non-finite values are ignored.

Source

pub fn set_bar_cnt(&mut self, count: usize)

Set the total number of bars in dataset

Source

pub fn set_bar_spacing(&mut self, spacing: f32)

Set bar spacing (with clamping to constraints). Non-finite values are ignored.

Source

pub fn set_min_bar_spacing(&mut self, min: f32)

Update min bar spacing, floored at 0.000001 pixels. Non-finite values are ignored.

Source

pub fn set_max_bar_spacing(&mut self, max: f32)

Update max bar spacing (0 = unlimited), with positive limits floored at 0.000001 pixels. Non-finite values are ignored.

Source

pub fn set_fix_left_edge(&mut self, fix: bool)

Configure whether left edge is fixed

Source

pub fn set_fix_right_edge(&mut self, fix: bool)

Configure whether right edge is fixed

Source

pub fn set_right_offset(&mut self, offset: impl Into<f64>)

Set right offset (with constraint checking). Non-finite values are ignored.

Source

pub fn jump_to_latest(&mut self)

Jump to latest bar position Restores the configured right offset, as scroll_to_realtime does.

Source

pub fn bar_spacing(&self) -> f32

Get current bar spacing

Source

pub fn right_offset(&self) -> f32

Get current right offset. Self::right_offset_precise retains sub-bar precision.

Source

pub fn right_offset_precise(&self) -> f64

The scroll offset without narrowing fractional movement far into a large history.

Source

pub fn width(&self) -> f32

Get current width

Source

pub fn base_idx(&self) -> usize

Get base index (last data point - coord anchor)

Source

pub fn visible_logical_range(&self) -> LogicalRange

Calculate visible logical range

Source

pub fn idx_to_coord( &self, index: usize, rect_min_x: f32, rect_width: f32, ) -> f32

Convert logical index to x coord

IMPORTANT: rect_width must be the actual width of the rect being drawn in, NOT self.width (which may differ from the chart area’s rect).

Source

pub fn idx_to_coord_precise( &self, index: impl Into<f64>, rect_min_x: f32, rect_width: f32, ) -> f32

Convert fractional bar index to x coord (preserves sub-bar precision) Used for drawings which store fractional bar indices for precise positioning

IMPORTANT: rect_width must be the actual width of the rect being drawn in, NOT self.width (which may differ from the chart area’s rect).

Source

pub fn coord_to_idx(&self, x: f32, rect_min_x: f32, rect_width: f32) -> f32

Convert x coord to logical index

IMPORTANT: rect_width must be the actual width of the rect being used, NOT self.width (which may differ from the chart area’s rect).

Source

pub fn coord_to_idx_precise( &self, x: f32, rect_min_x: f32, rect_width: f32, ) -> f64

Convert x to a fractional logical index without narrowing a large history to f32. rect_width is the actual width of the chart rect, as in Self::coord_to_idx.

Source

pub fn scroll_bars(&mut self, bars: f32)

Scroll by number of bars (negative = left, positive = right). Non-finite deltas are ignored.

Source

pub fn scroll_pixels(&mut self, pixels: f32)

Scroll by pixels. Non-finite deltas are ignored.

Source

pub fn zoom( &mut self, delta: f32, anchor_x: f32, _rect_min_x: f32, rect_width: f32, )

Zoom at a specific point

IMPORTANT: rect_width must be the actual width of the chart rect being zoomed. Non-finite deltas, anchors and widths are ignored.

Source

pub fn fit_content(&mut self)

Fit all data in view, then restore the configured right offset.

The bars and the configured offset in bars share the width, or the bars share the width less a configured pixel offset, so every bar stays in view.

Source

pub fn scroll_to_realtime(&mut self)

Scroll to real-time (latest data) Restores the right offset given to apply_options (2.5 bars before it is called), the pixel offset converted at the current bar spacing.

Source

pub fn visible_candles(&self) -> usize

Get number of visible candles

Trait Implementations§

Source§

impl Clone for TimeScale

Source§

fn clone(&self) -> TimeScale

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for TimeScale

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Default for TimeScale

Source§

fn default() -> Self

Returns the “default value” for a type. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
§

impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
where ST: ?Sized, DT: ?Sized,

§

impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ

Converts self into a Left variant of Either<Self, Self> if into_left is true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
where F: FnOnce(&Self) -> bool,

Converts self into a Left variant of Either<Self, Self> if into_left(&self) returns true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

impl<T> MaybeSend for T
where T: Send + Sync + ?Sized,

§

impl<T> Read<Exclusive, BecauseExclusive> for T
where T: ?Sized,

§

impl<T> SerializableAny for T
where T: 'static + Any + Clone + for<'a> Send + Sync,

§

impl<T, S> SimdFrom<T, S> for T
where S: Simd,

§

fn simd_from(_simd: S, value: T) -> T

§

impl<F, T, S> SimdInto<T, S> for F
where T: SimdFrom<F, S>, S: Simd,

§

fn simd_into(self, simd: S) -> T

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.