Files
learngo/interfaces/log-parser/oop/chartreport.go

46 lines
759 B
Go
Raw Normal View History

2019-08-17 15:55:25 +03:00
package main
import (
"os"
"strconv"
2019-08-26 17:22:53 +03:00
"github.com/wcharczuk/go-chart"
2019-08-17 15:55:25 +03:00
)
2019-08-19 20:00:27 +03:00
// You need to run:
// go get -u github.com/wcharczuk/go-chart
2019-08-26 14:37:58 +03:00
type chartReport struct {
2019-08-17 15:55:25 +03:00
title string
width, height int
}
2019-08-26 14:37:58 +03:00
func (s *chartReport) report(results iterator) error {
2019-08-17 15:55:25 +03:00
w := os.Stdout
2019-08-26 17:22:53 +03:00
donut := chart.DonutChart{
2019-08-17 15:55:25 +03:00
Title: s.title,
2019-08-26 17:22:53 +03:00
TitleStyle: chart.Style{
2019-08-17 15:55:25 +03:00
FontSize: 35,
Show: true,
2019-08-26 17:22:53 +03:00
FontColor: chart.ColorAlternateGreen,
2019-08-17 15:55:25 +03:00
},
Width: s.width,
Height: s.height,
}
results.each(func(r result) {
2019-08-26 17:22:53 +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:22:53 +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:22:53 +03:00
return donut.Render(chart.SVG, w)
2019-08-17 15:55:25 +03:00
}