Skip to content

Commit 30cb5b3

Browse files
authored
Support a legend key from metric or resource sources (#26)
1 parent aedae7d commit 30cb5b3

File tree

1 file changed

+11
-6
lines changed

1 file changed

+11
-6
lines changed

tsplot/plot.go

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -105,15 +105,20 @@ func NewPlotFromTimeSeriesIterator(tsi *monitoring.TimeSeriesIterator, legendKey
105105

106106
// add to legend
107107
if legendKey != "" {
108-
legendEntry, _ := plotter.NewPolygon()
109-
legendEntry.Color = lineColor
110-
p.Legend.Left = true
111-
p.Legend.Top = true
112-
p.Legend.Padding = vg.Points(2)
113-
p.Legend.Add(timeSeries.GetMetric().GetLabels()[legendKey], legendEntry)
108+
legendThumbnail, _ := plotter.NewPolygon()
109+
legendThumbnail.Color = lineColor
110+
legendEntry := timeSeries.GetMetric().GetLabels()[legendKey]
111+
if legendEntry == "" {
112+
legendEntry = timeSeries.GetResource().GetLabels()[legendKey]
113+
}
114+
p.Legend.Add(legendEntry, legendThumbnail)
114115
}
115116
}
116117

118+
p.Legend.Left = true
119+
p.Legend.Top = true
120+
p.Legend.Padding = vg.Points(2)
121+
117122
// set Y Axis scale
118123
p.Y.Max = yMax + (.1 * yMax)
119124

0 commit comments

Comments
 (0)