Skip to main content

Mapping

Struct Mapping 

Source
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

Source

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.

Source

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.

Source

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.

Source

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).

Source

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.

Source

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.

Source

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).

Source

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

The resolved y window; see Mapping::x_domain.

Source

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.

Source

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.

Source

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.

Source

pub fn format_y(&self, value: f64) -> String

Formats a y value the way the y axis would; see Mapping::format_x.

Source

pub fn viewport(&self) -> Viewport

A Viewport fixed to this mapping’s resolved domains — “the view I am looking at”, the natural seed for zoom and pan. Bands axes stay unfixed: a categorical axis has no continuous window.

Trait Implementations§

Source§

impl Clone for Mapping

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 Debug for Mapping

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
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.