plotlars/components/orientation.rs
1use plotly::common::Orientation as OrientationPlotly;
2
3/// An enumeration representing the orientation of the legend.
4///
5/// # Example
6///
7/// ```rust
8/// use polars::prelude::*;
9/// use plotlars::{BarPlot, Legend, Orientation, Plot, Rgb};
10///
11/// let dataset = df![
12/// "animal" => &["giraffe", "giraffe", "orangutan", "orangutan", "monkey", "monkey"],
13/// "gender" => &vec!["female", "male", "female", "male", "female", "male"],
14/// "value" => &vec![20.0f32, 25.0, 14.0, 18.0, 23.0, 31.0],
15/// "error" => &vec![1.0, 0.5, 1.5, 1.0, 0.5, 1.5],
16/// ]
17/// .unwrap();
18///
19/// let legend = Legend::new()
20/// .orientation(Orientation::Horizontal)
21/// .y(1.1)
22/// .x(0.3);
23///
24/// BarPlot::builder()
25/// .data(&dataset)
26/// .labels("animal")
27/// .values("value")
28/// .orientation(Orientation::Horizontal)
29/// .group("gender")
30/// .error("error")
31/// .colors(vec![Rgb(255, 127, 80), Rgb(64, 224, 208)])
32/// .legend(&legend)
33/// .build()
34/// .plot();
35/// ```
36///
37/// 
38#[derive(Clone)]
39pub enum Orientation {
40 Horizontal,
41 Vertical,
42}
43
44impl Orientation {
45 pub(crate) fn to_plotly(&self) -> OrientationPlotly {
46 match self {
47 Self::Horizontal => OrientationPlotly::Horizontal,
48 Self::Vertical => OrientationPlotly::Vertical,
49 }
50 }
51}