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.
Non-finite spacing retains the current spacing, clamped to the new bounds.
Non-finite right offsets retain their previous values.
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). Non-finite values are ignored.
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). Non-finite values are ignored.
Sourcepub fn set_min_bar_spacing(&mut self, min: f32)
pub fn set_min_bar_spacing(&mut self, min: f32)
Update min bar spacing, floored at 0.000001 pixels. Non-finite values are ignored.
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), with positive limits floored at 0.000001 pixels. Non-finite values are ignored.
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: impl Into<f64>)
pub fn set_right_offset(&mut self, offset: impl Into<f64>)
Set right offset (with constraint checking). Non-finite values are ignored.
Sourcepub fn jump_to_latest(&mut self)
pub fn jump_to_latest(&mut self)
Jump to latest bar position
Restores the configured right offset, as scroll_to_realtime does.
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. Self::right_offset_precise retains sub-bar precision.
Sourcepub fn right_offset_precise(&self) -> f64
pub fn right_offset_precise(&self) -> f64
The scroll offset without narrowing fractional movement far into a large history.
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: impl Into<f64>,
rect_min_x: f32,
rect_width: f32,
) -> f32
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).
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 coord_to_idx_precise(
&self,
x: f32,
rect_min_x: f32,
rect_width: f32,
) -> f64
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.
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). Non-finite deltas are ignored.
Sourcepub fn scroll_pixels(&mut self, pixels: f32)
pub fn scroll_pixels(&mut self, pixels: f32)
Scroll by pixels. Non-finite deltas are ignored.
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. Non-finite deltas, anchors and widths are ignored.
Sourcepub fn fit_content(&mut self)
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.
Sourcepub fn scroll_to_realtime(&mut self)
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.
Sourcepub fn visible_candles(&self) -> usize
pub fn visible_candles(&self) -> usize
Get number of visible candles
Trait Implementations§
Auto Trait Implementations§
impl Freeze for TimeScale
impl RefUnwindSafe for TimeScale
impl Send for TimeScale
impl Sync for TimeScale
impl Unpin for TimeScale
impl UnsafeUnpin for TimeScale
impl UnwindSafe for TimeScale
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
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 moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
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