draw circle if single value; do not position text on negative coordinates (#82)

This commit is contained in:
Bernhard Reisenberger 2018-10-12 02:21:06 +02:00 committed by Will Charczuk
parent 865ff54ab9
commit 6735e8990a

View File

@ -138,6 +138,12 @@ func (pc PieChart) drawSlices(r Renderer, canvasBox Box, values []Value) {
// draw the pie slices
var rads, delta, delta2, total float64
var lx, ly int
if len(values) == 1 {
pc.stylePieChartValue(0).WriteToRenderer(r)
r.MoveTo(cx, cy)
r.Circle(radius, cx, cy)
} else {
for index, v := range values {
v.Style.InheritFrom(pc.stylePieChartValue(index)).WriteToRenderer(r)
@ -152,6 +158,7 @@ func (pc PieChart) drawSlices(r Renderer, canvasBox Box, values []Value) {
r.FillStroke()
total = total + v.Value
}
}
// draw the labels
total = 0
@ -166,6 +173,13 @@ func (pc PieChart) drawSlices(r Renderer, canvasBox Box, values []Value) {
lx = lx - (tb.Width() >> 1)
ly = ly + (tb.Height() >> 1)
if lx < 0 {
lx = 0
}
if ly < 0 {
lx = 0
}
r.Text(v.Label, lx, ly)
}
total = total + v.Value