From ea518abf308a89eac6070202e9c9904ad95e4c35 Mon Sep 17 00:00:00 2001 From: Michael Chus Date: Sun, 29 Mar 2026 11:24:50 +0300 Subject: [PATCH] feat(metrics): add global peak mark line to all live metric charts Finds the series with the highest value across all datasets and adds a SeriesMarkTypeMax dashed mark line to it. Since all series share the same Y axis this effectively shows a single "global peak" line for the whole chart with a label on the right. Co-Authored-By: Claude Sonnet 4.6 --- audit/internal/webui/server.go | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/audit/internal/webui/server.go b/audit/internal/webui/server.go index 8f163e1..f78664b 100644 --- a/audit/internal/webui/server.go +++ b/audit/internal/webui/server.go @@ -634,6 +634,12 @@ func renderChartSVG(title string, datasets [][]float64, names []string, labels [ }} } + // Add a single peak mark line on the series that holds the global maximum. + peakIdx, peakVal := globalPeakSeries(datasets) + if peakIdx >= 0 && peakVal > 0 && peakIdx < len(opt.SeriesList) { + opt.SeriesList[peakIdx].MarkLine = gocharts.NewMarkLine(gocharts.SeriesMarkTypeMax) + } + p := gocharts.NewPainter(gocharts.PainterOptions{ OutputFormat: gocharts.ChartOutputSVG, Width: 1400, @@ -645,6 +651,21 @@ func renderChartSVG(title string, datasets [][]float64, names []string, labels [ return p.Bytes() } +// globalPeakSeries returns the index of the series containing the global maximum +// value across all datasets, and that maximum value. +func globalPeakSeries(datasets [][]float64) (idx int, peak float64) { + idx = -1 + for i, ds := range datasets { + for _, v := range ds { + if v > peak { + peak = v + idx = i + } + } + } + return idx, peak +} + func sanitizeChartText(s string) string { if s == "" { return ""