Skip to content

Commit

Permalink
add colors, move legend (#18)
Browse files Browse the repository at this point in the history
  • Loading branch information
myshkins authored Jan 2, 2024
1 parent 047e30c commit c953739
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 11 deletions.
28 changes: 19 additions & 9 deletions tsplot/color_palettes.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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
Expand Down
7 changes: 5 additions & 2 deletions tsplot/plot.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

Expand Down Expand Up @@ -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
}

Expand Down

0 comments on commit c953739

Please sign in to comment.