Struct Graph

Source
pub struct Graph { /* private fields */ }

Implementations§

Source§

impl Graph

Source

pub fn set_2d_data( &mut self, data: &[(usize, usize, char)], x_labels: &[Option<String>], y_labels: &[Option<String>], ) -> &mut Self

It plots characters on a 2-dimensional plane. The type of data is Vec<(x, y, character)>. The sizes of x_labels and y_labels must match self.plot_width and self.plot_height. If self.plot_width and self.plot_height are already set, it updates them.

Source

pub fn set_2d_data_high_resolution( &mut self, data: &[(usize, usize)], x_labels: &[Option<String>], y_labels: &[Option<String>], ) -> &mut Self

It’s like set_2d_data, but has twice higher resolution. You cannot set characters, you can only plot dots. That means the width and the height of data has to be twice of that of x_labels and y_labels.

Source

pub fn set_1d_data<T: TryInto<Ratio> + Clone>( &mut self, data: &[T], ) -> &mut Self

T can be any number type, including f32 and f64. NaN is converted to 0, -Inf is converted to f32::MIN and Inf to f32::MAX (or f64).
The data is labeled using indices (from 0).

Source

pub fn set_1d_labeled_data<T: TryInto<Ratio> + Clone>( &mut self, data: &[(String, T)], ) -> &mut Self

T can be any number type, including f32 and f64. NaN is converted to 0, -Inf is converted to f32::MIN and Inf to f32::MAX (or f64).\

Source

pub fn set_y_min<T: TryInto<Ratio>>(&mut self, y_min: T) -> &mut Self

Source

pub fn set_y_max<T: TryInto<Ratio>>(&mut self, y_max: T) -> &mut Self

Source

pub fn set_y_range<T: TryInto<Ratio>, U: TryInto<Ratio>>( &mut self, y_min: T, y_max: U, ) -> &mut Self

Source

pub fn set_pretty_y<T: TryInto<Ratio>>(&mut self, y: T) -> &mut Self

If the engine automatically sets the range of y axis, the value would be ugly. For example, let’s say (y_min, y_max) = (-0.1, 499.9). In this case, if you set set_pretty_y(5), it makes all the y_labels multiple of 5.

Source

pub fn set_plot_width(&mut self, plot_width: usize) -> &mut Self

Source

pub fn set_plot_height(&mut self, plot_height: usize) -> &mut Self

Source

pub fn set_x_label_margin(&mut self, x_label_margin: usize) -> &mut Self

Source

pub fn set_y_label_margin(&mut self, y_label_margin: usize) -> &mut Self

Source

pub fn set_block_width(&mut self, block_width: usize) -> &mut Self

It sets self.plot_width = self.data.len() * block_width. If the plot_width is already set, it overrides it. It only works with 1-dimensional data.

Source

pub fn set_padding_top(&mut self, padding_top: usize) -> &mut Self

Source

pub fn set_padding_bottom(&mut self, padding_bottom: usize) -> &mut Self

Source

pub fn set_padding_left(&mut self, padding_left: usize) -> &mut Self

Source

pub fn set_padding_right(&mut self, padding_right: usize) -> &mut Self

Source

pub fn set_paddings(&mut self, paddings: [usize; 4]) -> &mut Self

top, bottom, left, right

Source

pub fn set_title<T: ToString>(&mut self, title: T) -> &mut Self

Source

pub fn set_title_color(&mut self, title_color: Option<Color>) -> &mut Self

Source

pub fn set_x_axis_label<T: ToString>(&mut self, x_axis_label: T) -> &mut Self

Source

pub fn set_y_axis_label<T: ToString>(&mut self, y_axis_label: T) -> &mut Self

Source

pub fn set_big_title(&mut self, big_title: bool) -> &mut Self

Source

pub fn set_skip_range(&mut self, skip_value: SkipValue) -> &mut Self

It does not plot data between this range. It’s applied only when the plot height is greater than 18.

Source

pub fn set_skip_skip_range<T: TryInto<Ratio> + Clone, U: TryInto<Ratio> + Clone>( &mut self, from: Option<T>, to: Option<U>, ) -> &mut Self

I need a better name for this.

If the skip_range is included in this range, the skip_range is not set. It works only when its skip_value is SkipValue::Automatic. You can set open ends with None values.

Source

pub fn set_horizontal_break(&mut self, from: usize, to: usize) -> &mut Self

from and to are x indices of the output plot. It’s like skip_range, but it skips x-axis not y-axis.

Source

pub fn add_labeled_interval<T: ToString>( &mut self, start: i32, end: i32, label: T, ) -> &mut Self

See README.md to see how it works. start and end are both inclusive. start and end corresponds to the index of self.data. That means if the interval is (0, 32), it’s self.data[0] ~ self.data[32]. The actual number of the characters used depends on the size of the graph.

Source

pub fn set_primary_color(&mut self, color: Option<Color>) -> &mut Self

Source

pub fn set_color_mode(&mut self, color_mode: ColorMode) -> &mut Self

Source

pub fn set_y_label_formatter( &mut self, formatter: Box<dyn NumberFormatter>, ) -> &mut Self

Source§

impl Graph

Source

pub fn new(plot_width: usize, plot_height: usize) -> Self

Source

pub fn draw(&self) -> String

It panics if it’s not well-configured. If you’re not sure, call .is_valid before calling this method

Source

pub fn is_valid(&self) -> bool

  1. self.data must be set and for 1-D data, it must not be empty.
  2. If self.y_min and self.y_max are set, self.y_max has to be greater than self.y_min.
  3. If you’re using a 2-dimensional data, data, x_labels and y_labels must have the same dimension.
  4. If there’re labeled_intervals, their interval must be valid.
Source§

impl Graph

Source

pub fn from_json(json_str: &str) -> Result<Self, Error>

The json must be an object or an array.

If it’s an object, these keys are allowed:

  • 1d_data: Array[Number]
  • 1d_labeled_data: Array[[String, Number]]
  • y_min: Number
  • y_max: Number
  • y_range: [Number, Number]
  • pretty_y: Number
  • plot_width: Integer
  • plot_height: Integer
  • x_label_margin: Integer
  • y_label_margin: Integer
  • block_width: Integer
  • paddings: [Integer, Integer, Integer, Integer]
  • title: String
  • x_axis_label: String
  • y_axis_label: String
  • big_title: Bool
  • color_title: String
  • primary_color: String
  • color_mode: String
  • skip_range: Optional[[Number, Number]]
    • if it’s not set, it’s default to SkipValue::Automatic
    • if you want it to be SkipValue::None, set this value to null
    • otherwise, it’s set to SkipValue::Manual { from: v[0], to: v[1] }
  • y_label_prefix: String
  • y_label_suffix: String
  • labeled_intervals: Array[[Integer, Integer, String]]
  • horizontal_break: [Integer, Integer]

For Numbers in the above type annotations,

  1. If it’s an integer or a float in json, everything’s fine.
  2. If it’s a string in json, it tries to parse it.
  3. Otherwise, it’s a type error.

If it’s an array, it interprets the array as 1d_data.

Trait Implementations§

Source§

impl Clone for Graph

Source§

fn clone(&self) -> Graph

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Default for Graph

Source§

fn default() -> Self

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

impl Display for Graph

Source§

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

Formats the value using the given formatter. Read more

Auto Trait Implementations§

§

impl Freeze for Graph

§

impl !RefUnwindSafe for Graph

§

impl !Send for Graph

§

impl !Sync for Graph

§

impl Unpin for Graph

§

impl !UnwindSafe for Graph

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> 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> ToString for T
where T: Display + ?Sized,

Source§

fn to_string(&self) -> String

Converts the given value to a String. 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.