diff --git a/stacked_bar_chart.go b/stacked_bar_chart.go index cbf093e..b719e0c 100644 --- a/stacked_bar_chart.go +++ b/stacked_bar_chart.go @@ -4,6 +4,7 @@ import ( "errors" "fmt" "io" + "math" "github.com/golang/freetype/truetype" ) @@ -138,8 +139,8 @@ func (sbc StackedBarChart) drawBar(r Renderer, canvasBox Box, xoffset int, bar S normalizedBarComponents := Values(bar.Values).Normalize() yoffset := canvasBox.Top for index, bv := range normalizedBarComponents { - barHeight := int(bv.Value * float64(canvasBox.Height())) - barBox := Box{Top: yoffset, Left: bxl, Right: bxr, Bottom: yoffset + barHeight} + barHeight := int(math.Ceil(bv.Value * float64(canvasBox.Height()))) + barBox := Box{Top: yoffset, Left: bxl, Right: bxr, Bottom: Math.MinInt(yoffset+barHeight, canvasBox.Bottom-DefaultStrokeWidth)} Draw.Box(r, barBox, bv.Style.InheritFrom(sbc.styleDefaultsStackedBarValue(index))) yoffset += barHeight }