ggsci
Scientific and sci-fi color palettes from the R package ggsci, packaged as static Rust data.
This crate includes non-Gephi, non-iTerm palettes generated from upstream.
PaletteKind::Discrete maps categories to individual colors, while
PaletteKind::Continuous maps a continuous domain through an interpolated
gradient. These are scale semantics: whether palette data is stored or
generated is an orthogonal implementation detail.
The gsea, bs5, material, and tw3 families are continuous. Their
arbitrary-length output reproduces ggsci for R's
colorRamp(..., space = "Lab", interpolate = "spline"), including its FMM
cubic spline, gamut handling, rounding, and endpoint behavior.
Use take() for discrete category colors:
let palette = palette?;
let colors = palette.take_hex?;
assert_eq!;
# Ok::
Use interpolate() for a continuous gradient, or sample() when accepting
either kind:
use ;
let palette = palette_by_spec?;
let colors = palette.interpolate?;
let sampled = palette.sample?;
let reversed = palette.interpolate_with?;
let translucent = palette.interpolate_rgba?;
assert_eq!;
assert_eq!;
assert_eq!;
assert_eq!;
# Ok::
Palette::colors() returns canonical source colors: category colors for a
discrete palette and interpolation anchors for a continuous palette. Its
length therefore does not limit how many colors a continuous palette can
produce. Reverse is applied after interpolation, matching R. The continuous
RGBA methods accept finite alpha values in (0.0, 1.0].
Lookup is case-insensitive and accepts _, -, and spaces interchangeably:
let palette = palette_by_spec?;
assert_eq!;
assert_eq!;
# Ok::
The crate has no runtime dependencies, no feature flags, and no build script.
R-generated exact-channel fixtures are checked in and run as ordinary Rust
integration tests. R is only a maintainer dependency for regenerating palette
data and fixtures with cargo xtask update-palettes.