geom

package
v0.1.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: 8 Imported by: 0

Documentation

Overview

Package geom holds the visual marks a chart is made of.

A geom knows what its shape is and never how it is rendered: it reads columns, asks the scales where values go, and emits IR. It has no reference to a backend, no knowledge of SVG or raster, and no opinion about layout beyond the rectangle it is given.

Index

Constants

This section is empty.

Variables

View Source
var ErrNoColumn = errors.New("refract/geom: column not found")

ErrNoColumn reports a column named by an option that the source does not have. It is returned rather than panicking because the column name usually comes from user input or a config file.

Functions

This section is empty.

Types

type Frame

type Frame struct {
	// Area is the plot rectangle in device space. Scales already map into it.
	Area ir.Rect
	// X and Y are the trained, ranged scales.
	X, Y scale.Scale
	// Theme supplies defaults the geom did not override.
	Theme theme.Theme
	// Index is the geom's position among the chart's layers, used to pick a
	// default colour from the palette.
	Index int
}

Frame is everything a geom needs to turn data into IR.

type Geom

type Geom interface {
	// Train feeds the geom's data into the scales so they can establish their
	// domains. It runs before layout, because layout needs tick labels and
	// tick labels need a domain.
	Train(x, y scale.Scale) error

	// Build emits the geom's marks into b.
	Build(b ir.Backend, f Frame) error

	// Legend returns the entry this geom contributes, or ok == false if it
	// should not appear in the legend.
	Legend(f Frame) (LegendEntry, bool)
}

Geom is a layer of marks.

func Bar

func Bar(src data.Source, opts ...Option) Geom

Bar draws a rectangle per row, from a baseline to the row's Y value.

func Line

func Line(src data.Source, opts ...Option) Geom

Line connects consecutive rows with a stroked path.

func Scatter

func Scatter(src data.Source, opts ...Option) Geom

Scatter draws one marker per row.

type LegendEntry

type LegendEntry struct {
	Label  string
	Color  ir.Color
	Kind   SwatchKind
	Marker ir.Marker
	Dash   []float32
	Width  float32
}

LegendEntry is a geom's contribution to the legend.

type Missing

type Missing uint8

Missing is the policy for NaN and infinite values in a column.

const (
	Gap Missing = iota
	Interpolate
	Error
)

The missing-data policies. Gap is the default: a hole in the data should look like a hole, not like a straight line someone might read as real.

type Option

type Option func(*config)

Option configures a geom. Options are shared across geom constructors: an option a given geom has no use for is accepted and ignored, which keeps the API one namespace instead of six.

func BarWidth

func BarWidth(f float64) Option

BarWidth sets bar width as a fraction of the spacing between adjacent bars, in (0, 1]. The default is 0.8.

func Baseline

func Baseline(v float64) Option

Baseline sets the value bars grow from. The default is 0.

func Color

func Color(col ir.Color) Option

Color sets the mark colour, overriding the palette.

func Dash

func Dash(pattern ...float32) Option

Dash sets a dash pattern in device units. Dashing a series is redundant encoding: it keeps the chart readable in greyscale and for colourblind readers.

func Fill

func Fill(col ir.Color) Option

Fill sets a fill colour separately from the stroke colour, for geoms that have both.

func Label

func Label(s string) Option

Label names the series in the legend. It defaults to the Y column's name.

func OnMissing

func OnMissing(m Missing) Option

OnMissing sets the NaN/Inf policy.

func Shape

func Shape(m ir.Marker) Option

Shape sets the marker shape for scatter geoms.

func Size

func Size(s float32) Option

Size sets the marker diameter in device units.

func Tension

func Tension(t float64) Option

Tension smooths a line. 0 (the default) is a plain polyline; values in (0, 1] progressively round the corners using a Catmull-Rom spline.

func Width

func Width(w float32) Option

Width sets the stroke width in device units.

func X

func X(col string) Option

X selects the column mapped to the horizontal axis.

func Y

func Y(col string) Option

Y selects the column mapped to the vertical axis.

type SwatchKind

type SwatchKind uint8

SwatchKind is how a legend entry draws its sample.

const (
	SwatchLine SwatchKind = iota
	SwatchMarker
	SwatchBox
)

The swatch kinds.

Jump to

Keyboard shortcuts

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