theme

package
v0.2.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: May 27, 2026 License: MIT Imports: 7 Imported by: 0

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

func Names

func Names() []string

Names returns the registered theme names in sorted order.

func Register

func Register(name string, t *Theme)

Register adds (or replaces) a theme under name. Safe to call from any package's init() block.

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

func Get(name string) (*Theme, bool)

Get returns the named theme + true; (nil, false) when missing. Returned theme is a clone — callers may mutate freely.

func LoadBytes

func LoadBytes(body []byte) (*Theme, error)

LoadBytes parses a theme JSON blob. Same merge semantics as LoadFile.

func LoadFile

func LoadFile(path string) (*Theme, error)

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

func Merge(base, override *Theme) *Theme

Merge returns a new Theme that combines base with the non-zero fields of override. String/list zero values inherit from base.

func MustGet

func MustGet(name string) *Theme

MustGet panics if the theme is not registered. Convenience for hard-coded tests + init code.

func (*Theme) CSSVariables

func (t *Theme) CSSVariables() string

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

func (t *Theme) Clone() *Theme

Clone returns a deep copy of the theme; lists are duplicated so sparse-override merges do not aliasing-leak.

func (*Theme) ToSceneTheme

func (t *Theme) ToSceneTheme() *scene.Theme

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).

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL