Skip to content

Commit

Permalink
tsplot: Option for font size. (#14)
Browse files Browse the repository at this point in the history
Add option for setting the font size.
  • Loading branch information
jharshman authored Aug 12, 2021
1 parent 156f01d commit df4c8e6
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 0 deletions.
1 change: 1 addition & 0 deletions tscli/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,7 @@ func executeQuery(cmd *cobra.Command, args []string) error {

p, err := ts.Plot([]tsplot.PlotOption{tsplot.WithXAxisName("UTC"),
tsplot.WithXTimeTicks(time.Kitchen),
tsplot.WithFontSize(float64(12)),
tsplot.WithGrid(colornames.Darkgrey),
tsplot.WithTitle(metric)}...)
if err != nil {
Expand Down
11 changes: 11 additions & 0 deletions tsplot/options.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"time"

"gonum.org/v1/plot"
"gonum.org/v1/plot/font"
"gonum.org/v1/plot/plotter"
monitoringpb "google.golang.org/genproto/googleapis/monitoring/v3"
"google.golang.org/protobuf/types/known/durationpb"
Expand Down Expand Up @@ -84,6 +85,16 @@ func WithXTimeTicks(format string) PlotOption {
}
}

// WithFontSize configures the font sizes for the plot's Title, Axis', and Legend.
func WithFontSize(size float64) PlotOption {
return func(p *plot.Plot) {
p.Title.TextStyle.Font.Size = font.Length(size)
p.X.Label.TextStyle.Font.Size = font.Length(size)
p.Y.Label.TextStyle.Font.Size = font.Length(size)
p.Legend.TextStyle.Font.Size = font.Length(size)
}
}

// ApplyDefaultHighContrast applies the default high contrast color scheme to the *plot.Plot.
func ApplyDefaultHighContrast(p *plot.Plot) {
opts := []PlotOption{
Expand Down

0 comments on commit df4c8e6

Please sign in to comment.