layout

package
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: Sep 4, 2026 License: MIT Imports: 2 Imported by: 0

Documentation

Overview

Package layout decides where the plot area, titles and legend go.

v0.1 implements exactly one arrangement: a single Cartesian panel with axes on the left and bottom, an optional title above, and an optional legend to the right. It sizes everything by measuring the real text with the real backend, so an axis whose labels are wide gets a wide margin and nothing is ever clipped by a guessed constant.

It is deliberately not a constraint solver. Faceting and multi-panel axis alignment are the v0.3 milestone; the seam this package presents — measure, then hand back rectangles — is what that solver will slot into, so callers will not have to change.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Chart

type Chart struct {
	// Canvas is the full drawing surface.
	Canvas ir.Rect
	// Theme supplies sizes, paddings and fonts.
	Theme theme.Theme

	// Title is the chart title, or "" for none.
	Title string
	// XTitle and YTitle are axis titles, or "" for none.
	XTitle, YTitle string

	// XLabels and YLabels are the tick label texts. Only their measured
	// extents matter here; their positions are the scales' business.
	XLabels, YLabels []string

	// LegendLabels are the series names. An empty slice suppresses the legend.
	LegendLabels []string
}

Chart is everything layout needs to know about what will be drawn.

type Measurer

type Measurer interface {
	Measure(run ir.TextRun) ir.TextMetrics
}

Measurer is the text-measurement capability layout needs. Every backend provides it; taking the narrow interface rather than the whole backend keeps layout unable to draw anything by accident.

type Result

type Result struct {
	// Plot is the data area. Scales map into it.
	Plot ir.Rect
	// Title is the baseline anchor for the chart title, horizontally centred
	// on the plot area. Zero if there is no title.
	Title ir.Point
	// XTitle is the baseline anchor for the X axis title, centred on the plot
	// area. Zero if there is none.
	XTitle ir.Point
	// YTitle is the anchor for the Y axis title, centred on the plot area and
	// meant to be drawn rotated a quarter turn anticlockwise. Zero if there is
	// none.
	YTitle ir.Point
	// Legend is the rectangle reserved for the legend, empty if there is none.
	Legend ir.Rect
	// TickLabelPad is the distance from the axis to the near edge of a tick
	// label, copied from the theme so the renderer does not re-derive it.
	TickLabelPad float32
}

Result is where everything goes, in device space.

func Compute

func Compute(c Chart, m Measurer) Result

Compute lays out a chart.

Jump to

Keyboard shortcuts

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