-
-
Notifications
You must be signed in to change notification settings - Fork 32
/
Copy pathappMin.js
158 lines (147 loc) · 5.46 KB
/
appMin.js
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
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
/**
* Analytics
*
* SPDX-FileCopyrightText: 2019-2024 Marcel Scherello
* SPDX-License-Identifier: AGPL-3.0-or-later
*/
/** global: OCA */
/** global: OCP */
/** global: OC */
/** global: table */
/** global: Chart */
/** global: cloner */
/** global: _ */
'use strict';
let OCA;
OCA = {};
if (!OCA.Analytics) {
/**
* @namespace
*/
OCA.Analytics = {
initialDocumentTitle: null,
isDataset: false,
currentReportData: {},
chartObject: null,
// flexible mapping depending on type required by the used chart library
chartTypeMapping: {
'datetime': 'line',
'column': 'bar',
'columnSt': 'bar', // map stacked type also to base type; needed in filter
'columnSt100': 'bar', // map stacked type also to base type; needed in filter
'area': 'line',
'line': 'line',
'doughnut': 'doughnut'
},
datasources: [],
datasourceOptions: [],
datasets: [],
reports: [],
unsavedFilters: null,
refreshTimer: null,
currentXhrRequest: null,
};
}
OCA.Analytics.UI = {
initApplication: function () {
OCA.Analytics.Visualization.hideElement('analytics-intro');
OCA.Analytics.Visualization.hideElement('analytics-content');
OCA.Analytics.Visualization.hideElement('analytics-loading');
OCA.Analytics.Visualization.showElement('analytics-content');
document.getElementById('chartContainer').innerHTML = '';
document.getElementById('chartContainer').innerHTML = '<button id="chartZoomReset" hidden>Reset Zoom</button><canvas id="myChart" ></canvas>';
document.getElementById('chartZoomReset').addEventListener('click', OCA.Analytics.UI.handleZoomResetButton);
OCA.Analytics.currentReportData = JSON.parse(document.getElementById('data').value);
// if the user uses a special time parser (e.g. DD.MM), the data needs to be sorted differently
OCA.Analytics.currentReportData = OCA.Analytics.Visualization.sortDates(OCA.Analytics.currentReportData);
OCA.Analytics.currentReportData.data = OCA.Analytics.Visualization.formatDates(OCA.Analytics.currentReportData.data);
let ctx = document.getElementById('myChart').getContext('2d');
OCA.Analytics.Visualization.buildChart(ctx, OCA.Analytics.currentReportData, OCA.Analytics.UI.getDefaultChartOptions());
},
getDefaultChartOptions: function () {
return {
maintainAspectRatio: false,
responsive: true,
scales: {
'primary': {
type: 'linear',
stacked: false,
position: 'left',
display: true,
grid: {
display: true,
},
ticks: {
callback: function (value) {
return value.toLocaleString();
},
},
},
'secondary': {
type: 'linear',
stacked: false,
position: 'right',
display: false,
grid: {
display: false,
},
ticks: {
callback: function (value) {
return value.toLocaleString();
},
},
},
'xAxes': {
type: 'category',
time: {
parser: 'YYYY-MM-DD HH:mm',
tooltipFormat: 'LL',
},
distribution: 'linear',
grid: {
display: false
},
display: true,
},
},
animation: {
duration: 0 // general animation time
},
tooltips: {
callbacks: {
label: function (tooltipItem, data) {
// let datasetLabel = data.datasets[tooltipItem.datasetIndex].label || '';
let datasetLabel = data.datasets[tooltipItem.datasetIndex].label || data.labels[tooltipItem.index];
if (tooltipItem.yLabel !== '') {
return datasetLabel + ': ' + parseFloat(tooltipItem.yLabel).toLocaleString();
} else {
return datasetLabel;
}
}
}
},
plugins: {
datalabels: {
display: false,
formatter: (value, ctx) => {
let sum = 0;
let dataArr = ctx.chart.data.datasets[0].data;
dataArr.map(data => {
sum += data;
});
value = (value * 100 / sum).toFixed(0);
if (value > 5) {
return value + "%";
} else {
return '';
}
},
},
},
};
},
}
document.addEventListener('DOMContentLoaded', function () {
OCA.Analytics.UI.initApplication();
OCA.Analytics.Visualization.hideElement('analytics-warning');
});