plotters/style/colors/
mod.rs

1//! Basic predefined colors.
2use super::{RGBAColor, RGBColor};
3
4// Taken from https://stackoverflow.com/questions/60905060/prevent-line-break-in-doc-test
5/// Macro for allowing dynamic creation of doc attributes.
6#[macro_export]
7macro_rules! doc {
8    {
9        $(#[$m:meta])*
10        $(
11            [$doc:expr]
12            $(#[$n:meta])*
13        )*
14        @ $thing:item
15    } => {
16        $(#[$m])*
17        $(
18            #[doc = $doc]
19            $(#[$n])*
20        )*
21        $thing
22    }
23}
24
25/// Defines and names a color based on its R, G, B, A values.
26#[macro_export]
27macro_rules! define_color {
28    ($name:ident, $r:expr, $g:expr, $b:expr, $doc:expr) => {
29        doc! {
30        [$doc]
31        // Format a colored box that will show up in the docs
32        [concat!("(<span style='color: rgb(",  $r,",", $g, ",", $b, "); background-color: #ddd; padding: 0 0.2em;'>■</span>" )]
33        [concat!("*rgb = (", $r,", ", $g, ", ", $b, ")*)")]
34        @pub const $name: RGBColor = RGBColor($r, $g, $b);
35        }
36    };
37
38    ($name:ident, $r:expr, $g:expr, $b:expr, $a: expr, $doc:expr) => {
39        doc! {
40        [$doc]
41        // Format a colored box that will show up in the docs
42        [concat!("(<span style='color: rgba(",  $r,",", $g, ",", $b, ",", $a, "); background-color: #ddd; padding: 0 0.2em;'>■</span>" )]
43        [concat!("*rgba = (", $r,", ", $g, ", ", $b, ", ", $a, ")*)")]
44        @pub const $name: RGBAColor = RGBAColor($r, $g, $b, $a);
45        }
46    };
47}
48
49define_color!(WHITE, 255, 255, 255, "White");
50define_color!(BLACK, 0, 0, 0, "Black");
51define_color!(RED, 255, 0, 0, "Red");
52define_color!(GREEN, 0, 255, 0, "Green");
53define_color!(BLUE, 0, 0, 255, "Blue");
54define_color!(YELLOW, 255, 255, 0, "Yellow");
55define_color!(CYAN, 0, 255, 255, "Cyan");
56define_color!(MAGENTA, 255, 0, 255, "Magenta");
57define_color!(TRANSPARENT, 0, 0, 0, 0.0, "Transparent");
58
59#[cfg(feature = "colormaps")]
60#[cfg_attr(doc_cfg, doc(cfg(feature = "colormaps")))]
61/// Colormaps can be used to simply go from a scalar value to a color value which will be more/less
62/// intense corresponding to the value of the supplied scalar.
63/// These colormaps can also be defined by the user and be used with lower and upper bounds.
64pub mod colormaps;
65#[cfg(feature = "full_palette")]
66#[cfg_attr(doc_cfg, doc(cfg(feature = "full_palette")))]
67pub mod full_palette;