chart.html 4.3 KB
Newer Older
C
chomik 已提交
1
{% assign data = site.data.charts[include.chart-id] %}
C
codecalm 已提交
2
{% assign id = include.id | default: include.chart-id %}
C
codecalm 已提交
3
{% assign height = include.height | default: 10 %}
C
codecalm 已提交
4
{% assign class = include.class %}
C
codecalm 已提交
5 6

{% if include['size'] == 'sm' %}
C
codecalm 已提交
7 8
{% assign class = class | append: ' chart-sm' | strip %}
{% assign height = 2.5 %}
C
codecalm 已提交
9
{% endif %}
C
chomik 已提交
10

C
chomik 已提交
11
{% if data %}
C
codecalm 已提交
12 13 14 15
{% if data.extend %}
{% assign data = site.data.charts[data.extend] | concat_objects: site.data.charts[include.chart-id] %}
{% endif %}

C
codecalm 已提交
16
<div id="chart-{{ id }}" {% if class %} class="{{ class }}" {% endif %}{% if data.debug and jekyll.environment == 'development' %} style="outline: 1px solid red" {% endif %}></div>
C
codecalm 已提交
17

C
codecalm 已提交
18
{% append_lib apexcharts %}
C
codecalm 已提交
19
{% capture script %}
C
chomik 已提交
20
<script>
C
codecalm 已提交
21
	// @formatter:off
22
	document.addEventListener("DOMContentLoaded", function () {
C
codecalm 已提交
23 24 25 26
		{% if jekyll.environment == 'development' %}
		window.tabler_chart = window.tabler_chart || {};
		{% endif %}

C
codecalm 已提交
27
		window.ApexCharts && ({% if jekyll.environment == 'development' %}window.tabler_chart["chart-{{ include.chart-id }}"] = {% endif %}new ApexCharts(document.getElementById('chart-{{ id }}'), {
C
codecalm 已提交
28
			chart: {
C
codecalm 已提交
29
				type: "{{ data.type | default: 'bar' }}",
C
codecalm 已提交
30 31 32 33 34 35 36 37
				fontFamily: 'inherit',
				height: {{ height | times: 16 }},

				{% if data.sparkline %}
				sparkline: {
					enabled: true
				},
				{% else %}
C
codecalm 已提交
38
				parentHeightOffset: 0,
C
codecalm 已提交
39
				toolbar: {
C
codecalm 已提交
40
					show: false,
C
codecalm 已提交
41 42 43 44 45 46 47 48 49 50 51 52 53 54
				},
				{% endif %}

				{% unless data.animations %}
				animations: {
					enabled: false
				},
				{% endunless %}

				{% if data.stacked %}
				stacked: true,
				{% endif %}
			},

C
codecalm 已提交
55 56 57 58 59 60 61 62 63 64 65 66 67 68
			{% if data.type == 'bar' and data.horizontal %}
			plotOptions: {
				bar: {
			 		horizontal: true,
				}
			},
			{% endif %}

			{% if data.datalabels %}
			dataLabels: {
				enabled: true,
			},
			{% endif %}

C
codecalm 已提交
69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130
			fill: {
				opacity: {% if data.type == 'area' %}.16{% else %}1{% endif %},
				{% if data.type == 'area' %}type: 'solid'{% endif %}
			},

			{% if data.title %}
			title: {
				text: "{{ data.title | escape }}",
				margin: 0,
				floating: true,
				offsetX: 10,
				style: {
					fontSize: '18px',
				},
			},
			{% endif %}

			{% if data.type == 'area' or data.type == 'line' %}
			stroke: {
				width: {% if data.stroke-width %}[{{ data.stroke-width | join: ', '}}]{% else %}2{% endif %},
				{% if data.stroke-dash %}dashArray: [{{ data.stroke-dash | join: ', '}}],{% endif %}
				lineCap: "round",
				curve: "{{ data.stroke-curve | default: 'smooth' }}",
			},
			{% endif %}

			{% if data.series %}
			{% if data.type == 'pie' or data.type == 'donut' or data.type == 'radialBar' %}
			series: [{% for serie in data.series %}{{ serie.data }}{% unless forloop.last %}, {% endunless %}{% endfor %}],
			labels: [{% for serie in data.series %}"{{ serie.name }}"{% unless forloop.last %}, {% endunless %}{% endfor %}],

			{% else %}series: [{% for serie in data.series %}{
				name: "{{ serie.name }}",
				data: [{{ serie.data | join: ', ' }}]
			}{% unless forloop.last %},{% endunless %}{% endfor %}],
			{% endif %}
			{% endif %}

			{% if data.show - grid %}
			grid: {
				show: true,
			},
			{% endif %}

			{% if data.show-data-labels %}
			dataLabels: {
				enabled: true,
			},
			{% endif %}

			{% if data.categories or data.days-labels-count %}
			xaxis: {
				{% if data.categories %}
				categories: [{% for category in data.categories %}"{{ category }}"{% unless forloop.last %}, {% endunless %}{% endfor %}],
			{% endif %}

			{% if data.days-labels-count %}
				type: 'datetime', {% endif %}
			},
			{% endif %}

			{% if data.days-labels-count %}
C
codecalm 已提交
131
			labels: [...Array({{ data.days-labels-count }}).keys()].map(n => '2019-09-' + (n + 1)),
C
codecalm 已提交
132 133 134 135 136 137
			{% endif %}

			{% if data.series %}
			colors: [{% for serie in data.series %}{% assign color = serie.color | default: data.color | default: 'blue' %}"{{ color | tabler_color }}"{% unless forloop.last %}, {% endunless %}{% endfor %}],
			{% endif %}

C
codecalm 已提交
138
			{% unless data.show-legend %}
C
codecalm 已提交
139 140 141
			legend: {
				show: false,
			},
C
codecalm 已提交
142
			{% endunless %}
C
codecalm 已提交
143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163

			{% if data.hide-tooltip %}
			tooltip: {
				enabled: false
			},
			{% endif %}

			{% if data.hide-points %}
			point: {
				show: false
			},
			{% endif %}

			{% if data.show-markers %}
			markers: {
				size: 2
			},
			{% endif %}
		})).render();
	});
	// @formatter:on
C
chomik 已提交
164
</script>
C
codecalm 已提交
165 166 167
{% endcapture %}

{% if include.show-scripts %}
C
codecalm 已提交
168
{{ script }}
C
codecalm 已提交
169
{% else %}
C
codecalm 已提交
170 171 172
{% capture_global scripts %}
{{ script }}
{% endcapture_global %}
C
codecalm 已提交
173 174
{% endif %}

C
codecalm 已提交
175
{% endif %}