scene

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: 3 Imported by: 0

Documentation

Overview

Package scene holds the Prism Scene IR — the renderer-agnostic intermediate representation produced by the encode stage and consumed by every Renderer (SVG ships in P05; PNG / PDF / canvas land in later phases). Types mirror design/06-scene-ir.md verbatim.

Coordinates are pre-resolved to pixel space. Renderers do not run scale math.

JSON serialisation is the cross-implementation contract (D011): the JS port consumes the same shape via the Node test harness in P12. Every field uses snake_case JSON tags per D019.

Mark uses a discriminated union with nine nullable *Geom pointers (only one populated). The wasted bytes (~70 per mark) buy us byte-stable round-trips without per-type MarshalJSON dispatch.

Index

Constants

View Source
const (
	WarnTimeScaleStubbed    = "PRISM_WARN_TIME_SCALE_STUBBED"
	WarnMarkNotImplemented  = "PRISM_WARN_MARK_NOT_IMPLEMENTED"
	WarnNoDataForLayer      = "PRISM_WARN_NO_DATA_FOR_LAYER"
	WarnPrecisionTruncation = "PRISM_WARN_PRECISION_TRUNCATION"
	// WarnLayerSkipped fires when a composite layer is dropped because
	// its upstream Source / sub-DAG produced no table (typically a
	// partial-failure cascade per D006). The other layers still render.
	WarnLayerSkipped = "PRISM_WARN_LAYER_SKIPPED"
)

Known warning codes emitted by the encoder / renderer in P05+.

View Source
const CurrentVersion = "1.0"

CurrentVersion is the SceneDoc.Version every encoder emits. Bump in lockstep with the JS port; additive changes keep "1.0".

Variables

This section is empty.

Functions

This section is empty.

Types

type Animation

type Animation struct {
	DurationMs int    `json:"duration_ms"`
	Easing     string `json:"easing"`
	StaggerMs  int    `json:"stagger_ms,omitempty"`
	Enter      string `json:"enter,omitempty"`
	Exit       string `json:"exit,omitempty"`
}

Animation is the scene-IR projection of the spec animation block. Fields carry resolved defaults — the encoder never emits a partial Animation. SVG and PDF renderers ignore this struct; only the browser web component and the WASM runtime consume it.

JSON shape uses omitempty on the optional fields so existing goldens stay byte-identical when no animation is declared.

type Annotation

type Annotation struct {
	Type AnnotationType  `json:"type"`
	Data json.RawMessage `json:"data,omitempty"`
}

Annotation carries a typed payload as raw JSON. The renderer dispatches on Type and decodes Data accordingly.

type AnnotationType

type AnnotationType string

AnnotationType is the discriminator for annotation payloads. Underspecified intentionally in v1 — text + line are common; richer types (region, arrow) land when fixtures demand.

const (
	AnnotationText   AnnotationType = "text"
	AnnotationLine   AnnotationType = "line"
	AnnotationRegion AnnotationType = "region"
	AnnotationArrow  AnnotationType = "arrow"
)

type ArcGeom

type ArcGeom struct {
	Cx         float64 `json:"cx"`
	Cy         float64 `json:"cy"`
	StartAngle float64 `json:"start_angle"`
	EndAngle   float64 `json:"end_angle"`
	InnerR     float64 `json:"inner_r,omitempty"`
	OuterR     float64 `json:"outer_r"`
	PadAngle   float64 `json:"pad_angle,omitempty"`
}

ArcGeom is the geometry for arc / pie / donut marks (declared for JSON stability; encoder emits PRISM_WARN_MARK_NOT_IMPLEMENTED in P05).

type AreaGeom

type AreaGeom struct {
	Upper [][2]float64 `json:"upper"`
	Lower [][2]float64 `json:"lower,omitempty"`
	Curve CurveType    `json:"curve,omitempty"`
}

AreaGeom is the geometry for an area mark. Lower=nil → baseline 0.

type Axis

type Axis struct {
	ID         string       `json:"id"`
	Channel    Channel      `json:"channel"`
	Position   AxisPosition `json:"position"`
	Scale      ScaleSpec    `json:"scale"`
	Ticks      []Tick       `json:"ticks,omitempty"`
	Title      string       `json:"title,omitempty"`
	Domain     Line         `json:"domain,omitempty"`
	Grid       []Line       `json:"grid,omitempty"`
	LabelAngle float64      `json:"label_angle,omitempty"`
	LabelStyle Style        `json:"label_style,omitempty"`
	TitleStyle Style        `json:"title_style,omitempty"`
}

Axis is the post-resolve description of one chart axis.

type AxisPosition

type AxisPosition string

AxisPosition controls where an axis renders relative to its plot.

const (
	AxisPositionBottom AxisPosition = "bottom"
	AxisPositionLeft   AxisPosition = "left"
	AxisPositionTop    AxisPosition = "top"
	AxisPositionRight  AxisPosition = "right"
)

type Channel

type Channel string

Channel is the encoding channel discriminator (matches the channel names in spec.Encoding).

const (
	ChannelX       Channel = "x"
	ChannelY       Channel = "y"
	ChannelX2      Channel = "x2"
	ChannelY2      Channel = "y2"
	ChannelColor   Channel = "color"
	ChannelSize    Channel = "size"
	ChannelShape   Channel = "shape"
	ChannelOpacity Channel = "opacity"
)

type Color

type Color struct {
	R uint8 `json:"r"`
	G uint8 `json:"g"`
	B uint8 `json:"b"`
	A uint8 `json:"a"`
}

Color is an 8-bit RGBA color. Gradient / pattern fills go through scene-level Defs and a string ID reference (not modelled here).

func ColorFromHex

func ColorFromHex(s string) (*Color, error)

ColorFromHex parses a #RRGGBB or #RRGGBBAA hex string. Missing alpha defaults to 255 (opaque).

func (*Color) CSS

func (c *Color) CSS() string

CSS returns a CSS-renderable string for the color (`rgba(...)` when alpha != 255; #RRGGBB otherwise). Used by render/svg/style.go to emit theme + mark fills.

func (*Color) Hex

func (c *Color) Hex() string

Hex returns the color as #RRGGBB (alpha == 255) or #RRGGBBAA (alpha != 255). Matches the format ColorFromHex accepts.

type ConditionalAttr

type ConditionalAttr struct {
	// Attr is the resolved SVG / scene-IR attribute name. One of
	// "fill", "stroke", "stroke_width", "opacity", "size" today.
	Attr string `json:"attr"`
	// Selection is the declared selection name whose active state
	// flips the attribute on. Empty selection means a degenerate
	// always-on entry (treated as static; the encoder normally bakes
	// such entries into Style and they should not appear here).
	Selection string `json:"selection,omitempty"`
	// WhenValue is the attribute value applied while Selection is
	// active. Type is per-attribute: hex strings for fill/stroke,
	// numbers for stroke_width/opacity/size.
	WhenValue any `json:"when_value,omitempty"`
	// Otherwise is the attribute value applied when Selection is
	// inactive. Mirrors the channel's resolved fallback so the
	// browser does not need to re-encode the spec to revert.
	Otherwise any `json:"otherwise,omitempty"`
}

ConditionalAttr is one selection-driven attribute switch attached to a Mark. The browser-side selection layer toggles attributes by reading these entries when its selection state changes; the server renderers (SVG / PDF) ignore them so static output is unaffected.

Static, expression-driven conditions (`{test: "..."}`) are evaluated at encode time and baked into Mark.Style — they never appear here. See `.planning/tier1-01-condition-encodings-plan.md`.

type CurveType

type CurveType string

CurveType is the line / area interpolation discriminator.

const (
	CurveLinear   CurveType = "linear"
	CurveMonotone CurveType = "monotone"
	CurveStep     CurveType = "step"
	CurveCardinal CurveType = "cardinal"
)

type DatasetRef

type DatasetRef struct {
	Name string `json:"name"`
	Hash string `json:"hash,omitempty"`
}

DatasetRef carries back-references to the named datasets that fed this scene. Browser dataset-registry uses these to skip refetch on re-render when no upstream dataset changed.

type Datum

type Datum struct {
	LayerID string         `json:"layer_id"`
	RowID   int64          `json:"row_id"`
	Fields  map[string]any `json:"fields,omitempty"`
}

Datum is the back-reference from a mark to its source row. Used for selection wiring and tooltip rendering.

type DatumRef

type DatumRef struct {
	LayerID string `json:"layer_id"`
	RowID   int64  `json:"row_id"`
}

DatumRef is a thin reference to a row in a layer (used by SelectionState.Points). Carries no field bag.

type Defs

type Defs struct {
	Gradients map[string]Gradient `json:"gradients,omitempty"`
	Patterns  map[string]Pattern  `json:"patterns,omitempty"`
	Clips     map[string]Rect     `json:"clips,omitempty"`
	Filters   map[string]Filter   `json:"filters,omitempty"`
}

Defs holds scene-level reusable resources. SVG renderer emits a single <defs> block; Canvas pre-builds equivalents keyed by the same IDs. P05 never populates these (no fixture needs gradients).

type Filter

type Filter struct {
	Type   string  `json:"type"`
	Radius float64 `json:"radius,omitempty"`
}

Filter is a post-process effect (blur, drop-shadow).

type Gradient

type Gradient struct {
	Type  string         `json:"type"` // "linear" | "radial"
	Stops []GradientStop `json:"stops"`
	X1    float64        `json:"x1,omitempty"`
	Y1    float64        `json:"y1,omitempty"`
	X2    float64        `json:"x2,omitempty"`
	Y2    float64        `json:"y2,omitempty"`
}

Gradient is a linear or radial color gradient.

type GradientStop

type GradientStop struct {
	Offset float64 `json:"offset"`
	Color  Color   `json:"color"`
}

GradientStop is one color stop in a gradient.

type GridHeaders

type GridHeaders struct {
	Top    []string `json:"top,omitempty"`
	Left   []string `json:"left,omitempty"`
	Right  []string `json:"right,omitempty"`
	Bottom []string `json:"bottom,omitempty"`
}

GridHeaders carries header/title rows or columns for facet grids.

type GridLayout

type GridLayout struct {
	Rows     int         `json:"rows"`
	Cols     int         `json:"cols"`
	GapPx    int         `json:"gap_px,omitempty"`
	RowSizes []float64   `json:"row_sizes,omitempty"`
	ColSizes []float64   `json:"col_sizes,omitempty"`
	Headers  GridHeaders `json:"headers,omitempty"`
}

GridLayout carries the grid's dimensions and per-cell sizing.

type ImageGeom

type ImageGeom struct {
	X    float64 `json:"x"`
	Y    float64 `json:"y"`
	W    float64 `json:"w"`
	H    float64 `json:"h"`
	Href string  `json:"href"`
}

ImageGeom is the geometry for an image mark.

type Legend

type Legend struct {
	ID         string         `json:"id"`
	Channel    Channel        `json:"channel"`
	Position   LegendPosition `json:"position"`
	Title      string         `json:"title,omitempty"`
	Entries    []LegendEntry  `json:"entries"`
	Frame      Rect           `json:"frame"`
	TitleStyle Style          `json:"title_style,omitempty"`
	LabelStyle Style          `json:"label_style,omitempty"`
}

Legend is the resolved legend (post-layout). P05 ships the types but the encoder never populates them — no fixture has more than one color band.

type LegendEntry

type LegendEntry struct {
	Label  string     `json:"label"`
	Swatch SwatchSpec `json:"swatch"`
}

LegendEntry is one row in a legend.

type LegendPosition

type LegendPosition string

LegendPosition controls where a legend renders relative to its scene.

const (
	LegendRight       LegendPosition = "right"
	LegendLeft        LegendPosition = "left"
	LegendTop         LegendPosition = "top"
	LegendBottom      LegendPosition = "bottom"
	LegendTopRight    LegendPosition = "top-right"
	LegendTopLeft     LegendPosition = "top-left"
	LegendBottomRight LegendPosition = "bottom-right"
	LegendBottomLeft  LegendPosition = "bottom-left"
)

type Line

type Line struct {
	X1 float64 `json:"x1"`
	Y1 float64 `json:"y1"`
	X2 float64 `json:"x2"`
	Y2 float64 `json:"y2"`
}

Line is a pre-resolved line segment, used for axis domain lines and grid lines (both anchored to the plot region).

type LineGeom

type LineGeom struct {
	Points [][2]float64 `json:"points"`
	Dash   []float64    `json:"dash,omitempty"`
	Curve  CurveType    `json:"curve,omitempty"`
}

LineGeom is the geometry for a line mark (one polyline per mark).

type Mark

type Mark struct {
	Type MarkType `json:"type"`
	ID   string   `json:"id,omitempty"`
	// Key carries the resolved animation join-key string (e.g.
	// "region=west") materialised from whichever encoding channel
	// declared `key: true` in the spec. Empty when no animation is in
	// play; SVG and PDF renderers ignore it.
	Key     string   `json:"key,omitempty"`
	Style   Style    `json:"style,omitempty"`
	Tooltip *Tooltip `json:"tooltip,omitempty"`
	Datum   *Datum   `json:"datum,omitempty"`

	// Conditions carries per-mark selection-driven conditional attrs
	// resolved at encode time. The SVG / PDF renderers ignore this
	// slice (it travels through scene JSON only); the browser-side
	// selection module reacts to entries here when its selection state
	// changes. Static `test`-based conditions are baked into Style
	// directly and do not appear in this slice. See
	// `.planning/tier1-01-condition-encodings-plan.md`.
	Conditions []ConditionalAttr `json:"conditions,omitempty"`

	Rect     *RectGeom    `json:"rect,omitempty"`
	Line     *LineGeom    `json:"line,omitempty"`
	Area     *AreaGeom    `json:"area,omitempty"`
	Point    *PointGeom   `json:"point,omitempty"`
	Rule     *RuleGeom    `json:"rule,omitempty"`
	Arc      *ArcGeom     `json:"arc,omitempty"`
	Text     *TextGeom    `json:"text,omitempty"`
	Path     *PathGeom    `json:"path,omitempty"`
	Image    *ImageGeom   `json:"image,omitempty"`
	Geoshape *PolygonGeom `json:"geoshape,omitempty"`
}

Mark is the atomic visual primitive. Discriminated union: exactly one of the nine *Geom pointers is non-nil. JSON shape uses omitempty so unused slots disappear from the wire form even though they are nullable.

func (*Mark) Validate

func (m *Mark) Validate() error

Validate confirms that exactly one geometry pointer is non-nil and that its Type field matches the populated geom. Defensive helper used by the encoder before passing marks to the renderer.

type MarkType

type MarkType string

MarkType is the canonical mark-type discriminator.

const (
	MarkRect     MarkType = "rect"
	MarkLine     MarkType = "line"
	MarkArea     MarkType = "area"
	MarkPoint    MarkType = "point"
	MarkRule     MarkType = "rule"
	MarkArc      MarkType = "arc"
	MarkText     MarkType = "text"
	MarkPath     MarkType = "path"
	MarkImage    MarkType = "image"
	MarkGeoshape MarkType = "geoshape"
)

Mark types. The first five are the P05 core set; the remaining four are declared for JSON stability and round-trip parity but raise PRISM_WARN_MARK_NOT_IMPLEMENTED at encode time today.

type PathGeom

type PathGeom struct {
	D string `json:"d"`
}

PathGeom is the SVG-passthrough escape hatch for shapes Prism does not have first-class.

type Pattern

type Pattern struct {
	Type string  `json:"type"`
	Size float64 `json:"size"`
}

Pattern is a tiled fill pattern (e.g. crosshatch for accessibility).

type PointGeom

type PointGeom struct {
	Cx    float64    `json:"cx"`
	Cy    float64    `json:"cy"`
	R     float64    `json:"r"`
	Shape PointShape `json:"shape,omitempty"`
}

PointGeom is the geometry for a point / scatter mark.

type PointShape

type PointShape string

PointShape is the point mark's symbol discriminator.

const (
	ShapeCircle   PointShape = "circle"
	ShapeSquare   PointShape = "square"
	ShapeTriangle PointShape = "triangle"
	ShapeCross    PointShape = "cross"
	ShapeDiamond  PointShape = "diamond"
)

type PolygonGeom

type PolygonGeom struct {
	Outer [][2]float64   `json:"outer"`
	Holes [][][2]float64 `json:"holes,omitempty"`
}

PolygonGeom is the geometry for a geoshape mark. Points are already in plot-space pixels (the projection has been applied upstream). Outer is the outer ring; Holes are inner rings (rendered with the SVG fill-rule cutout). Multipolygon features emit one PolygonGeom per disjoint piece on its own scene.Mark.

type Reactive

type Reactive string

Reactive controls where a selection's filtering loop runs.

const (
	ReactiveClient Reactive = "client"
	ReactiveServer Reactive = "server"
	ReactiveBoth   Reactive = "both"
)

type Rect

type Rect struct {
	X float64 `json:"x"`
	Y float64 `json:"y"`
	W float64 `json:"w"`
	H float64 `json:"h"`
}

Rect is a pixel-resolved bounding box.

func (Rect) Bottom

func (r Rect) Bottom() float64

Bottom returns the Y coordinate of the bottom edge.

func (Rect) CenterX

func (r Rect) CenterX() float64

CenterX returns the horizontal center.

func (Rect) CenterY

func (r Rect) CenterY() float64

CenterY returns the vertical center.

func (Rect) Right

func (r Rect) Right() float64

Right returns the X coordinate of the right edge.

type RectGeom

type RectGeom struct {
	X       float64 `json:"x"`
	Y       float64 `json:"y"`
	W       float64 `json:"w"`
	H       float64 `json:"h"`
	CornerR float64 `json:"corner_r,omitempty"`
}

RectGeom is the geometry for a bar / rect mark.

type ResolveStrategy

type ResolveStrategy string

ResolveStrategy controls how a selection is resolved across layers.

const (
	ResolveGlobal      ResolveStrategy = "global"
	ResolveIndependent ResolveStrategy = "independent"
	ResolveUnion       ResolveStrategy = "union"
	ResolveIntersect   ResolveStrategy = "intersect"
)

type RuleGeom

type RuleGeom struct {
	X1   float64   `json:"x1"`
	Y1   float64   `json:"y1"`
	X2   float64   `json:"x2"`
	Y2   float64   `json:"y2"`
	Dash []float64 `json:"dash,omitempty"`
}

RuleGeom is the geometry for a rule mark (horizontal or vertical line).

type ScaleSpec

type ScaleSpec struct {
	Type    ScaleType  `json:"type"`
	Domain  []any      `json:"domain,omitempty"`
	Range   [2]float64 `json:"range"`
	Padding float64    `json:"padding,omitempty"`
	Base    float64    `json:"base,omitempty"`
	Exp     float64    `json:"exp,omitempty"`
	Nice    bool       `json:"nice,omitempty"`
	Clamp   bool       `json:"clamp,omitempty"`
}

ScaleSpec is the post-resolve scale (Type + Domain + Range + flags).

type ScaleType

type ScaleType string

ScaleType is the canonical scale-type discriminator.

const (
	ScaleLinear  ScaleType = "linear"
	ScaleLog     ScaleType = "log"
	ScalePow     ScaleType = "pow"
	ScaleSqrt    ScaleType = "sqrt"
	ScaleTime    ScaleType = "time"
	ScaleBand    ScaleType = "band"
	ScalePoint   ScaleType = "point"
	ScaleOrdinal ScaleType = "ordinal"
)

type Scene

type Scene struct {
	ID          string       `json:"id"`
	Frame       Rect         `json:"frame"`
	Plot        Rect         `json:"plot"`
	Title       *TextElement `json:"title,omitempty"`
	Subtitle    *TextElement `json:"subtitle,omitempty"`
	Axes        []Axis       `json:"axes,omitempty"`
	Legends     []Legend     `json:"legends,omitempty"`
	Layers      []SceneLayer `json:"layers"`
	Annotations []Annotation `json:"annotations,omitempty"`
	Selections  []Selection  `json:"selections,omitempty"`
	Defs        *Defs        `json:"defs,omitempty"`
	Animation   *Animation   `json:"animation,omitempty"`
}

Scene is one chart with layered marks. Coordinates in Frame/Plot are pre-resolved to pixel space.

type SceneCell

type SceneCell struct {
	Row     int   `json:"row"`
	Col     int   `json:"col"`
	RowSpan int   `json:"row_span,omitempty"`
	ColSpan int   `json:"col_span,omitempty"`
	Scene   Scene `json:"scene"`
}

SceneCell is one Scene plus its row/col span in the grid.

type SceneDoc

type SceneDoc struct {
	Version  string       `json:"version"`
	Theme    *Theme       `json:"theme,omitempty"`
	Grid     SceneGrid    `json:"grid"`
	Datasets []DatasetRef `json:"datasets,omitempty"`
	Warnings []Warning    `json:"warnings,omitempty"`
}

SceneDoc is the top-level Scene IR document. Renderer entry point.

func NewDoc

func NewDoc() *SceneDoc

NewDoc returns a SceneDoc skeleton with Version pinned and Theme set to Default(). The encoder fills Grid before returning.

type SceneGrid

type SceneGrid struct {
	Layout GridLayout  `json:"layout"`
	Cells  []SceneCell `json:"cells"`
	Shared SharedAxes  `json:"shared,omitempty"`
}

SceneGrid wraps one or more Scenes in an N×M layout. Flat charts use a 1×1 grid; composition (P08+) populates more cells.

type SceneLayer

type SceneLayer struct {
	ID      string   `json:"id"`
	Source  string   `json:"source,omitempty"`
	Mark    MarkType `json:"mark"`
	Marks   []Mark   `json:"marks"`
	Clip    bool     `json:"clip,omitempty"`
	Opacity float64  `json:"opacity,omitempty"`
	ZIndex  int      `json:"z_index,omitempty"`
	Hidden  bool     `json:"hidden,omitempty"`
}

SceneLayer is one Pulse-query-worth of marks. Layers stack back-to-front per ZIndex; renderer emits one <g> per layer for DOM addressability + selection styling.

type Selection

type Selection struct {
	ID        string          `json:"id"`
	Kind      SelectionKind   `json:"kind"`
	Channels  []Channel       `json:"channels,omitempty"`
	On        SelectionEvent  `json:"on,omitempty"`
	Resolve   ResolveStrategy `json:"resolve,omitempty"`
	Encodings []string        `json:"encodings,omitempty"`
	InitState *SelectionState `json:"init_state,omitempty"`
	Reactive  Reactive        `json:"reactive,omitempty"`
}

Selection is the post-resolve selection descriptor.

type SelectionEvent

type SelectionEvent string

SelectionEvent describes the user gesture that triggers a selection.

const (
	EventClick    SelectionEvent = "click"
	EventHover    SelectionEvent = "hover"
	EventBrush    SelectionEvent = "brush"
	EventLasso    SelectionEvent = "lasso"
	EventDblclick SelectionEvent = "dblclick"
)

type SelectionKind

type SelectionKind string

SelectionKind is the discriminator between point and interval selections. P05 ships the types; selection wiring lands in P13.

const (
	SelectionPoint    SelectionKind = "point"
	SelectionInterval SelectionKind = "interval"
)

type SelectionRange

type SelectionRange struct {
	X [2]float64 `json:"x,omitempty"`
	Y [2]float64 `json:"y,omitempty"`
}

SelectionRange is the value-space bounds of an interval selection.

type SelectionState

type SelectionState struct {
	Points []DatumRef      `json:"points,omitempty"`
	Range  *SelectionRange `json:"range,omitempty"`
}

SelectionState carries the active selection's data (post-event).

type SharedAxes

type SharedAxes struct {
	X *Axis `json:"x,omitempty"`
	Y *Axis `json:"y,omitempty"`
}

SharedAxes carries grid-level axes that are shared across cells. nil = per-cell axes.

type Style

type Style struct {
	Fill        *Color    `json:"fill,omitempty"`
	Stroke      *Color    `json:"stroke,omitempty"`
	StrokeWidth float64   `json:"stroke_width,omitempty"`
	StrokeDash  []float64 `json:"stroke_dash,omitempty"`
	Opacity     float64   `json:"opacity,omitempty"`
	FontFamily  string    `json:"font_family,omitempty"`
	FontWeight  int       `json:"font_weight,omitempty"`
	Cursor      string    `json:"cursor,omitempty"`
}

Style carries per-mark visual properties. Pointer-typed fields preserve the unset / explicit-zero distinction.

type SwatchSpec

type SwatchSpec struct {
	Type       SwatchType `json:"type"`
	Color      *Color     `json:"color,omitempty"`
	GradientID string     `json:"gradient_id,omitempty"`
	Shape      PointShape `json:"shape,omitempty"`
}

SwatchSpec describes a single legend swatch.

type SwatchType

type SwatchType string

SwatchType discriminates the visual form of a legend entry's swatch.

const (
	SwatchSolid    SwatchType = "solid"
	SwatchGradient SwatchType = "gradient"
	SwatchSymbol   SwatchType = "symbol"
)

type TextAnchor

type TextAnchor string

TextAnchor controls horizontal text anchoring.

const (
	AnchorStart  TextAnchor = "start"
	AnchorMiddle TextAnchor = "middle"
	AnchorEnd    TextAnchor = "end"
)

type TextBaseline

type TextBaseline string

TextBaseline controls vertical text alignment.

const (
	BaselineAlphabetic TextBaseline = "alphabetic"
	BaselineMiddle     TextBaseline = "middle"
	BaselineHanging    TextBaseline = "hanging"
	BaselineTop        TextBaseline = "top"
	BaselineBottom     TextBaseline = "bottom"
)

type TextElement

type TextElement struct {
	Content string  `json:"content"`
	X       float64 `json:"x"`
	Y       float64 `json:"y"`
	Style   Style   `json:"style,omitempty"`
}

TextElement carries one text placement (title, subtitle, etc).

type TextGeom

type TextGeom struct {
	X        float64      `json:"x"`
	Y        float64      `json:"y"`
	Content  string       `json:"content"`
	Anchor   TextAnchor   `json:"anchor,omitempty"`
	Baseline TextBaseline `json:"baseline,omitempty"`
	Angle    float64      `json:"angle,omitempty"`
	FontSize float64      `json:"font_size,omitempty"`
}

TextGeom is the geometry for a text mark.

type Theme

type Theme struct {
	Name       string `json:"name,omitempty"`
	ColorAxis  *Color `json:"color_axis,omitempty"`
	ColorGrid  *Color `json:"color_grid,omitempty"`
	ColorText  *Color `json:"color_text,omitempty"`
	Background string `json:"background,omitempty"`
	FontSans   string `json:"font_sans,omitempty"`
	FontMono   string `json:"font_mono,omitempty"`
	// CSS carries the pre-rendered <style> block produced by the
	// theme package. The renderer emits this verbatim when set, and
	// falls back to a hardcoded block when empty (back-compat with
	// scene.Default()). Serialised to JSON so the JS port (prism.mjs)
	// receives the same theme bytes the Go renderer emits — required
	// for cross-impl parity (D075 + D076).
	CSS string `json:"css,omitempty"`
}

Theme is the placeholder theme struct shipped in P05. P06 expands this into a registry with light / dark / print variants + sparse spec-level overrides (D009). The CSS-variable manifest emitted by render/svg/style.go is derived from this struct so the P06 swap is interface-clean.

func Default

func Default() *Theme

Default returns the hard-coded P05 theme:

  • axis: #6b7280 (gray-500)
  • grid: #e5e7eb (gray-200)
  • text: #111827 (gray-900)
  • sans: Inter, system-ui, sans-serif
  • mono: ui-monospace, SF Mono, monospace
  • background: transparent

Hex strings are guaranteed-valid by tests; the function never returns nil for any color pointer.

type Tick

type Tick struct {
	Value       any     `json:"value"`
	Pixel       float64 `json:"pixel"`
	Label       string  `json:"label"`
	Minor       bool    `json:"minor,omitempty"`
	LabelHidden bool    `json:"label_hidden,omitempty"`
}

Tick is one resolved tick mark: value + pixel + pre-formatted label.

type Tooltip

type Tooltip struct {
	Lines    []TooltipLine   `json:"lines"`
	Position TooltipPosition `json:"position,omitempty"`
}

Tooltip is the pre-formatted, layout-ready tooltip for one mark.

type TooltipLine

type TooltipLine struct {
	Label string `json:"label"`
	Style Style  `json:"style,omitempty"`
}

TooltipLine is one row of tooltip text.

type TooltipPosition

type TooltipPosition string

TooltipPosition controls where the tooltip renders relative to the mark.

const (
	TooltipAuto   TooltipPosition = "auto"
	TooltipTop    TooltipPosition = "top"
	TooltipRight  TooltipPosition = "right"
	TooltipBottom TooltipPosition = "bottom"
	TooltipLeft   TooltipPosition = "left"
)

type Warning

type Warning struct {
	Code    string         `json:"code"`
	Layer   string         `json:"layer,omitempty"`
	Message string         `json:"message"`
	Details map[string]any `json:"details,omitempty"`
}

Warning is the structured-warning shape attached to SceneDoc and surfaced by the CLI / browser. Codes use the PRISM_WARN_* form.

Jump to

Keyboard shortcuts

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