PluginProbe ʕ •ᴥ•ʔ
Matomo Analytics – Powerful, Privacy-First Insights for WordPress / trunk
Matomo Analytics – Powerful, Privacy-First Insights for WordPress vtrunk
5.11.1 5.11.0 5.10.2 5.10.1 trunk 1.0.2 1.0.3 1.0.4 1.0.5 1.0.6 1.1.0 1.1.1 1.1.2 1.1.3 1.2.0 1.3.0 1.3.1 1.3.2 4.0.0 4.0.1 4.0.2 4.0.3 4.0.4 4.1.0 4.1.1 4.1.2 4.1.3 4.10.0 4.11.0 4.12.0 4.13.0 4.13.2 4.13.3 4.13.4 4.13.5 4.14.0 4.14.1 4.14.2 4.15.0 4.15.1 4.15.2 4.15.3 4.2.0 4.3.0 4.3.1 4.4.1 4.4.2 4.5.0 4.6.0 5.0.1 5.0.2 5.0.3 5.0.4 5.0.5 5.0.6 5.0.7 5.0.8 5.1.0 5.1.1 5.1.2 5.1.3 5.1.4 5.1.5 5.1.6 5.1.7 5.10.0 5.2.0 5.2.1 5.2.2 5.3.0 5.3.1 5.3.2 5.3.3 5.6.0 5.6.1 5.7.0 5.7.1 5.8.0 5.8.1 5.8.2
matomo / assets / chart.js
matomo / assets Last commit date
css 1 month ago img 1 month ago js 2 weeks ago chart.js 3 months ago
chart.js
86 lines
1 jQuery(document).ready(function(){
2 jQuery('.matomo-table[data-chart]').each(function() {
3 var LABEL_EVERY_N_TICKS = 2;
4 var colors = [
5 "#55bae7",
6 "#ddb745",
7 "#4c2a9c",
8 "#3e7b2d"
9 ];
10 var currentColorIndex = 0;
11 var $this = jQuery(this);
12 var $postbox = $this.parents('div.postbox');
13 var $table = $postbox.find('table');
14 $table.hide();
15 var $canvas = jQuery('<canvas/>',{'id':$this.attr('data-chart')});
16 $canvas.insertAfter($table);
17 var labels = [];
18 var metrics = JSON.parse($table.attr('data-metrics'));
19 var datasets = {};
20 $table.find('tr').each(function() {
21 var $row = jQuery(this);
22
23 var labelCell = $row.find('td:nth-child(1)');
24 labels.unshift(labelCell.attr('data-label') || labelCell.text());
25
26 Object.keys(metrics).forEach((metricName, i) => {
27 var metricTitle = metrics[metricName];
28
29 if (!datasets[metricName]) {
30 var color = colors[currentColorIndex];
31 currentColorIndex = (currentColorIndex + 1) % colors.length;
32
33 datasets[metricName] = {
34 label: metricTitle,
35 data: [],
36 borderColor: color,
37 pointBackgroundColor: color,
38 pointBorderColor: color,
39 pointHoverBackgroundColor: color,
40 pointHoverBorderColor: color,
41 };
42 }
43
44 var value = $row.find('td:nth-child(' + (i + 2) + ')').text();
45 if ( '-' === value ) {
46 value = 0;
47 }
48
49 datasets[metricName].data.unshift(value);
50 });
51 });
52
53 var myChart = new Chart($canvas, {
54 type: 'line',
55 data: {
56 labels: labels,
57 datasets: Object.values(datasets)
58 },
59 options: {
60 plugins: {
61 legend: {
62 display: false
63 }
64 },
65 scales: {
66 x: {
67 ticks: {
68 callback: function (value, index, values) {
69 if ( index % LABEL_EVERY_N_TICKS !== 0 ) {
70 return '';
71 }
72
73 return labels[index];
74 },
75 maxRotation: 0,
76 }
77 },
78 y: {
79 beginAtZero: true
80 }
81 }
82 }
83 });
84 });
85 });
86