Struct Page

Source
pub struct Page<'a, P>
where P: IntoPoint,
{ /* private fields */ }
Expand description

Page to render charts as HTML

A Page containing one or more Charts can be rendered as HTML using the Display trait. That is, using println!, or even to_string() is all that’s needed.

Implementations§

Source§

impl<'a, P> Page<'a, P>
where P: IntoPoint,

Source

pub fn new() -> Self

Create a new page

Examples found in repository?
examples/area.rs (line 6)
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
fn main() {
    let data_a = vec![(13, 74), (111, 37), (125, 52), (190, 66)];
    let data_b = vec![(22, 50), (105, 44), (120, 67), (180, 39)];
    let page = Page::new().chart(
        Chart::new()
            .title("Area Plot")
            .domain(&data_a[..])
            .axis("X Axis", Edge::Bottom)
            .axis("Y Axis", Edge::Left)
            .axis("", Edge::Right)
            .plot(Plot::area("Series A", &data_a))
            .plot(Plot::area("Series B", &data_b)),
    );
    print!("{page}");
}
More examples
Hide additional examples
examples/scatter.rs (line 6)
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
fn main() {
    let data_a = vec![(13, 74), (111, 37), (125, 52), (190, 66)];
    let data_b = vec![(22, 50), (105, 44), (120, 67), (180, 39)];
    let page = Page::new().chart(
        Chart::new()
            .title("Scatter Plot")
            .domain(&data_a[..])
            .axis("X Axis", Edge::Bottom)
            .axis("Y Axis", Edge::Left)
            .axis("", Edge::Right)
            .plot(Plot::scatter("Series A", &data_a).label())
            .plot(Plot::scatter("Series B", &data_b)),
    );
    print!("{page}");
}
examples/line.rs (line 6)
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
fn main() {
    let data_a = vec![(13, 74), (111, 37), (125, 52), (190, 66)];
    let data_b = vec![(22, 50), (105, 44), (120, 67), (180, 39), (210, 43)];
    let page = Page::new().chart(
        Chart::new()
            .title("Line Plot")
            .domain(Domain::from(&data_a[..]).including(&data_b))
            .axis("X Axis", Edge::Bottom)
            .axis("Y Axis", Edge::Left)
            .axis("", Edge::Right)
            .plot(Plot::line("Series A", &data_a).label())
            .plot(Plot::line("Series B", &data_b)),
    );
    print!("{page}");
}
Source

pub fn chart(self, chart: Chart<'a, P>) -> Self

Add a Chart

Examples found in repository?
examples/area.rs (lines 6-15)
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
fn main() {
    let data_a = vec![(13, 74), (111, 37), (125, 52), (190, 66)];
    let data_b = vec![(22, 50), (105, 44), (120, 67), (180, 39)];
    let page = Page::new().chart(
        Chart::new()
            .title("Area Plot")
            .domain(&data_a[..])
            .axis("X Axis", Edge::Bottom)
            .axis("Y Axis", Edge::Left)
            .axis("", Edge::Right)
            .plot(Plot::area("Series A", &data_a))
            .plot(Plot::area("Series B", &data_b)),
    );
    print!("{page}");
}
More examples
Hide additional examples
examples/scatter.rs (lines 6-15)
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
fn main() {
    let data_a = vec![(13, 74), (111, 37), (125, 52), (190, 66)];
    let data_b = vec![(22, 50), (105, 44), (120, 67), (180, 39)];
    let page = Page::new().chart(
        Chart::new()
            .title("Scatter Plot")
            .domain(&data_a[..])
            .axis("X Axis", Edge::Bottom)
            .axis("Y Axis", Edge::Left)
            .axis("", Edge::Right)
            .plot(Plot::scatter("Series A", &data_a).label())
            .plot(Plot::scatter("Series B", &data_b)),
    );
    print!("{page}");
}
examples/line.rs (lines 6-15)
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
fn main() {
    let data_a = vec![(13, 74), (111, 37), (125, 52), (190, 66)];
    let data_b = vec![(22, 50), (105, 44), (120, 67), (180, 39), (210, 43)];
    let page = Page::new().chart(
        Chart::new()
            .title("Line Plot")
            .domain(Domain::from(&data_a[..]).including(&data_b))
            .axis("X Axis", Edge::Bottom)
            .axis("Y Axis", Edge::Left)
            .axis("", Edge::Right)
            .plot(Plot::line("Series A", &data_a).label())
            .plot(Plot::line("Series B", &data_b)),
    );
    print!("{page}");
}

Trait Implementations§

Source§

impl<'a, P> Default for Page<'a, P>
where P: IntoPoint,

Source§

fn default() -> Self

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

impl<'a, P> Display for Page<'a, P>
where P: IntoPoint,

Source§

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

Formats the value using the given formatter. Read more

Auto Trait Implementations§

§

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

§

impl<'a, P> RefUnwindSafe for Page<'a, P>
where P: RefUnwindSafe,

§

impl<'a, P> Send for Page<'a, P>
where P: Sync,

§

impl<'a, P> Sync for Page<'a, P>
where P: Sync,

§

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

§

impl<'a, P> UnwindSafe for Page<'a, P>
where P: RefUnwindSafe,

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