From 8b4432ece182a8e20ed6730224dde9f091916d75 Mon Sep 17 00:00:00 2001 From: surtur Date: Fri, 29 Jul 2022 21:04:15 +0200 Subject: [PATCH] go(plot): use consts for common strings --- algo/plot.go | 39 ++++++++++++++++++++++----------------- 1 file changed, 22 insertions(+), 17 deletions(-) diff --git a/algo/plot.go b/algo/plot.go index bfbb226..50664c2 100644 --- a/algo/plot.go +++ b/algo/plot.go @@ -19,27 +19,32 @@ import ( "gonum.org/v1/plot/vg" ) -const preferredFontStyle = "Mono" +const ( + preferredFont = "Mono" + titlePreferredFont = "Sans" + yAxisLabel = "CF value" + xAxisLabel = "Generations" +) func plotMeanVals(meanVals []float64, title string, fes int) *plot.Plot { - plotter.DefaultFont.Typeface = preferredFontStyle + plotter.DefaultFont.Typeface = preferredFont plotter.DefaultLineStyle.Width = vg.Points(2.0) p := plot.New() p.Title.Text = "Mean - " + title - p.X.Label.Text = "Generations" - p.X.Label.TextStyle.Font.Variant = preferredFontStyle + p.X.Label.Text = xAxisLabel + p.X.Label.TextStyle.Font.Variant = preferredFont p.X.Label.TextStyle.Font.Weight = 1 // Medium - p.X.Tick.Label.Font.Variant = preferredFontStyle - p.Y.Label.Text = "CF value" - p.Y.Label.TextStyle.Font.Variant = preferredFontStyle + p.X.Tick.Label.Font.Variant = preferredFont + p.Y.Label.Text = yAxisLabel + p.Y.Label.TextStyle.Font.Variant = preferredFont p.Y.Label.TextStyle.Font.Weight = 1 // Medium - p.Y.Tick.Label.Font.Variant = preferredFontStyle + p.Y.Tick.Label.Font.Variant = preferredFont p.Title.TextStyle.Font.Size = 14.5 - p.Title.TextStyle.Font.Variant = "Sans" + p.Title.TextStyle.Font.Variant = titlePreferredFont p.Title.TextStyle.Font.Weight = 2 // SemiBold p.Title.Padding = 3 * vg.Millimeter @@ -96,7 +101,7 @@ func plotAllDims(algoStats []stats.Stats, fPrefix, fExt string, ch chan report.P pWidth := 13 * vg.Centimeter pHeight := 13 * vg.Centimeter - plotter.DefaultFont.Typeface = preferredFontStyle + plotter.DefaultFont.Typeface = preferredFont plotter.DefaultLineStyle.Width = vg.Points(1.5) for _, s := range algoStats { @@ -116,17 +121,17 @@ func plotAllDims(algoStats []stats.Stats, fPrefix, fExt string, ch chan report.P pL.Bench = s.BenchFuncStats[0].BenchName pLMean.Bench = s.BenchFuncStats[0].BenchName - p.X.Label.Text = "Generations" - p.X.Label.TextStyle.Font.Variant = preferredFontStyle + p.X.Label.Text = xAxisLabel + p.X.Label.TextStyle.Font.Variant = preferredFont p.X.Label.TextStyle.Font.Weight = 1 // Medium - p.X.Tick.Label.Font.Variant = preferredFontStyle - p.Y.Label.Text = "CF value" - p.Y.Label.TextStyle.Font.Variant = preferredFontStyle + p.X.Tick.Label.Font.Variant = preferredFont + p.Y.Label.Text = yAxisLabel + p.Y.Label.TextStyle.Font.Variant = preferredFont p.Y.Label.TextStyle.Font.Weight = 1 // Medium - p.Y.Tick.Label.Font.Variant = preferredFontStyle + p.Y.Tick.Label.Font.Variant = preferredFont p.Title.TextStyle.Font.Size = 14.5 - p.Title.TextStyle.Font.Variant = "Sans" + p.Title.TextStyle.Font.Variant = titlePreferredFont p.Title.TextStyle.Font.Weight = 2 // SemiBold p.Title.Padding = 3 * vg.Millimeter