pub struct Mapping { /* private fields */ }Expand description
How a rendered plot maps cells onto data: the plot rectangle and the resolved scales, computed by the same layout pass rendering uses.
Obtained purely from Plot::mapping — or cached by
the ratatui PlotState after a stateful render. A mapping answers the
questions interactive hosts ask: which data coordinates live under a cell
(Mapping::data_at), which cell shows a data point (Mapping::cell_at),
what window the axes resolved to (Mapping::x_domain), and how to write a
value the way the axis itself would (Mapping::format_x).
Coordinates follow the conventions marks already use: band axes answer in
band-index space (0 is the first band; on y, the top band), time axes in
unix seconds, log axes in data values. Queries outside the plot rectangle —
or on a layout so small the plot shed to nothing — return None.
A mapping is a plain value (Clone + Send + Sync) describing one
(plot, frame) pair; render again after either changes and query the new
mapping. It is derived state, deliberately not serializable.
Implementations§
Source§impl Mapping
impl Mapping
Sourcepub fn plot_area(&self) -> Option<Panel>
pub fn plot_area(&self) -> Option<Panel>
The plot panel in frame cells — the data rectangle only, chrome
excluded — or None when the frame was too small to draw one.
Sourcepub fn data_at(&self, column: usize, row: usize) -> Option<(f64, f64)>
pub fn data_at(&self, column: usize, row: usize) -> Option<(f64, f64)>
The data coordinates at the center of the frame cell (column, row),
or None outside the plot rectangle.
One cell spans an interval of data, not a point — Mapping::x_span_at
discloses how much. Band axes answer in fractional band-index space;
snap with round() and clamp to the band count.
Sourcepub fn column_at(&self, x: f64) -> Option<usize>
pub fn column_at(&self, x: f64) -> Option<usize>
The frame column where the data value x draws — the x-only half of
Mapping::cell_at — or None when it falls outside the plot
rectangle (or is not finite). This is what lets a passive pane mirror
another pane’s cursor exactly, whatever their gutters: share the data
x, let each mapping place it. Band axes answer in band-index space.
Sourcepub fn cell_at(&self, x: f64, y: f64) -> Option<(usize, usize)>
pub fn cell_at(&self, x: f64, y: f64) -> Option<(usize, usize)>
The frame cell (column, row) where the data point (x, y) draws, or
None when it falls outside the plot rectangle (or is not finite).
Sourcepub fn x_span_at(&self, column: usize) -> Option<(f64, f64)>
pub fn x_span_at(&self, column: usize) -> Option<(f64, f64)>
The data interval one plot column covers — the x resolution a cell-level
cursor honestly has — or None when column is outside the plot.
Sourcepub fn y_span_at(&self, row: usize) -> Option<(f64, f64)>
pub fn y_span_at(&self, row: usize) -> Option<(f64, f64)>
The data interval one plot row covers — Mapping::x_span_at’s
vertical counterpart.
Sourcepub fn x_domain(&self) -> (f64, f64)
pub fn x_domain(&self) -> (f64, f64)
The resolved x window: the manual domain if one was set, otherwise the
automatic domain grown to its ticks. A bands axis answers in band-index
space: (0, count - 1).
Sourcepub fn y_domain(&self) -> (f64, f64)
pub fn y_domain(&self) -> (f64, f64)
The resolved y window; see Mapping::x_domain.
Sourcepub fn x_categories(&self) -> Option<&[String]>
pub fn x_categories(&self) -> Option<&[String]>
The x axis’s categories, in band order, when it is categorical —
None on a continuous axis. The labels themselves, not a bare count:
a host hit-testing a bands axis wants to name what it hit.
Sourcepub fn y_categories(&self) -> Option<&[String]>
pub fn y_categories(&self) -> Option<&[String]>
The y axis’s categories, in band order (band 0 is the top row), when it is categorical.
Sourcepub fn format_x(&self, value: f64) -> String
pub fn format_x(&self, value: f64) -> String
Formats an x value the way the x axis would: exact decimals at the
resolution one cell actually has (never 0.30000000000000004, never
false precision), in the axis’s unit, calendar instants on a time
axis, the category label on a bands axis.
Sourcepub fn format_y(&self, value: f64) -> String
pub fn format_y(&self, value: f64) -> String
Formats a y value the way the y axis would; see Mapping::format_x.
Trait Implementations§
Auto Trait Implementations§
impl Freeze for Mapping
impl RefUnwindSafe for Mapping
impl Send for Mapping
impl Sync for Mapping
impl Unpin for Mapping
impl UnsafeUnpin for Mapping
impl UnwindSafe for Mapping
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
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