summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNick White <git@njw.name>2019-10-11 16:28:48 +0100
committerNick White <git@njw.name>2019-10-11 16:28:48 +0100
commite92a3571e87ed6ac8aed4b6a5cb5a3fa489da4f4 (patch)
tree079a7c2ee8c23020665aeaf8d4830b8a123867f2
parent7807cae93dadf4772828d465b0a367095e4dcd46 (diff)
Ensure graph produces output by falling back on generic page numbers if none can be determined
-rw-r--r--graph.go17
1 files changed, 15 insertions, 2 deletions
diff --git a/graph.go b/graph.go
index 1604d06..d42baee 100644
--- a/graph.go
+++ b/graph.go
@@ -42,6 +42,10 @@ func createLine(xvalues []float64, y float64, c drawing.Color) chart.ContinuousS
}
func Graph(confs map[string]*Conf, bookname string, w io.Writer) error {
+ if len(confs) == 0 {
+ return errors.New("No valid confidences")
+ }
+
// Organise confs to sort them by page
var graphconf []GraphConf
for _, conf := range confs {
@@ -60,12 +64,21 @@ func Graph(confs map[string]*Conf, bookname string, w io.Writer) error {
c.Conf = conf.Conf
graphconf = append(graphconf, c)
}
- sort.Slice(graphconf, func(i, j int) bool { return graphconf[i].Pgnum < graphconf[j].Pgnum })
+ // If we failed to get any page numbers, just fake the lot
if len(graphconf) == 0 {
- return errors.New("No valid confidences")
+ i := float64(1)
+ for _, conf := range confs {
+ var c GraphConf
+ c.Pgnum = i
+ c.Conf = conf.Conf
+ graphconf = append(graphconf, c)
+ i++
+ }
}
+ sort.Slice(graphconf, func(i, j int) bool { return graphconf[i].Pgnum < graphconf[j].Pgnum })
+
// Create main xvalues and yvalues, annotations and ticks
var xvalues, yvalues []float64
var annotations []chart.Value2