summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNick White <git@njw.name>2019-10-23 13:23:20 +0100
committerNick White <git@njw.name>2019-10-23 13:23:20 +0100
commitd9974362e406611b86a5a47b2c9f1771fb2a2719 (patch)
treea13b3df1d58051b685738bbdfa9101ba862f9785
parent6f4f10e91cb083bfd0a64e15c86197da6461aa2d (diff)
Manually calculate yticks, so they fall on reasonable numbers
-rw-r--r--graph.go8
1 files changed, 8 insertions, 0 deletions
diff --git a/graph.go b/graph.go
index bcdf2d8..44e650b 100644
--- a/graph.go
+++ b/graph.go
@@ -17,6 +17,7 @@ const maxticks = 40
const goodCutoff = 70
const mediumCutoff = 65
const badCutoff = 60
+const yticknum = 40
type Conf struct {
Path, Code string
@@ -82,6 +83,7 @@ func Graph(confs map[string]*Conf, bookname string, w io.Writer) error {
// Create main xvalues, yvalues ticks
var xvalues, yvalues []float64
var ticks []chart.Tick
+ var yticks []chart.Tick
tickevery := len(graphconf) / maxticks
if tickevery < 1 {
tickevery = 1
@@ -96,6 +98,11 @@ func Graph(confs map[string]*Conf, bookname string, w io.Writer) error {
// Make last tick the final page
final := graphconf[len(graphconf)-1]
ticks[len(ticks)-1] = chart.Tick{final.Pgnum, fmt.Sprintf("%.0f", final.Pgnum)}
+ for i := 1; i <= yticknum; i++ {
+ n := float64(i * 100) / yticknum
+ yticks = append(yticks, chart.Tick{n, fmt.Sprintf("%.1f", n)})
+ }
+
mainSeries := chart.ContinuousSeries{
XValues: xvalues,
YValues: yvalues,
@@ -162,6 +169,7 @@ func Graph(confs map[string]*Conf, bookname string, w io.Writer) error {
Min: 0.0,
Max: 100.0,
},
+ Ticks: yticks,
},
Series: []chart.Series{
mainSeries,