plot::color
On this page
sRGB colours with alpha, CSS-style parsing, and the colour cycles a theme draws series colours from.
Structs
ColorSource
pub struct ColorAn sRGB colour with alpha, 8 bits a channel.
use plot::Color;
let c = try Color::parse("#0072b2");
assert(c == Color::rgb(0, 114, 178));
assert(c.with_alpha(0.5).to_hex() == "#0072b280");
An opaque colour.
nabiassert(plot::Color::rgb(1, 2, 3).a == 255);A colour with alpha (
255is opaque).nabiassert(plot::Color::rgba(1, 2, 3, 0).opacity() == 0.0);From channels in [0, 1], rounded to the nearest 8-bit value.
nabiassert(plot::Color::unit(1.0, 0.5, 0.0) == plot::Color::rgb(255, 128, 0));Fully transparent black.
nabiassert(plot::Color::clear().a == 0);Reads
#rgb,#rrggbb,#rrggbbaa, a CSS basic colour name ("red","gray", ...),"none"or"transparent".nabiuse plot::Color; assert((try Color::parse("#f00")) == Color::rgb(255, 0, 0)); assert((try Color::parse("navy")).b == 128); assert((try? Color::parse("#12")) is none);#rrggbb, or#rrggbbaawhen not opaque.nabiassert(plot::Color::rgb(255, 128, 0).to_hex() == "#ff8000");The same colour with alpha
ain [0, 1].nabiassert(plot::Color::rgb(0, 0, 0).with_alpha(1.0).a == 255);Alpha as a fraction in [0, 1].
nabiassert(plot::Color::rgba(0, 0, 0, 255).opacity() == 1.0);tof the way fromselftoo, channel by channel (alpha too).nabiuse plot::Color; assert(Color::rgb(0, 0, 0).mix(Color::rgb(255, 255, 255), 0.5) == Color::rgb(128, 128, 128));Relative luminance (WCAG), 0 for black to 1 for white.
nabiassert(plot::Color::rgb(0, 0, 0).luminance() == 0.0);
Trait implementations 1
impl Display for Color
Type aliases
ColorSpecSource
pub type ColorSpec = Color | str | noneWhat a builder takes for a colour: a Color, a string that
Color::parse reads or "C0" to "C9" (the theme's cycle), or
none for the next colour of the cycle.
let ax = plot::line([0, 1], [0, 1]).color("C2").line([0, 1], [1, 0]).color(plot::Color::rgb(9, 9, 9));
assert((try ax.svg()).contains("#090909"));
Functions
okabe_itoSource
pub fn okabe_ito() -> List<Color> The Okabe-Ito palette (Okabe and Ito 2008), safe for the common colour-vision deficiencies; the default cycle. Ordered for contrast on a light background: blue, vermillion, bluish green, orange, sky blue, reddish purple, yellow, black.
assert(plot::color::okabe_ito()[0].to_hex() == "#0072b2");
tableau10Source
pub fn tableau10() -> List<Color> Tableau 10 (the 2016 palette), as matplotlib's tab10 successor.
assert(plot::color::tableau10().len() == 10);