Skip to content

Color System

Every color rule is a ColorRule — a pair of one selector (which rows to affect) and one assigner (what colors to apply to those rows). Rules are applied in order; later rules override earlier ones for the selected rows.

Example

from orama.color import (
    ColorRule,
    ColorSelectMaxValue,
    ColorAssignerByCategory,
)
from polychromos.color import HSLColor

rule = ColorRule(
    assigner=ColorAssignerByCategory(
        anchor_colors=[HSLColor.from_hex("#ef4444")],
    ),
    selector=ColorSelectMaxValue(),  # highlight only the maximum bar
)

strategy = BarChartStrategy(
    fields_metadata=fields_metadata,
    category_variables=["region"],
    aggregation=Aggregation(name="count", function="count"),
    color_rules=[rule],
)

Selectors

Class Selects
ColorSelectorStrategy All entries (use as first rule to override defaults)
ColorSelectByCategoryName(names) Entries whose category name is in names
ColorSelectValuesBelow(threshold) Entries with value ≤ threshold
ColorSelectValuesAbove(threshold) Entries with value ≥ threshold
ColorSelectMinValue() Entry/entries with the minimum value
ColorSelectMaxValue() Entry/entries with the maximum value
ColorSelectValuesBelowMean() Entries with value ≤ weighted mean (bar charts only)
ColorSelectValuesAboveMean() Entries with value ≥ weighted mean (bar charts only)

Assigners

Class Assigns
ColorAssignerByCategory(anchor_colors, shuffle=False) One color per distinct category, interpolated from anchor colors; shuffle=True alternates colors across categories
ColorAssignerByGroup(anchor_colors, shuffle=False) One color per distinct group; shuffle=True alternates colors across groups
ColorAssignerByValue(anchor_colors, range_min, range_max, range_center_at) Continuous color scale mapped to values; optionally centered at a pivot

anchor_colors is an HSLColorSequence from polychromos. When two colors are provided and more entries exist, colors are interpolated via cylindrical shortest-path. When more than two colors are provided, a multi-stop color scale is constructed.

Note

Each strategy documents which selectors and assigners it accepts. Passing an unsupported combination raises ValueError at construction time.