plot

package
v0.1.9 Latest Latest
Warning

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

Go to latest
Published: Oct 9, 2026 License: MIT Imports: 14 Imported by: 0

README

ui/plot

English | 简体中文

Exposed custom chart basics: continuous/categorical scales, positive and negative stacking, pie chart layout, and columns, lines, areas, arcs, points, guides, and axes on the clipped canvas.

Directly depends on ui/core (drawing context), ui/theme (axis font), and indirectly depends on ui/internal/loop. Does not reference kit, el, window, or native; currently used by the app and component library examples, existing kit diagrams are not migrated to this package.

The numerical layout has no mutable global state, and the current frame Canvas is used for drawing. The application is responsible for colors, size conversions, interactions, prompts, and accessible data descriptions. See Public Drawing Basics for complete instructions.

Documentation

Overview

Package plot provides scales, data layouts and immediate-mode chart drawing. Shapes use local pixel coordinates; applications own data, interaction and accessible descriptions. kit.Plot and kit.Chart provide complete chart views.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Stack

func Stack(series [][]float64) ([][]StackValue, error)

Stack lays out series-major values. Positive and negative totals accumulate separately from zero. NaN represents a missing sample; infinities and total overflow fail atomically. Input slices are never retained.

Types

type Arc

type Arc struct {
	Center       f32.Point
	Inner, Outer float32
	Start, End   float64
	Fill         color.NRGBA
}

Arc paints a pie or donut sector. Radii are nonnegative pixels and inner must not exceed outer. The sampled outline includes exact angular endpoints.

func (Arc) Paint

func (a Arc) Paint(c Canvas)

type Area

type Area struct {
	Upper, Lower []f32.Point
	Fill, Stroke color.NRGBA
	Width        float32
	Curve        Curve
}

Area fills between matching upper and lower boundaries. Invalid pairs split the polygon. Both slices must have equal length; neither is retained.

func (Area) Paint

func (a Area) Paint(c Canvas)

type Axis

type Axis struct {
	Side                          AxisSide
	At, From, To, TickSize, Width float32
	Ticks                         []AxisText
	Stroke, TextColor             color.NRGBA
	TextSize                      unit.Sp
}

Axis paints a baseline, ticks and labels in a local canvas. At is Y for horizontal axes and X for vertical axes. Labels are clipped to Canvas bounds; reserve margins there. TextSize is sp; geometry and stroke width are pixels.

func (Axis) Paint

func (a Axis) Paint(c Canvas)

type AxisSide

type AxisSide uint8
const (
	AxisBottom AxisSide = iota
	AxisTop
	AxisLeft
	AxisRight
)

type AxisText

type AxisText struct {
	Position float32
	Text     string
}

type Bar

type Bar struct {
	Rect   Rectangle
	Fill   color.NRGBA
	Radius float32
}

func (Bar) Paint

func (b Bar) Paint(c Canvas)

type Canvas

type Canvas struct {
	Context core.C
	Bounds  image.Rectangle
}

Canvas clips every primitive to Bounds and translates local pixels to its origin. Construct it during Layout; do not retain it across frames.

type CrossLine

type CrossLine struct {
	At                   f32.Point
	Horizontal, Vertical bool
	Stroke               color.NRGBA
	Width                float32
}

CrossLine draws optional horizontal/vertical guides through At.

func (CrossLine) Paint

func (x CrossLine) Paint(c Canvas)

type Curve

type Curve uint8
const (
	CurveLinear Curve = iota
	CurveStepAfter
	CurveSmooth
)

type Dot

type Dot struct {
	At     f32.Point
	Radius float32
	Fill   color.NRGBA
}

func (Dot) Paint

func (d Dot) Paint(c Canvas)

type Line

type Line struct {
	Points           []f32.Point
	Stroke           color.NRGBA
	Width, DotRadius float32
	Curve            Curve
}

Line splits at invalid points; dots use the original samples. Smooth uses a per-segment smoothstep interpolation and preserves both sample endpoints.

func (Line) Paint

func (l Line) Paint(c Canvas)

type PieSlice

type PieSlice struct {
	Index             int
	Value, Start, End float64
}

PieSlice retains the input index and value. Angles are radians, with zero on positive X; positive sweeps turn clockwise in screen coordinates.

func Pie

func Pie(values []float64, start, sweep, padding float64) ([]PieSlice, error)

Pie lays out positive values over a signed sweep of at most one revolution. Zeros are omitted. Negative/non-finite values fail atomically. Padding is a nonnegative angular gap, capped at the available angle per positive item.

type Rectangle

type Rectangle struct{ Min, Max f32.Point }

Bar paints a rectangle, including horizontal or negative bars supplied by the caller. Reversed rectangle corners are normalized. Radius is in pixels.

type ScaleBand

type ScaleBand[T comparable] struct {
	// contains filtered or unexported fields
}

ScaleBand owns a unique, insertion-ordered categorical domain. Map returns the low coordinate of each band even for descending ranges.

func NewBand

func NewBand[T comparable](domain []T, extent [2]float64) ScaleBand[T]

func (ScaleBand[T]) Align

func (s ScaleBand[T]) Align(f float64) ScaleBand[T]

func (ScaleBand[T]) Bandwidth

func (s ScaleBand[T]) Bandwidth() float64

func (ScaleBand[T]) Domain

func (s ScaleBand[T]) Domain() []T

func (ScaleBand[T]) Map

func (s ScaleBand[T]) Map(x T) (float64, bool)

func (ScaleBand[T]) Padding

func (s ScaleBand[T]) Padding(inner, outer float64) ScaleBand[T]

type ScaleLinear

type ScaleLinear struct {
	Domain, Range [2]float64
	Clamp         bool
}

ScaleLinear supports reversed domains/ranges. Equal domains map to the range midpoint. Invalid input or an unrepresentable extrapolation returns false.

func (ScaleLinear) Invert

func (s ScaleLinear) Invert(y float64) (float64, bool)

func (ScaleLinear) Map

func (s ScaleLinear) Map(x float64) (float64, bool)

func (ScaleLinear) Ticks

func (s ScaleLinear) Ticks(count int) []float64

Ticks returns evenly spaced domain values, including endpoints (2..1000). It preserves descending order and returns one tick for a constant domain.

type ScaleOrdinal

type ScaleOrdinal[K comparable, V any] struct {
	// contains filtered or unexported fields
}

ScaleOrdinal cycles a discrete range across a fixed domain. Missing keys and empty ranges return false; Map never extends the domain.

func NewOrdinal

func NewOrdinal[K comparable, V any](domain []K, values []V) ScaleOrdinal[K, V]

func (ScaleOrdinal[K, V]) Map

func (s ScaleOrdinal[K, V]) Map(x K) (V, bool)

type ScalePoint

type ScalePoint[T comparable] struct {
	// contains filtered or unexported fields
}

ScalePoint places categories on points; a singleton is centered.

func NewPoint

func NewPoint[T comparable](domain []T, extent [2]float64) ScalePoint[T]

func (ScalePoint[T]) Domain

func (s ScalePoint[T]) Domain() []T

func (ScalePoint[T]) Map

func (s ScalePoint[T]) Map(x T) (float64, bool)

func (ScalePoint[T]) Padding

func (s ScalePoint[T]) Padding(p float64) ScalePoint[T]

type StackValue

type StackValue struct {
	Series, Index int
	Low, High     float64
	Valid         bool
}

StackValue retains the source series/sample index. Missing samples are invalid.

Jump to

Keyboard shortcuts

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