1
0
mirror of https://github.com/nikolaydubina/calendarheatmap.git synced 2024-12-05 03:58:50 +02:00
This commit is contained in:
Nikolay 2021-02-27 16:16:51 +00:00 committed by GitHub
parent ca80e3c75e
commit 155466daf9
3 changed files with 10 additions and 14 deletions

Binary file not shown.

View File

@ -54,7 +54,7 @@ type HeatmapConfig struct {
// WriteHeatmap writes image with heatmap and additional elements
func WriteHeatmap(conf HeatmapConfig, w io.Writer) error {
if conf.Format == "svg" {
return writeSVG(conf, w)
writeSVG(conf, w)
}
width := conf.TextWidthLeft + numWeekCols*(conf.BoxSize+conf.Margin)

View File

@ -8,7 +8,7 @@ import (
"text/template"
)
// Day contains info to render single cell of a day
// Day is SVG template day parameters
type Day struct {
Count int
Date string
@ -16,13 +16,13 @@ type Day struct {
Show bool
}
// WeekdayLabel contains details for single weekday label like Monday or Tuesday
// WeekdayLabel is SVG template weekday label parameters
type WeekdayLabel struct {
Label string
Show bool
}
// Params specify parameters to render SVG
// Params is total SVG template parameters
type Params struct {
Days [53][7]Day
LabelsMonths [12]string
@ -30,11 +30,11 @@ type Params struct {
LabelsColor string
}
func writeColor(c color.RGBA) string {
func writeSVGColor(c color.RGBA) string {
return fmt.Sprintf("rgb(%d,%d,%d)", c.R, c.G, c.B)
}
func writeSVG(conf HeatmapConfig, w io.Writer) error {
func writeSVG(conf HeatmapConfig, w io.Writer) {
fullYearTemplate := template.Must(template.New("fullyear").Funcs(template.FuncMap{
"mul": func(a int, b int) int { return a * b },
"add": func(a int, b int) int { return a + b },
@ -47,7 +47,7 @@ func writeSVG(conf HeatmapConfig, w io.Writer) error {
days[iter.Col][iter.Row] = Day{
Count: iter.Count(),
Date: iter.Time().Format("2006-01-02"),
Color: writeColor(conf.ColorScale.GetColor(iter.Value())),
Color: writeSVGColor(conf.ColorScale.GetColor(iter.Value())),
Show: true,
}
}
@ -68,14 +68,10 @@ func writeSVG(conf HeatmapConfig, w io.Writer) error {
labelsWeekdays[i] = WeekdayLabel{v, true}
}
params := Params{
fullYearTemplate.Execute(w, Params{
Days: days,
LabelsMonths: labelsMonths,
LabelsWeekdays: labelsWeekdays,
LabelsColor: writeColor(conf.TextColor),
}
fullYearTemplate.Execute(w, params)
return nil
LabelsColor: writeSVGColor(conf.TextColor),
})
}