Skip to main content

Axis

Struct Axis 

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

One axis of a Chart: its bounds, title, labels and scale.

use rich_ext::chart::{Axis, AxisScale, Labels};

let axis = Axis::default()
    .bounds(1.0, 1000.0)
    .scale(AxisScale::Log)
    .labels(Labels::Auto(4))
    .title("Hz");
assert_eq!(axis.label_values(), vec![1.0, 10.0, 100.0, 1000.0]);

Implementations§

Source§

impl Axis

Source

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

The values at either end, in either order. Without bounds, the axis spans the chart’s data.

Source

pub fn title(self, title: impl Into<String>) -> Self

The axis title: the y axis’s above its top left, the x axis’s at the right end of the plot’s bottom row.

Source

pub fn title_style(self, style: impl Into<String>) -> Self

The title’s style: a theme key or a definition (default chart.label).

Source

pub fn labels(self, labels: Labels) -> Self

The labels (default Labels::None: no labels and no axis line).

Source

pub fn labels_align(self, align: HorizontalAlign) -> Self

How the labels sit, as ratatui’s labels_alignment.

  • On the y axis, in the column left of the axis line. By default Labels::Auto and Labels::Values are right-aligned and Labels::Text and Labels::Markup left-aligned, as in ratatui.
  • On the x axis, the first text label against the y axis line: Left (the default) ends it under the line, Center centres it on the line, Right starts it there. A label placed at a value (Labels::Auto, Labels::Values) starts at its value (Left), is centred on it (the default) or ends at it (Right).
Source

pub fn scale(self, scale: AxisScale) -> Self

Linear (the default) or logarithmic.

Source

pub fn style(self, style: impl Into<String>) -> Self

The style of the axis line and labels: a theme key or a definition (default chart.axis).

Source

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

How Labels::Auto and Labels::Values are written (default ValueFormat::Compact).

Source

pub fn grid(self, values: impl IntoIterator<Item = f64>) -> Self

Grid lines across the plot at these values, in the axis’s grid_style (else its style), drawn under the datasets with the axis’s grid_marker (else the chart’s marker, else the first dataset’s, else Braille): the x axis’s run up the plot, the y axis’s along it. Values the axis cannot show (outside its bounds, or not positive on a log axis) are left out. With Layering::PerDataset each line is a layer of its own, the y axis’s first, and the datasets are drawn over them, so a line crossing another and a trace crossing a line break what they cross, as datasets drawn for the purpose do in ratatui (scope-tui’s reference lines).

use rich::Console;
use rich_ext::chart::{Axis, Chart, Dataset, Marker};

let console = Console::builder().width(9).color_system(None).build();
let chart = Chart::new(vec![Dataset::new([(2.0, 1.0)]).marker(Marker::Ascii('o'))])
    .x_axis(Axis::default().bounds(0.0, 8.0).grid([4.0]))
    .y_axis(Axis::default().bounds(0.0, 2.0).grid([0.0]))
    .width(9)
    .height(3);
// The point at (2, 1); the grid at x = 4 and y = 0, in the axis style.
assert_eq!(console.render_export(&chart), "    o    \n  o o    \nooooooooo\n");
Source

pub fn grid_style(self, style: impl Into<String>) -> Self

The style of the grid lines: a theme key or a definition (default: the axis’s style, else chart.axis), so the lines can be fainter than the axis line and labels.

use rich::Console;
use rich_ext::chart::{Axis, Chart, Dataset, Labels, Marker};

let console = Console::builder().width(5).force_terminal(true).build();
let chart = Chart::new(Vec::<Dataset>::new())
    .marker(Marker::Ascii('.'))
    .x_axis(Axis::default().bounds(0.0, 4.0))
    .y_axis(
        Axis::default()
            .bounds(0.0, 1.0)
            .labels(Labels::Text(vec!["0".into(), "1".into()]))
            .style("bold")
            .grid([0.0])
            .grid_style("dim"),
    )
    .width(5)
    .height(2);
// The labels and the axis line bold, the grid line dim.
assert_eq!(
    console.render_export(&chart),
    "\u{1b}[1m1│\u{1b}[0m   \n\u{1b}[1m0│\u{1b}[0m\u{1b}[2m...\u{1b}[0m\n"
);
Source

pub fn grid_marker(self, marker: Marker) -> Self

The marker the grid lines are drawn with (default: the chart’s marker, else the first dataset’s, else Marker::Braille).

Source

pub fn label_values(&self) -> Vec<f64>

The values labelled with Labels::Auto or Labels::Values, when the axis spans its bounds (or 0..1 without them).

Trait Implementations§

Source§

impl Clone for Axis

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 Axis

Source§

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

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

impl Default for Axis

Source§

fn default() -> Self

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

impl PartialEq for Axis

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 StructuralPartialEq for Axis

Auto Trait Implementations§

§

impl Freeze for Axis

§

impl RefUnwindSafe for Axis

§

impl Send for Axis

§

impl Sync for Axis

§

impl Unpin for Axis

§

impl UnsafeUnpin for Axis

§

impl UnwindSafe for Axis

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