From 1a62cfa10f5c4ed646460abad6081086829471a4 Mon Sep 17 00:00:00 2001 From: Caleb Bassi Date: Thu, 24 Jan 2019 05:38:28 -0800 Subject: [PATCH] Only draw StackedBarChart label if it exists --- widgets/stacked_barchart.go | 20 +++++++++++--------- 1 file changed, 11 insertions(+), 9 deletions(-) diff --git a/widgets/stacked_barchart.go b/widgets/stacked_barchart.go index 34fd2c9..87e0580 100644 --- a/widgets/stacked_barchart.go +++ b/widgets/stacked_barchart.go @@ -79,15 +79,17 @@ func (self *StackedBarChart) Draw(buf *Buffer) { } // draw label - labelXCoordinate := barXCoordinate + MaxInt( - int((float64(self.BarWidth)/2))-int((float64(rw.StringWidth(self.Labels[i]))/2)), - 0, - ) - buf.SetString( - TrimString(self.Labels[i], self.BarWidth), - SelectStyle(self.LabelStyles, i), - image.Pt(labelXCoordinate, self.Inner.Max.Y-1), - ) + if i < len(self.Labels) { + labelXCoordinate := barXCoordinate + MaxInt( + int((float64(self.BarWidth)/2))-int((float64(rw.StringWidth(self.Labels[i]))/2)), + 0, + ) + buf.SetString( + TrimString(self.Labels[i], self.BarWidth), + SelectStyle(self.LabelStyles, i), + image.Pt(labelXCoordinate, self.Inner.Max.Y-1), + ) + } barXCoordinate += (self.BarWidth + self.BarGap) }