From 7b7fdbedd38f691ead99c5f4a2a691482fe724d0 Mon Sep 17 00:00:00 2001
From: Nick White <git@njw.name>
Date: Mon, 20 Jul 2020 18:40:53 +0100
Subject: [pggraph] Simplify and correct x ticks

---
 cmd/pggraph/main.go | 22 ++++++----------------
 1 file changed, 6 insertions(+), 16 deletions(-)

diff --git a/cmd/pggraph/main.go b/cmd/pggraph/main.go
index 9d9d26c..7d56145 100644
--- a/cmd/pggraph/main.go
+++ b/cmd/pggraph/main.go
@@ -33,7 +33,7 @@ this module.
 `
 
 const middlePercent = 20
-const tickEvery = 30
+const numTicks = 30
 
 // sideways flips an image sideways
 func sideways(img *image.Gray) *image.Gray {
@@ -112,23 +112,13 @@ func graph(title string, points map[int]float64, w io.Writer) error {
 		InnerSeries: middleSeries,
 	}
 
-	width := xs[1]
 	var ticks []chart.Tick
-	// if width is larger than tickEvery, just have a tick for each point,
-	// otherwise have a tick every tickEvery period
-	if width > tickEvery {
-		for _, v := range xs {
-			ticks = append(ticks, chart.Tick{float64(v), fmt.Sprintf("%d", v)})
-		}
-	} else {
-		for i := 0; i < len(xs) - 1; i += tickEvery {
-			ticks = append(ticks, chart.Tick{float64(xs[i]), fmt.Sprintf("%d", xs[i])})
-		}
-		if len(ticks) > 1 {
-			lastx := xs[len(xs) - 1]
-			ticks[len(ticks) - 1] = chart.Tick{float64(lastx), fmt.Sprintf("%d", lastx)}
-		}
+	var tickEvery = xs[len(xs) - 1] / numTicks
+	for i := 0; i < xs[len(xs) - 1]; i += tickEvery {
+		ticks = append(ticks, chart.Tick{float64(i), fmt.Sprintf("%d", i)})
 	}
+	lastx := xs[len(xs) - 1]
+	ticks[len(ticks) - 1] = chart.Tick{float64(lastx), fmt.Sprintf("%d", lastx)}
 
 	graph := chart.Chart{
 		Title: title,
-- 
cgit v1.2.1-24-ge1ad