Skip to content

SOURCE CODE plotnine_prism.pal DOCS

"""Provides available palettes"""

from functools import lru_cache
from pathlib import Path

import rtoml
from diot import Diot

SCHEMES_DIR = Path(__file__).parent.joinpath("schemes")


@lru_cache()DOCS
def list_themes():
    """List all available theme palettes"""
    return [
        tfile.stem
        for tfile in SCHEMES_DIR.glob("*.toml")
        if not tfile.stem.startswith("_")
    ]


@lru_cache()
def _all_color_pals():
    with SCHEMES_DIR.joinpath("_color_palettes.toml").open() as fcolor:
        return rtoml.load(fcolor)


@lru_cache()
def _all_fill_pals():
    with SCHEMES_DIR.joinpath("_fill_palettes.toml").open() as ffill:
        return rtoml.load(ffill)


@lru_cache()
def _all_shape_pals():
    with SCHEMES_DIR.joinpath("_shape_palettes.toml").open() as fshape:
        return rtoml.load(fshape)


@lru_cache()DOCS
def theme_colors(palette):
    """Get the colors for a specific theme"""
    with SCHEMES_DIR.joinpath(f"{palette}.toml").open() as fsch:
        return Diot(rtoml.load(fsch))


def list_color_pals():DOCS
    """List all available color palettes"""
    return list(_all_color_pals())


def list_fill_pals():DOCS
    """List all available fill palettes"""
    return list(_all_fill_pals())


def list_shape_pals():DOCS
    """List all available shape palettes"""
    return list(_all_shape_pals())


def prism_color_pal(palette):DOCS
    """Get the prism color palette by name"""
    return lambda n: _all_color_pals()[palette][:n]


def prism_fill_pal(palette):DOCS
    """Get the prism fill palette by name"""
    return lambda n: _all_fill_pals()[palette][:n]


def prism_shape_pal(palette):DOCS
    """Get the prism shape palette by name"""
    return lambda n: _all_shape_pals()[palette][:n]


list_colour_pals = list_color_pals
prism_colour_pal = prism_color_pal