theme/material3/linechart.go

Functions Structs

Functions

func PaintChart

PaintChart renders a line chart according to Material 3 specifications.

func (p LineChartPainter) PaintChart(canvas widget.Canvas, bounds geometry.Rect, state linechart.PaintState) {
	if bounds.IsEmpty() {
		return
	}

	colors := p.resolveColors()

	// Background fill.
	bg := state.Background
	if bg == (widget.Color{}) {
		bg = colors.Background
	}
	canvas.DrawRect(bounds, bg)

	// Compute the plot area (inset for labels if enabled).
	plotArea := m3ChartPlotArea(bounds, state.ShowLabels)
	if plotArea.Width() <= 0 || plotArea.Height() <= 0 {
		return
	}

	// Clip to bounds.
	canvas.PushClip(bounds)
	defer canvas.PopClip()

	// Grid lines.
	if state.ShowGrid {
		gridColor := state.GridColor
		if gridColor == (widget.Color{}) {
			gridColor = colors.GridColor
		}
		m3ChartDrawGrid(canvas, plotArea, gridColor)
	}

	// Y-axis labels.
	if state.ShowLabels {
		m3ChartDrawLabels(canvas, bounds, plotArea, state, colors.LabelColor)
	}

	// Data lines.
	for _, series := range state.Series {
		lineColor := series.Color
		if lineColor == (widget.Color{}) {
			lineColor = colors.LineColor
		}
		m3ChartDrawSeries(canvas, plotArea, series, state, lineColor)
	}
}

Structs

type LineChartPainter struct

LineChartPainter renders line charts using Material 3 design tokens.

It maps M3 color roles to chart elements: primary for data lines,

surface for background, and on-surface-variant for grid/labels.

 

If Theme is nil, LineChartPainter falls back to the default M3 purple palette.

type LineChartPainter struct {
	Theme *Theme	// nil uses default M3 purple fallback
}