Files
learngo/advfuncs/logparser/functional/chartwriter.go

47 lines
808 B
Go
Raw Normal View History

2019-08-17 15:55:25 +03:00
package main
import (
"io"
"sort"
"strconv"
2019-08-26 17:19:27 +03:00
"github.com/wcharczuk/go-chart"
2019-08-17 15:55:25 +03:00
)
func chartWriter(w io.Writer) outputFn {
return func(res []result) error {
return chartWrite(w, res)
}
}
func chartWrite(w io.Writer, res []result) error {
sort.Slice(res, func(i, j int) bool {
return res[i].domain > res[j].domain
})
2019-08-26 17:19:27 +03:00
donut := chart.DonutChart{
2019-08-17 15:55:25 +03:00
Title: "Total Visits Per Domain",
2019-08-26 17:19:27 +03:00
TitleStyle: chart.Style{
2019-08-17 15:55:25 +03:00
FontSize: 35,
Show: true,
2019-08-26 17:19:27 +03:00
FontColor: chart.ColorAlternateGreen,
2019-08-17 15:55:25 +03:00
},
Width: 1920,
Height: 800,
}
for _, r := range res {
2019-08-26 17:19:27 +03:00
v := chart.Value{
2019-08-17 15:55:25 +03:00
Label: r.domain + r.page + ": " + strconv.Itoa(r.visits),
Value: float64(r.visits),
2019-08-26 17:19:27 +03:00
Style: chart.Style{
2019-08-17 15:55:25 +03:00
FontSize: 14,
},
}
donut.Values = append(donut.Values, v)
}
2019-08-26 17:19:27 +03:00
return donut.Render(chart.SVG, w)
2019-08-17 15:55:25 +03:00
}