Spaces:
Sleeping
Sleeping
File size: 2,240 Bytes
0fff343 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 | """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")
|