from typing import List from .charts_palette_data import PALETTES def palette(scheme: str, count: int, cycle: bool) -> List[str]: """The first ``count`` colours of a named categorical scheme, in its order. Asking for more colours than the scheme has is an error unless ``cycle`` says repeating them is acceptable. """ colours = [c.hex for c in sorted((c for c in PALETTES if c.scheme == scheme), key=lambda c: c.position)] if not colours: raise ValueError('unknown palette "%s"; use okabe-ito or tol-bright' % (scheme,)) if isinstance(count, bool) or not isinstance(count, int) or count < 0: raise ValueError("count must be a whole number of at least 0, received %r" % (count,)) if count > len(colours) and not cycle: raise ValueError('palette "%s" has only %d colours; pass cycle to repeat them' % (scheme, len(colours))) return [colours[i % len(colours)] for i in range(count)]