draw circle if single value; do not position text on negative coordinates (#82)
This commit is contained in:
parent
865ff54ab9
commit
6735e8990a
1 changed files with 23 additions and 9 deletions
14
pie_chart.go
14
pie_chart.go
|
@ -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
|
||||
|
|
Loading…
Reference in a new issue