forked from Sylius/Stack
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathstatistics_chart.js
More file actions
134 lines (122 loc) · 2.7 KB
/
statistics_chart.js
File metadata and controls
134 lines (122 loc) · 2.7 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
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
131
132
133
134
import ApexCharts from 'apexcharts';
let chart = null;
function renderChart() {
// eslint-disable-next-line no-undef
const statisticsChart = document.querySelector('#statistics-chart');
if (!statisticsChart) {
return;
}
const styles = getComputedStyle(document.documentElement);
const labelColor = styles.getPropertyValue('--tblr-body-color').trim();
const primaryColor = styles.getPropertyValue('--tblr-primary').trim();
const options = {
colors: [primaryColor],
fill: {
colors: [primaryColor]
},
series: [{
name: 'talks',
data: JSON.parse(statisticsChart.dataset.talks)
}],
chart: {
toolbar: {
show: false
},
height: 350,
type: 'bar'
},
plotOptions: {
bar: {
borderRadius: 4,
dataLabels: {
position: 'top' // top, center, bottom
}
}
},
dataLabels: {
enabled: true,
offsetY: -20,
style: {
fontSize: '12px',
colors: [labelColor]
}
},
xaxis: {
categories: JSON.parse(statisticsChart.dataset.intervals),
position: 'top',
labels: {
style: {
colors: labelColor
}
},
axisBorder: {
show: false
},
axisTicks: {
show: false
},
crosshairs: {
fill: {
type: 'gradient',
gradient: {
colorFrom: primaryColor,
colorTo: primaryColor,
stops: [0, 100],
opacityFrom: 0.4,
opacityTo: 0.5
}
}
},
tooltip: {
enabled: true
}
},
yaxis: {
axisBorder: {
show: false
},
axisTicks: {
show: false
},
labels: {
show: false,
}
},
title: {
floating: true,
offsetY: 330,
align: 'center',
style: {
color: labelColor
}
}
};
chart = new ApexCharts(statisticsChart, options);
chart.render();
}
renderChart();
const element = document.querySelector('#statistics-chart');
if (element) {
const observer = new MutationObserver(function(mutations) {
mutations.forEach(function(mutation) {
if (mutation.attributeName === 'data-talks' || mutation.attributeName === 'data-intervals') {
chart.destroy();
renderChart();
}
});
});
observer.observe(element, {
attributes: true
});
const themeObserver = new MutationObserver(function(mutations) {
mutations.forEach(function(mutation) {
if (mutation.attributeName === 'data-bs-theme') {
chart.destroy();
renderChart();
}
});
});
themeObserver.observe(document.documentElement, {
attributes: true
});
}