1
0
mirror of https://github.com/nikolaydubina/calendarheatmap.git synced 2025-02-08 11:47:59 +02:00
calendarheatmap/main.go

51 lines
1.3 KiB
Go
Raw Normal View History

2020-07-02 02:48:34 +08:00
package main
import (
2020-12-08 07:23:11 +08:00
"encoding/json"
2020-07-02 02:48:34 +08:00
"flag"
2020-07-03 09:44:39 +08:00
"image/color"
"io/ioutil"
2020-07-02 02:48:34 +08:00
"log"
"os"
2020-07-02 17:58:02 +08:00
"github.com/nikolaydubina/calendarheatmap/charts"
"github.com/nikolaydubina/calendarheatmap/colorscales"
2020-07-02 02:48:34 +08:00
)
func main() {
2020-12-08 07:23:11 +08:00
os.Setenv("CALENDAR_HEATMAP_ASSETS_PATH", "charts/assets")
colorScale := *flag.String("colorscale", "PuBu9", "refer to colorscales for examples")
labels := *flag.Bool("labels", true, "labels for weekday and months")
monthSep := *flag.Bool("monthsep", true, "render month separator")
outputFormat := *flag.String("output", "png", "output format (png, jpeg, gif, svg)")
locale := *flag.String("locale", "en_US", "locale of labels (en_US, ko_KR)")
2020-07-02 02:48:34 +08:00
flag.Parse()
data, err := ioutil.ReadAll(os.Stdin)
2020-07-02 02:48:34 +08:00
if err != nil {
2020-12-08 07:23:11 +08:00
log.Fatal(err)
2020-07-02 02:48:34 +08:00
}
2020-12-08 07:23:11 +08:00
var counts map[string]int
if err := json.Unmarshal(data, &counts); err != nil {
log.Fatal(err)
}
2020-07-02 02:48:34 +08:00
2020-12-07 19:55:29 +08:00
conf := charts.HeatmapConfig{
2020-12-08 07:23:11 +08:00
Counts: counts,
ColorScale: colorscales.LoadColorScale(colorScale),
DrawMonthSeparator: monthSep,
DrawLabels: labels,
2020-09-29 20:02:08 +08:00
Margin: 30,
BoxSize: 150,
TextWidthLeft: 350,
TextHeightTop: 200,
2020-07-03 09:44:39 +08:00
TextColor: color.RGBA{100, 100, 100, 255},
BorderColor: color.RGBA{200, 200, 200, 255},
2020-12-08 07:23:11 +08:00
Locale: locale,
Format: outputFormat,
2020-07-02 02:48:34 +08:00
}
2020-12-08 07:23:11 +08:00
charts.WriteHeatmap(conf, os.Stdout)
2020-07-02 02:48:34 +08:00
}