Skip to main content

LineChart

Struct LineChart 

Source
pub struct LineChart { /* private fields */ }
Expand description

A line or scatter chart: one or more Series with a y axis, x axis labels and a legend.

  • Charset::Braille (the default) plots 2×4 dots per cell. Charset::Blocks and Charset::Ascii plot at cell resolution, each series with its own marker (●◆▲■○, or *, +, o, x, .), lines drawn as a run of markers.
  • Series are told apart by colour (chart.series.1 to .5) and by marker: the legend shows each series’ marker in its colour. Braille dots carry no shape, so when the console shows no colour and there is more than one series, the chart plots at cell resolution with markers instead.
  • Every row and column of the plot stands for one exact value, at its centre. Axis labels sit on evenly spaced rows and columns, and each names the value of the row or column it is on. The scales round out to a step that fits whole rows and columns (2, 5, 10, 25… a label apart), unless you fix them with y_range and x_range; then only rows whose value the format writes exactly are labelled (at least the two bounds).
  • It is height rows of plot (6 to 10 by default, the one the labels fit best) plus an axis line, a row of x labels and the legend. It fills the width it is given (or width); when that is short it drops the y labels, then the axes, and the x labels and legend are cut to fit.
use rich::Console;
use rich_ext::chart::{Charset, LineChart, Series};

let console = Console::builder().width(24).color_system(None).build();
let chart = LineChart::new()
    .series(Series::from_values("load", [1.0, 3.0, 2.0, 5.0, 4.0]))
    .height(6)
    .charset(Charset::Ascii);
assert_eq!(
    console.render_export(&chart),
    concat!(
        "6 +                     \n",
        "5 +               ***   \n",
        "4 +             **   ***\n",
        "3 +    ****   **        \n",
        "2 +  **    ***          \n",
        "1 +**                   \n",
        "  ++----+----+----+----+\n",
        "   0    1    2    3    4\n",
        "* load                  \n",
    )
);

Implementations§

Source§

impl LineChart

Source

pub fn new() -> Self

An empty chart; add series with series.

Source

pub fn series(self, series: Series) -> Self

Add a series.

Source

pub fn all_series(&self) -> &[Series]

The series, in legend order.

Source

pub fn height(self, rows: usize) -> Self

Rows of plot, not counting the axis, x labels and legend (at least 1, at most 65535). By default the chart takes 6 to 10 rows, near 8, picking the height whose rows its y labels divide evenly.

Source

pub fn width(self, width: usize) -> Self

Width in cells (default: the width it is given).

Source

pub fn x_range(self, min: f64, max: f64) -> Self

Fix the x scale; points outside are clamped to its edges.

Source

pub fn y_range(self, min: f64, max: f64) -> Self

Fix the y scale; points outside are clamped to its edges.

Source

pub fn charset(self, charset: Charset) -> Self

Glyphs to draw with (default Charset::Auto: Braille).

Source

pub fn legend(self, show: bool) -> Self

Show the legend (default on, when any series has a name).

Source

pub fn y_format(self, format: ValueFormat) -> Self

How the y axis writes values (default ValueFormat::Compact).

Source

pub fn x_format(self, format: ValueFormat) -> Self

How the x axis writes values (default ValueFormat::Compact).

Trait Implementations§

Source§

impl AccessibleText for LineChart

Line chart, 2 series, x from 0 to 23, y from 12 to 52, then a line per series: its name and kind, then its facts (24 points, min 12, max 52, last 14, trend up). The ranges are the fixed ones, else the data’s.

Source§

fn accessible_text(&self, _width: usize) -> String

The content as plain lines, laid out for width where layout matters.
Source§

impl Clone for LineChart

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 LineChart

Source§

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

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

impl Default for LineChart

Source§

fn default() -> Self

Returns the “default value” for a type. Read more
Source§

impl Draw for LineChart

Source§

fn draw( &self, console: &Console, options: &ConsoleOptions, screen: &mut Screen, rect: Rect, )

Draw into rect of screen, rendered with options (its width and height are the rectangle’s): the cells screen.write_lines(rect, &console.render_lines(self, options, false)) would give.
Source§

impl From<LineChart> for Facet

Source§

fn from(chart: LineChart) -> Self

Converts to this type from the input type.
Source§

impl PartialEq for LineChart

Source§

fn eq(&self, other: &Self) -> bool

Equality operator ==. Read more
1.0.0 (const: unstable) · Source§

fn ne(&self, other: &Rhs) -> bool

Inequality operator !=. Read more
Source§

impl Renderable for LineChart

Source§

fn rich_render( &self, console: &Console, options: &ConsoleOptions, ) -> Vec<Segment>

Source§

fn measure(&self, _console: &Console, options: &ConsoleOptions) -> Measurement

The (minimum, maximum) cell width this renderable wants. Port of __rich_measure__. The default is what upstream’s Measurement.get returns for a renderable without one: anything from nothing to the whole width, (0, max_width).
Source§

fn fit_to_measurement(&self) -> bool

Whether a top-level Console::print shrinks this renderable to its measured width. Upstream renders every top-level renderable at the full console width, so the default is false; an extension may opt in.
Source§

fn vertical(&self) -> Option<VerticalAlign>

The vertical alignment a Table cell holding this renderable uses in place of its column’s. Upstream reads getattr(renderable, "vertical", None); Align sets it.
Source§

fn print_end_line(&self, _options: &ConsoleOptions) -> bool

Whether a top-level print ends this renderable’s last line. This port’s renderables separate lines, where upstream’s end each line with "\n", so a print adds the final line break. A renderable whose upstream output stops without one (Screen, LiveRender, a Rule whose end has no newline) returns false, and the next output continues its last line. options are the print’s options.
Source§

impl StructuralPartialEq for LineChart

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> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self> ⓘ

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self> ⓘ

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
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> 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.
Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self> ⓘ
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self> ⓘ

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more