Skip to content

Commit c953739

Browse files
authored
add colors, move legend (#18)
1 parent 047e30c commit c953739

File tree

2 files changed

+24
-11
lines changed

2 files changed

+24
-11
lines changed

tsplot/color_palettes.go

Lines changed: 19 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -10,15 +10,21 @@ var usedColors = make(map[string]color.RGBA)
1010

1111
// simple colors (subset of golang.org/x/image/colornames)
1212
var availableColors = map[string]color.RGBA{
13-
"blue": color.RGBA{0x00, 0x00, 0xff, 0xff}, // rgb(0, 0, 255)
14-
"brown": color.RGBA{0xa5, 0x2a, 0x2a, 0xff}, // rgb(165, 42, 42)
15-
"orange": color.RGBA{0xff, 0xa5, 0x00, 0xff}, // rgb(255, 165, 0)
16-
"hotpink": color.RGBA{0xff, 0x69, 0xb4, 0xff}, // rgb(255, 105, 180)
17-
"red": color.RGBA{0xff, 0x00, 0x00, 0xff}, // rgb(255, 0, 0)
18-
"purple": color.RGBA{0x80, 0x00, 0x80, 0xff}, // rgb(128, 0, 128)
19-
"yellow": color.RGBA{0xff, 0xff, 0x00, 0xff}, // rgb(255, 255, 0)
20-
"green": color.RGBA{0x00, 0x80, 0x00, 0xff}, // rgb(0, 128, 0)
21-
13+
"aqua": color.RGBA{0x00, 0xff, 0xff, 0xff}, //(rgb: 0, 255, 255),
14+
"brown": color.RGBA{0xa5, 0x2a, 0x2a, 0xff}, // rgb(165, 42, 42)
15+
"darkkhaki": color.RGBA{0xbd, 0xb7, 0x6b, 0xff}, // rgb(189, 183, 107)
16+
"deepskyblue": color.RGBA{0x00, 0xbf, 0xff, 0xff}, //(rgb: 0, 191, 255),
17+
"gold": color.RGBA{0xff, 0xd7, 0x00, 0xff}, //(rgb: 255, 215, 0),
18+
"gray": color.RGBA{0x80, 0x80, 0x80, 0xff}, // rgb(128, 128, 128)
19+
"green": color.RGBA{0x00, 0x80, 0x00, 0xff}, //(rgb: 0, 128, 0),
20+
"lime": color.RGBA{0x00, 0xff, 0x00, 0xff}, //(rgb: 0, 255, 0),
21+
"magenta": color.RGBA{0xff, 0x00, 0xff, 0xff}, //(rgb: 255, 0, 255),
22+
"mediumturquoise": color.RGBA{0x48, 0xd1, 0xcc, 0xff}, // rgb(72, 209, 204)
23+
"orange": color.RGBA{0xff, 0xa5, 0x00, 0xff}, //(rgb: 255, 165, 0),
24+
"purple": color.RGBA{0x80, 0x00, 0x80, 0xff}, // rgb(128, 0, 128)
25+
"red": color.RGBA{0xff, 0x00, 0x00, 0xff}, //(rgb: 255, 0, 0),
26+
"royalblue": color.RGBA{0x41, 0x69, 0xe1, 0xff}, // rgb(65, 105, 225)
27+
"violet": color.RGBA{0xee, 0x82, 0xee, 0xff}, //(rgb: 238, 130, 238),
2228
}
2329

2430
func getUnusedColor() color.RGBA {
@@ -31,6 +37,10 @@ func getUnusedColor() color.RGBA {
3137
return colornames.Black
3238
}
3339

40+
func resetUsedColors() {
41+
usedColors = make(map[string]color.RGBA)
42+
}
43+
3444
type ColorPalette struct {
3545
Foreground color.Color
3646
Background color.Color

tsplot/plot.go

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ func NewPlotFromTimeSeries(ts *monitoringpb.TimeSeries, opts ...PlotOption) (*pl
7070
opt(p)
7171
}
7272

73-
p.Y.Max = YMax + 200
73+
p.Y.Max = YMax + (.1 * YMax)
7474
return p, nil
7575
}
7676

@@ -107,17 +107,20 @@ func NewPlotFromTimeSeriesIterator(tsi *monitoring.TimeSeriesIterator, legendKey
107107
legendEntry, _ := plotter.NewPolygon()
108108
legendEntry.Color = lineColor
109109
p.Legend.Left = true
110+
p.Legend.Top = true
110111
p.Legend.Add(timeSeries.GetMetric().GetLabels()[legendKey], legendEntry)
111112
}
112113
}
113114

114115
// set Y Axis scale
115-
p.Y.Max = yMax + 200
116+
p.Y.Max = yMax + (.1 * yMax)
116117

117118
for _, opt := range opts {
118119
opt(p)
119120
}
120121

122+
resetUsedColors()
123+
121124
return p, nil
122125
}
123126

0 commit comments

Comments
 (0)