From 56e73633839b548af4e929b2881c2e2fa914ca03 Mon Sep 17 00:00:00 2001 From: Josh Harshman Date: Tue, 8 Jul 2025 16:12:39 -0600 Subject: [PATCH] Support a legend key from metric or resource sources --- tsplot/plot.go | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) diff --git a/tsplot/plot.go b/tsplot/plot.go index 6f13ea0..cea0912 100644 --- a/tsplot/plot.go +++ b/tsplot/plot.go @@ -105,15 +105,20 @@ func NewPlotFromTimeSeriesIterator(tsi *monitoring.TimeSeriesIterator, legendKey // add to legend if legendKey != "" { - legendEntry, _ := plotter.NewPolygon() - legendEntry.Color = lineColor - p.Legend.Left = true - p.Legend.Top = true - p.Legend.Padding = vg.Points(2) - p.Legend.Add(timeSeries.GetMetric().GetLabels()[legendKey], legendEntry) + legendThumbnail, _ := plotter.NewPolygon() + legendThumbnail.Color = lineColor + legendEntry := timeSeries.GetMetric().GetLabels()[legendKey] + if legendEntry == "" { + legendEntry = timeSeries.GetResource().GetLabels()[legendKey] + } + p.Legend.Add(legendEntry, legendThumbnail) } } + p.Legend.Left = true + p.Legend.Top = true + p.Legend.Padding = vg.Points(2) + // set Y Axis scale p.Y.Max = yMax + (.1 * yMax)