2019-08-17 15:55:25 +03:00
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
|
|
|
"os"
|
|
|
|
"strconv"
|
|
|
|
|
|
|
|
c "github.com/wcharczuk/go-chart"
|
|
|
|
)
|
|
|
|
|
2019-08-19 20:00:27 +03:00
|
|
|
// You need to run:
|
|
|
|
// go get -u github.com/wcharczuk/go-chart
|
|
|
|
|
2019-08-17 15:55:25 +03:00
|
|
|
type chartSummary struct {
|
|
|
|
title string
|
|
|
|
width, height int
|
|
|
|
}
|
|
|
|
|
|
|
|
func (s *chartSummary) summarize(results iterator) error {
|
|
|
|
w := os.Stdout
|
|
|
|
|
|
|
|
donut := c.DonutChart{
|
|
|
|
Title: s.title,
|
|
|
|
TitleStyle: c.Style{
|
|
|
|
FontSize: 35,
|
|
|
|
Show: true,
|
|
|
|
FontColor: c.ColorAlternateGreen,
|
|
|
|
},
|
|
|
|
Width: s.width,
|
|
|
|
Height: s.height,
|
|
|
|
}
|
|
|
|
|
|
|
|
results.each(func(r result) {
|
|
|
|
v := c.Value{
|
|
|
|
Label: r.domain + r.page + ": " + strconv.Itoa(r.visits),
|
|
|
|
Value: float64(r.visits),
|
|
|
|
Style: c.Style{
|
|
|
|
FontSize: 14,
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
|
|
|
donut.Values = append(donut.Values, v)
|
|
|
|
})
|
|
|
|
|
|
|
|
return donut.Render(c.SVG, w)
|
|
|
|
}
|