Struct ContinuousView

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

Standard 1-dimensional view with a continuous x-axis

Implementations§

Source§

impl ContinuousView

Source

pub fn new() -> ContinuousView

Create an empty view

Examples found in repository?
examples/histogram_text.rs (line 9)
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 11)
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 12)
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/with_grid.rs (line 18)
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}
examples/line_and_point_svg.rs (line 15)
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/function_svg.rs (line 14)
6fn main() {
7    let f1 =
8        Plot::from_function(|x| x * 5., 0., 10.).line_style(LineStyle::new().colour("burlywood"));
9    let f2 = Plot::from_function(|x| x.powi(2), 0., 10.)
10        .line_style(LineStyle::new().colour("darkolivegreen").width(2.));
11    let f3 = Plot::from_function(|x| x.sqrt() * 20., 0., 10.)
12        .line_style(LineStyle::new().colour("brown").width(1.));
13
14    let v = ContinuousView::new().add(f1).add(f2).add(f3);
15
16    Page::single(&v).save("function.svg").expect("saving svg");
17}
Source

pub fn x_max_ticks(self, val: usize) -> Self

Set the maximum number of ticks along the x axis.

Source

pub fn y_max_ticks(self, val: usize) -> Self

Set the maximum number of ticks along the y axis.

Source

pub fn add<R: ContinuousRepresentation + 'static>(self, repr: R) -> Self

Add a representation to the view

Examples found in repository?
examples/histogram_text.rs (line 9)
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 11)
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 12)
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/with_grid.rs (line 18)
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}
examples/line_and_point_svg.rs (line 15)
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/function_svg.rs (line 14)
6fn main() {
7    let f1 =
8        Plot::from_function(|x| x * 5., 0., 10.).line_style(LineStyle::new().colour("burlywood"));
9    let f2 = Plot::from_function(|x| x.powi(2), 0., 10.)
10        .line_style(LineStyle::new().colour("darkolivegreen").width(2.));
11    let f3 = Plot::from_function(|x| x.sqrt() * 20., 0., 10.)
12        .line_style(LineStyle::new().colour("brown").width(1.));
13
14    let v = ContinuousView::new().add(f1).add(f2).add(f3);
15
16    Page::single(&v).save("function.svg").expect("saving svg");
17}
Source

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

Set the x range for the view

Examples found in repository?
examples/scatter_text.rs (line 22)
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}
More examples
Hide additional examples
examples/scatter_svg.rs (line 35)
6fn main() {
7    // Scatter plots expect a list of pairs
8    let data1 = vec![
9        (-3.0, 2.3),
10        (-1.6, 5.3),
11        (0.3, 0.7),
12        (4.3, -1.4),
13        (6.4, 4.3),
14        (8.5, 3.7),
15    ];
16
17    // We create our scatter plot from the data
18    let s1: Plot = Plot::new(data1).point_style(
19        PointStyle::new()
20            .marker(PointMarker::Square) // setting the marker to be a square
21            .colour("#DD3355"),
22    ); // and a custom colour
23
24    // We can plot multiple data sets in the same view
25    let data2 = vec![(-1.4, 2.5), (7.2, -0.3)];
26    let s2: Plot = Plot::new(data2).point_style(
27        PointStyle::new() // uses the default marker
28            .colour("#35C788"),
29    ); // and a different colour
30
31    // The 'view' describes what set of data is drawn
32    let v = ContinuousView::new()
33        .add(s1)
34        .add(s2)
35        .x_range(-5., 10.)
36        .y_range(-2., 6.)
37        .x_label("Some varying variable")
38        .y_label("The response of something");
39
40    // A page with a single view is then saved to an SVG file
41    Page::single(&v).save("scatter.svg").unwrap();
42}
Source

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

Set the y range for the view

Examples found in repository?
examples/scatter_text.rs (line 23)
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}
More examples
Hide additional examples
examples/scatter_svg.rs (line 36)
6fn main() {
7    // Scatter plots expect a list of pairs
8    let data1 = vec![
9        (-3.0, 2.3),
10        (-1.6, 5.3),
11        (0.3, 0.7),
12        (4.3, -1.4),
13        (6.4, 4.3),
14        (8.5, 3.7),
15    ];
16
17    // We create our scatter plot from the data
18    let s1: Plot = Plot::new(data1).point_style(
19        PointStyle::new()
20            .marker(PointMarker::Square) // setting the marker to be a square
21            .colour("#DD3355"),
22    ); // and a custom colour
23
24    // We can plot multiple data sets in the same view
25    let data2 = vec![(-1.4, 2.5), (7.2, -0.3)];
26    let s2: Plot = Plot::new(data2).point_style(
27        PointStyle::new() // uses the default marker
28            .colour("#35C788"),
29    ); // and a different colour
30
31    // The 'view' describes what set of data is drawn
32    let v = ContinuousView::new()
33        .add(s1)
34        .add(s2)
35        .x_range(-5., 10.)
36        .y_range(-2., 6.)
37        .x_label("Some varying variable")
38        .y_label("The response of something");
39
40    // A page with a single view is then saved to an SVG file
41    Page::single(&v).save("scatter.svg").unwrap();
42}
Source

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

Set the label for the x-axis

Examples found in repository?
examples/scatter_text.rs (line 24)
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}
More examples
Hide additional examples
examples/scatter_svg.rs (line 37)
6fn main() {
7    // Scatter plots expect a list of pairs
8    let data1 = vec![
9        (-3.0, 2.3),
10        (-1.6, 5.3),
11        (0.3, 0.7),
12        (4.3, -1.4),
13        (6.4, 4.3),
14        (8.5, 3.7),
15    ];
16
17    // We create our scatter plot from the data
18    let s1: Plot = Plot::new(data1).point_style(
19        PointStyle::new()
20            .marker(PointMarker::Square) // setting the marker to be a square
21            .colour("#DD3355"),
22    ); // and a custom colour
23
24    // We can plot multiple data sets in the same view
25    let data2 = vec![(-1.4, 2.5), (7.2, -0.3)];
26    let s2: Plot = Plot::new(data2).point_style(
27        PointStyle::new() // uses the default marker
28            .colour("#35C788"),
29    ); // and a different colour
30
31    // The 'view' describes what set of data is drawn
32    let v = ContinuousView::new()
33        .add(s1)
34        .add(s2)
35        .x_range(-5., 10.)
36        .y_range(-2., 6.)
37        .x_label("Some varying variable")
38        .y_label("The response of something");
39
40    // A page with a single view is then saved to an SVG file
41    Page::single(&v).save("scatter.svg").unwrap();
42}
Source

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

Set the label for the y-axis

Examples found in repository?
examples/scatter_text.rs (line 25)
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}
More examples
Hide additional examples
examples/scatter_svg.rs (line 38)
6fn main() {
7    // Scatter plots expect a list of pairs
8    let data1 = vec![
9        (-3.0, 2.3),
10        (-1.6, 5.3),
11        (0.3, 0.7),
12        (4.3, -1.4),
13        (6.4, 4.3),
14        (8.5, 3.7),
15    ];
16
17    // We create our scatter plot from the data
18    let s1: Plot = Plot::new(data1).point_style(
19        PointStyle::new()
20            .marker(PointMarker::Square) // setting the marker to be a square
21            .colour("#DD3355"),
22    ); // and a custom colour
23
24    // We can plot multiple data sets in the same view
25    let data2 = vec![(-1.4, 2.5), (7.2, -0.3)];
26    let s2: Plot = Plot::new(data2).point_style(
27        PointStyle::new() // uses the default marker
28            .colour("#35C788"),
29    ); // and a different colour
30
31    // The 'view' describes what set of data is drawn
32    let v = ContinuousView::new()
33        .add(s1)
34        .add(s2)
35        .x_range(-5., 10.)
36        .y_range(-2., 6.)
37        .x_label("Some varying variable")
38        .y_label("The response of something");
39
40    // A page with a single view is then saved to an SVG file
41    Page::single(&v).save("scatter.svg").unwrap();
42}

Trait Implementations§

Source§

impl Default for ContinuousView

Source§

fn default() -> ContinuousView

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

impl View for ContinuousView

Source§

fn to_svg(&self, face_width: f64, face_height: f64) -> Result<Group, Error>

Create an SVG rendering of the view

Source§

fn to_text(&self, face_width: u32, face_height: u32) -> Result<String, Error>

Create a text rendering of the view

Source§

fn add_grid(&mut self, grid: Grid)

Source§

fn grid(&self) -> &Option<Grid>

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.