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
- func Linear(typ string) bool
- type Axis
- type Bounds
- type Legend
- type Style
- func (s Style) Axis(a *Axis) scene.Mark
- func (s Style) ClearTitles(marks []scene.Mark, axes []*Axis)
- func (s Style) ItemBounds(typ string, it *scene.Item) Bounds
- func (s Style) Legend(l *Legend) scene.Mark
- func (s Style) MarkBounds(m *scene.Mark) Bounds
- func (s Style) TextSize(it *scene.Item) (float64, float64)
- func (s Style) Title(t *Title) scene.Mark
- type Title
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 line of the // axis by default: a tick and the padding of a label (D46). LabelPad = theme.TickSize + theme.LabelPadding // 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 ¶
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
// MinStep is the least step between two ticks that the spec asks for,
// in the units of the domain, which are milliseconds for times, or 0.
MinStep float64
// EndTicks chooses a step of the ticks that lands on both ends of a
// nice domain, for an axis whose spec gives no tickCount and no values
// (D46).
EndTicks bool
// Format writes the label of a value.
Format func(any) string
// Grid, Labels, Domain and Ticks say which parts the spec asks for:
// the grid lines, the labels, the line of the axis and its ticks.
Grid, Labels, Domain, Ticks bool
// TickSize is the length of a tick, from the line of the axis away
// from the plot area. A tick of 0 or less draws nothing.
TickSize float64
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 grid line sits, from 0 to 1. A
// label stays in the middle of its band.
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
// LabelAlign is the align of each label that the spec gives, over the
// align of the look, the angle and the flush. It is "" for none.
LabelAlign string
// TitleX and TitleY place the title from the origin of the axis, as the
// spec gives them, or are nil for the place of the look. The origin is
// where the line of the axis starts, at the offset of the axis.
TitleX, TitleY *float64
// TitleAngle turns the title, in degrees, or is nil for no turn.
TitleAngle *float64
// TitleAlign and TitleBaseline are the align and the baseline of the
// title that the spec gives, or "" for those of the look.
TitleAlign, TitleBaseline string
// LabelPadding is the distance between the labels and the end of the
// ticks that the spec gives, or nil for the padding of the look. It
// can be below 0, which puts the labels inside the plot area.
LabelPadding *float64
// LabelOffset moves each label along the axis, in pixels.
LabelOffset float64
// LabelBaseline is the baseline of each label that the spec gives, over
// the baseline of the look, the angle and the flush. It is "" for none.
LabelBaseline string
// TitleAnchor is start, middle or end: the point of the range of the
// scale at which the title sits, as the spec gives it. It is "" for the
// place of the look.
TitleAnchor string
// TitlePadding is the space between the labels and the title that the
// spec gives, or nil for the space of the look.
TitlePadding *float64
}
Axis is an axis, with the settings that the view resolved from the spec.
func (*Axis) PlacedByLook ¶ added in v0.8.0
PlacedByLook reports whether the look places the title of the axis: the spec gives no titleX, titleY, titleAngle, titleAnchor or titleBaseline, which win over the place of the look (D46).
func (*Axis) TickCount ¶ added in v0.7.2
TickCount returns the number of ticks that the axis asks its scale for: the count of the spec, or one each 40 pixels. A scale of numbers has no more than MaxLabels ticks.
func (*Axis) TickStep ¶ added in v0.8.0
TickStep returns the step whose precision the labels of the ticks of a scale of numbers from lo to hi need.
func (*Axis) TickValues ¶ added in v0.8.0
TickValues returns the values of the ticks of the axis: the values of the spec, the ticks of its scale, or the ticks that land on both ends of the domain when the axis asks for them.
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
// StrokeDash is the scale of the dashes, whose entries are short lines.
StrokeDash scale.Scale
// StrokeWidth is the scale of the widths of lines, whose entries are
// short lines, and Opacity the scale of the opacity of the symbols.
StrokeWidth, Opacity 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, and GradientThickness its
// width. 0 takes the length or the width of the look.
GradientLength, GradientThickness 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
// ClipHeight cuts each symbol to this height about its center, and
// sets the height of each row. 0 cuts no symbol.
ClipHeight float64
// SymbolLimit is the most entries that the legend draws. The last of
// them counts the values that do not fit. 0 takes the limit of the
// look.
SymbolLimit int
// LabelLimit is the widest that a label draws before an ellipsis cuts
// it. 0 takes the limit of the look.
LabelLimit float64
// SymbolType is the shape of a symbol that no scale shapes, and
// SymbolSize is the area of a symbol that no scale sizes. Empty and 0
// take the symbols of the look.
SymbolType string
SymbolSize float64
// Hollow draws each symbol as an outline with no fill, as the marks
// that the legend names draw.
Hollow bool
// Color is the color of the symbols of a legend with no scale of color,
// or empty for the first categorical color.
Color string
// LineValues holds the values, written as strings, whose marks are
// lines, and whose symbols are short lines.
LineValues map[string]bool
// RowPadding and ColumnPadding are the space between two rows and
// between two columns of entries. nil takes the space of the look.
RowPadding, ColumnPadding *float64
// Entries draws a legend of sizes alone as entries, never as nested
// circles, because the spec sets a property of its entries, such as
// its direction.
Entries bool
}
Legend is a legend, with the settings that the view resolved from the spec. Its entries take their values from the first of its scales that it has, in the order of Vega: the size, the shape, the fill, the stroke, the dash, the width of the stroke or the opacity.
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) ClearTitles ¶ added in v0.8.0
ClearTitles moves the title of each axis that the look places away from the plot area until it covers no label of any of the axes, and no title before it, so that a title never covers a label (D46). Such a covered label is of an axis across, such as an axis at the top under the title of a vertical axis, which sits above the plot area. The title of a vertical axis and of an axis at the top moves up, and the title of an axis at the bottom moves down. marks are the marks that Axis drew for axes, in the same order, and a nil axis keeps its title where it is.
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
// Angle, when it is not nil, turns the text by that many degrees in
// place of the turn of the side. Align and Baseline, when they are not
// empty, place the text in place of the anchor and the side.
Angle *float64
Align, Baseline string
}
Title is a title, with the settings that the view resolved from the spec.