Skip to main content

Crate ggsci

Crate ggsci 

Source
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§

ContinuousOptions
Options controlling continuous palette interpolation.
GephiFilter
A Gephi hue/chroma/luminance filter in the engine’s normalized color space.
GephiPalette
A named Gephi generative discrete palette definition.
ItermPalette
A fixed discrete iTerm theme with normal and bright variants.
Palette
A generated ggsci palette with discrete or continuous scale semantics.
PaletteSpec
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.
ItermChannel
A terminal color channel in canonical ggsci iTerm order.
ItermVariant
A normal or bright iTerm theme variant.
PaletteKind
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:variant specification.
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 palettes by scale semantics.
total_color_count
Returns the number of stored source colors across the core registry.