core/linechart/painter.go
Functions
func PaintChart
func (p DefaultPainter) PaintChart(canvas widget.Canvas, bounds geometry.Rect, cs PaintState) {
if bounds.IsEmpty() {
return
}
// Background fill.
canvas.DrawRect(bounds, cs.Background)
// Compute the plot area (inset for labels if enabled).
plotArea := computePlotArea(bounds, cs.ShowLabels)
if plotArea.Width() <= 0 || plotArea.Height() <= 0 {
return
}
// Clip to bounds.
canvas.PushClip(bounds)
defer canvas.PopClip()
// Grid lines.
if cs.ShowGrid {
drawGrid(canvas, plotArea, cs)
}
// Y-axis labels.
if cs.ShowLabels {
drawLabels(canvas, bounds, plotArea, cs)
}
// Data lines.
for _, series := range cs.Series {
drawSeriesLine(canvas, plotArea, series, cs)
}
}
Structs
type PaintState struct
PaintState holds the read-only snapshot passed to the painter.
type PaintState struct {
Series []Series
MaxPoints int
YMin float64
YMax float64
ShowGrid bool
ShowLabels bool
GridColor widget.Color
Background widget.Color
}
type DefaultPainter struct
DefaultPainter provides a minimal fallback painter with no design system styling.
It draws background, grid lines, Y-axis labels, and line segments for each series.
type DefaultPainter struct{}
Interfaces
type Painter interface
Painter renders the chart visuals.
Each design system (Material 3, Fluent, Cupertino) provides its own
Painter implementation to render the chart in its visual style.
If no Painter is set, [DefaultPainter] is used.
type Painter interface {
PaintChart(canvas widget.Canvas, bounds geometry.Rect, state PaintState)
}
PaintChart renders the chart with background, optional grid, optional labels,
and line segments for each data series.