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
impl View
Sourcepub fn zoom(&mut self, anchor: f64, steps: i32)
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.
Sourcepub fn on_scroll(&mut self, x: u16, area: Rect, steps: i32)
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.
Sourcepub fn range(&self, min: f64, max: f64) -> (f64, f64)
pub fn range(&self, min: f64, max: f64) -> (f64, f64)
Map a data range onto the window, e.g. for Axis::bounds.
Trait Implementations§
impl Copy for View
impl StructuralPartialEq for View
Auto Trait Implementations§
impl Forget for View
impl Freeze for View
impl Move 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> 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
Mutably borrows from an owned value. Read more
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> ⓘ
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 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> ⓘ
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