Skip to main content

Plot

Struct Plot 

Source
#[non_exhaustive]
pub struct Plot<G: GraphicsArea> { /* private fields */ }
Expand description

A complete plot: graphics area, annotations, border, title, and axis labels.

Plot owns its graphics and carries all metadata needed for rendering. Use the free-standing constructors (barplot, lineplot, etc.) to create plots, then call render to write output.

Implementations§

Source§

impl<G: GraphicsArea> Plot<G>

Source

pub const DEFAULT_MARGIN: u16 = 3

Default left margin (in characters) between the terminal edge and labels.

Source

pub const DEFAULT_PADDING: u16 = 1

Default padding (in characters) between labels and the plot border.

Source

pub fn new(graphics: G) -> Self

Creates a new plot wrapping the given graphics area with default settings.

Source

pub fn annotate_left( &mut self, row: usize, text: impl Into<String>, color: Option<TermColor>, )

Adds or replaces a labeled annotation on the left side of the plot body.

Pass None for color to use the terminal’s default foreground color.

Source

pub fn annotate_right( &mut self, row: usize, text: impl Into<String>, color: Option<TermColor>, )

Adds or replaces a labeled annotation on the right side of the plot body.

Pass None for color to use the terminal’s default foreground color.

Source

pub fn set_decoration( &mut self, position: DecorationPosition, text: impl Into<String>, )

Sets edge decoration text at one of the six border positions.

Source

pub fn next_color(&mut self) -> NamedColor

Returns the next color from the auto-series palette and advances the index.

Source

pub const fn annotations(&self) -> &PlotAnnotations

Returns all annotations attached to this plot.

Source

pub fn graphics(&self) -> &G

Returns a reference to the underlying graphics area.

Source

pub fn graphics_mut(&mut self) -> &mut G

Returns a mutable reference to the underlying graphics area.

Source

pub fn title(&self) -> Option<&str>

The plot title, rendered centered above the border.

Source

pub fn xlabel(&self) -> Option<&str>

The x-axis label, rendered centered below the border.

Source

pub fn ylabel(&self) -> Option<&str>

The y-axis label, rendered vertically along the left margin.

Source

pub const fn border(&self) -> BorderType

The border style for this plot.

Source

pub const fn margin(&self) -> u16

The left margin width in characters.

Source

pub const fn padding(&self) -> u16

The padding between labels and the plot border.

Source

pub const fn show_labels(&self) -> bool

Whether left/right row labels are rendered.

Source

pub const fn auto_color_index(&self) -> u8

The current auto-color palette index (wraps at 6).

Source

pub fn render(&self, writer: &mut impl Write, color: bool) -> IoResult<()>

Render this plot into the provided writer.

§Errors

Returns any I/O error produced by writing to writer.

Source

pub fn render_with_mode( &self, writer: &mut impl Write, color_mode: ColorMode, writer_is_terminal: bool, ) -> IoResult<()>

Render this plot using a ColorMode policy.

§Errors

Returns any I/O error produced by writing to writer.

Source

pub fn render_with_mode_auto<W: Write + IsTerminal>( &self, writer: &mut W, color_mode: ColorMode, ) -> IoResult<()>

Render this plot using a ColorMode policy and terminal auto-detection.

§Errors

Returns any I/O error produced by writing to writer.

Auto Trait Implementations§

§

impl<G> Freeze for Plot<G>
where G: Freeze,

§

impl<G> RefUnwindSafe for Plot<G>
where G: RefUnwindSafe,

§

impl<G> Send for Plot<G>
where G: Send,

§

impl<G> Sync for Plot<G>
where G: Sync,

§

impl<G> Unpin for Plot<G>
where G: Unpin,

§

impl<G> UnsafeUnpin for Plot<G>
where G: UnsafeUnpin,

§

impl<G> UnwindSafe for Plot<G>
where G: UnwindSafe,

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