web/sparkline: two-axis trend chart with hover dots

This commit is contained in:
2026-05-07 18:55:31 +01:00
parent 9c209a952e
commit ea74965830
4 changed files with 250 additions and 0 deletions
+33
View File
@@ -5,6 +5,7 @@ import (
"path/filepath"
"strings"
"testing"
"time"
)
func loadGolden(t *testing.T, name string) string {
@@ -39,3 +40,35 @@ func TestSparkline_ThreePoints(t *testing.T) {
t.Errorf("three_points sparkline mismatch:\nwant:\n%s\ngot:\n%s", want, got)
}
}
func TestChart_Empty(t *testing.T) {
got := strings.TrimRight(string(RenderChart(nil, nil, ChartOpts{Width: 600, Height: 220})), "\n")
want := loadGolden(t, "chart_empty.svg")
if got != want {
t.Errorf("empty chart mismatch:\nwant:\n%s\ngot:\n%s", want, got)
}
}
func TestChart_TwoSeries(t *testing.T) {
days := []time.Time{
time.Date(2026, 5, 1, 0, 0, 0, 0, time.UTC),
time.Date(2026, 5, 2, 0, 0, 0, 0, time.UTC),
time.Date(2026, 5, 3, 0, 0, 0, 0, time.UTC),
time.Date(2026, 5, 4, 0, 0, 0, 0, time.UTC),
}
series := []Series{
{
Name: "size", Stroke: "#3b82f6", Axis: AxisLeft, Format: FormatBytes,
Points: []float64{1024, 2048, 4096, 8192},
},
{
Name: "snapshots", Stroke: "#f59e0b", Axis: AxisRight, Format: FormatCount,
Points: []float64{1, 2, 3, 4},
},
}
got := strings.TrimRight(string(RenderChart(series, days, ChartOpts{Width: 600, Height: 220})), "\n")
want := loadGolden(t, "chart_two_series.svg")
if got != want {
t.Errorf("two_series chart mismatch:\nwant:\n%s\ngot:\n%s", want, got)
}
}