Playing around with SVG

This commit is contained in:
2017-07-07 02:37:43 +02:00
parent 8c438ba08b
commit a80266358d
4 changed files with 32 additions and 25 deletions

View File

@ -1,6 +1,7 @@
package statistics
import (
"fmt"
"net/http"
"github.com/aerogo/aero"
@ -63,9 +64,21 @@ func Get(ctx *aero.Context) string {
}
}
if len(screenSizesSorted) > 5 {
screenSizesSorted = screenSizesSorted[:5]
slices := []*utils.PieChartSlice{}
current := 0.0
for _, item := range screenSizesSorted {
percentage := float64(item.Value) / float64(len(analytics))
slices = append(slices, &utils.PieChartSlice{
From: current,
To: current + percentage,
Title: fmt.Sprintf("%s (%d%%)", item.Key, int(percentage*100+0.5)),
Color: fmt.Sprintf("rgba(255, 64, 0, %.3f)", 0.8-current*0.8),
})
current += percentage
}
return ctx.HTML(components.Statistics(screenSizesSorted))
return ctx.HTML(components.Statistics(slices))
}