Expand description
Scientific and sci-fi color palettes from the R package ggsci.
This crate ships checked-in Rust source generated from upstream
ggsci/R/palettes.R and ggsci/R/palettes-iterm.R, plus a pure Rust Gephi
palette engine. It does not require R, Python, or network access at build
time.
Use Palette::take for discrete category colors:
use ggsci::palette_by_spec;
fn main() -> Result<(), ggsci::Error> {
let palette = palette_by_spec("observable:observable10")?;
let colors = palette.take_hex(3)?;
assert_eq!(colors, ["#4269D0", "#EFB118", "#FF725C"]);
Ok(())
}Use Palette::interpolate for continuous gradient samples:
use ggsci::{palette_by_spec, ContinuousOptions};
fn main() -> Result<(), ggsci::Error> {
let palette = palette_by_spec("material:blue-grey")?;
let colors = palette.interpolate(256)?;
let reversed = palette.interpolate_with(
256,
ContinuousOptions::new().with_reverse(true),
)?;
assert_eq!(reversed, colors.into_iter().rev().collect::<Vec<_>>());
Ok(())
}Use Palette::sample for kind-aware dispatch when accepting either
palette kind.
iTerm themes use a dedicated fixed-discrete registry that preserves their normal/bright variants and terminal-channel ordering:
use ggsci::{iterm_palette, ItermVariant};
fn main() -> Result<(), ggsci::Error> {
let rose_pine = iterm_palette("Rose Pine")?;
let colors = rose_pine.take_hex(ItermVariant::Normal, 6)?;
assert_eq!(colors.len(), 6);
Ok(())
}Gephi palettes are generative discrete palettes with a dedicated API:
use ggsci::gephi_palette;
fn main() -> Result<(), ggsci::Error> {
let gephi = gephi_palette("fancy-light")?;
let colors = gephi.generate_with_seed(20, 42)?;
assert_eq!(colors.len(), 20);
Ok(())
}Structs§
- Continuous
Options - Options controlling continuous palette interpolation.
- Gephi
Filter - A Gephi hue/chroma/luminance filter in the engine’s normalized color space.
- Gephi
Palette - A named Gephi generative discrete palette definition.
- Iterm
Palette - A fixed discrete iTerm theme with normal and bright variants.
- Palette
- A generated ggsci palette with discrete or continuous scale semantics.
- Palette
Spec - A canonical palette specification.
- Rgb
- A packed RGB color stored as
0xRRGGBB. - Rgba
- A packed RGBA color stored as
0xRRGGBBAA.
Enums§
- Error
- Error type for palette lookup and color conversion.
- Iterm
Channel - A terminal color channel in canonical ggsci iTerm order.
- Iterm
Variant - A normal or bright iTerm theme variant.
- Palette
Kind - The scale semantics of a palette.
Constants§
- ITERM_
CHANNELS - Canonical iTerm channel order from ggsci for R.
Functions§
- gephi_
palette - Looks up a Gephi generator by name.
- gephi_
palette_ count - Returns the number of Gephi generators in the dedicated registry.
- gephi_
palette_ names - Returns all canonical Gephi palette names in upstream order.
- gephi_
palettes - Returns the dedicated Gephi generator registry.
- iterm_
palette - Looks up an iTerm palette by theme name.
- iterm_
palette_ count - Returns the number of iTerm themes in the dedicated registry.
- iterm_
palette_ names - Returns all canonical iTerm theme names in upstream order.
- iterm_
palettes - Returns the dedicated iTerm palette registry.
- iterm_
total_ color_ count - Returns the number of stored colors across both variants of all themes.
- palette
- Looks up a palette by family and variant.
- palette_
by_ spec - Looks up a palette by a
family:variantspecification. - palette_
names - Returns canonical
(family, variant)names for all palettes. - palettes
- Returns all generated core palettes.
- palettes_
by_ kind - Filters the core records returned by
palettesby scale semantics. - total_
color_ count - Returns the number of stored source colors across the core registry.