Skip to content

Commit 1cee736

Browse files
authored
add sans serif font, adjust legend padding (#20)
1 parent c4aad58 commit 1cee736

File tree

2 files changed

+12
-0
lines changed

2 files changed

+12
-0
lines changed

tsplot/options.go

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,16 @@ func WithFontSize(size float64) PlotOption {
9494
}
9595
}
9696

97+
// WithFontSize configures the font variant as Sans-Serif
98+
func WithSansFont() PlotOption {
99+
return func(p *plot.Plot) {
100+
p.Title.TextStyle.Font.Variant = "Sans"
101+
p.X.Label.TextStyle.Font.Variant = "Sans"
102+
p.Y.Label.TextStyle.Font.Variant = "Sans"
103+
p.Legend.TextStyle.Font.Variant = "Sans"
104+
}
105+
}
106+
97107
// ApplyDefaultHighContrast applies the default high contrast color scheme to the *plot.Plot.
98108
func ApplyDefaultHighContrast(p *plot.Plot) {
99109
opts := []PlotOption{

tsplot/plot.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import (
66
monitoring "cloud.google.com/go/monitoring/apiv3/v2"
77
"gonum.org/v1/plot"
88
"gonum.org/v1/plot/plotter"
9+
"gonum.org/v1/plot/vg"
910
"google.golang.org/api/iterator"
1011
"google.golang.org/genproto/googleapis/api/metric"
1112
monitoringpb "google.golang.org/genproto/googleapis/monitoring/v3"
@@ -108,6 +109,7 @@ func NewPlotFromTimeSeriesIterator(tsi *monitoring.TimeSeriesIterator, legendKey
108109
legendEntry.Color = lineColor
109110
p.Legend.Left = true
110111
p.Legend.Top = true
112+
p.Legend.Padding = vg.Points(2)
111113
p.Legend.Add(timeSeries.GetMetric().GetLabels()[legendKey], legendEntry)
112114
}
113115
}

0 commit comments

Comments
 (0)