From ba1e1fefb4cc595ae12a2d22350e35fb4b5b1aed Mon Sep 17 00:00:00 2001 From: codecalm Date: Thu, 19 Dec 2019 22:47:40 +0100 Subject: [PATCH] charts extend, new params --- pages/_data/charts.yml | 27 +++++++++++++++++++++++++++ pages/_includes/ui/chart.html | 29 ++++++++++++++++++++++------- pages/_plugins/jekyll-filters.rb | 8 ++++++++ pages/tmp.html | 20 +++++++++++++------- 4 files changed, 70 insertions(+), 14 deletions(-) diff --git a/pages/_data/charts.yml b/pages/_data/charts.yml index 9c6219f5b..08cbe4e10 100644 --- a/pages/_data/charts.yml +++ b/pages/_data/charts.yml @@ -6,6 +6,33 @@ completion-tasks: - name: Tasks completion data: [155, 65, 465, 265, 225, 325, 80] +completion-tasks2: + extend: completion-tasks + type: line + +completion-tasks3: + extend: completion-tasks + type: area + +completion-tasks4: + extend: completion-tasks + stroke-curve: straight + type: line + +completion-tasks5: + extend: completion-tasks + stroke-curve: stepline + type: line + +completion-tasks6: + extend: completion-tasks + type: bar + horizontal: true + +completion-tasks7: + extend: completion-tasks + type: line + datalabels: true tasks-overview: type: bar diff --git a/pages/_includes/ui/chart.html b/pages/_includes/ui/chart.html index 6f1213b60..654e728bb 100644 --- a/pages/_includes/ui/chart.html +++ b/pages/_includes/ui/chart.html @@ -1,7 +1,7 @@ {% assign data = site.data.charts[include.chart-id] %} {% assign id = include.id | default: include.chart-id %} {% assign height = include.height | default: 10 %} -{% assign class = include.class | default: '' %} +{% assign class = include.class %} {% if include['size'] == 'sm' %} {% assign class = class | append: ' chart-sm' | strip %} @@ -9,8 +9,11 @@ {% endif %} {% if data %} -
+{% if data.extend %} +{% assign data = site.data.charts[data.extend] | concat_objects: site.data.charts[include.chart-id] %} +{% endif %} + +
{% append_lib apexcharts %} {% capture script %} @@ -21,12 +24,10 @@ window.tabler_chart = window.tabler_chart || {}; {% endif %} - window.ApexCharts && ({% if jekyll.environment == 'development' %} - window.tabler_chart["chart-{{ include.chart-id }}"] = {% endif %} - new ApexCharts(document.getElementById('chart-{{ id }}'), { + window.ApexCharts && ({% if jekyll.environment == 'development' %}window.tabler_chart["chart-{{ include.chart-id }}"] = {% endif %}new ApexCharts(document.getElementById('chart-{{ id }}'), { chart: { type: "{{ data.type }}", - {% if data.title %} + {% if data.title or data.type == "bar" or data.type == "line" %} fontFamily: 'inherit', {% endif %} height: {{ height | times: 16 }}, @@ -52,6 +53,20 @@ {% endif %} }, + {% if data.type == 'bar' and data.horizontal %} + plotOptions: { + bar: { + horizontal: true, + } + }, + {% endif %} + + {% if data.datalabels %} + dataLabels: { + enabled: true, + }, + {% endif %} + fill: { opacity: {% if data.type == 'area' %}.16{% else %}1{% endif %}, {% if data.type == 'area' %}type: 'solid'{% endif %} diff --git a/pages/_plugins/jekyll-filters.rb b/pages/_plugins/jekyll-filters.rb index b8e64d9ef..1ab0c17b5 100644 --- a/pages/_plugins/jekyll-filters.rb +++ b/pages/_plugins/jekyll-filters.rb @@ -80,6 +80,14 @@ module Jekyll "rgb(#{r.hex}, #{g.hex}, #{b.hex})" end + def concat_objects(object, object2) + if object and object2 and object.is_a?(Hash) and object2.is_a?(Hash) + return object.merge(object2) + end + + object + end + def tabler_color(color, variation = false) if variation color = color + '-' + variation diff --git a/pages/tmp.html b/pages/tmp.html index f9cafe51d..376389e42 100644 --- a/pages/tmp.html +++ b/pages/tmp.html @@ -3,13 +3,19 @@ tmp: true ---
-
-
-
- {% include ui/chart.html chart-id="completion-tasks" height=15 %} -
-
-
+ + {% assign charts = 'completion-tasks,completion-tasks2,completion-tasks3,completion-tasks4,completion-tasks5,completion-tasks6,completion-tasks7' | split: ',' %} + {% for chart in charts %} +
+
+
+ {% include ui/chart.html chart-id=chart height=15 %} +
+
+
+ {% endfor %} + +