Files
learngo/interfaces/05-log-parser/oop/chartsummary.go
2019-08-19 20:00:27 +03:00

46 lines
742 B
Go

package main
import (
"os"
"strconv"
c "github.com/wcharczuk/go-chart"
)
// You need to run:
// go get -u github.com/wcharczuk/go-chart
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)
}