pub struct ChartState { /* private fields */ }Expand description
Backend chart state – owns bar data, time-scale coordinate system, price auto-scaling logic, and zoom history.
This is the pure-logic layer with no UI or rendering dependencies. The UI
layer reads from ChartState to determine what to draw and writes back
interaction results (scroll, zoom, data updates).
§Example
use egui_charts::model::BarData;
use egui_charts::studies::ChartState;
let data = BarData::new();
let state = ChartState::new(data);
assert!(state.visible_data().is_empty());Implementations§
Source§impl ChartState
impl ChartState
Sourcepub fn time_scale_mut(&mut self) -> &mut TimeScale
pub fn time_scale_mut(&mut self) -> &mut TimeScale
Get mutable reference to time scale
Sourcepub fn time_scale(&self) -> &TimeScale
pub fn time_scale(&self) -> &TimeScale
Get reference to time scale
Sourcepub fn revision(&self) -> u64
pub fn revision(&self) -> u64
Identifies the bars before the last one. It changes when any of them changes or bars are removed, and stays the same when bars are appended or the last bar is updated, so results computed from the bars can be cached under it and extended as the series streams.
Sourcepub fn set_data(&mut self, data: BarData) -> Option<usize>
pub fn set_data(&mut self, data: BarData) -> Option<usize>
Replaces the bars (also updates the bar count of the time scale). Returns the index of the
first bar that differs from the previous bars, counting a change of length: the shorter
length when one is a prefix of the other, None when they are identical.
Sourcepub fn shown(&self) -> &[Bar]
pub fn shown(&self) -> &[Bar]
The series drawn on the time scale, one OHLC bar per element on price-based charts. Indices returned by the chart hover and selection APIs refer to this series.
Sourcepub fn visible_data(&self) -> &[Bar]
pub fn visible_data(&self) -> &[Bar]
The bars of visible_range: source bars, or one OHLC bar per
element on a price-based chart type.
Sourcepub fn visible_range(&self) -> (usize, usize)
pub fn visible_range(&self) -> (usize, usize)
Indices of the bars in view, end exclusive, counting elements on price-based chart types and bars otherwise. A bar the plot’s edge cuts is in view. With no bar in view the range is empty: it starts at 0 before the first bar and at the number of bars after the last.
Sourcepub fn price_scale(&self) -> &PriceScale
pub fn price_scale(&self) -> &PriceScale
Returns the main series’ price scale.
Sourcepub fn price_scale_mut(&mut self) -> &mut PriceScale
pub fn price_scale_mut(&mut self) -> &mut PriceScale
Returns the main series’ price scale for changing its options or range.
Sourcepub fn fit_price_scale<'a>(
&mut self,
indicators: impl IntoIterator<Item = &'a dyn Indicator>,
) -> PriceTransform
pub fn fit_price_scale<'a>( &mut self, indicators: impl IntoIterator<Item = &'a dyn Indicator>, ) -> PriceTransform
Fits the price scale to the visible bars and the visible values of the visible overlay
studies in indicators, unless the user scaled by hand, and returns this frame’s
transform: percentage and indexed modes are relative to the first visible close.
Sourcepub fn push_zoom_state(&mut self)
pub fn push_zoom_state(&mut self)
Save current zoom state to history
Sourcepub fn pop_zoom_state(&mut self) -> bool
pub fn pop_zoom_state(&mut self) -> bool
Restore previous zoom state (zoom out button)
Sourcepub fn clear_zoom_history(&mut self)
pub fn clear_zoom_history(&mut self)
Clear zoom history
Sourcepub fn has_zoom_history(&self) -> bool
pub fn has_zoom_history(&self) -> bool
Check if there are zoom states to restore
Trait Implementations§
Source§impl Clone for ChartState
impl Clone for ChartState
Auto Trait Implementations§
impl Freeze for ChartState
impl RefUnwindSafe for ChartState
impl Send for ChartState
impl Sync for ChartState
impl Unpin for ChartState
impl UnsafeUnpin for ChartState
impl UnwindSafe for ChartState
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