Skip to content

Commit eabd4bb

Browse files
committed
Support a legend key from metric or resource sources
1 parent aedae7d commit eabd4bb

File tree

1 file changed

+7
-3
lines changed

1 file changed

+7
-3
lines changed

tsplot/plot.go

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -105,12 +105,16 @@ func NewPlotFromTimeSeriesIterator(tsi *monitoring.TimeSeriesIterator, legendKey
105105

106106
// add to legend
107107
if legendKey != "" {
108-
legendEntry, _ := plotter.NewPolygon()
109-
legendEntry.Color = lineColor
108+
legendThumbnail, _ := plotter.NewPolygon()
109+
legendThumbnail.Color = lineColor
110110
p.Legend.Left = true
111111
p.Legend.Top = true
112112
p.Legend.Padding = vg.Points(2)
113-
p.Legend.Add(timeSeries.GetMetric().GetLabels()[legendKey], legendEntry)
113+
legendEntry := timeSeries.GetMetric().GetLabels()[legendKey]
114+
if legendEntry == "" {
115+
legendEntry = timeSeries.GetResource().GetLabels()[legendKey]
116+
}
117+
p.Legend.Add(legendEntry, legendThumbnail)
114118
}
115119
}
116120

0 commit comments

Comments
 (0)