theme

package
v0.8.3 Latest Latest
Warning

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

Go to latest
Published: Nov 22, 2026 License: MIT Imports: 5 Imported by: 1 module, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package theme holds the themes of zuzu: a mode, light or dark, and a color scheme, which a caller swaps apart from the mode (D14).

The mode sets the neutral colors: the background, the text, the grid and the axes. The scheme sets the colors of the data. docs/STYLE.md holds the tokens of both, and a test checks that this package holds the same values.

Index

Constants

View Source
const (
	GrayChroma = 0.1
	GrayDark   = 0.3
	GrayLight  = 0.7
)

The bounds of a gray near black or near white, which the dark mode flips (D48 part 1). A color is such a gray when its channels of red, green and blue differ by at most GrayChroma of the full range, and its lightness in HSL is at most GrayDark or at least GrayLight.

View Source
const (
	ConfigMode       = "zuzu.mode"
	ConfigScheme     = "zuzu.scheme"
	ConfigBackground = "zuzu.background"
	ConfigLook       = "zuzu.look"
	ConfigLookSeed   = "zuzu.lookSeed"
)

The keys of the config of a spec that ask for a look (D32): a mode, light or dark, and a scheme by its name, such as mermaid-forest. A Mermaid diagram fills them from its theme. A mode or a scheme that the caller of a render gives wins over them. ConfigBackground is a color of CSS that fills the page and is the background of the theme, such as the bgcolor of a graph of DOT (D37). The mode follows its lightness, over the mode of the caller and of ConfigMode. A background that the caller gives wins over it.

ConfigLook names a Look, such as excalidraw, and ConfigLookSeed is the seed of a look drawn by hand, a whole number (D35 part 12, D40). A Mermaid diagram fills them from its look and its handDrawnSeed. A look that the caller gives wins over ConfigLook.

View Source
const (
	// StyleFill is the style of a mark whose fill is the color of the mark.
	StyleFill = "zuzu.fill"
	// StyleStroke is the style of a mark whose stroke is the color of the
	// mark.
	StyleStroke = "zuzu.stroke"
	// StyleText is the style of a text whose fill is the text color.
	StyleText = "zuzu.text"
	// StyleBar is the prefix of the style of a bar, which its orient,
	// vertical or horizontal, ends.
	StyleBar = "zuzu.bar."
	// StylePoint is the style of a point, which gives it a ring in the
	// background color.
	StylePoint = "zuzu.point"
	// CornerRadiusEnd is the property of a style of a bar that rounds the
	// end of the bar away from zero, and only the last bar of a stack. It
	// is a rule of the look of zuzu that Vega has no config for, and 0
	// turns it off (D14).
	CornerRadiusEnd = "zuzu.cornerRadiusEnd"
	// LargestFirst is the property of the config of a symbol that draws the
	// largest first, when the symbols have sizes, so that the small ones
	// stay on top.
	LargestFirst = "zuzu.largestFirst"
	// EndLabel is the property of the config of a line that names its
	// series at its last point, with a dot.
	EndLabel = "zuzu.endLabel"
	// MarkHigh is the property of a style of an area that marks its highest
	// point with its value.
	MarkHigh = "zuzu.markHigh"
	// Reference is the property of a style of a rule that dashes it and
	// names its value where it starts.
	Reference = "zuzu.reference"
	// StyleReference is the style of a rule of Vega-Lite across the whole
	// plot, a reference line.
	StyleReference = "zuzu.reference"
	// StyleOwn is the prefix of a style that says that the spec gives a
	// property to a part of a box plot, an error bar or an error band,
	// such as zuzu.own.color for "median": {"color": "red"}. The look of
	// zuzu keeps that property (docs/STYLE.md).
	StyleOwn = "zuzu.own."
	// Hierarchy is the property of the config of a rect, a symbol and an
	// arc that draws the nodes of a hierarchy: a group as a tint of its
	// color, with its name.
	Hierarchy = "zuzu.hierarchy"
	// Total is the property of the config of an arc that writes the total
	// of a donut in its center.
	Total = "zuzu.total"
	// Sankey is the property of the config of a path and a rect that draws
	// the links of a sankey at 0.32 opacity and its nodes with round
	// corners.
	Sankey = "zuzu.sankey"
	// StyleNode and the styles after it are the styles of the marks of a
	// diagram of DOT or Mermaid (D31): a node, a solid node, which fills
	// with the color of its outline (D55), a node in the neutral color
	// muted, such as an external element of a C4 diagram (D32),
	// its label, an edge, its arrowheads, filled and open, its label and the
	// box under the label, a cluster and its title, an icon of one
	// color, filled and stroked, a guide line, such as a lifeline of a
	// sequence diagram, and a band behind a group of rows, such as a
	// section of a gantt.
	StyleNode      = "zuzu.node"
	StyleNodeSolid = "zuzu.node.solid"
	StyleNodeMuted = "zuzu.node.muted"
	StyleNote      = "zuzu.note"
	// RangeTint is the named range of the solid tints of the categorical
	// colors (D55).
	RangeTint         = "zuzu.tint"
	StyleNodeLabel    = "zuzu.nodeLabel"
	StyleEdge         = "zuzu.edge"
	StyleArrow        = "zuzu.arrow"
	StyleArrowOpen    = "zuzu.arrow.open"
	StyleEdgeLabel    = "zuzu.edgeLabel"
	StyleEdgeLabelBox = "zuzu.edgeLabelBox"
	StyleCluster      = "zuzu.cluster"
	StyleClusterTitle = "zuzu.clusterTitle"
	StyleIcon         = "zuzu.icon"
	StyleIconStroke   = "zuzu.icon.stroke"
	StyleGuide        = "zuzu.guide"
	StyleBand         = "zuzu.band"
	// StyleHalo gives a text a halo: a stroke of 3 in the color of the
	// background, which draws under the fill. A label that sits on a busy
	// mark takes it after the style of its fill.
	StyleHalo = "zuzu.halo"
	// StackGap is the property of a style of a bar that opens a gap of that
	// width between the bars of a stack.
	StackGap = "zuzu.stackGap"
	// StyleArea is the style of an area that stacks on no other, which
	// draws its color as a gradient with a line on top.
	StyleArea = "zuzu.area"
	// StyleAreaStacked is the style of the layer of a stacked area.
	StyleAreaStacked = "zuzu.area.stacked"
	// StyleAreaRanged is the style of an area with an end of its own, y2
	// or x2, such as a band, which draws as a flat tint of its color with
	// no line along its top (D48 part 3).
	StyleAreaRanged = "zuzu.area.ranged"
	// StyleCurve is the style of a line or an area along x, which draws as
	// a monotone curve.
	StyleCurve = "zuzu.curve"
	// Gradient is the property of a style of an area that fills it from an
	// opacity at its line to an opacity at its base.
	Gradient = "zuzu.gradient"
	// TopLine is the property of a style of an area that draws a line of
	// that width along its top.
	TopLine = "zuzu.topLine"
	// Tint is the property of a style of an area that fills it with its
	// color at that opacity, when the spec sets no opacity of its own.
	Tint = "zuzu.tint"
)

The styles that the compiler of Vega-Lite names for the color of a mark that a spec does not set (D6, D14). The config of a theme gives them the first color of the categories, or the text color.

View Source
const (
	// SketchRoughness is how far a line strays from its path.
	SketchRoughness = 0.7
	// SketchEdgeRoughness is the roughness of the lines and the
	// arrowheads of an edge of a graph.
	SketchEdgeRoughness = 0.3
	// SketchStroke is the width of a stroke that the item does not set.
	SketchStroke = 1.3
	// SketchFillWeight is the width of each line of a hachure.
	SketchFillWeight = 1.5
	// SketchClusterFillWeight is the width of each line of the hachure of
	// the box of a cluster of a graph.
	SketchClusterFillWeight = 3.0
	// SketchHachureGap is the space between the lines of a hachure.
	SketchHachureGap = 1.5
	// SketchHachureAngle is the angle of the lines of a hachure, in
	// degrees, the default of rough.js.
	SketchHachureAngle = -41.0
	// SketchGradientGap is the space between the lines of the hachure of
	// a gradient, the gap of Excalidraw (D50).
	SketchGradientGap = 5.0
	// SketchGradientTint is the opacity of the tint under the hachure of a
	// gradient, times the opacity of the fill.
	SketchGradientTint = 0.25
	// SketchGradientInset is how far the hachure of a gradient stays
	// inside the outline.
	SketchGradientInset = 2.0
	// SketchGradientLeast is the least width and height of a shape whose
	// gradient draws over a tint. A thinner shape, such as the bar of a
	// legend, keeps the hachure of SketchHachureGap.
	SketchGradientLeast = 20.0
	// SketchSlack is the most that the canvas grows at a side for a line
	// that wobbles out of it. A mark that reaches further past the side
	// stays cut there, as in the standard look.
	SketchSlack = 10.0
	// SketchSeed is the seed of a chart that sets none (D40 part 6).
	SketchSeed = 1
)

The tokens of the look like Excalidraw, from "The look like Excalidraw" in docs/STYLE.md. They are the options of rough.js that Mermaid 12.3 gives for look: handDrawn (D40 part 5).

View Source
const (
	// EdgeWidth is the width of the line of an edge, and of the outline of
	// an open arrowhead.
	EdgeWidth = 1.5
	// ArrowLength is the length of the arrowhead normal of DOT at an
	// arrowsize of 1. It is 0.8 of this length wide.
	ArrowLength = 8.0
)

The sizes of an edge of a diagram, from "Edges" in docs/STYLE.md.

View Source
const (
	// TickSize is the length of a tick, from the line of the axis.
	TickSize = 5.0
	// TickWidth is the width of a tick.
	TickWidth = 1.0
	// DomainWidth is the width of the line of an axis.
	DomainWidth = 1.0
	// LabelPadding is the space between the end of a tick and its label.
	LabelPadding = 3.0
)

The sizes of an axis, from "Axes and grids" in docs/STYLE.md. The line and the ticks of an axis are in the color Axis (D46).

View Source
const (
	// NodeTint is how far the solid tint of a node goes from the
	// background to its color (D55).
	NodeTint = 0.14
	// NodeOutline is the width of the outline of a node.
	NodeOutline = 1.25
)

The paint of a node of a diagram, from "Marks" in docs/STYLE.md: a tint of its color and an outline.

View Source
const BandOpacity = 0.06

BandOpacity is the opacity of the text that draws a band behind a group of rows. Band is the text at this opacity over the background, and zuzu draws the band in the text color at this opacity, so that the grid lines and the labels under it still show.

View Source
const NoteHue = 52.0

NoteHue is the hue, in degrees, of the yellow of a note on paper, which the color of a note of a diagram comes nearest to.

View Source
const RampStart = 0.4

RampStart is how far the sequential ramp of the theme starts from the background toward its first color, so that the lowest value of a scale shows in both modes (D48 part 4).

View Source
const RangedTint = 0.32

RangedTint is the opacity of the tint of an area with an end of its own, as docs/STYLE.md says (D48 part 3). It is the opacity of the top of the gradient of an area from zero.

Variables

View Source
var (
	Zuzu = Scheme{
			// contains filtered or unexported fields
	}
	Pastel = Scheme{
			// contains filtered or unexported fields
	}
	Harbor = Scheme{
			// contains filtered or unexported fields
	}
	Ember = Scheme{
			// contains filtered or unexported fields
	}
)

The schemes that zuzu ships (D14). The maintainers accepted these four on 2026-11-10.

Functions

func FlipGray added in v0.8.0

func FlipGray(r, g, b float64) (float64, float64, float64, bool)

FlipGray returns a color with each channel from 0 to 255 with its lightness in HSL flipped, from l to 1 - l, and true, when the color is a gray near black or near white. The hue and the saturation stay. It returns the color as it is, and false, for any other color.

func IsDark added in v0.7.5

func IsDark(background string) bool

IsDark reports whether a background in the form #rrggbb is dark: its lightness in HSL is below 0.5 (D35, D37). A color in another form reads as black, and so as dark.

func Schemes

func Schemes() []string

Schemes returns the names of the schemes, in the order of docs/STYLE.md.

Types

type Look added in v0.8.0

type Look string

Look is a way to draw the marks of a chart or a diagram: the standard look of zuzu, or a look drawn by hand (D39, D40). A look changes the shapes and the font, and keeps the colors of the mode and the scheme. "The look like Excalidraw" in docs/STYLE.md holds its rules.

const (
	// LookStandard draws each mark as docs/STYLE.md says. It is the
	// default.
	LookStandard Look = "standard"
	// LookExcalidraw draws each mark as if by hand, as Excalidraw and the
	// look handDrawn of Mermaid draw it, with the options of rough.js that
	// Mermaid 12.3 gives, and draws its text in Excalifont.
	LookExcalidraw Look = "excalidraw"
)

The looks. A look like xkcd waits for a font (D40).

func (Look) HandDrawn added in v0.8.0

func (l Look) HandDrawn() bool

HandDrawn reports whether a look draws its marks as if by hand.

func (Look) Known added in v0.8.0

func (l Look) Known() bool

Known reports whether zuzu draws a look.

type Mode

type Mode int

Mode is the light or the dark mode.

const (
	Light Mode = iota
	Dark
)

The modes.

func (Mode) String

func (m Mode) String() string

String returns the name of the mode.

type Neutrals

type Neutrals struct {
	Background string // the background of the chart
	Panel      string // a panel inside the chart, such as a tooltip
	Text       string // the title, the labels on the data, a value
	Muted      string // the subtitle, the labels and the title of an axis, a legend
	Faint      string // the source line, the title of a legend, a guide line
	Grid       string // the grid lines
	Axis       string // the line and the ticks of an axis, a base line, a border
	Edge       string // an edge of a diagram, its arrowheads, a message
	Band       string // a band behind a group of rows, as it shows over the background
}

Neutrals are the colors of a mode that do not carry data.

type Scheme

type Scheme struct {
	// contains filtered or unexported fields
}

Scheme is a color scheme: the colors of the data. A scheme from an upstream theme can also bring neutrals of its own for a mode (D15).

func Lookup

func Lookup(name string) (Scheme, bool)

Lookup returns the scheme with a name.

func (Scheme) Name

func (s Scheme) Name() string

Name returns the name of the scheme, such as zuzu.

type Theme

type Theme struct {
	Neutrals

	// Category holds ten categorical colors for the mode.
	Category []string
	// Up and Down are the colors of a rise and a fall.
	Up   string
	Down string
	// FillOpacity is the opacity of a tinted fill, such as a box of a box
	// plot.
	FillOpacity float64
	// Note is the color of a note of a diagram: the categorical color whose
	// hue is nearest the yellow of a note on paper, NoteHue.
	Note string
	// contains filtered or unexported fields
}

Theme is a mode and a scheme together: every color that a chart uses.

func New

func New(m Mode, s Scheme) Theme

New returns the theme of a mode and a scheme. A scheme without its own dark colors lifts each light color for the dark mode, and a scheme with fewer than ten colors gets the rest mixed toward the text color. A neutral that the scheme brings for the mode replaces that of the mode.

func (Theme) Config

func (t Theme) Config() map[string]any

Config returns the theme as a Vega config (D14): the defaults of each kind of mark, in the colors of the theme and with the rules of the marks of docs/STYLE.md, and the styles that the compiler of Vega-Lite names. The config of a spec goes over it, and the encoding of a mark goes over both. Each call returns a new value, which the caller owns.

func (Theme) Diverging added in v0.7.5

func (t Theme) Diverging(v float64) string

Diverging returns the color at v, from 0 to 1, on the diverging ramp of the theme. The ramp runs from the color of a fall through the grid color to the color of a rise.

func (Theme) Mode

func (t Theme) Mode() Mode

Mode returns the mode of the theme.

func (Theme) Sequential

func (t Theme) Sequential(v float64) string

Sequential returns the color at v, from 0 to 1, on the sequential ramp of the theme. The ramp starts at a tint of the first color, RampStart of the way from the background, and runs through a tint halfway from there to the first color, then through the first color, so that it reads in both modes. It runs on to a lighter color on a dark background, and to a darker color on a light one. A caller that draws another background, such as the background of a spec, sets Background first (D35, D48).

func (Theme) Tint added in v0.8.0

func (t Theme) Tint(c string) string

Tint returns the solid tint of a color: the color mixed into the background at NodeTint, with no opacity, so that it reads the same over a panel as over the background (D55).

Jump to

Keyboard shortcuts

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