Documentation
¶
Overview ¶
Package style says how a diagram looks, at three levels.
A Theme is the first: a handful of colors and measures every diagram is drawn from, as Pele's --pele-* variables are. A diagram's parts name its colors by Token (Surface, Border, Series(2)…) rather than by value, so a change of theme only redraws.
Overrides are the second: a Style for each role of the parts of diagrams, such as "flowchart.node" or "sequence.actor", that sets some of what the theme gives. Over them lies the style the diagram's author set in its text, with style and classDef lines and a palette, which a scene's items carry apart from the diagram's own. A Look that is ThemeOnly leaves it out, for a host that draws with its design tokens alone.
The third, drawing a part some way of one's own, belongs to the backends, as each draws with tools of its own; see the svg package.
What changes where things are — the font, the sizes of text — is not style: it is given to layout, and a change of it lays the diagram out again.
Index ¶
Constants ¶
This section is empty.
Variables ¶
var ( None = Paint{/* contains filtered or unexported fields */} Bg = Paint{/* contains filtered or unexported fields */} Fg = Paint{/* contains filtered or unexported fields */} Muted = Paint{/* contains filtered or unexported fields */} Line = Paint{/* contains filtered or unexported fields */} Surface = Paint{/* contains filtered or unexported fields */} SurfaceAlt = Paint{/* contains filtered or unexported fields */} Border = Paint{/* contains filtered or unexported fields */} Accent = Paint{/* contains filtered or unexported fields */} Critical = Paint{/* contains filtered or unexported fields */} )
The colors of the theme, and None, which draws nothing.
var Solid = Dash{nil, true}
Solid is a line with no gaps.
Functions ¶
This section is empty.
Types ¶
type Cap ¶
type Cap uint8
A Cap is how the ends of a stroked line are drawn, as SVG's stroke-linecap: the ends of a line and of each of its dashes. The zero Cap is unset, and takes what is under it; a line nothing sets one for ends flat, as SVG's do.
type Color ¶
type Color struct{ R, G, B, A uint8 }
A Color is a color in sRGB with straight alpha.
func Hex ¶
Hex is the color #rgb, #rgba, #rrggbb or #rrggbbaa writes; it panics on anything else, so it is for colors written in code. ParseColor reads them from text.
func ParseColor ¶
ParseColor reads a CSS color: a hex color, rgb() or rgba(), hsl() or hsla(), a named color or transparent, with the white space of CSS about it, its names in either case of their ASCII letters. A hue may be in degrees, gradians, radians or turns, and a channel none, which is 0. It reports false for anything else, such as currentColor or var().
type Dash ¶
type Dash struct {
// contains filtered or unexported fields
}
A Dash is the pattern of a line's dashes and gaps, or a solid line, or unset.
type Join ¶
type Join uint8
A Join is how a stroked line turns its corners, as SVG's stroke-linejoin. The zero Join is unset, and takes what is under it; a line nothing sets one for turns its corners mitred, as SVG's do.
const ( // JoinMiter turns a corner in a point where the line's sides meet, or bevelled where // SVG's miter limit of 4 would: where the point is more than four times half the line's // width from the corner. JoinMiter Join = iota + 1 JoinRound // an arc about the corner JoinBevel // straight across, from one side's end to the other's )
type Look ¶
type Look struct {
Theme *Theme // nil is Default
Overrides Overrides
// ThemeOnly draws a scene with the theme and the overrides alone, leaving out all that
// the diagram's author set for painting: the style the author gave each part, a
// palette's colors among it, the colors picked for what lies on a fill the author set,
// and the casings drawn about the lines inside such a fill. A host sets it to keep a
// look its design tokens restrict. It moves nothing: the size, weight and slant of text
// the author set stay, as the layout measured them.
ThemeOnly bool
}
A Look is a theme and the overrides on it: all of style a backend is given.
func (*Look) Cascade ¶
Cascade is the style of a part of a role: the theme's measures under the diagram's own style for the part, under the overrides for its role, under the style its author gave it in the diagram's text. Text is written in Fg unless something sets another paint. Where the look is ThemeOnly, the author's style is left out, and so are the part's Ground and TextGround, which a diagram sets only on a fill the author set.
func (*Look) Draws ¶ added in v0.5.0
Draws reports whether a backend draws the parts of a role: all but the casings, the roles ending in ".casing", where the look is ThemeOnly, since a diagram draws a casing only about a line inside a fill the author set.
func (*Look) Shade ¶ added in v0.4.0
Shade is what a part painted scene.Shade is filled with, before the opacity a backend lays it at over a fill the author sets: the theme's Bg, or, on a fill the author sets that ink picks a color on, the other of Fg and Bg, the one that stands out less on the fill, as Pele 1.12 keeps an entity's stripes light on a light fill and dark on a dark one. It reports whether it was picked on a fill. A fill an override sets leaves the shade the theme's Bg, since the backend lays a shade at an opacity only over a fill the author sets. Where the look is ThemeOnly, the shade is the theme's Bg, as for a part its author set no fill on.
func (*Look) ThemeOrDefault ¶
ThemeOrDefault is the look's theme, or Default when it has none. The default is shared: to change it, change a copy.
type Num ¶
type Num struct {
// contains filtered or unexported fields
}
A Num is a measure that may be unset, and then takes what is under it.
type Overrides ¶
Overrides give styles to the roles of diagrams' parts, as "flowchart.node", by the names of scene.Role.
type Paint ¶
type Paint struct {
// contains filtered or unexported fields
}
A Paint is what a part is filled, stroked or written with: a color of the theme, a color of its own, or nothing. The zero Paint is unset, and takes what is under it.
func (Paint) Color ¶
Color is the color the paint draws with in a theme; its alpha is 0 when it draws nothing.
func (Paint) Over ¶
Over is the paint laid over a color of the theme: an opaque color, the paint's color at its opacity mixed into base's, as CSS's color-mix does in sRGB. It is for what must hide what is under it in the color it would seem to have there: a title's halo over a group.
type Resolved ¶
type Resolved struct {
// Fill and Stroke are at the style's fill and stroke opacities; alpha 0 draws nothing.
Fill, Stroke, Text Color
// Marker is the stroke's color without the stroke opacity, which markers are filled
// with, as Pele fills them in the color of the line alone.
Marker Color
Line Color // the theme's color of lines, for parts painted solid
Bg Color // the theme's background
Shade Color // for parts painted shade, as Look.Shade picks it
Hollow Color // the theme's background, or the ground, for parts painted hollow
StrokeWidth float64
Radius float64
Dash []float64 // none for a solid line
Cap Cap // CapButt when nothing set it, as SVG's initial value
Join Join // JoinMiter when nothing set it, as SVG's initial value
Opacity float64
Halo Color // alpha 0 draws none
HaloWidth float64
}
Resolved is a style with its colors and measures settled, ready to draw.
type Style ¶
type Style struct {
Fill Paint
Stroke Paint // outlines and lines, and the markers at their ends
Text Paint
// FillOpacity and StrokeOpacity are the opacities the fill and the stroke are drawn at,
// from 0 to 1, as SVG's fill-opacity and stroke-opacity: apart from the paints, so that
// each is laid over what is under it on its own, as CSS cascades them. A fill the author
// sets over a part the diagram draws at an opacity is drawn at that opacity. They do not
// reach the part's text, and markers are filled in the stroke's color without its
// opacity and stroked with it, as Pele draws them.
FillOpacity Num
StrokeOpacity Num
StrokeWidth Num
Radius Num // of the corners of a box that takes the theme's
// MaxRadius caps the theme's radius where no level sets one, as a treemap's small boxes
// are rounded by min(var(--_r), cap) in Pele.
MaxRadius Num
Dash Dash
Cap Cap // of the ends of lines and of their dashes
Join Join // of the corners of lines and outlines
Opacity Num // of the whole part
// Halo is drawn about the letters of the part's text, HaloWidth wide, so that lines
// under the text stop short of it: the title of a group an edge runs through.
Halo Paint
HaloWidth Num
// OnFill says that the part's text is set on its fill. Where an override or the part's
// author sets a fill over the diagram's own, and neither sets a color for the text, the
// text is drawn in the theme's Fg or Bg, whichever stands out more against that fill, as
// Pele's ink picks a color for a label on a fill a style sets. A diagram sets it on the
// parts whose labels Pele draws so.
OnFill bool
// Ground is the fill under the part where it lies inside a fill its author sets on
// another part, as an edge inside a group with a fill of its own. Unless an override or
// the part's author sets them, the part's stroke and text are drawn in the theme's Fg or
// Bg, whichever stands out more against the ground, as Pele draws an edge or a label
// inside one fill in the color of that fill's labels, and what it paints Hollow is filled
// with the ground, as Pele's hollowOn fills a marker. A diagram sets it only on a fill ink
// can pick a color on.
Ground Paint
// TextGround is the fill under the part's text alone, where the text lies inside a fill
// its author sets on another part and the rest of the part keeps its own colors, as the
// name under a sequence diagram's figure in a box. Unless an override or the part's
// author sets one, the text is drawn in the theme's Fg or Bg, whichever stands out more
// against it. A diagram sets it only on a fill ink can pick a color on.
TextGround Paint
}
A Style is how a part is painted. What it leaves unset comes from under it.
type Theme ¶
type Theme struct {
Bg Color // behind the diagram, and behind labels on lines
Fg Color // text
Muted Color // secondary text, as the titles of groups
Line Color // edges and other lines
Surface Color // the inside of shapes
SurfaceAlt Color // the inside of groups, and of shapes set apart
Border Color // the outlines of shapes
Accent Color // what a diagram marks out
Critical Color // what a diagram marks as critical
Series [8]Color
Radius float64 // of the corners of rounded boxes
StrokeWidth float64 // of outlines and lines
}
A Theme is the colors and measures diagrams are drawn with.
func Kohu ¶
func Kohu() *Theme
Kohu is limu's light theme, in the colors of limu kohu, the red limu of Hawaiʻi, in a tide pool: neutrals of the pool's teal, the limu's red for the accent, and amber for what is critical, so that it is not taken for the accent. The series are colors of algae.