plot

package
v0.3.0 Latest Latest
Warning

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

Go to latest
Published: Nov 23, 2026 License: Apache-2.0 Imports: 9 Imported by: ? modules, 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

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type AppearScope

type AppearScope struct {
	// ID is what the scope remembers for, a comparable value: when it
	// changes the scope forgets, and the plots in it draw in afresh.
	ID        func() any
	Class     string
	Style     core.Style
	StyleFunc func() core.Style
	Children  []core.Node
}

AppearScope remembers which plots inside it have finished appearing, as gpui-base's PlotAppearScope, so a plot made again after a gap, a row a list scrolled out of its window and back, shows its marks whole at once instead of drawing in again.

A plot is remembered by its AppearGeneration once its appear has finished: give each row's plot its own. A new generation still replays the appear, and one taken away before its appear finished draws in again from the start; once a plot finishes a new generation, its last one is forgotten. The memory lasts while the scope lives, and a new ID forgets it. The innermost scope is the one a plot remembers in.

func (AppearScope) Render

func (a AppearScope) Render(cx *core.Scope) core.Node

Render implements core.Node.

type Arc

type Arc struct {
	// StartAngle and EndAngle are a Pie's, 0 and a whole turn without them.
	StartAngle, EndAngle func() float32
	// InnerRadius and OuterRadius are a Pie's.
	InnerRadius, OuterRadius func() core.Length
	// CornerRadius rounds its corners; half the thickness gives round caps.
	// A whole ring has none.
	CornerRadius core.Points
	Class        string
	Style        core.Style
	StyleFunc    func() core.Style
	TestID       string
}

Arc is an arc of a Plot, as gpui-base's Arc: the sector from StartAngle to EndAngle around the plot's center, between InnerRadius and OuterRadius; a gauge's track and its value, or a ring behind a pie. It fills with its Fill, the text color where none is set, and strokes with its Stroke, none where none is set, as CSS inherits them from the plot, and sweeps in from StartAngle with the plot's appear; when its angles or radii change it moves to the new ones with Motion.Update, so a gauge sweeps round to its new value. It is a shape, not a row: the pointer over it finds nothing.

func (Arc) Render

func (a Arc) Render(cx *core.Scope) core.Node

Render implements core.Node.

type Area

type Area struct {
	// Y1 makes its top edge, one value per row; the plot's Y without.
	Y1 func() []float64
	// X gives it rows of its own, as a Line's.
	X func() []float64
	// Y0 is the value of its baseline on the y scale; without it or Lows,
	// the end of the y scale where its smallest values are: the bottom edge,
	// the top one when the scale is reversed.
	Y0 func() float64
	// Lows is a bottom value per row, in place of Y0: a day's low to its
	// high, a forecast's fan. A row without one is skipped.
	Lows func() []float64
	// Scale is the y scale its edges go along.
	Scale ValueScale
	Curve Curve
	// Color is the category of its rows, as a Line's; its Fill where
	// nothing sets one.
	Color func() []string
	// BackgroundStyle's Background and Gradients fill a box around its
	// shape, from its first point to its last and from its highest point
	// to its baseline, shown only inside the shape, under its Fill, as
	// CSS's clip-path shows a box's background: a gradient that fades out
	// toward the baseline.
	BackgroundClass     string
	BackgroundStyle     core.Style
	BackgroundStyleFunc func() core.Style
	// HoverDotStyle merges over the plot's DotStyle for its hover dot, and
	// HoverDotClass follows its DotClass; a DisplayNone shows none, as for
	// an area under a line with its own.
	HoverDotClass     string
	HoverDotStyle     core.Style
	HoverDotStyleFunc func() core.Style
	// Style is its paint: Fill, and Stroke, StrokeWidth and StrokeDash for
	// its top edge.
	Class     string
	Style     core.Style
	StyleFunc func() core.Style
	TestID    string
}

Area is a series of a Plot drawn as the region between its line and a baseline, as gpui-base's Area: its top edge goes through its points as a Line's does and it closes down to Y0, or with Lows along a bottom edge through those values with the same curve, a band (d3's area().y0). It fills with its Fill (inherited from the plot), the text color where none is set or with Color its category's, over its background (BackgroundStyle's Background and Gradients, shown inside its shape only; Fill is then none where none is set), and strokes its top edge with its Stroke, none where none is set. Its values and baseline make the y scale's domain when the plot has none; it has a hover dot when it or the plot styles one, and draws in with the plot's appear.

func (Area) Render

func (a Area) Render(cx *core.Scope) core.Node

Render implements core.Node.

type Axis

type Axis struct {
	Placement      AxisPlacement
	LabelPlacement AxisLabelPlacement
	// Scale is the y scale a left or right axis carries; a bottom or top
	// axis carries the x scale.
	Scale ValueScale
	// Ticks is about how many ticks it takes, as d3's axis.ticks: on a
	// linear scale d3's nice values inside the domain (10 without), on a
	// point or band scale this many rows spread evenly from the first to
	// the last (every row without).
	Ticks int
	// TickValues is the values of its ticks, in place of Ticks: values of
	// the scale, row indices on a point or band scale. Those outside the
	// scale's domain have no place and no tick.
	TickValues func() []float64
	// Format is the text of each tick, as d3's axis.tickFormat: without it,
	// the category of a band on a band scale of categories, else d3's
	// default, the value with the decimals the step between ticks needs,
	// thousands grouped.
	Format func(value float64, index int) string
	// LabelStyle styles its labels: a text per tick, its font, color and
	// padding (its distance from the edge) the app's.
	LabelClass     string
	LabelStyle     core.Style
	LabelStyleFunc func() core.Style
	// TickStyle styles its tick marks: a view per tick from the edge toward
	// its label, centered on the tick; none without a class or style.
	TickClass     string
	TickStyle     core.Style
	TickStyleFunc func() core.Style
	// LineStyle styles its line: a view along the whole edge on its labels'
	// side; none without a class or style.
	LineClass     string
	LineStyle     core.Style
	LineStyleFunc func() core.Style
}

Axis is an axis of a Plot, as gpui-base's PlotAxis and d3's axes: along one edge, ticks at values of the scale the edge carries (d3's nice values on a linear scale, rows on a point or band one), each with its label, laid out natively by the plot's layout: centered on its tick along the edge (along the x scale's, the first and last moved inward so no label passes the plot's ends; beside the y scale's, the plot keeping what a label near its top or bottom edge would pass it by inside it, so every label sits on its tick within the plot), and past the edge or along its inside. Its parts are the app's to style (the labels, the tick marks and the line), and only the labels show unless the app styles the others. It follows the plot's size and scales, and takes no pointer; screen readers hear the plot, not its labels.

func (Axis) Render

func (a Axis) Render(cx *core.Scope) core.Node

Render implements core.Node.

type AxisLabelPlacement

type AxisLabelPlacement uint8

AxisLabelPlacement is which side of its edge an Axis lays its labels on.

const (
	// LabelsOutside puts them past the plot's edge, in the room the app
	// leaves around the plot, as d3's axes sit in a chart's margins: they
	// never cover a mark.
	LabelsOutside AxisLabelPlacement = iota
	// LabelsInside puts them over the plot, along the inside of its edge,
	// so the plot keeps its whole size.
	LabelsInside
)

type AxisPlacement

type AxisPlacement uint8

AxisPlacement is the edge of a Plot an Axis runs along, as d3's axisBottom, axisTop, axisLeft and axisRight: the bottom and top edges carry the x scale's ticks, the left and right ones the y scale's.

const (
	AxisBottom AxisPlacement = iota
	AxisTop
	AxisLeft
	AxisRight
)

type Band

type Band struct {
	// Domain is the categories its bands stand for, in order: a Cell goes
	// in the band of its row's category and an Axis labels each band with
	// its category; one written twice keeps its first place. Without one,
	// the categories the plot's cells read along the axis, in the order
	// met, and without cells a band per row.
	Domain []string
	// PaddingInner is the gap between neighbouring bands, 0 to 1, and
	// PaddingOuter the gap before the first and after the last.
	PaddingInner, PaddingOuter float32
	// MaxBandWidth is the widest a band may be: a few bands across a wide
	// plot stay narrow, each in the middle of its place. 0 sets none.
	MaxBandWidth core.Points
	// BandCount is the bands the axis is laid out for when more than the
	// rows: the rows take the leading ones and keep their width and place
	// as rows come.
	BandCount int
	// GroupPadding is the gap between the bars side by side in a band, a
	// share of each bar's place.
	GroupPadding float32
}

Band says how a band scale lays its bands out, as d3's scaleBand: gaps are shares of a band's step.

type Bar

type Bar struct {
	// Value is what each bar shows; the plot's Y without. A row without a
	// value has no bar.
	Value func() []float64
	// Base is the value its bars grow from on the plot's value scale, 0
	// without it, so a negative value grows the other way. A stack grows
	// from its first bar's, row by row. It counts in the scale's domain.
	Base func() float64
	// Bases is a base per row, in place of Base: each bar is then a range
	// from its row's base to its value (a waterfall's step, a candle's body,
	// a task's span), a row without one having no bar.
	Bases func() []float64
	// Stack is the stack it joins: the bars of a plot with the same Stack
	// pile up in order, each row's starting where the one before it ends.
	// Bars in different stacks, or in none, stand side by side in each band.
	Stack string
	// Scale is the y scale its upright bars' values go along; a stack piles
	// only the bars on its scale. Bars across put their values along x.
	Scale ValueScale
	// Corners rounds its bars' corners; square by default.
	Corners Corners
	// Stagger is the share of the plot's appear, 0 to 0.95, over which its
	// bars start, row by row, each growing for the rest of it.
	Stagger float32
	// HoverDim is how much its bars away from the row under the pointer
	// fade, as a share of their opacity: handed from bar to bar as the hover
	// glides, with the hover's fade.
	HoverDim float32
	// Color is the category of each bar, which the plot's ColorScale gives
	// a color: the bar's Fill where nothing sets one.
	Color func() []string
	// Label is the text beside each bar, one per row, at its value end:
	// above an upright bar, below one that grows down, after a bar across
	// and before one that grows back. LabelStyle styles it: its size, color
	// and padding, its distance from the bar, are the app's.
	Label          func() []string
	LabelClass     string
	LabelStyle     core.Style
	LabelStyleFunc func() core.Style
	// BackgroundStyle's Background and Gradients fill each bar's box, shown
	// only inside the bar, from its base to its tip, as an Area's.
	BackgroundClass     string
	BackgroundStyle     core.Style
	BackgroundStyleFunc func() core.Style
	Class               string
	Style               core.Style
	StyleFunc           func() core.Style
	TestID              string
}

Bar is a series of a Plot drawn as bars, as gpui-base's Bar: one per row with a value, in the row's band of the plot's band scale (XScale for upright bars, YScale for bars across), from Base to the row's value on the other scale. Bars with the same Stack pile up; the others stand side by side in each band. It fills with its Fill (inherited from the plot), the text color where none is set or with Color each bar's category's, over its background (a gradient per bar; Fill is then none where none is set), its corners rounded by Corners. Its values and base count in the value scale's domain when the plot has none. With the plot's appear, its bars grow out of their base, one after another with Stagger; while the pointer is over the plot, the bars of other rows fade by HoverDim; both on the platform's frame clock, with no mark drawn again. Label writes a text at each bar's end. It shows no hover dot.

func (Bar) Render

func (b Bar) Render(cx *core.Scope) core.Node

Render implements core.Node.

type Cell

type Cell struct {
	// X and Y are the column and line of each row: the row's cell goes in
	// the band of that category. A row without one has no cell.
	X, Y func() []string
	// Value is the number of each cell, which a ramp of the plot's
	// ColorScale makes its color; a row without one then has no cell, or the
	// scale's Unknown color.
	Value func() []float64
	// Color is the category of each cell, which an ordinal ColorScale gives
	// a color.
	Color func() []string
	// Corners rounds its cells' corners; square by default.
	Corners Corners
	// Stagger and HoverDim are a Bar's.
	Stagger, HoverDim float32
	// Label is the text in each cell, centered, shown only where its
	// laid-out size fits inside the cell. LabelStyle styles it, and
	// DarkLabelStyle merges over it on a cell whose color is dark, where
	// light text reads better, as DarkLabelClass follows LabelClass.
	Label          func() []string
	LabelClass     string
	LabelStyle     core.Style
	LabelStyleFunc func() core.Style
	DarkLabelClass string
	DarkLabelStyle core.Style
	// HoverCellStyle styles a view as big as the cell under the pointer or
	// the keys, over it; none without a class or style.
	HoverCellClass     string
	HoverCellStyle     core.Style
	HoverCellStyleFunc func() core.Style
	Class              string
	Style              core.Style
	StyleFunc          func() core.Style
	TestID             string
}

Cell is a series of a Plot drawn as a rectangle per row, as Observable Plot's cell and Vega-Lite's rect over two band scales: heatmaps, correlation matrices, calendars of monthly returns. It goes in the band of its X category along the plot's x scale and of its Y category along its y scale, both band scales (the cells name their bands where a scale has no domain), filling the two bands, so the scales' paddings are the gaps between and around the cells. Its color is its row's of the plot's ColorScale: of its Value along a ramp, of its Color category, or its Fill where the app sets one, the text color where nothing does. Label writes a text in each cell, shown where it fits. The pointer finds the cell under it, or the nearest across a gap, which the plot reports and marks with the hover cell; the keys step across the grid and screen readers through the rows. With the plot's appear, its cells grow from their middles, one after another with Stagger; with Motion.Update a cell's color glides to its new one, new rows' cells grow in, those of rows that are gone shrink away and cells move to new bands; while one is hovered, the others fade by HoverDim.

func (Cell) Render

func (c Cell) Render(cx *core.Scope) core.Node

Render implements core.Node.

type ColorScale

type ColorScale struct {
	// contains filtered or unexported fields
}

ColorScale is the colors of a Plot's marks: a color per category, or the colors of numbers along a ramp, as d3's scaleOrdinal, scaleSequential and scaleDiverging. A mark's Color names each row's category; a Cell's Value and a Treemap's ColorValue are the numbers of a ramp. The zero value colors nothing.

func DivergingColors

func DivergingColors(colors ...core.Color) ColorScale

DivergingColors is SequentialColors about a pivot, 0 until Pivot says otherwise: the values below it take the ramp's first half and those above its second, so the pivot takes the middle color. Without a domain it is the values' extent made even on both sides of the pivot.

func OrdinalColors

func OrdinalColors(domain []string, colors ...core.Color) ColorScale

OrdinalColors gives domain's categories colors in order, repeating them over a longer domain. A category outside the domain takes Unknown's color; without one it joins the domain the first time a mark meets it (marks in order, rows in order) and takes the next color, as d3's implicit domain.

func SequentialColors

func SequentialColors(colors ...core.Color) ColorScale

SequentialColors places numbers along a ramp of colors, from the low end of the domain to the high one, the colors spread evenly and mixed in OKLab; values outside the domain take its ends.

func (ColorScale) Over

func (s ColorScale) Over(lo, hi float64) ColorScale

Over returns s with the ramp's ends at lo and hi, in place of the extent of the values it colors.

func (ColorScale) Pivot

func (s ColorScale) Pivot(p float64) ColorScale

Pivot returns s with its ramp's middle at p.

func (ColorScale) Unknown

func (s ColorScale) Unknown(c core.Color) ColorScale

Unknown returns s with c for a category outside its domain or a row without a number.

type Corners

type Corners struct {
	TopLeft, TopRight, BottomRight, BottomLeft core.Points
}

Corners is the radius of each corner of a mark's rectangles; a radius larger than half a rectangle is made to fit it, as a canvas's roundRect makes it fit.

func AllCorners

func AllCorners(r core.Points) Corners

AllCorners is one radius for every corner.

type Curve

type Curve uint8

Curve is how a Line or a Area connects its points, as gpui-base's Curve and d3's curve factories.

const (
	// CurveDefault is a mark's own: smooth for a Line and an Area, straight
	// for a RadialLine.
	CurveDefault Curve = iota
	// CurveNatural is a smooth curve through every point: cubic Béziers
	// through the neighbours' tangents.
	CurveNatural
	// CurveLinear is straight segments between points.
	CurveLinear
	// CurveStepAfter holds each value until the next point.
	CurveStepAfter
)

type Dot

type Dot struct {
	// Value is where each dot goes along the value axis; the plot's Y
	// without. A row without a value has no dot.
	Value func() []float64
	// R is the radius of every dot, 3 without it.
	R core.Points
	// Sizes is a value per row in place of R, which RScale makes a radius
	// (the value is the radius without one). A row whose value is missing
	// has no dot.
	Sizes  func() []float64
	RScale *RadiusScale
	// Stagger and HoverDim are a Bar's.
	Stagger, HoverDim float32
	// Color is the category of each dot, which the plot's ColorScale gives
	// a color: its Fill where nothing sets one.
	Color func() []string
	// HitRadius is how far past a dot's edge the pointer still finds it, 8
	// without it; of the dots within it, the one whose center is nearest
	// (Voronoi's cells), so a small bubble over a big one is found around
	// its own center.
	HitRadius core.Points
	// Scale is the y scale its values go along; dots across a band y scale
	// put their values along x.
	Scale ValueScale
	// HoverDotStyle styles its hover dot, a view as big as the dot under the
	// pointer, centered on it; the plot's DotStyle where none is set. There
	// is none where neither styles one.
	HoverDotClass     string
	HoverDotStyle     core.Style
	HoverDotStyleFunc func() core.Style
	Class             string
	Style             core.Style
	StyleFunc         func() core.Style
	TestID            string
}

Dot is a series of a Plot drawn as a dot per row, as Observable Plot's dot and Vega-Lite's point: at the row's place along the x axis and its Value along the y axis, or across, down a band y scale, its value along x. Its radius is R, one for every dot, or Sizes, one per row (a bubble chart, the area in proportion to a value with RScale), the bigger dots drawn first. It fills with its Fill (inherited from the plot), the text color where none is set or with Color each dot's category's, and strokes with its Stroke where one is set. Its values count in the value scale's domain when the plot has none. The pointer finds the dot whose center is nearest to it, among those within HitRadius of their edge, which the plot reports and marks with the hover dot, as big as that dot; the keys and screen readers step through the dots in the rows' order. With the plot's appear, its dots grow from nothing, one after another with Stagger; with Motion.Update they move to new values and sizes, new rows' dots grow in and the dots of rows that are gone shrink away; while one is hovered, the others fade by HoverDim.

func (Dot) Render

func (t Dot) Render(cx *core.Scope) core.Node

Render implements core.Node.

type Grid

type Grid struct {
	X, Y      func() []float64
	Scale     ValueScale
	Ticks     int
	Class     string
	Style     core.Style
	StyleFunc func() core.Style
	TestID    string
}

Grid is lines across a Plot, as gpui-base's Grid: vertical at the values X of its x scale (row indices on a point scale) and horizontal at the values Y of the y scale Scale names, from edge to edge, each on whole device pixels so a thin line stays sharp. With neither X nor Y, it follows the ticks of the scale the values go along, where an Axis of that scale puts them: about Ticks of them, or the axis's default ones, the aligned step of a dual-axis chart, so one grid serves both axes. It strokes with its paint style (Stroke, StrokeWidth, StrokeDash; inherited from the plot), the text color where none is set. Its values do not count in the domains, and each line moves with its scale's domain.

func (Grid) Render

func (g Grid) Render(cx *core.Scope) core.Node

Render implements core.Node.

type Label

type Label struct {
	Texts func() []PlotText
	// Scale is the y scale its texts' Y are values of.
	Scale     ValueScale
	Class     string
	Style     core.Style
	StyleFunc func() core.Style
}

Label is texts at points of a Plot, as gpui-base's PlotLabel: a text over a peak, a tag at a line's last point, a caption at a grid line's end. The layout places the texts, so they follow the plot's size; they glide with the scales' domains, fade in with the plot's appear, and take no pointer. Their look is the app's: Class and Style give them the text styles they inherit. Screen readers hear the plot, not its labels.

func (Label) Render

func (l Label) Render(cx *core.Scope) core.Node

Render implements core.Node.

type Line

type Line struct {
	// Y is what it draws, one value per row; the plot's Y without.
	Y func() []float64
	// X gives it rows of its own, placed along the plot's x axis by these
	// values on a linear scale and by index on a point scale; without it
	// Y is a column of the plot's rows.
	X func() []float64
	// Scale is the y scale its values go along.
	Scale ValueScale
	Curve Curve
	// Color is the category of each row, which the plot's ColorScale gives
	// a color: a line is one series, so its first row with one gives it.
	Color func() []string
	// Dot shows a view styled by DotStyle centered on every point.
	Dot          bool
	DotClass     string
	DotStyle     core.Style
	DotStyleFunc func() core.Style
	// HoverDotStyle merges over the plot's DotStyle for its hover dot, and
	// HoverDotClass follows its DotClass; a DisplayNone shows none.
	HoverDotClass     string
	HoverDotStyle     core.Style
	HoverDotStyleFunc func() core.Style
	// Style is its paint: Stroke, StrokeWidth and StrokeDash.
	Class     string
	Style     core.Style
	StyleFunc func() core.Style
	TestID    string
}

Line is a series of a Plot drawn as a line through its points, as gpui-base's Line: one point per row with a value, placed by the plot's scales, a smooth curve unless Curve says otherwise. It strokes with its paint style (Stroke, StrokeWidth, StrokeDash; inherited from the plot), the text color where none is set, or with Color its category's of the plot's ColorScale, and with Dot shows a view the app styles on every point. Its values make the y scale's domain when the plot has none, it has a hover dot when it or the plot styles one, and it draws in with the plot's appear.

func (Line) Render

func (l Line) Render(cx *core.Scope) core.Node

Render implements core.Node.

type Motion

type Motion struct {
	// Pointer is the spring the hover's parts glide to the next row with
	// when the keys or a screen reader step there, and a pie's slice under
	// the pointer lifts with. The pointer's own moves never take it: the
	// parts follow the pointer in the same frame, so the hover never trails
	// the hand.
	Pointer *core.SpringConfig
	// Enter fades the hover's parts in as the pointer comes over the plot,
	// and Exit fades them out after it leaves.
	Enter, Exit *core.TimingConfig
	// Appear draws the marks in, when the plot is first shown with an
	// AppearGeneration and whenever that changes: lines and areas from the
	// leading edge, bars growing out of their base.
	Appear *core.TimingConfig
	// Update moves marks to a new shape when the app changes it, as d3's
	// update transitions: a pie's and an arc's radii and angles, and a
	// linear scale's domain, interpolated as d3 transitions a scale's
	// domain, so the marks keep their shapes while the grid lines, the
	// axes' ticks and the hover's parts move with them.
	Update *core.TimingConfig
}

Motion is the timing of a plot's motion. Each is the app's; a nil one moves at once, as does every one while the user asks for reduced motion.

type Pie

type Pie struct {
	// Value is what each row is worth; the plot's Y without. A row worth
	// nothing, less, or no number has no slice.
	Value func() []float64
	// StartAngle is where the first slice starts, 0 without it, and EndAngle
	// where the last ends, a whole turn without it; less than StartAngle
	// lays the slices out the other way. Radians from 12 o'clock, clockwise.
	StartAngle, EndAngle func() float32
	// PadAngle is the angle between neighbouring slices at the rim: each gap
	// keeps the width it has there at every radius.
	PadAngle func() float32
	// InnerRadius is the radius of the hole, 0 without it: a donut. And
	// OuterRadius of the slices, 100% without it. Points, or a percentage of
	// the largest circle the plot holds.
	InnerRadius, OuterRadius func() core.Length
	// CornerRadius rounds each slice's corners, as d3's arc.cornerRadius: at
	// most half the ring's thickness and smaller on a slice too narrow for
	// two whole corners.
	CornerRadius core.Points
	// SliceStyle gives every slice its Fill and Stroke, and SliceStyleOf and
	// SliceClassOf a slice of a row its own, over them.
	SliceClass   string
	SliceClassOf func(row int) string
	SliceStyle   core.Style
	SliceStyleOf func(row int) core.Style
	// HoverLift is how far the slice under the pointer grows past the
	// others, on the plot's pointer spring; HoverDim how much the others
	// fade, as a share of their opacity, with the hover's fade.
	HoverLift core.Points
	HoverDim  float32
	// Color is the category of each slice, which the plot's ColorScale
	// gives a color: its Fill where nothing sets one.
	Color func() []string
	// Label is the text beside each slice, outside the ring toward its
	// middle, LabelGap past the rim, then across to that radius on the
	// slice's side of the pie: it starts there on the right half and ends
	// there on the left. An empty text, or a slice narrower than half a
	// degree, has none. LabelGap is 15 without it.
	Label          func() []string
	LabelGap       core.Points
	LabelClass     string
	LabelStyle     core.Style
	LabelStyleFunc func() core.Style
	// LabelLineStyle styles a label's leader line, and LabelLineStyleOf and
	// LabelLineClassOf a row's over it: from the slice's rim out to the
	// label's radius, then across to the text, its Stroke the text color
	// where none is set. Drawn only with a class or a style.
	LabelLineClass   string
	LabelLineClassOf func(row int) string
	LabelLineStyle   core.Style
	LabelLineStyleOf func(row int) core.Style
	Class            string
	Style            core.Style
	StyleFunc        func() core.Style
	TestID           string
}

Pie is a pie of a Plot's rows, as gpui-base's Pie: a slice per row worth more than nothing, each its share of the turn from StartAngle to EndAngle, in the rows' order, around the plot's center between InnerRadius, a donut's hole, and OuterRadius, PadAngle apart. Each slice is a canvas of its own, so each paints with its own classes and styles over the pie's, as CSS inherits Fill and Stroke: Fill, the text color where none is set or with Color its category's, and Stroke, none. Over a pie, the plot reports the row of the slice under the pointer, none in the hole or outside, and its tooltip follows the pointer; that slice grows by HoverLift and the others fade by HoverDim. The ring sweeps in from its first slice with the plot's appear, and when the values or the radii change each slice moves from its old angles to its new ones with Motion.Update, d3's arcTween. With a Label, each slice has a text outside the ring and, styled, a leader line to it. Its values take no part in the plot's scales.

func (Pie) Render

func (p Pie) Render(cx *core.Scope) core.Node

Render implements core.Node.

type Plot

type Plot struct {
	// Count is how many rows it has; the length of X, else of Y, without.
	Count func() int
	// Y is the values the marks draw unless they have their own, one per
	// row; NaN skips a row.
	Y func() []float64
	// X places the rows along a linear x scale; a row's index without it.
	X func() []float64
	// XScale is a point scale unless it says otherwise (linear with a band
	// YScale, for bars across); YScale is linear, its domain the extent of
	// what the marks draw unless it gives one.
	XScale, YScale func() Scale
	// Y2Scale is a second linear scale along the y axis, for the values of
	// the marks that name it (ScaleY2), as dual-axis charts put a series of
	// other units on a scale of its own. Without it, marks on ScaleY2 go on
	// a linear scale of their values' extent.
	Y2Scale func() Scale
	// NoAlignTicks keeps each y domain the extent of its values. Otherwise,
	// while both are automatic and marks are on both, each is widened to
	// nice steps, the same number on both, zero on the same place when both
	// hold it, as ECharts' alignTicks; the axes' default ticks and a Grid
	// without values take those steps.
	NoAlignTicks bool
	// ColorScale gives the marks the colors of their rows' categories and
	// numbers; none where it is nil.
	ColorScale func() ColorScale
	// NoHover draws the marks only, following no pointer: a sparkline in
	// a list.
	NoHover bool
	Motion  Motion
	// AppearGeneration opts in to Motion.Appear: the marks draw in when
	// the plot is first shown, and again whenever it changes. It returns a
	// comparable value: a row's key, a period. Inside an AppearScope, a
	// generation that finished there shows whole at once.
	AppearGeneration func() any
	// Label says what the chart shows and what stands out;
	// AccessibilityValue the app's words for the row under the pointer.
	Label              string
	LabelFunc          func() string
	AccessibilityValue func() core.AccessibilityValue
	// CrossLineStyle styles the cross line, a view as tall as the plot
	// centered on the row under the pointer; there is none without it or
	// CrossLineClass. On a band scale it is as wide as the band sits in the
	// row's band, so a width of 100% fills it, and on a band y scale it lies
	// across the plot.
	CrossLineClass     string
	CrossLineStyle     core.Style
	CrossLineStyleFunc func() core.Style
	// DotStyle styles the hover's dots, a view per Line and Area
	// centered on its point at the row under the pointer; a mark's
	// HoverDotStyle merges over it for its own dot, its color over the
	// plot's size and ring, and its HoverDotClass follows DotClass.
	DotClass     string
	DotStyle     core.Style
	DotStyleFunc func() core.Style
	// Tooltip is the app's tooltip, placed by TooltipPlacement
	// TooltipOffset away and moved and faded with the cross line.
	Tooltip          core.Node
	TooltipPlacement TooltipPlacement
	TooltipOffset    core.Points
	// OnHoverChange receives the row under the pointer when another one
	// is, and -1 once the pointer leaves the plot.
	OnHoverChange func(index int)
	Class         string
	Style         core.Style
	StyleFunc     func() core.Style
	Children      []core.Node
	TestID        string
	// OnLayout is its view's, as a core.View's.
	OnLayout func(core.Bounds)
}

Plot is the frame of a chart, as gpui-base's: the rows of data, the scales of its axes, its size as their range, the pointer over it and its motion. It draws nothing itself: its marks (Line, Area, Bar, Rule, Dot, Cell, Grid, Pie, Arc, RadialLine, RadialGrid, Sankey, Treemap), its children, each fill it and draw in order over each other, natively from the rows, each in a canvas of its own or more, and its Axis and Label children write its edges and texts at values of its scales.

It reports the row nearest to the pointer along the axis of the rows, or what a mark finds under it (a slice, a dot, a cell), with OnHoverChange and shows the hover's parts the app styles (the cross line, a dot per mark, the tooltip), moved and faded on the platform's frame clock with Motion; the pointer moves them and never draws a mark again.

The keyboard drives the same hover: the plot is a stop of the focus, and while it has it Left and Right move to the row on that side, Home and End to the first and last, Escape clears it; over a grid of cells the arrows step across it on the screen. Screen readers hear one image, Label and AccessibilityValue, and increment and decrement step through the rows. Style sizes it, and the marks inherit its paint properties (Stroke, Fill, StrokeWidth, StrokeDash) as CSS inherits them.

func (Plot) Render

func (p Plot) Render(cx *core.Scope) core.Node

Render implements core.Node.

type PlotText

type PlotText struct {
	Text string
	// X and Y are values of the plot's scales: a row's index on a point or
	// band scale, a value on a linear one.
	X, Y  float64
	Align TextAlign
	// Class and Style are over what it inherits from the Label: its font
	// and color, and its distance from the point.
	Class string
	Style core.Style
}

PlotText is a text a Label draws, as gpui-base's Text: what it reads, the point its box's top edge is at, as values of the plot's scales, and how it sits along x from that point.

type RadialGrid

type RadialGrid struct {
	// Rings is where its rings go, as values of the plot's y scale.
	Rings func() []float64
	// Spokes draws a spoke at each row's angle, the rows evenly from
	// StartAngle to EndAngle as a RadialLine without an Angle places them.
	Spokes bool
	// Circular makes its rings circles, arcs over a part of a turn; by
	// default they are polygons through the rows' angles, circles with
	// fewer than three rows.
	Circular bool
	// StartAngle, EndAngle, InnerRadius and OuterRadius are a RadialLine's.
	StartAngle, EndAngle     func() float32
	InnerRadius, OuterRadius func() core.Length
	Class                    string
	Style                    core.Style
	StyleFunc                func() core.Style
	TestID                   string
}

RadialGrid is a radar's grid in a Plot, Grid's polar counterpart: rings around the plot's center at the values Rings of its y scale, polygons through the rows' angles or Circular, and with Spokes a line out from the inner radius at each row's angle. It strokes with its paint style, inherited from the plot, the text color where none is set. Its values do not count in the scale's domain; its rings move with the domain and the radii over Motion.Update, with the radial lines.

func (RadialGrid) Render

func (g RadialGrid) Render(cx *core.Scope) core.Node

Render implements core.Node.

type RadialLine

type RadialLine struct {
	// Radius places each row out from the center, values of the plot's y
	// scale, from InnerRadius at the domain's smallest to OuterRadius at its
	// largest; the plot's Y without. NaN skips a row.
	Radius func() []float64
	// Angle is where each row goes round the center, radians from 12
	// o'clock, clockwise. Without it, the rows go evenly from StartAngle to
	// EndAngle, in order.
	Angle func() []float64
	// StartAngle and EndAngle are 0 and a whole turn without them. Over a
	// part of a turn the last row is on EndAngle; round a whole one, a step
	// before the first.
	StartAngle, EndAngle func() float32
	// InnerRadius and OuterRadius are a Pie's.
	InnerRadius, OuterRadius func() core.Length
	// Curve is straight segments by default.
	Curve  Curve
	Closed bool
	// Dot shows a view styled by DotStyle centered on every point.
	Dot          bool
	DotClass     string
	DotStyle     core.Style
	DotStyleFunc func() core.Style
	// BackgroundStyle's Background and Gradients fill a box around its outer
	// circle, shown only inside its area, under its Fill, as an Area's.
	BackgroundClass     string
	BackgroundStyle     core.Style
	BackgroundStyleFunc func() core.Style
	// HoverDotStyle styles its hover dot, on its point at the row under the
	// pointer; the plot's DotStyle where none is set.
	HoverDotClass     string
	HoverDotStyle     core.Style
	HoverDotStyleFunc func() core.Style
	Class             string
	Style             core.Style
	StyleFunc         func() core.Style
	TestID            string
}

RadialLine is a series of a Plot around its center, as gpui-base's RadialLine and d3's lineRadial and areaRadial: a point per row with a value, at the row's angle and as far out as the plot's y scale puts its value between InnerRadius and OuterRadius, the rows without one skipped; Closed joins the last point to the first, a radar's polygon. It strokes its line with its Stroke, the text color where none is set, and fills its area down to InnerRadius with its Fill, none where none is set, over its background; its paint inherits from the plot as CSS's does. Its values count in the y scale's domain when the plot has none, with 0, the center. Over it, the plot reports the row whose angle is nearest the pointer's within the outer radius, and its hover dot sits on that row's point. It grows out of its inner radius with the plot's appear, and moves to new values, angles and radii with Motion.Update.

func (RadialLine) Render

func (r RadialLine) Render(cx *core.Scope) core.Node

Render implements core.Node.

type RadiusScale

type RadiusScale struct {
	Min, Max core.Points
	// Domain is the values the range's ends stand for; 0 to the largest
	// value without HasDomain.
	Domain    [2]float64
	HasDomain bool
}

RadiusScale is how a Dot's values of Sizes become radii, as d3's scaleSqrt: the square roots of Domain onto the radii Min to Max, so with a Min of 0 a dot's area is in proportion to its value, as a bubble's should be. Values outside the domain take the range's ends.

type Rule

type Rule struct {
	// Value is where each line ends; the plot's Y without. A row without a
	// value has no line.
	Value func() []float64
	// Base is where each line starts, 0 without it, and Bases a start per
	// row in its place, as a Bar's. They count in the scale's domain.
	Base  func() float64
	Bases func() []float64
	// Scale is the y scale its values go along; lines across the plot put
	// their values along x.
	Scale ValueScale
	// Stagger and HoverDim are a Bar's.
	Stagger, HoverDim float32
	// Color is the category of each line, which the plot's ColorScale gives
	// a color: its Stroke where nothing sets one.
	Color     func() []string
	Class     string
	Style     core.Style
	StyleFunc func() core.Style
	TestID    string
}

Rule is a series of a Plot drawn as a straight line per row along the value axis, as Vega-Lite's and Observable Plot's rule mark: from Base to the row's value, in the middle of the row's band on a band scale (across the plot on a band YScale), at the row's place along the x axis otherwise. A candle is a Bar from its open to its close over a Rule from its low to its high; a box plot's whiskers, error bars and lollipops' stems are rules. It strokes with its Stroke (inherited from the plot), the text color where none is set or with Color each line's category's. Its values and base count in the value scale's domain when the plot has none. With the plot's appear, its lines grow out of their start, one after another with Stagger; while the pointer is over the plot, the lines of other rows fade by HoverDim. It shows no hover dot.

func (Rule) Render

func (r Rule) Render(cx *core.Scope) core.Node

Render implements core.Node.

type Sankey

type Sankey struct {
	Links func() []SankeyLink
	// NodeWidth is the width of each node, 24 without it; NodePadding the
	// gap between the nodes of a column, 8 without it, less in a column too
	// crowded for it.
	NodeWidth, NodePadding core.Points
	NodeAlign              SankeyAlign
	// Iterations is how many times the layout relaxes the nodes toward their
	// flows, 6 without it.
	Iterations int
	ValueScale SankeyValueScale
	// MinLinkWidth is the thinnest a ribbon draws, 1 without it, so a small
	// flow stays visible.
	MinLinkWidth core.Points
	// NodeCornerRadius rounds each node's corners.
	NodeCornerRadius core.Points
	// NodeStyle gives every node its Fill and Stroke, and NodeStyleOf and
	// NodeClassOf a node of a row its own, over them.
	NodeClass   string
	NodeClassOf func(row int) string
	NodeStyle   core.Style
	NodeStyleOf func(row int) core.Style
	// LinkStyle, LinkStyleOf and LinkClassOf are a ribbon's, by its index in
	// Links.
	LinkClass   string
	LinkClassOf func(link int) string
	LinkStyle   core.Style
	LinkStyleOf func(link int) core.Style
	// LinkBackgroundStyle's Background and Gradients fill a box from each
	// ribbon's source to its target, shown only inside the ribbon, under
	// its Fill, as an Area's; LinkBackgroundStyleOf gives each its own, its
	// source's color to its target's. A ribbon's Fill is then none where
	// none is set.
	LinkBackgroundClass   string
	LinkBackgroundClassOf func(link int) string
	LinkBackgroundStyle   core.Style
	LinkBackgroundStyleOf func(link int) core.Style
	// HoverDim is how much the links not attached to the node under the
	// pointer fade, as a share of their opacity, on the plot's pointer
	// spring and with the hover's fade.
	HoverDim float32
	// NodeLabel is the name beside each node, the last line of its label.
	NodeLabel func() []string
	// ValueLabel is the value above its name, of the node's row and its
	// throughput: the most that flows into or out of it, in the links'
	// values, whatever the ValueScale.
	ValueLabel func(row int, value float64) string
	// NodeLabelStyle styles each node's label: a box holding the value and
	// the name, left of a node in the first column, right of one in the last
	// and above one between them, kept between the plot's top and bottom
	// beside the node; its padding is the gap to the node.
	NodeLabelClass     string
	NodeLabelStyle     core.Style
	NodeLabelStyleFunc func() core.Style
	// ValueLabelStyle styles the value line, over the label's text styles.
	ValueLabelClass     string
	ValueLabelStyle     core.Style
	ValueLabelStyleFunc func() core.Style
	Class               string
	Style               core.Style
	StyleFunc           func() core.Style
	TestID              string
}

Sankey is flows between a Plot's rows, as gpui-base's Sankey layout drawn as gpui-component's SankeyChart draws it: the rows are its nodes and Links the flows between them, laid out by d3-sankey's algorithm in the plot's size: a node per row, in columns by NodeAlign, as tall as the most that flows through it, and a ribbon per link from its source's right edge to its target's left edge, as wide at each end as its share of that node's side, at least MinLinkWidth. Each node and each ribbon is a canvas of its own, so each paints with its own classes and styles over the sankey's, as CSS inherits Fill and Stroke: Fill, the text color where none is set, and Stroke, none. The ribbons draw under the nodes, and both from the leading edge with the plot's appear; NodeLabel and ValueLabel label the nodes beside them, fading in with it. Over a sankey, the plot reports the node under the pointer, and the links not attached to it fade by HoverDim; the keys step through the nodes. When the app changes the flows, each node and ribbon moves from its old place to its new one with Motion.Update, a new node growing from its middle and a new ribbon from no width; links are told apart by their source and target, so reordering them moves nothing. Links that make a cycle or name a row the plot does not have log a warning and draw nothing. Its values take no part in the plot's scales.

func (Sankey) Render

func (s Sankey) Render(cx *core.Scope) core.Node

Render implements core.Node.

type SankeyAlign

type SankeyAlign uint8

SankeyAlign is which column a Sankey's node goes in, as d3-sankey's nodeAlign.

const (
	// SankeyJustify is its depth, and a node with no links out in the last
	// column.
	SankeyJustify SankeyAlign = iota
	// SankeyLeft is its depth: the longest path from a node with no links
	// in.
	SankeyLeft
	// SankeyRight is as far right as its height lets it.
	SankeyRight
	// SankeyCenter is its depth, or for a node with only links out, the
	// column before the nearest of its targets.
	SankeyCenter
)
type SankeyLink struct {
	Source, Target int
	Value          float64
}

SankeyLink is a flow of a Sankey: from the plot's row Source to its row Target, by their indices, Value its size. A value that is not a number, or below zero, carries nothing.

type SankeyValueScale

type SankeyValueScale uint8

SankeyValueScale is how a Sankey's values map to its nodes' heights and its ribbons' widths.

const (
	// SankeyLinear is in proportion to the value.
	SankeyLinear SankeyValueScale = iota
	// SankeySqrt is in proportion to its square root: a wide range of values
	// compressed, so a dominant flow does not dwarf the small ones.
	SankeySqrt
)

type Scale

type Scale struct {
	// contains filtered or unexported fields
}

Scale is how an axis of a Plot places values, as gpui-base's scales and d3-scale's do: a point scale places the rows in order, evenly from one edge to the other (one row in the middle), a linear scale places a number in proportion to where it lies in its domain, and a band scale gives each row, or each category of its domain, a band of the axis for the bars and cells drawn in it. The zero value is a point scale.

func BandScale

func BandScale(band Band) Scale

BandScale gives each row a band of the axis, or each category of band's Domain.

func LinearScale

func LinearScale(domain ...float64) Scale

LinearScale places values in proportion over the extent of domain's two values, in either order; without them, over the extent of what the plot draws.

func PointScale

func PointScale() Scale

PointScale places the rows in order.

func (Scale) Reversed

func (s Scale) Reversed() Scale

Reversed returns s running from its other edge: the first row or the domain's smallest value at the right edge of the x axis, and on the y axis the domain's smallest value at the top edge (bars grow down from it) and the first row at the bottom edge.

type TextAlign

type TextAlign uint8

TextAlign is where a PlotText sits along the x axis from its point.

const (
	// TextLeft starts the text at the point.
	TextLeft TextAlign = iota
	// TextCenter centers it on the point.
	TextCenter
	// TextRight ends it at the point.
	TextRight
)

type TooltipPlacement

type TooltipPlacement uint8

TooltipPlacement is where a Plot's tooltip goes; either way it stays inside the plot's edges.

const (
	// TooltipTop puts it at the top of the plot, centered on the cross
	// line, TooltipOffset below the top edge.
	TooltipTop TooltipPlacement = iota
	// TooltipPointer puts it beside the pointer: on the side of the cross
	// line toward the plot's middle, below the pointer in the upper half
	// and above it in the lower one, TooltipOffset from both.
	TooltipPointer
)

type Treemap

type Treemap struct {
	// ID is the id of each row's node, its index without one: what Parent
	// names, and what a node is known by when the rows change.
	ID func() []string
	// Parent is the id of each row's parent: a row whose parent is empty, or
	// names no row, is a top-level node; without one, every row is. Rows that
	// others name are groups, the rest leaves; a row that is its own ancestor
	// is left out.
	Parent func() []string
	// Value is the size of each leaf. A group's is the sum of its children's.
	// A leaf whose value is 0, below 0 or not a number takes no area.
	Value func() []float64
	Sort  TreemapSort
	// Ratio is the aspect ratio the tiles approach, at least 1; the golden
	// ratio without it.
	Ratio float64
	// PaddingInner is the gap between siblings, PaddingOuter the room inside
	// each group around its children and PaddingTop the band at the top of
	// each group, GroupLabel written in it, by level from the top one down,
	// the last for those below. A level's band goes on all the siblings of a
	// parent or none of them, so the groups of a level read alike.
	PaddingInner, PaddingOuter, PaddingTop []core.Points
	// Corners rounds its rectangles' corners; square by default.
	Corners Corners
	// Color is the category of each node, which an ordinal ColorScale gives
	// a color: the node's Fill where nothing sets one.
	Color func() []string
	// ColorValue is the number of each node, which a ramp of the plot's
	// ColorScale makes its color, over the extent of the rows' values
	// without a domain.
	ColorValue func() []float64
	// LeafStyle is every leaf's paint, and LeafClassOf gives a leaf of a row
	// its own classes. The leaves that share classes share a canvas.
	LeafClass   string
	LeafClassOf func(row int) string
	LeafStyle   core.Style
	// GroupStyle and GroupClassOf are a group's: a rectangle under its
	// children, showing in the gaps, its padding and its band. Drawn only
	// with a class or a style.
	GroupClass   string
	GroupClassOf func(row int) string
	GroupStyle   core.Style
	// HoverDim is how much the nodes away from the one under the pointer,
	// and their labels, fade, as a share of their opacity: a leaf keeps its
	// own and its groups', a group its own and what is under it.
	HoverDim float32
	// Label is the name in each leaf, on one line, cut with an ellipsis
	// where the leaf is narrower.
	Label func() []string
	// ValueLabel is the value in each leaf, the line under its name, of the
	// leaf's row and its value; shown only where it fits whole.
	ValueLabel     func(row int, value float64) string
	LabelPlacement TreemapLabelPlacement
	// LabelStyle styles each leaf's label: a box as big as the leaf holding
	// its lines, its padding the room from the leaf's edges. A label is shown
	// only where its first line fits inside the box's padding. DarkLabelStyle
	// merges over it where the leaf's color is dark.
	LabelClass      string
	LabelStyle      core.Style
	DarkLabelClass  string
	DarkLabelStyle  core.Style
	ValueLabelClass string
	ValueLabelStyle core.Style
	// GroupLabel is the name of each group, written in its band, on one
	// line, cut with an ellipsis; GroupLabelStyle styles a box as big as the
	// band.
	GroupLabel      func() []string
	GroupLabelClass string
	GroupLabelStyle core.Style
	// Stagger is the share of the plot's appear over which its top-level
	// nodes start, in their tiling order.
	Stagger float32
	// HoverStyle styles a view as big as the node under the pointer or the
	// keys, over it; none without a class or style.
	HoverClass     string
	HoverStyle     core.Style
	HoverStyleFunc func() core.Style
	Class          string
	Style          core.Style
	StyleFunc      func() core.Style
	TestID         string
}

Treemap is a treemap of a Plot's rows, as d3's treemap of a stratify hierarchy: one rectangle per node, its rows made a tree by their ID and Parent, each leaf's area in proportion to its Value and each group the box of what is under it, squarified in order of value, with the gaps of PaddingInner, the room of PaddingOuter and the band of PaddingTop per level. A node's color is its row's of the plot's ColorScale: of its ColorValue along a ramp, of its Color category, or its Fill where the app sets one. Labels write each leaf's name and value and each group's name in its band, where they fit. The pointer finds the leaf under it (across a gap, the nearest; in a band or padding, the group), which the plot reports and marks with the hover box, the other nodes fading by HoverDim; the arrows step to the leaf beside on the screen, Home and End to the first and last, and screen readers through the rows. The plot's x and y scales are not used. With the plot's appear, the top-level nodes grow from their middles, one after another with Stagger; with Motion.Update, the nodes glide to their new boxes and colors, known by their IDs, new ones grow from their middles and those that are gone shrink to theirs.

func (Treemap) Render

func (t Treemap) Render(cx *core.Scope) core.Node

Render implements core.Node.

type TreemapLabelPlacement

type TreemapLabelPlacement uint8

TreemapLabelPlacement is where a Treemap's labels go in their leaves.

const (
	// TreemapLabelStart is at the leaf's top left.
	TreemapLabelStart TreemapLabelPlacement = iota
	// TreemapLabelCenter is in the leaf's middle, the lines centered.
	TreemapLabelCenter
)

type TreemapSort

type TreemapSort uint8

TreemapSort is the order a Treemap's siblings are tiled in, from its top left corner.

const (
	// TreemapByValue is largest first, equal values in the rows' order: the
	// tiles nearest to square.
	TreemapByValue TreemapSort = iota
	// TreemapByRow is the rows' order: the nodes keep their places as their
	// values change, at the cost of less square tiles.
	TreemapByRow
)

type ValueScale

type ValueScale uint8

ValueScale is the scale along the y axis a mark places its values on.

const (
	// ScaleY is the plot's YScale.
	ScaleY ValueScale = iota
	// ScaleY2 is its second one, Y2Scale: a dual-axis chart's right-hand
	// scale.
	ScaleY2
)

Jump to

Keyboard shortcuts

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