From db88baaee44cbaafb9291758c5d0c630770e05ba Mon Sep 17 00:00:00 2001 From: Alex Krenitsky Date: Wed, 20 Dec 2023 22:18:54 +0000 Subject: [PATCH] add colors, move legend --- tsplot/color_palettes.go | 28 +++++++++++++++++++--------- tsplot/plot.go | 7 +++++-- 2 files changed, 24 insertions(+), 11 deletions(-) diff --git a/tsplot/color_palettes.go b/tsplot/color_palettes.go index ce09289..34ef403 100644 --- a/tsplot/color_palettes.go +++ b/tsplot/color_palettes.go @@ -10,15 +10,21 @@ var usedColors = make(map[string]color.RGBA) // simple colors (subset of golang.org/x/image/colornames) var availableColors = map[string]color.RGBA{ - "blue": color.RGBA{0x00, 0x00, 0xff, 0xff}, // rgb(0, 0, 255) - "brown": color.RGBA{0xa5, 0x2a, 0x2a, 0xff}, // rgb(165, 42, 42) - "orange": color.RGBA{0xff, 0xa5, 0x00, 0xff}, // rgb(255, 165, 0) - "hotpink": color.RGBA{0xff, 0x69, 0xb4, 0xff}, // rgb(255, 105, 180) - "red": color.RGBA{0xff, 0x00, 0x00, 0xff}, // rgb(255, 0, 0) - "purple": color.RGBA{0x80, 0x00, 0x80, 0xff}, // rgb(128, 0, 128) - "yellow": color.RGBA{0xff, 0xff, 0x00, 0xff}, // rgb(255, 255, 0) - "green": color.RGBA{0x00, 0x80, 0x00, 0xff}, // rgb(0, 128, 0) - + "aqua": color.RGBA{0x00, 0xff, 0xff, 0xff}, //(rgb: 0, 255, 255), + "brown": color.RGBA{0xa5, 0x2a, 0x2a, 0xff}, // rgb(165, 42, 42) + "darkkhaki": color.RGBA{0xbd, 0xb7, 0x6b, 0xff}, // rgb(189, 183, 107) + "deepskyblue": color.RGBA{0x00, 0xbf, 0xff, 0xff}, //(rgb: 0, 191, 255), + "gold": color.RGBA{0xff, 0xd7, 0x00, 0xff}, //(rgb: 255, 215, 0), + "gray": color.RGBA{0x80, 0x80, 0x80, 0xff}, // rgb(128, 128, 128) + "green": color.RGBA{0x00, 0x80, 0x00, 0xff}, //(rgb: 0, 128, 0), + "lime": color.RGBA{0x00, 0xff, 0x00, 0xff}, //(rgb: 0, 255, 0), + "magenta": color.RGBA{0xff, 0x00, 0xff, 0xff}, //(rgb: 255, 0, 255), + "mediumturquoise": color.RGBA{0x48, 0xd1, 0xcc, 0xff}, // rgb(72, 209, 204) + "orange": color.RGBA{0xff, 0xa5, 0x00, 0xff}, //(rgb: 255, 165, 0), + "purple": color.RGBA{0x80, 0x00, 0x80, 0xff}, // rgb(128, 0, 128) + "red": color.RGBA{0xff, 0x00, 0x00, 0xff}, //(rgb: 255, 0, 0), + "royalblue": color.RGBA{0x41, 0x69, 0xe1, 0xff}, // rgb(65, 105, 225) + "violet": color.RGBA{0xee, 0x82, 0xee, 0xff}, //(rgb: 238, 130, 238), } func getUnusedColor() color.RGBA { @@ -31,6 +37,10 @@ func getUnusedColor() color.RGBA { return colornames.Black } +func resetUsedColors() { + usedColors = make(map[string]color.RGBA) +} + type ColorPalette struct { Foreground color.Color Background color.Color diff --git a/tsplot/plot.go b/tsplot/plot.go index 12b19f2..73539fc 100644 --- a/tsplot/plot.go +++ b/tsplot/plot.go @@ -70,7 +70,7 @@ func NewPlotFromTimeSeries(ts *monitoringpb.TimeSeries, opts ...PlotOption) (*pl opt(p) } - p.Y.Max = YMax + 200 + p.Y.Max = YMax + (.1 * YMax) return p, nil } @@ -107,17 +107,20 @@ func NewPlotFromTimeSeriesIterator(tsi *monitoring.TimeSeriesIterator, legendKey legendEntry, _ := plotter.NewPolygon() legendEntry.Color = lineColor p.Legend.Left = true + p.Legend.Top = true p.Legend.Add(timeSeries.GetMetric().GetLabels()[legendKey], legendEntry) } } // set Y Axis scale - p.Y.Max = yMax + 200 + p.Y.Max = yMax + (.1 * yMax) for _, opt := range opts { opt(p) } + resetUsedColors() + return p, nil }