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_offsetImplementations§
Source§impl TimeScale
impl TimeScale
Sourcepub 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>,
)
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.
Sourcepub fn set_width(&mut self, width: f32)
pub fn set_width(&mut self, width: f32)
Set the width of the chart area (must be called when chart resizes)
Sourcepub fn set_bar_cnt(&mut self, count: usize)
pub fn set_bar_cnt(&mut self, count: usize)
Set the total number of bars in dataset
Sourcepub fn set_bar_spacing(&mut self, spacing: f32)
pub fn set_bar_spacing(&mut self, spacing: f32)
Set bar spacing (with clamping to constraints)
Sourcepub fn set_min_bar_spacing(&mut self, min: f32)
pub fn set_min_bar_spacing(&mut self, min: f32)
Update min bar spacing
Sourcepub fn set_max_bar_spacing(&mut self, max: f32)
pub fn set_max_bar_spacing(&mut self, max: f32)
Update max bar spacing (0 = unlimited)
Sourcepub fn set_fix_left_edge(&mut self, fix: bool)
pub fn set_fix_left_edge(&mut self, fix: bool)
Configure whether left edge is fixed
Sourcepub fn set_fix_right_edge(&mut self, fix: bool)
pub fn set_fix_right_edge(&mut self, fix: bool)
Configure whether right edge is fixed
Sourcepub fn set_right_offset(&mut self, offset: f32)
pub fn set_right_offset(&mut self, offset: f32)
Set right offset (with constraint checking)
Sourcepub fn jump_to_latest(&mut self)
pub fn jump_to_latest(&mut self)
Jump to latest bar position Resets right_offset to the default sticky offset (2.5 bars)
Sourcepub fn bar_spacing(&self) -> f32
pub fn bar_spacing(&self) -> f32
Get current bar spacing
Sourcepub fn right_offset(&self) -> f32
pub fn right_offset(&self) -> f32
Get current right offset
Sourcepub fn visible_logical_range(&self) -> LogicalRange
pub fn visible_logical_range(&self) -> LogicalRange
Calculate visible logical range
Sourcepub fn idx_to_coord(
&self,
index: usize,
rect_min_x: f32,
rect_width: f32,
) -> f32
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).
Sourcepub fn idx_to_coord_precise(
&self,
index: f32,
rect_min_x: f32,
rect_width: f32,
) -> f32
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).
Sourcepub fn coord_to_idx(&self, x: f32, rect_min_x: f32, rect_width: f32) -> f32
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).
Sourcepub fn scroll_bars(&mut self, bars: f32)
pub fn scroll_bars(&mut self, bars: f32)
Scroll by number of bars (negative = left, positive = right)
Sourcepub fn scroll_pixels(&mut self, pixels: f32)
pub fn scroll_pixels(&mut self, pixels: f32)
Scroll by pixels
Sourcepub fn zoom(
&mut self,
delta: f32,
anchor_x: f32,
rect_min_x: f32,
rect_width: f32,
)
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.
Sourcepub fn fit_content(&mut self)
pub fn fit_content(&mut self)
Fit all data in view
Sourcepub fn scroll_to_realtime(&mut self)
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
Sourcepub fn visible_candles(&self) -> usize
pub fn visible_candles(&self) -> usize
Get number of visible candles