/
actions.go
48 lines (42 loc) · 910 Bytes
/
actions.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
package fiowatch
import (
"bytes"
"github.com/blockpane/fiowatch/assets"
"github.com/wcharczuk/go-chart/v2"
"image"
)
func Pie(summary BlockSummarys, w int, h int) image.Image {
if len(summary.ToValues()) < 2 {
i, _, _ := fioassets.NewFioLogo()
return i
}
style := chart.StyleTextDefaults()
style.Padding = chart.Box{
Top: 6,
Left: 6,
Right: 6,
Bottom: 6,
}
style.FontSize = 30
var cp interface{}
cp = pieLightPalette{}
pie := chart.PieChart{
Width: w,
Height: h,
Font: font,
DPI: 288,
Canvas: style,
ColorPalette: cp.(chart.ColorPalette),
Values: summary.ToValues(),
}
buf := bytes.NewBuffer(nil)
err := pie.Render(chart.PNG, buf)
if err != nil {
return image.NewRGBA(image.Rect(0, 0, w, h))
}
img, _, err := image.Decode(buf)
if err != nil {
return image.NewRGBA(image.Rect(0, 0, w, h))
}
return img
}