plotlars/components/
line.rs

1use plotly::common::DashType;
2
3/// An enumeration representing different styles of lines that can be used in plots.
4///
5/// # Example
6///
7/// ```rust
8/// use polars::prelude::*;
9/// use plotlars::{Legend, Line, Plot, Rgb, TimeSeriesPlot};
10///
11/// let dataset = LazyCsvReader::new(PlPath::new("data/revenue_and_cost.csv"))
12///     .finish()
13///     .unwrap()
14///     .select([
15///         col("Date").cast(DataType::String),
16///         col("Revenue").cast(DataType::Int32),
17///         col("Cost").cast(DataType::Int32),
18///     ])
19///     .collect()
20///     .unwrap();
21///
22/// TimeSeriesPlot::builder()
23///     .data(&dataset)
24///     .x("Date")
25///     .y("Revenue")
26///     .additional_series(vec!["Cost"])
27///     .size(8)
28///     .colors(vec![Rgb(255, 0, 0), Rgb(0, 255, 0)])
29///     .lines(vec![Line::Dash, Line::Solid])
30///     .legend(
31///         &Legend::new()
32///             .x(0.05)
33///             .y(0.9)
34///     )
35///     .build()
36///     .plot();
37/// ```
38///
39/// ![Example](https://imgur.com/y6ZyypZ.png)
40#[derive(Clone, Copy)]
41pub enum Line {
42    Solid,
43    Dot,
44    Dash,
45    LongDash,
46    DashDot,
47    LongDashDot,
48}
49
50impl Line {
51    #[allow(clippy::wrong_self_convention)]
52    pub(crate) fn to_plotly(&self) -> DashType {
53        match self {
54            Line::Solid => DashType::Solid,
55            Line::Dot => DashType::Dot,
56            Line::Dash => DashType::Dash,
57            Line::LongDash => DashType::LongDash,
58            Line::DashDot => DashType::DashDot,
59            Line::LongDashDot => DashType::LongDashDot,
60        }
61    }
62}