From 300b01406c1fb8b3e8fc9563d3de06329f9beb2e Mon Sep 17 00:00:00 2001 From: Alex Krenitsky Date: Wed, 17 Jan 2024 20:31:52 +0000 Subject: [PATCH] add sans serif font, adjust legend padding --- tsplot/options.go | 10 ++++++++++ tsplot/plot.go | 2 ++ 2 files changed, 12 insertions(+) diff --git a/tsplot/options.go b/tsplot/options.go index 9bb291b..474ccfc 100644 --- a/tsplot/options.go +++ b/tsplot/options.go @@ -94,6 +94,16 @@ func WithFontSize(size float64) PlotOption { } } +// WithFontSize configures the font variant as Sans-Serif +func WithSansFont() PlotOption { + return func(p *plot.Plot) { + p.Title.TextStyle.Font.Variant = "Sans" + p.X.Label.TextStyle.Font.Variant = "Sans" + p.Y.Label.TextStyle.Font.Variant = "Sans" + p.Legend.TextStyle.Font.Variant = "Sans" + } +} + // ApplyDefaultHighContrast applies the default high contrast color scheme to the *plot.Plot. func ApplyDefaultHighContrast(p *plot.Plot) { opts := []PlotOption{ diff --git a/tsplot/plot.go b/tsplot/plot.go index 73539fc..6f13ea0 100644 --- a/tsplot/plot.go +++ b/tsplot/plot.go @@ -6,6 +6,7 @@ import ( monitoring "cloud.google.com/go/monitoring/apiv3/v2" "gonum.org/v1/plot" "gonum.org/v1/plot/plotter" + "gonum.org/v1/plot/vg" "google.golang.org/api/iterator" "google.golang.org/genproto/googleapis/api/metric" monitoringpb "google.golang.org/genproto/googleapis/monitoring/v3" @@ -108,6 +109,7 @@ func NewPlotFromTimeSeriesIterator(tsi *monitoring.TimeSeriesIterator, legendKey legendEntry.Color = lineColor p.Legend.Left = true p.Legend.Top = true + p.Legend.Padding = vg.Points(2) p.Legend.Add(timeSeries.GetMetric().GetLabels()[legendKey], legendEntry) } }