mod categorical;
mod cividis;
mod color;
mod common;
mod diverging;
mod rainbow;
mod sequential;
mod sinebow;
mod turbo;
mod viridis;
mod warm_cold;
pub use self::{
categorical::CategoricalSpace,
color::{Color, ParseError},
common::{ColorMap, Scheme},
diverging::DivergingSpace,
sequential::SequentialSpace,
viridis::ViridisSpace,
};
use self::{
cividis::cividis, common::RGBInterpolator, rainbow::rainbow, sinebow::sinebow, turbo::turbo,
viridis::ViridisInterpolator, warm_cold::CubehelixInterpolator,
};
#[derive(Debug, Clone)]
pub enum WarmColdSpace {
#[doc = concat!("180° rotation\n\n", include_str!("../docs/warm.svg"))]
Warm,
#[doc = concat!("0° rotation\n\n", include_str!("../docs/cold.svg"))]
Cold,
}
#[derive(Clone)]
pub struct WarmCold {
interpolator: CubehelixInterpolator,
}
impl WarmCold {
pub fn new(space: WarmColdSpace) -> Self {
match space {
WarmColdSpace::Warm => Self {
interpolator: CubehelixInterpolator::warm(),
},
WarmColdSpace::Cold => Self {
interpolator: CubehelixInterpolator::cold(),
},
}
}
pub fn gamma(self, gamma: f32) -> Self {
Self {
interpolator: self.interpolator.gamma(gamma),
}
}
}
impl ColorMap for WarmCold {
fn interpolate<T>(&self, t: f32) -> T
where
Color: Into<T>,
{
self.interpolator.interpolate(t)
}
}
#[derive(Clone)]
pub struct Viridis<'a> {
interpolator: ViridisInterpolator<'a>,
}
impl<'a> Viridis<'a> {
pub fn new(space: &'a ViridisSpace) -> Self {
Self {
interpolator: space.interpolator(),
}
}
}
impl<'a> ColorMap for Viridis<'a> {
fn interpolate<T>(&self, t: f32) -> T
where
Color: Into<T>,
{
self.interpolator.interpolate(t)
}
}
#[derive(Clone)]
pub struct Sequential {
interpolator: RGBInterpolator,
}
impl Sequential {
pub fn new(space: SequentialSpace) -> Self {
Self {
interpolator: space.interpolator(),
}
}
}
impl ColorMap for Sequential {
fn interpolate<T>(&self, t: f32) -> T
where
Color: Into<T>,
{
self.interpolator.interpolate(t)
}
}
#[derive(Clone)]
pub struct Diverging {
interpolator: RGBInterpolator,
}
impl Diverging {
pub fn new(space: DivergingSpace) -> Self {
Self {
interpolator: space.interpolator(),
}
}
}
impl ColorMap for Diverging {
fn interpolate<T>(&self, t: f32) -> T
where
Color: Into<T>,
{
self.interpolator.interpolate(t)
}
}
#[doc = concat!(
"Color map from [`WarmColdSpace::Warm`] in range [0.0, 0.5] followed by the",
"[`WarmColdSpace::Cold`] in range [0.5, 1.0], thus implementing the cyclical less-angry",
"rainbow color scheme.\n\n",
include_str!("../docs/rainbow.svg")
)]
#[derive(Default, Clone)]
pub struct Rainbow;
impl ColorMap for Rainbow {
fn interpolate<T>(&self, t: f32) -> T
where
Color: Into<T>,
{
rainbow(t)
}
}
#[doc = concat!(
"Color map from the \"cividis\" color vision deficiency-optimized color scheme designed by",
"Nuñez, Anderton, and Renslow.\n\n",
include_str!("../docs/cividis.svg")
)]
#[derive(Default, Clone)]
pub struct Cividis;
impl ColorMap for Cividis {
fn interpolate<T>(&self, t: f32) -> T
where
Color: Into<T>,
{
cividis(t)
}
}
#[doc = concat!(
"Color map from the \"sinebow\" color scheme by Jim Bumgardner and Charlie Loyd.\n\n",
include_str!("../docs/sinebow.svg")
)]
#[derive(Default, Clone)]
pub struct Sinebow;
impl ColorMap for Sinebow {
fn interpolate<T>(&self, t: f32) -> T
where
Color: Into<T>,
{
sinebow(t)
}
}
#[doc = concat!(
"Color map from the \"turbo\" color scheme by Anton Mikhailov.\n\n",
include_str!("../docs/turbo.svg")
)]
#[derive(Default, Clone)]
pub struct Turbo;
impl ColorMap for Turbo {
fn interpolate<T>(&self, t: f32) -> T
where
Color: Into<T>,
{
turbo(t)
}
}