This repository has been archived by the owner on Oct 26, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 3
/
chart.go
69 lines (60 loc) · 1.45 KB
/
chart.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
package main
import "html/template"
var (
chartSCcolorLost = "#c33c"
chartSCcolorWon = "#3c3c"
chartSCcolorNeutral = "#17fc"
)
type primitiveStackedChart struct {
Caption string
AxisY string
AxisX string
Data []primitiveStackedChartColumn
TotalData int
}
type primitiveStackedChartColumn struct {
Label template.HTML
Values []primitiveStackedChartColumnValue
}
type primitiveStackedChartColumnValue struct {
Label string
Color string
Value int
}
func newSCColVal(l, c string, v int) primitiveStackedChartColumnValue {
return primitiveStackedChartColumnValue{
Label: l,
Color: c,
Value: v,
}
}
func newSC(c, x, y string) *primitiveStackedChart {
return &primitiveStackedChart{
Caption: c,
AxisY: y,
AxisX: x,
Data: []primitiveStackedChartColumn{},
TotalData: 0,
}
}
func (ch *primitiveStackedChart) calcTotals() *primitiveStackedChart {
ch.TotalData = 0
for _, v := range ch.Data {
for _, vv := range v.Values {
ch.TotalData += vv.Value
}
}
return ch
}
func (ch *primitiveStackedChart) appendToColumn(colname, label, color string, value int) {
for i, v := range ch.Data {
if v.Label == template.HTML(colname) {
ch.Data[i].Values = append(ch.Data[i].Values, newSCColVal(label, color, value))
return
}
}
ch.Data = append(ch.Data, primitiveStackedChartColumn{
Label: template.HTML(colname),
Values: []primitiveStackedChartColumnValue{newSCColVal(label, color, value)},
})
}