Struct BarChart

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

Implementations§

Source§

impl BarChart

Source

pub fn new(v: f64) -> Self

Examples found in repository?
examples/barchart_svg.rs (line 7)
6fn main() {
7    let b1 = BarChart::new(5.3).label("1");
8    let b2 = BarChart::new(2.6)
9        .label("2")
10        .style(&BoxStyle::new().fill("darkolivegreen"));
11
12    let v = CategoricalView::new().add(b1).add(b2).x_label("Experiment");
13
14    Page::single(&v).save("barchart.svg").expect("saving svg");
15}
More examples
Hide additional examples
examples/with_grid.rs (line 29)
25fn render_barchart<S>(filename: S)
26where
27    S: AsRef<str>,
28{
29    let b1 = BarChart::new(5.3).label("1");
30    let b2 = BarChart::new(2.6)
31        .label("2")
32        .style(&BoxStyle::new().fill("darkolivegreen"));
33    let mut v = CategoricalView::new().add(b1).add(b2).x_label("Experiment");
34    v.add_grid(Grid::new(3, 8));
35    Page::single(&v)
36        .save(filename.as_ref())
37        .expect("saving svg");
38}
examples/letter_counter.rs (line 18)
3fn main() {
4    let mut data = Vec::new();
5    let message: &str = "This is a long message";
6    let mut count = BTreeMap::new();
7
8    for c in message.trim().to_lowercase().chars() {
9        if c.is_alphabetic() {
10            *count.entry(c).or_insert(0) += 1
11        }
12    }
13
14    println!("Number of occurences per character");
15    for (ch, count) in &count {
16        println!("{:?}: {}", ch, count);
17        let count = *count as f64;
18        data.push(plotlib::repr::BarChart::new(count).label(ch.to_string()));
19    }
20    // Add data to the view
21    let v = data
22        .into_iter()
23        .fold(plotlib::view::CategoricalView::new(), |view, datum| {
24            view.add(datum)
25        });
26
27    plotlib::page::Page::single(&v)
28        .save("barchart.svg")
29        .expect("saving svg");
30}
Source

pub fn style(self, style: &BoxStyle) -> Self

Examples found in repository?
examples/barchart_svg.rs (line 10)
6fn main() {
7    let b1 = BarChart::new(5.3).label("1");
8    let b2 = BarChart::new(2.6)
9        .label("2")
10        .style(&BoxStyle::new().fill("darkolivegreen"));
11
12    let v = CategoricalView::new().add(b1).add(b2).x_label("Experiment");
13
14    Page::single(&v).save("barchart.svg").expect("saving svg");
15}
More examples
Hide additional examples
examples/with_grid.rs (line 32)
25fn render_barchart<S>(filename: S)
26where
27    S: AsRef<str>,
28{
29    let b1 = BarChart::new(5.3).label("1");
30    let b2 = BarChart::new(2.6)
31        .label("2")
32        .style(&BoxStyle::new().fill("darkolivegreen"));
33    let mut v = CategoricalView::new().add(b1).add(b2).x_label("Experiment");
34    v.add_grid(Grid::new(3, 8));
35    Page::single(&v)
36        .save(filename.as_ref())
37        .expect("saving svg");
38}
Source

pub fn get_style(&self) -> &BoxStyle

Source

pub fn label<T>(self, label: T) -> Self
where T: Into<String>,

Examples found in repository?
examples/barchart_svg.rs (line 7)
6fn main() {
7    let b1 = BarChart::new(5.3).label("1");
8    let b2 = BarChart::new(2.6)
9        .label("2")
10        .style(&BoxStyle::new().fill("darkolivegreen"));
11
12    let v = CategoricalView::new().add(b1).add(b2).x_label("Experiment");
13
14    Page::single(&v).save("barchart.svg").expect("saving svg");
15}
More examples
Hide additional examples
examples/with_grid.rs (line 29)
25fn render_barchart<S>(filename: S)
26where
27    S: AsRef<str>,
28{
29    let b1 = BarChart::new(5.3).label("1");
30    let b2 = BarChart::new(2.6)
31        .label("2")
32        .style(&BoxStyle::new().fill("darkolivegreen"));
33    let mut v = CategoricalView::new().add(b1).add(b2).x_label("Experiment");
34    v.add_grid(Grid::new(3, 8));
35    Page::single(&v)
36        .save(filename.as_ref())
37        .expect("saving svg");
38}
examples/letter_counter.rs (line 18)
3fn main() {
4    let mut data = Vec::new();
5    let message: &str = "This is a long message";
6    let mut count = BTreeMap::new();
7
8    for c in message.trim().to_lowercase().chars() {
9        if c.is_alphabetic() {
10            *count.entry(c).or_insert(0) += 1
11        }
12    }
13
14    println!("Number of occurences per character");
15    for (ch, count) in &count {
16        println!("{:?}: {}", ch, count);
17        let count = *count as f64;
18        data.push(plotlib::repr::BarChart::new(count).label(ch.to_string()));
19    }
20    // Add data to the view
21    let v = data
22        .into_iter()
23        .fold(plotlib::view::CategoricalView::new(), |view, datum| {
24            view.add(datum)
25        });
26
27    plotlib::page::Page::single(&v)
28        .save("barchart.svg")
29        .expect("saving svg");
30}
Source

pub fn get_label(&self) -> &String

Trait Implementations§

Source§

impl CategoricalRepresentation for BarChart

Source§

fn range(&self) -> (f64, f64)

The maximum range. Used for auto-scaling axis

Source§

fn ticks(&self) -> Vec<String>

The ticks that this representation covers. Used to collect all ticks for display

Source§

fn to_svg( &self, x_axis: &CategoricalAxis, y_axis: &ContinuousAxis, face_width: f64, face_height: f64, ) -> Group

Source§

fn to_text( &self, _x_axis: &CategoricalAxis, _y_axis: &ContinuousAxis, _face_width: u32, _face_height: u32, ) -> String

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