plotlib/repr/
mod.rs

1/*!
2*Representations* are the interface between the data coming from the user and the rendered output.
3
4Each type that implements `Representation` or `CategoricalRepresentation` knows how to read in data
5and convert that into a concrete element to be incorporated into a larger plot.
6
7For example the `scatter::Scatter` representation can be created from a list of coordinates.
8When `to_svg()` is called on it, it will create the SVG elements showing the points from within
9the range that was requested by the caller.
10
11These points may then be layered with other SVG elements from other representations into a
12`view::View`.
13*/
14
15use crate::axis;
16
17mod barchart;
18mod boxplot;
19mod histogram;
20mod plot;
21pub use barchart::*;
22pub use boxplot::*;
23pub use histogram::*;
24pub use plot::*;
25
26/**
27A representation of data that is continuous in two dimensions.
28*/
29pub trait ContinuousRepresentation {
30    /// The maximum range in each dimension. Used for auto-scaling axes.
31    fn range(&self, dim: u32) -> (f64, f64);
32
33    fn to_svg(
34        &self,
35        x_axis: &axis::ContinuousAxis,
36        y_axis: &axis::ContinuousAxis,
37        face_width: f64,
38        face_height: f64,
39    ) -> svg::node::element::Group;
40
41    /// Returns None if no legend has been specified for this representation
42    fn legend_svg(&self) -> Option<svg::node::element::Group>;
43
44    fn to_text(
45        &self,
46        x_axis: &axis::ContinuousAxis,
47        y_axis: &axis::ContinuousAxis,
48        face_width: u32,
49        face_height: u32,
50    ) -> String;
51}
52
53/**
54A representation of data that is categorical in the x-axis but continuous in the y-axis.
55*/
56pub trait CategoricalRepresentation {
57    /// The maximum range in the y-axis. Used for auto-scaling the axis.
58    fn range(&self) -> (f64, f64);
59
60    /// The ticks that this representation covers. Used to collect all ticks for display.
61    fn ticks(&self) -> Vec<String>;
62
63    fn to_svg(
64        &self,
65        x_axis: &axis::CategoricalAxis,
66        y_axis: &axis::ContinuousAxis,
67        face_width: f64,
68        face_height: f64,
69    ) -> svg::node::element::Group;
70
71    fn to_text(
72        &self,
73        x_axis: &axis::CategoricalAxis,
74        y_axis: &axis::ContinuousAxis,
75        face_width: u32,
76        face_height: u32,
77    ) -> String;
78}