Struct Page

Source
pub struct Page<'a> { /* private fields */ }
Expand description

A single page page laying out the views in a grid

Implementations§

Source§

impl<'a> Page<'a>

Source

pub fn empty() -> Self

Creates an empty page container for plots to be added to

Source

pub fn single(view: &'a dyn View) -> Self

Creates a plot containing a single view

Examples found in repository?
examples/histogram_text.rs (line 11)
5fn main() {
6    let data = [0.3, 0.5, 6.4, 5.3, 3.6, 3.6, 3.5, 7.5, 4.0];
7    let h = Histogram::from_slice(&data, HistogramBins::Count(10));
8
9    let v = ContinuousView::new().add(h);
10
11    println!("{}", Page::single(&v).dimensions(60, 15).to_text().unwrap());
12}
More examples
Hide additional examples
examples/histogram_svg.rs (line 13)
6fn main() {
7    let data = [0.3, 0.5, 6.4, 5.3, 3.6, 3.6, 3.5, 7.5, 4.0];
8    let h = Histogram::from_slice(&data, HistogramBins::Count(10))
9        .style(&BoxStyle::new().fill("burlywood"));
10
11    let v = ContinuousView::new().add(h);
12
13    Page::single(&v).save("histogram.svg").expect("saving svg");
14}
examples/line_svg.rs (line 13)
6fn main() {
7    let l1 = Plot::new(vec![(0., 1.), (2., 1.5), (3., 1.2), (4., 1.1)]).line_style(
8        LineStyle::new()
9            .colour("burlywood")
10            .linejoin(LineJoin::Round),
11    );
12    let v = ContinuousView::new().add(l1);
13    Page::single(&v).save("line.svg").expect("saving svg");
14}
examples/barchart_svg.rs (line 14)
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}
examples/with_grid.rs (line 20)
12fn render_line_chart<S>(filename: S)
13where
14    S: AsRef<str>,
15{
16    let l1 = Plot::new(vec![(0., 1.), (2., 1.5), (3., 1.2), (4., 1.1)])
17        .line_style(LineStyle::new().colour("burlywood"));
18    let mut v = ContinuousView::new().add(l1);
19    v.add_grid(Grid::new(3, 8));
20    Page::single(&v)
21        .save(filename.as_ref())
22        .expect("saving svg");
23}
24
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/line_and_point_svg.rs (line 16)
6fn main() {
7    let l1 = Plot::new(vec![(0., 1.), (2., 1.5), (3., 1.2), (4., 1.1)])
8        .line_style(
9            LineStyle::new()
10                .colour("burlywood")
11                .linejoin(LineJoin::Round),
12        )
13        .point_style(PointStyle::new());
14
15    let v = ContinuousView::new().add(l1);
16    Page::single(&v)
17        .save("line_and_point.svg")
18        .expect("saving svg");
19}
Source

pub fn dimensions(self, x: u32, y: u32) -> Self

Set the dimensions of the plot.

Examples found in repository?
examples/histogram_text.rs (line 11)
5fn main() {
6    let data = [0.3, 0.5, 6.4, 5.3, 3.6, 3.6, 3.5, 7.5, 4.0];
7    let h = Histogram::from_slice(&data, HistogramBins::Count(10));
8
9    let v = ContinuousView::new().add(h);
10
11    println!("{}", Page::single(&v).dimensions(60, 15).to_text().unwrap());
12}
More examples
Hide additional examples
examples/boxplot_svg.rs (line 19)
6fn main() {
7    let b1 = BoxPlot::from_slice(&[1.0, 4.0, 2.0, 3.5, 6.4, 2.5, 7.5, 1.8, 9.6]).label("1");
8    let b2 = BoxPlot::from_slice(&[3.0, 4.3, 2.0, 3.5, 6.9, 4.5, 7.5, 1.8, 10.6])
9        .label("2")
10        .style(&BoxStyle::new().fill("darkolivegreen"));
11
12    let v = CategoricalView::new()
13        .add(b1)
14        .add(b2)
15        .x_label("Experiment")
16        .y_label("y");
17
18    Page::single(&v)
19        .dimensions(400, 300)
20        .save("boxplot.svg")
21        .expect("saving svg");
22}
examples/scatter_text.rs (line 27)
6fn main() {
7    let data = vec![
8        (-3.0, 2.3),
9        (-1.6, 5.3),
10        (0.3, 0.7),
11        (4.3, -1.4),
12        (6.4, 4.3),
13        (8.5, 3.7),
14    ];
15    let s1 = Plot::new(data).point_style(PointStyle::new().marker(PointMarker::Circle));
16    let s2 = Plot::new(vec![(-1.4, 2.5), (7.2, -0.3)])
17        .point_style(PointStyle::new().marker(PointMarker::Square));
18
19    let v = ContinuousView::new()
20        .add(s1)
21        .add(s2)
22        .x_range(-5., 10.)
23        .y_range(-2., 6.)
24        .x_label("Some varying variable")
25        .y_label("The response of something");
26
27    println!("{}", Page::single(&v).dimensions(80, 30).to_text().unwrap());
28}
Source

pub fn add_plot(self, view: &'a dyn View) -> Self

Add a view to the plot

Source

pub fn to_svg(&self) -> Result<Document, Error>

Render the plot to an svg document

Source

pub fn to_text(&self) -> Result<String, Error>

Render the plot to an String

Examples found in repository?
examples/histogram_text.rs (line 11)
5fn main() {
6    let data = [0.3, 0.5, 6.4, 5.3, 3.6, 3.6, 3.5, 7.5, 4.0];
7    let h = Histogram::from_slice(&data, HistogramBins::Count(10));
8
9    let v = ContinuousView::new().add(h);
10
11    println!("{}", Page::single(&v).dimensions(60, 15).to_text().unwrap());
12}
More examples
Hide additional examples
examples/scatter_text.rs (line 27)
6fn main() {
7    let data = vec![
8        (-3.0, 2.3),
9        (-1.6, 5.3),
10        (0.3, 0.7),
11        (4.3, -1.4),
12        (6.4, 4.3),
13        (8.5, 3.7),
14    ];
15    let s1 = Plot::new(data).point_style(PointStyle::new().marker(PointMarker::Circle));
16    let s2 = Plot::new(vec![(-1.4, 2.5), (7.2, -0.3)])
17        .point_style(PointStyle::new().marker(PointMarker::Square));
18
19    let v = ContinuousView::new()
20        .add(s1)
21        .add(s2)
22        .x_range(-5., 10.)
23        .y_range(-2., 6.)
24        .x_label("Some varying variable")
25        .y_label("The response of something");
26
27    println!("{}", Page::single(&v).dimensions(80, 30).to_text().unwrap());
28}
Source

pub fn save<P>(&self, path: P) -> Result<(), Error>
where P: AsRef<Path>,

Save the plot to a file.

The type of file will be based on the file extension.

Examples found in repository?
examples/histogram_svg.rs (line 13)
6fn main() {
7    let data = [0.3, 0.5, 6.4, 5.3, 3.6, 3.6, 3.5, 7.5, 4.0];
8    let h = Histogram::from_slice(&data, HistogramBins::Count(10))
9        .style(&BoxStyle::new().fill("burlywood"));
10
11    let v = ContinuousView::new().add(h);
12
13    Page::single(&v).save("histogram.svg").expect("saving svg");
14}
More examples
Hide additional examples
examples/line_svg.rs (line 13)
6fn main() {
7    let l1 = Plot::new(vec![(0., 1.), (2., 1.5), (3., 1.2), (4., 1.1)]).line_style(
8        LineStyle::new()
9            .colour("burlywood")
10            .linejoin(LineJoin::Round),
11    );
12    let v = ContinuousView::new().add(l1);
13    Page::single(&v).save("line.svg").expect("saving svg");
14}
examples/barchart_svg.rs (line 14)
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}
examples/with_grid.rs (line 21)
12fn render_line_chart<S>(filename: S)
13where
14    S: AsRef<str>,
15{
16    let l1 = Plot::new(vec![(0., 1.), (2., 1.5), (3., 1.2), (4., 1.1)])
17        .line_style(LineStyle::new().colour("burlywood"));
18    let mut v = ContinuousView::new().add(l1);
19    v.add_grid(Grid::new(3, 8));
20    Page::single(&v)
21        .save(filename.as_ref())
22        .expect("saving svg");
23}
24
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/line_and_point_svg.rs (line 17)
6fn main() {
7    let l1 = Plot::new(vec![(0., 1.), (2., 1.5), (3., 1.2), (4., 1.1)])
8        .line_style(
9            LineStyle::new()
10                .colour("burlywood")
11                .linejoin(LineJoin::Round),
12        )
13        .point_style(PointStyle::new());
14
15    let v = ContinuousView::new().add(l1);
16    Page::single(&v)
17        .save("line_and_point.svg")
18        .expect("saving svg");
19}
examples/boxplot_svg.rs (line 20)
6fn main() {
7    let b1 = BoxPlot::from_slice(&[1.0, 4.0, 2.0, 3.5, 6.4, 2.5, 7.5, 1.8, 9.6]).label("1");
8    let b2 = BoxPlot::from_slice(&[3.0, 4.3, 2.0, 3.5, 6.9, 4.5, 7.5, 1.8, 10.6])
9        .label("2")
10        .style(&BoxStyle::new().fill("darkolivegreen"));
11
12    let v = CategoricalView::new()
13        .add(b1)
14        .add(b2)
15        .x_label("Experiment")
16        .y_label("y");
17
18    Page::single(&v)
19        .dimensions(400, 300)
20        .save("boxplot.svg")
21        .expect("saving svg");
22}

Auto Trait Implementations§

§

impl<'a> Freeze for Page<'a>

§

impl<'a> !RefUnwindSafe for Page<'a>

§

impl<'a> !Send for Page<'a>

§

impl<'a> !Sync for Page<'a>

§

impl<'a> Unpin for Page<'a>

§

impl<'a> !UnwindSafe for Page<'a>

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.