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.

Source

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

Set the width of the chart area (must be called when chart resizes)

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)

Source

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

Update min bar spacing

Source

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

Update max bar spacing (0 = unlimited)

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: f32)

Set right offset (with constraint checking)

Source

pub fn jump_to_latest(&mut self)

Jump to latest bar position Resets right_offset to the default sticky offset (2.5 bars)

Source

pub fn bar_spacing(&self) -> f32

Get current bar spacing

Source

pub fn right_offset(&self) -> f32

Get current right offset

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: f32, 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 scroll_bars(&mut self, bars: f32)

Scroll by number of bars (negative = left, positive = right)

Source

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

Scroll by pixels

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.

Source

pub fn fit_content(&mut self)

Fit all data in view

Source

pub fn scroll_to_realtime(&mut self)

Scroll to real-time (latest data) Maintains sticky offset - keeps ~2.5 bars of whitespace on the right for price labels and visual breathing room

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 · 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
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> 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.
Source§

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