layout

package
v0.7.2 Latest Latest
Warning

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

Go to latest
Published: Nov 15, 2026 License: MIT Imports: 10 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 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

View Source
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.

func (*Axis) TickCount added in v0.7.2

func (a *Axis) TickCount() float64

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.

type Bounds

type Bounds struct {
	X1, Y1, X2, Y2 float64
}

Bounds is a box: the least and the greatest x and y.

func Empty

func Empty() Bounds

Empty returns bounds that hold nothing, which any point grows.

func (Bounds) IsEmpty

func (b Bounds) IsEmpty() bool

IsEmpty reports whether the bounds hold nothing.

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
	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, the size or the dash.

type Style

type Style struct {
	Theme   theme.Theme
	Font    string
	Measure text.Measurer
}

Style is what a guide draws with: the colors of the theme, the font and the measure of text.

func (Style) Axis

func (s Style) Axis(a *Axis) scene.Mark

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

func (s Style) ItemBounds(typ string, it *scene.Item) Bounds

ItemBounds returns the bounds of an item of a kind of mark, in the coordinates of the group that holds it.

func (Style) Legend

func (s Style) Legend(l *Legend) scene.Mark

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

func (s Style) MarkBounds(m *scene.Mark) Bounds

MarkBounds returns the bounds of the items of a mark, in the coordinates of the group that holds it.

func (Style) TextSize

func (s Style) TextSize(it *scene.Item) (float64, float64)

TextSize returns the width and the height of the text of an item, as the writer draws it.

func (Style) Title

func (s Style) Title(t *Title) scene.Mark

Title draws a title as a group of the role title, with the title and the subtitle. The title of a chart is at the top left, above the plot area.

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.

Jump to

Keyboard shortcuts

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