-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathplot_piechart.go
103 lines (81 loc) · 2.03 KB
/
plot_piechart.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
package gig
import (
"github.com/leonsal/gig/imgui"
)
type PlotPieChart struct {
Widget
labelIds imgui.CStrArr
labelFmt imgui.CString
v interface{}
count int
x float64
y float64
radius float64
angle0 float64
normalize bool
renderIndex int
}
func NewPlotPieChart(labels []string) *PlotPieChart {
p := new(PlotPieChart)
p.Init(p)
p.labelIds.Append(labels...)
p.labelFmt.SetString("%.1f")
p.angle0 = 90
p.normalize = false
p.SetRender(func() {
switch p.renderIndex {
case indexPlotI32:
imgui.PlotPieChartInt32CS(p.labelIds, p.v.(*int32), p.count, p.x, p.y, p.radius, p.normalize, p.labelFmt, p.angle0)
case indexPlotF32:
imgui.PlotPieChartFloat32CS(p.labelIds, p.v.(*float32), p.count, p.x, p.y, p.radius, p.normalize, p.labelFmt, p.angle0)
case indexPlotF64:
imgui.PlotPieChartFloat64CS(p.labelIds, p.v.(*float64), p.count, p.x, p.y, p.radius, p.normalize, p.labelFmt, p.angle0)
}
})
return p
}
func (p *PlotPieChart) Save(pp **PlotPieChart) *PlotPieChart {
*pp = p
return p
}
func (p *PlotPieChart) SetLabels(labels []string) *PlotPieChart {
p.labelIds.Clear()
p.labelIds.Append(labels...)
return p
}
func (p *PlotPieChart) SetPos(x, y, radius float64) *PlotPieChart {
p.x = x
p.y = y
p.radius = radius
return p
}
func (p *PlotPieChart) SetNormalize(normalize bool) *PlotPieChart {
p.normalize = normalize
return p
}
func (p *PlotPieChart) SetAngle0(angle0 float64) *PlotPieChart {
p.angle0 = angle0
return p
}
func (p *PlotPieChart) SetLabelFmt(fmt string) *PlotPieChart {
p.labelFmt.SetString(fmt)
return p
}
func (p *PlotPieChart) SetValuesInt32(v *int32, count int) *PlotPieChart {
p.v = v
p.count = count
p.renderIndex = indexPlotI32
return p
}
func (p *PlotPieChart) SetValuesFloat32(v *float32, count int) *PlotPieChart {
p.v = v
p.count = count
p.renderIndex = indexPlotF32
return p
}
func (p *PlotPieChart) SetValuesFloat64(v *float64, count int) *PlotPieChart {
p.v = v
p.count = count
p.renderIndex = indexPlotF64
return p
}