Skip to main content

PlotSpec

Struct PlotSpec 

Source
pub struct PlotSpec {
    pub marks: Vec<Mark>,
    pub x: Axis,
    pub y: Axis,
    pub style: PlotStyle,
    pub crosshair: bool,
    pub y_autoscale: bool,
    pub x_autoscale: bool,
    pub controls: PlotControls,
    pub legend: Option<LegendPosition>,
    pub downsample: Option<Decimation>,
}
Expand description

The full declarative description of a plot: marks, per-axis scales, view behaviour, and styling. Assemble fluently and pass to plot:

plot(
    PlotSpec::new()
        .x(Scale::time())
        .line(&cpu)
        .line(&mem)
        .crosshair(true),
)
.key("metrics")

Fields§

§marks: Vec<Mark>

The marks, drawn in order.

§x: Axis

Horizontal-axis configuration.

§y: Axis

Vertical-axis configuration.

§style: PlotStyle

Plot-level styling.

§crosshair: bool

Whether to show a crosshair reading out the nearest sample.

§y_autoscale: bool

Whether the vertical axis auto-fits to the data visible in the current horizontal window each frame (vs. a fixed Y window).

§x_autoscale: bool

Whether the horizontal axis auto-fits to the full data extent each frame (vs. sticking at the window it was first seeded with). On by default so a plot whose series grow — a streaming dashboard fed by SeriesHandle::append — keeps the new samples in view. Any manual X gesture (pan, wheel zoom, X box-zoom) or crate::state::UiState::set_plot_view takes manual control and stops the tracking until a double-click reset or a PlotRequest::FitAll. With static data the re-fit resolves to the same window every frame, so this is invisible for non-streaming plots.

§controls: PlotControls

Pointer control scheme — what the primary drag does (see PlotControls).

§legend: Option<LegendPosition>

Legend placement, or None for no legend.

§downsample: Option<Decimation>

Library-side down-sampling for over-dense line series (the dump-everything path). None draws every sample; Some reduces each line to the pixel budget over the visible window before upload. A virtual app that resamples its own source leaves this None.

Implementations§

Source§

impl PlotSpec

Source

pub fn new() -> Self

An empty spec with default axes and styling.

Source

pub fn line(self, series: &SeriesHandle) -> Self

Add a default-styled line mark for series.

Source

pub fn scatter(self, series: &SeriesHandle) -> Self

Add a default-styled scatter mark for series.

Source

pub fn add_mark(self, mark: impl Into<Mark>) -> Self

Add a fully-built mark (the escape hatch for styled marks, e.g. spec.add_mark(line(&h).color(c).width(2.0))).

Source

pub fn x(self, scale: Scale) -> Self

Set the horizontal-axis Scale (keeps any existing title).

Source

pub fn y(self, scale: Scale) -> Self

Set the vertical-axis Scale (keeps any existing title).

Source

pub fn x_axis(self, axis: Axis) -> Self

Replace the whole horizontal-axis configuration.

Source

pub fn y_axis(self, axis: Axis) -> Self

Replace the whole vertical-axis configuration.

Source

pub fn crosshair(self, on: bool) -> Self

Set whether to draw the crosshair / nearest-sample readout.

Source

pub fn y_autoscale(self, on: bool) -> Self

Set whether the vertical axis auto-scales to the visible window.

Source

pub fn x_autoscale(self, on: bool) -> Self

Set whether the horizontal axis auto-scales to the full data extent each frame (see Self::x_autoscale; on by default). Turn this off for a plot that should hold a fixed time window regardless of what the series contain.

Source

pub fn controls(self, controls: PlotControls) -> Self

Set the pointer control scheme (what the primary drag does). Defaults to PlotControls::ZoomDrag.

Source

pub fn legend(self, position: LegendPosition) -> Self

Show a legend at position. Series are labelled by their label, falling back to "Series N".

Source

pub fn grid(self, on: bool) -> Self

Set whether gridlines are drawn.

Source

pub fn downsample(self, decimation: Decimation) -> Self

Enable library-side down-sampling of line series to the pixel budget (the dump-everything path). Leave unset for the virtual-data flow.

Source

pub fn background(self, color: Color) -> Self

Set the data-rect background fill.

Trait Implementations§

Source§

impl Clone for PlotSpec

Source§

fn clone(&self) -> PlotSpec

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 PlotSpec

Source§

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

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

impl Default for PlotSpec

Source§

fn default() -> Self

Returns the “default value” for a type. 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<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
where ST: ?Sized, DT: ?Sized,

Source§

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> Read<Exclusive, BecauseExclusive> for T
where T: ?Sized,

Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<SS, SP> SupersetOf<SS> for SP
where SS: SubsetOf<SP>,

Source§

fn to_subset(&self) -> Option<SS>

The inverse inclusion map: attempts to construct self from the equivalent element of its superset. Read more
Source§

fn is_in_subset(&self) -> bool

Checks if self is actually part of its subset T (and can be converted to it).
Source§

fn to_subset_unchecked(&self) -> SS

Use with care! Same as self.to_subset but without any property checks. Always succeeds.
Source§

fn from_subset(element: &SS) -> SP

The inclusion map: converts self to the equivalent element of its superset.
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.