Skip to content

Commit df4c8e6

Browse files
authored
tsplot: Option for font size. (#14)
Add option for setting the font size.
1 parent 156f01d commit df4c8e6

File tree

2 files changed

+12
-0
lines changed

2 files changed

+12
-0
lines changed

tscli/main.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -163,6 +163,7 @@ func executeQuery(cmd *cobra.Command, args []string) error {
163163

164164
p, err := ts.Plot([]tsplot.PlotOption{tsplot.WithXAxisName("UTC"),
165165
tsplot.WithXTimeTicks(time.Kitchen),
166+
tsplot.WithFontSize(float64(12)),
166167
tsplot.WithGrid(colornames.Darkgrey),
167168
tsplot.WithTitle(metric)}...)
168169
if err != nil {

tsplot/options.go

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import (
55
"time"
66

77
"gonum.org/v1/plot"
8+
"gonum.org/v1/plot/font"
89
"gonum.org/v1/plot/plotter"
910
monitoringpb "google.golang.org/genproto/googleapis/monitoring/v3"
1011
"google.golang.org/protobuf/types/known/durationpb"
@@ -84,6 +85,16 @@ func WithXTimeTicks(format string) PlotOption {
8485
}
8586
}
8687

88+
// WithFontSize configures the font sizes for the plot's Title, Axis', and Legend.
89+
func WithFontSize(size float64) PlotOption {
90+
return func(p *plot.Plot) {
91+
p.Title.TextStyle.Font.Size = font.Length(size)
92+
p.X.Label.TextStyle.Font.Size = font.Length(size)
93+
p.Y.Label.TextStyle.Font.Size = font.Length(size)
94+
p.Legend.TextStyle.Font.Size = font.Length(size)
95+
}
96+
}
97+
8798
// ApplyDefaultHighContrast applies the default high contrast color scheme to the *plot.Plot.
8899
func ApplyDefaultHighContrast(p *plot.Plot) {
89100
opts := []PlotOption{

0 commit comments

Comments
 (0)