Documentation
¶
Overview ¶
Package layout draws the guides of a chart in the look of zuzu: the axes, the legends and the titles (D12). It also measures the bounds of a scene, which the autosize of a spec reads. The rules of the look are in docs/STYLE.md. The view resolves each guide from the spec, and this package draws it.
Index ¶
Constants ¶
const ( // LabelSize is the size of a label of an axis or a legend. LabelSize = 11 // SmallSize is the size of the title of an axis or a legend. SmallSize = 10 // TitleSize is the size of the title of a chart. TitleSize = 16 // SubtitleSize is the size of a subtitle. SubtitleSize = 12.5 // LabelPad is the space between a label of an axis and the plot area. LabelPad = 8 // MaxLabels is the most labels that an axis of numbers has. MaxLabels = 6 )
The sizes of the type of docs/STYLE.md.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Axis ¶
type Axis struct {
// Orient is top, bottom, left or right.
Orient string
Scale scale.Scale
// Length is the size of the plot area along the axis, and Cross the
// size across it, which the grid lines span.
Length, Cross float64
// Values are the values of the ticks, or nil for those of the scale.
Values []any
// Count is the number of ticks the spec asks for, or 0.
Count float64
// Format writes the label of a value.
Format func(any) string
// Grid, Labels and Domain say which parts the spec asks for. A domain
// line is drawn only along a band axis.
Grid, Labels, Domain bool
Title string
// LabelAngle turns the labels, in degrees.
LabelAngle float64
// Overlap drops every other label, in turns, until no two overlap.
Overlap bool
// Offset moves the axis away from the plot area.
Offset float64
// BandPosition is where in a band a tick sits, from 0 to 1.
BandPosition float64
// LabelFlush is the distance from an end of the axis within which a
// label aligns flush with that end, so that it stays inside the axis,
// or a negative number for none.
LabelFlush float64
// LabelLimit is the widest that a label draws, in pixels, before it is
// cut with an ellipsis, or 0 for no limit.
LabelLimit float64
}
Axis is an axis, with the settings that the view resolved from the spec.
type Bounds ¶
type Bounds struct {
X1, Y1, X2, Y2 float64
}
Bounds is a box: the least and the greatest x and y.
type Legend ¶
type Legend struct {
Fill, Stroke, Shape, Size scale.Scale
Title string
// Values are the values of the entries, or nil for those of the scale.
Values []any
// Format writes the label of a value.
Format func(any) string
// Width is the width that a row of entries can fill before it wraps.
Width float64
// Line draws each entry as a short line, for a line chart.
Line bool
// Gradient draws a continuous color scale as a bar, rather than as
// entries.
Gradient bool
// GradientLength is the length of the bar.
GradientLength float64
// Direction is horizontal or vertical. A vertical legend draws its
// entries in one column, and its gradient upright.
Direction string
// Columns is the number of columns of the entries. 0 draws them in one
// row that wraps at Width, or in one column for a vertical legend.
Columns int
}
Legend is a legend, with the settings that the view resolved from the spec. It draws the first of its scales that it has: the fill, the stroke, the shape or the size.
type Style ¶
Style is what a guide draws with: the colors of the theme, the font and the measure of text.
func (Style) Axis ¶
Axis draws an axis as a group of the role axis, with its grid, its labels, its base line and its title. The group sits at the origin of the plot area.
func (Style) ItemBounds ¶
ItemBounds returns the bounds of an item of a kind of mark, in the coordinates of the group that holds it.
func (Style) Legend ¶
Legend draws a legend as a group of the role legend, at the origin: its title, then a row of entries that wraps, or a gradient bar.
func (Style) MarkBounds ¶
MarkBounds returns the bounds of the items of a mark, in the coordinates of the group that holds it.
type Title ¶
type Title struct {
Text []string
Subtitle []string
// Orient is top, bottom, left or right.
Orient string
// Anchor is start, middle or end.
Anchor string
// Width and Height are the size of the plot area that the title names.
Width, Height float64
// Offset is the space between the title and what it names.
Offset float64
// Kind is title for the title of a chart, label for a header of a
// facet, and small for the title of a guide in a facet.
Kind string
}
Title is a title, with the settings that the view resolved from the spec.