From e92a3571e87ed6ac8aed4b6a5cb5a3fa489da4f4 Mon Sep 17 00:00:00 2001 From: Nick White Date: Fri, 11 Oct 2019 16:28:48 +0100 Subject: Ensure graph produces output by falling back on generic page numbers if none can be determined --- graph.go | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) (limited to 'graph.go') 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 -- cgit v1.2.1-24-ge1ad