Skip to content

Commit

Permalink
check for empty legendEntry param
Browse files Browse the repository at this point in the history
  • Loading branch information
jharshman committed Dec 13, 2023
1 parent 1f82d7d commit 54f14a9
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 5 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ func main() {
tsi := GoogleCloudMonitoringClient.ListTimeSeries(context.Background(), request)
// Create the plot from the GAPI TimeSeries
plot, _ := tsplot.NewPlotFromTimeSeriesIterator(tsi)
plot, _ := tsplot.NewPlotFromTimeSeriesIterator(tsi, "", nil)
// Save the new plot to disk.
plot.Save(8*vg.Inch, 4*vg.Inch, "my_plot.png")
Expand Down
10 changes: 6 additions & 4 deletions tsplot/plot.go
Original file line number Diff line number Diff line change
Expand Up @@ -103,10 +103,12 @@ func NewPlotFromTimeSeriesIterator(tsi *monitoring.TimeSeriesIterator, legendKey
applyLine(p)

// add to legend
legendEntry, _ := plotter.NewPolygon()
legendEntry.Color = lineColor
p.Legend.Left = true
p.Legend.Add(timeSeries.GetMetric().GetLabels()[legendKey], legendEntry)
if legendKey != "" {
legendEntry, _ := plotter.NewPolygon()
legendEntry.Color = lineColor
p.Legend.Left = true
p.Legend.Add(timeSeries.GetMetric().GetLabels()[legendKey], legendEntry)
}
}

// set Y Axis scale
Expand Down

0 comments on commit 54f14a9

Please sign in to comment.