From 7674fa264017b4ddfb419e6bfaa3d23938a1fe3f Mon Sep 17 00:00:00 2001 From: Eltrac Date: Wed, 21 May 2025 21:05:29 +0800 Subject: feat: replace heatmap with wordcount bar chart --- layouts/_default/section.html | 2 +- layouts/partials/components/heatmap.html | 88 ----------------------- layouts/partials/components/wordCountChart.html | 93 +++++++++++++++++++++++++ 3 files changed, 94 insertions(+), 89 deletions(-) delete mode 100644 layouts/partials/components/heatmap.html create mode 100644 layouts/partials/components/wordCountChart.html diff --git a/layouts/_default/section.html b/layouts/_default/section.html index 1849c814..d1ad5401 100644 --- a/layouts/_default/section.html +++ b/layouts/_default/section.html @@ -2,7 +2,7 @@
{{ partial "header.html" . }}
- {{ partial "components/heatmap.html" . }} + {{ partial "components/wordCountChart.html" . }} {{ $first := true }} {{ range (where site.RegularPages "Type" "eq" "posts").GroupByDate "2006" -}} diff --git a/layouts/partials/components/heatmap.html b/layouts/partials/components/heatmap.html deleted file mode 100644 index f2058258..00000000 --- a/layouts/partials/components/heatmap.html +++ /dev/null @@ -1,88 +0,0 @@ - -
-
-
- - - - diff --git a/layouts/partials/components/wordCountChart.html b/layouts/partials/components/wordCountChart.html new file mode 100644 index 00000000..65d0e986 --- /dev/null +++ b/layouts/partials/components/wordCountChart.html @@ -0,0 +1,93 @@ + + +{{/* Group word counts per month */}} +{{ $monthly := dict }} +{{ range .Site.RegularPages }} + {{ $month := .Date.Format "2006-01" }} + {{ $count := .WordCount }} + {{ with index $monthly $month }} + {{ $monthly = merge $monthly (dict $month (add . $count)) }} + {{ else }} + {{ $monthly = merge $monthly (dict $month $count) }} + {{ end }} +{{ end }} + +{{/* Sort months */}} +{{ $months := slice }} +{{ range $month, $_ := $monthly }} + {{ $months = $months | append $month }} +{{ end }} +{{ $months = sort $months }} + +{{/* Find max value */}} +{{ $max := 0 }} +{{ range $month := $months }} + {{ $val := index $monthly $month }} + {{ if gt $val $max }}{{ $max = $val }}{{ end }} +{{ end }} + +
+ {{ range $month := $months }} + {{ $val := index $monthly $month }} + {{ $height := mul (div (float $val) (float $max)) 100 }} + {{ $opacity := add 0.5 (div $height 200) }} +
+
+
{{ $val }}
+
+
+
{{ $month }}
+
+ {{ end }} +
-- cgit v1.2.3