Documentation
¶
Overview ¶
Package theme owns the resolved-theme registry, JSON loader, and sparse-override engine. Three built-in themes (Light, Dark, Print) register at init time; user themes load via LoadFile from a JSON blob whose shape mirrors the Theme struct (with an optional `base` field for sparse overrides on top of a registered theme).
scene.Theme is the wire-stable subset embedded in SceneDoc for JSON round-trip parity (D044); theme.Theme is the full struct renderers consume. Convert via ToSceneTheme / FromSceneTheme.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
Types ¶
type Theme ¶
type Theme struct {
Name string `json:"name,omitempty"`
Base string `json:"base,omitempty"` // optional registered base theme
// Core palette.
AxisColor string `json:"axis_color,omitempty"`
GridColor string `json:"grid_color,omitempty"`
TextColor string `json:"text_color,omitempty"`
BackgroundColor string `json:"background_color,omitempty"`
// Typography.
FontSans string `json:"font_sans,omitempty"`
FontMono string `json:"font_mono,omitempty"`
FontSizeLabel float64 `json:"font_size_label,omitempty"`
FontSizeTitle float64 `json:"font_size_title,omitempty"`
FontSizeAxisTitle float64 `json:"font_size_axis_title,omitempty"`
// Color schemes (categorical + sequential).
ColorSchemeCategorical []string `json:"color_scheme_categorical,omitempty"`
ColorSchemeSequential []string `json:"color_scheme_sequential,omitempty"`
}
Theme is the full resolved theme. Fields use named primitives (string for hex, float for font-size) so JSON merges sparsely.
func ApplyOverride ¶
func ApplyOverride(base *Theme, o *spec.ThemeOverride) *Theme
ApplyOverride folds a spec-level ThemeOverride into a base theme. Maps spec.ThemeOverride fields to the corresponding Theme fields; spec-side fields without a Theme counterpart (Mark, Axis, Legend, Scale, Title maps) are accepted but not yet plumbed — they land when per-mark style overrides ship in a later phase.
Returns a fresh Theme; base is not mutated.
func Get ¶
Get returns the named theme + true; (nil, false) when missing. Returned theme is a clone — callers may mutate freely.
func LoadFile ¶
LoadFile reads a theme JSON from disk. When the file's `base` field is set to a registered theme name, the file's other fields merge sparsely on top of that base. Standalone (base == "") returns the theme as declared.
func Merge ¶
Merge returns a new Theme that combines base with the non-zero fields of override. String/list zero values inherit from base.
func MustGet ¶
MustGet panics if the theme is not registered. Convenience for hard-coded tests + init code.
func (*Theme) CSSVariables ¶
CSSVariables returns the <style>...</style> block that the SVG renderer embeds at the top of every output document. Format mirrors design/07-rendering.md § Theming via CSS variables.
Output shape:
<style>:root{
--prism-color-axis:#...;
--prism-color-grid:#...;
...
}
.prism-axis-domain { ... }
.prism-grid-line { ... }
...
</style>
The CSS class set is fixed; theme values populate via var().
func (*Theme) Clone ¶
Clone returns a deep copy of the theme; lists are duplicated so sparse-override merges do not aliasing-leak.
func (*Theme) ToSceneTheme ¶
ToSceneTheme converts a Theme into the wire-stable scene.Theme shape. Used by the encoder to embed the resolved theme into SceneDoc.Theme. Renderers that need richer fields look up the full theme registry via Get(name).