diff options
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> |
