Skip to main content

View

Struct View 

Source
pub struct View { /* private fields */ }
Expand description

Zoom / pan state for the x axis: a window lo..hi of the full 0..=1 span.

Feed it scroll events and apply the window to your data, or to an axis:

use ratatui::layout::Rect;
use tui_chart::View;

let mut view = View::default();
let plot = Rect::new(0, 0, 80, 20);
view.on_scroll(40, plot, 1);            // wheel up at the middle: zoom in
let (x0, x1) = view.range(0.0, 100.0);  // -> LineChart x_axis bounds
assert!(x0 > 0.0 && x1 < 100.0);
let data: Vec<u32> = (0..100).collect();
assert!(view.slice(&data).len() < 100); // -> candles / bars
view.reset();
assert!(!view.is_zoomed());

Implementations§

Source§

impl View

Source

pub fn min_span(self, span: f64) -> Self

Smallest visible fraction (default 0.02).

Source

pub fn window(&self) -> (f64, f64)

Visible window as fractions (lo, hi) of the full span.

Source

pub fn is_zoomed(&self) -> bool

true when zoomed in.

Source

pub fn reset(&mut self)

Back to the full span.

Source

pub fn zoom(&mut self, anchor: f64, steps: i32)

Zoom by steps (> 0 in, < 0 out) keeping the fraction anchor (0..=1 of the full span) under the pointer.

Source

pub fn on_scroll(&mut self, x: u16, area: Rect, steps: i32)

Scroll wheel at cell column x over the plot area; steps > 0 zooms in.

Source

pub fn pan(&mut self, frac: f64)

Pan by a fraction of the visible window (> 0 moves right).

Source

pub fn range(&self, min: f64, max: f64) -> (f64, f64)

Map a data range onto the window, e.g. for Axis::bounds.

Source

pub fn indices(&self, len: usize) -> Range<usize> ⓘ

Index window over len items (at least one when len > 0).

Source

pub fn slice<'a, T>(&self, data: &'a [T]) -> &'a [T]

The visible part of data.

Trait Implementations§

Source§

impl Clone for View

Source§

fn clone(&self) -> Self

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

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

Performs copy-assignment from source. Read more
Source§

impl Copy for View

Source§

impl Debug for View

Source§

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

Formats the value using the given formatter. Read more
Source§

impl Default for View

Source§

fn default() -> Self

Returns the “default value” for a type. Read more
Source§

impl PartialEq for View

Source§

fn eq(&self, other: &Self) -> bool

Equality operator ==. Read more
1.0.0 (const: unstable) · Source§

fn ne(&self, other: &Rhs) -> bool

Inequality operator !=. Read more
Source§

impl StructuralPartialEq for View

Auto Trait Implementations§

§

impl Forget for View

§

impl Freeze for View

§

impl RefUnwindSafe for View

§

impl Send for View

§

impl Sync for View

§

impl Unpin for View

§

impl UnsafeUnpin for View

§

impl UnwindSafe for View

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> 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> 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 = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

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.