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 <noreply@anthropic.com>
This commit is contained in:
@@ -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{
|
p := gocharts.NewPainter(gocharts.PainterOptions{
|
||||||
OutputFormat: gocharts.ChartOutputSVG,
|
OutputFormat: gocharts.ChartOutputSVG,
|
||||||
Width: 1400,
|
Width: 1400,
|
||||||
@@ -645,6 +651,21 @@ func renderChartSVG(title string, datasets [][]float64, names []string, labels [
|
|||||||
return p.Bytes()
|
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 {
|
func sanitizeChartText(s string) string {
|
||||||
if s == "" {
|
if s == "" {
|
||||||
return ""
|
return ""
|
||||||
|
|||||||
Reference in New Issue
Block a user