diff options
| author | Martin Kagamino Lehoux <martin@lehoux.net> | 2025-10-06 09:28:43 +0200 |
|---|---|---|
| committer | Martin Kagamino Lehoux <martin@lehoux.net> | 2025-10-06 09:50:00 +0200 |
| commit | 6573a54c50738e455b2b0d4863498b916046a466 (patch) | |
| tree | 6a4c8c10ef94e58d2a09377a352ae4aa1c731131 /layouts/shortcodes/chart.html | |
| parent | 39e2da08e72e23356298e8daa14ea8a51c6f638b (diff) | |
Simpler perf charts
Diffstat (limited to 'layouts/shortcodes/chart.html')
| -rw-r--r-- | layouts/shortcodes/chart.html | 17 |
1 files changed, 17 insertions, 0 deletions
diff --git a/layouts/shortcodes/chart.html b/layouts/shortcodes/chart.html index 69689cd..2198b63 100644 --- a/layouts/shortcodes/chart.html +++ b/layouts/shortcodes/chart.html @@ -1,8 +1,25 @@ {{- $id := printf "chart-%d" (now.UnixNano) -}} {{- $type := .Get "type" | default "bar" -}} +{{- $preset := .Get "preset" -}} +{{- $title := .Get "title" -}} {{- $data := .Get "data" -}} {{- $options := .Get "options" | default "{}" -}} +{{/* Load chart presets */}} +{{- $presets := site.Data.chart_presets -}} + +{{/* Handle preset-based charts */}} +{{- if $preset -}} + {{- $presetData := index $presets.charts $preset -}} + {{- if $presetData -}} + {{- $data = $presetData.data | jsonify -}} + {{- if and $title (not (index $presetData.options.plugins.title "text")) -}} + {{- $presetData = merge $presetData (dict "options" (merge $presetData.options (dict "plugins" (merge $presetData.options.plugins (dict "title" (dict "text" $title)))))) -}} + {{- end -}} + {{- $options = $presetData.options | jsonify -}} + {{- end -}} +{{- end -}} + <div class="chart-container mb-5"> <canvas id="{{ $id }}"></canvas> </div> |
