-
-
Notifications
You must be signed in to change notification settings - Fork 17
/
main.go
103 lines (91 loc) · 2.55 KB
/
main.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
package main
import (
"bytes"
"encoding/json"
"flag"
"image/color"
"io/ioutil"
"log"
"os"
"path"
"time"
_ "embed"
"github.com/nikolaydubina/calendarheatmap/charts"
"golang.org/x/image/font"
"golang.org/x/image/font/opentype"
)
//go:embed assets/fonts/Sunflower-Medium.ttf
var defaultFontFaceBytes []byte
//go:embed assets/colorscales/green-blue-9.csv
var defaultColorScaleBytes []byte
func main() {
var (
colorScale string
labels bool
locale string
monthSep bool
outputFormat string
)
flag.BoolVar(&labels, "labels", true, "labels for weekday and months")
flag.BoolVar(&monthSep, "monthsep", true, "render month separator")
flag.StringVar(&colorScale, "colorscale", "green-blue-9.csv", "filename of colorscale")
flag.StringVar(&locale, "locale", "en_US", "locale of labels (en_US, ko_KR)")
flag.StringVar(&outputFormat, "output", "png", "output format (png, jpeg, gif, svg)")
flag.Parse()
var colorscale charts.BasicColorScale
if assetsPath := os.Getenv("CALENDAR_HEATMAP_ASSETS_PATH"); assetsPath != "" {
var err error
colorscale, err = charts.NewBasicColorscaleFromCSVFile(path.Join(assetsPath, "colorscales", colorScale))
if err != nil {
log.Fatal(err)
}
} else {
var err error
if colorScale != "green-blue-9.csv" {
log.Printf("defaulting to colorscale %s since CALENDAR_HEATMAP_ASSETS_PATH is not set", "green-blue-9.csv")
}
colorscale, err = charts.NewBasicColorscaleFromCSV(bytes.NewBuffer(defaultColorScaleBytes))
if err != nil {
log.Fatal(err)
}
}
fontFace, err := charts.LoadFontFace(defaultFontFaceBytes, opentype.FaceOptions{
Size: 26,
DPI: 280,
Hinting: font.HintingNone,
})
if err != nil {
log.Fatal(err)
}
data, err := ioutil.ReadAll(os.Stdin)
if err != nil {
log.Fatal(err)
}
var counts map[string]int
if err := json.Unmarshal(data, &counts); err != nil {
log.Fatal(err)
}
conf := charts.HeatmapConfig{
Counts: counts,
ColorScale: colorscale,
DrawMonthSeparator: monthSep,
DrawLabels: labels,
Margin: 30,
BoxSize: 150,
MonthSeparatorWidth: 5,
MonthLabelYOffset: 50,
TextWidthLeft: 300,
TextHeightTop: 200,
TextColor: color.RGBA{100, 100, 100, 255},
BorderColor: color.RGBA{200, 200, 200, 255},
Locale: locale,
Format: outputFormat,
FontFace: fontFace,
ShowWeekdays: map[time.Weekday]bool{
time.Monday: true,
time.Wednesday: true,
time.Friday: true,
},
}
charts.WriteHeatmap(conf, os.Stdout)
}