Skip to main content

ChartState

Struct ChartState 

Source
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

Source

pub fn new(data: BarData) -> Self

Create new chart state with data

Source

pub fn data(&self) -> &BarData

Get reference to bar data

Source

pub fn time_scale_mut(&mut self) -> &mut TimeScale

Get mutable reference to time scale

Source

pub fn time_scale(&self) -> &TimeScale

Get reference to time scale

Source

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.

Source

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.

Source

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.

Source

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.

Source

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.

Source

pub fn price_scale(&self) -> &PriceScale

Returns the main series’ price scale.

Source

pub fn price_scale_mut(&mut self) -> &mut PriceScale

Returns the main series’ price scale for changing its options or range.

Source

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.

Source

pub fn push_zoom_state(&mut self)

Save current zoom state to history

Source

pub fn pop_zoom_state(&mut self) -> bool

Restore previous zoom state (zoom out button)

Source

pub fn clear_zoom_history(&mut self)

Clear zoom history

Source

pub fn has_zoom_history(&self) -> bool

Check if there are zoom states to restore

Trait Implementations§

Source§

impl Clone for ChartState

Source§

fn clone(&self) -> Self

A copy with a revision of its own, since its bars change independently.

1.0.0 (const: unstable) · Source§

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

Performs copy-assignment from source. Read more
Source§

impl Debug for ChartState

Source§

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

Formats the value using the given formatter. 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.