-
Notifications
You must be signed in to change notification settings - Fork 1
/
chart.go
71 lines (66 loc) · 1.31 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
70
71
package main
import (
"fmt"
"io"
"time"
"github.com/wcharczuk/go-chart"
"github.com/wcharczuk/go-chart/drawing"
)
func writeStarsChart(stars []stargazer, w io.Writer) error {
series := chart.TimeSeries{
Style: chart.Style{
Show: true,
StrokeColor: drawing.Color{
R: 129,
G: 199,
B: 239,
A: 255,
},
StrokeWidth: 2,
},
}
for i, star := range stars {
series.XValues = append(series.XValues, star.StarredAt)
series.YValues = append(series.YValues, float64(i))
}
if len(series.XValues) < 2 {
series.XValues = append(series.XValues, time.Now())
series.YValues = append(series.YValues, 1)
}
graph := chart.Chart{
XAxis: chart.XAxis{
Name: "Time",
NameStyle: chart.StyleShow(),
Style: chart.Style{
Show: true,
StrokeWidth: 2,
StrokeColor: drawing.Color{
R: 85,
G: 85,
B: 85,
A: 255,
},
},
},
YAxis: chart.YAxis{
Name: "Stargazers",
NameStyle: chart.StyleShow(),
Style: chart.Style{
Show: true,
StrokeWidth: 2,
StrokeColor: drawing.Color{
R: 85,
G: 85,
B: 85,
A: 255,
},
},
ValueFormatter: intValueFormatter,
},
Series: []chart.Series{series},
}
return graph.Render(chart.SVG, w)
}
func intValueFormatter(v any) string {
return fmt.Sprintf("%.0f", v)
}