plotlars/components/
palette.rs

1use plotly::common::{ColorScale, ColorScalePalette};
2
3///
4///
5/// # Example
6///
7/// ```rust
8/// use polars::prelude::*;
9/// use plotlars::{ColorBar, HeatMap, Palette, Plot, Text, ValueExponent};
10///
11/// let dataset = LazyCsvReader::new(PlPath::new("data/heatmap.csv"))
12///     .finish()
13///     .unwrap()
14///     .collect()
15///     .unwrap();
16///
17/// HeatMap::builder()
18///     .data(&dataset)
19///     .x("x")
20///     .y("y")
21///     .z("z")
22///     .color_bar(
23///         &ColorBar::new()
24///             .length(290)
25///             .value_exponent(ValueExponent::None)
26///             .separate_thousands(true)
27///             .tick_length(5)
28///             .tick_step(2500.0)
29///     )
30///     .color_scale(Palette::Portland)
31///     .build()
32///     .plot();
33/// ```
34///
35/// ![Example](https://imgur.com/E9LHPAy.png)
36#[derive(Clone, Copy)]
37pub enum Palette {
38    Greys,
39    YlGnBu,
40    Greens,
41    YlOrRd,
42    Bluered,
43    RdBu,
44    Reds,
45    Blues,
46    Picnic,
47    Rainbow,
48    Portland,
49    Jet,
50    Hot,
51    Blackbody,
52    Earth,
53    Electric,
54    Viridis,
55    Cividis,
56}
57
58impl Palette {
59    #[allow(clippy::wrong_self_convention)]
60    pub(crate) fn to_plotly(&self) -> ColorScale {
61        match self {
62            Palette::Greys => ColorScale::Palette(ColorScalePalette::Greys),
63            Palette::YlGnBu => ColorScale::Palette(ColorScalePalette::YlGnBu),
64            Palette::Greens => ColorScale::Palette(ColorScalePalette::Greens),
65            Palette::YlOrRd => ColorScale::Palette(ColorScalePalette::YlOrRd),
66            Palette::Bluered => ColorScale::Palette(ColorScalePalette::Bluered),
67            Palette::RdBu => ColorScale::Palette(ColorScalePalette::RdBu),
68            Palette::Reds => ColorScale::Palette(ColorScalePalette::Reds),
69            Palette::Blues => ColorScale::Palette(ColorScalePalette::Blues),
70            Palette::Picnic => ColorScale::Palette(ColorScalePalette::Picnic),
71            Palette::Rainbow => ColorScale::Palette(ColorScalePalette::Rainbow),
72            Palette::Portland => ColorScale::Palette(ColorScalePalette::Portland),
73            Palette::Jet => ColorScale::Palette(ColorScalePalette::Jet),
74            Palette::Hot => ColorScale::Palette(ColorScalePalette::Hot),
75            Palette::Blackbody => ColorScale::Palette(ColorScalePalette::Blackbody),
76            Palette::Earth => ColorScale::Palette(ColorScalePalette::Earth),
77            Palette::Electric => ColorScale::Palette(ColorScalePalette::Electric),
78            Palette::Viridis => ColorScale::Palette(ColorScalePalette::Viridis),
79            Palette::Cividis => ColorScale::Palette(ColorScalePalette::Cividis),
80        }
81    }
82}