"""Single source of truth for OncoDSL viewer presentation. Holds the MSI palette + order used by every chart, and registers (and enables) a custom Altair theme `oncodsl` for a calm, consistent chart look. Importing this module is enough to activate the theme. """ from __future__ import annotations import altair as alt # MSI-H is the warm highlight; MSS recedes into a cool grey-blue. Indeterminate # and NA are quieter neutrals so they don't compete for attention. MSI_COLORS: dict[str, str] = { "MSI-H": "#BC6B2E", "MSI-Indeterminate": "#A7B6BE", "MSS": "#6E7F8C", "NA": "#D9D5CE", } MSI_ORDER: list[str] = ["MSI-H", "MSI-Indeterminate", "MSS", "NA"] # Single muted colour for charts that aren't split by MSI. MUTED: str = "#6E7F8C" _FONT = "Helvetica Neue, Helvetica, Arial, sans-serif" def _oncodsl_theme() -> dict: return { "config": { "background": "transparent", "view": {"stroke": None}, "axis": { "gridColor": "#ECEAE4", "domainColor": "#D8D5CE", "tickColor": "#D8D5CE", "labelColor": "#5A6670", "titleColor": "#23303A", "labelFontSize": 12, "titleFontSize": 12, "labelFont": _FONT, "titleFont": _FONT, }, "legend": { "labelColor": "#5A6670", "titleColor": "#23303A", "labelFont": _FONT, "titleFont": _FONT, "labelFontSize": 12, "titleFontSize": 12, }, "title": { "color": "#23303A", "font": _FONT, "fontSize": 13, }, } } def msi_color_scale(*, include_na: bool = True) -> alt.Scale: """An Altair colour scale that maps every MSI bucket to its themed colour.""" domain = MSI_ORDER if include_na else [k for k in MSI_ORDER if k != "NA"] return alt.Scale(domain=domain, range=[MSI_COLORS[k] for k in domain]) # Register + enable on import. alt.themes.register("oncodsl", _oncodsl_theme) alt.themes.enable("oncodsl")