@osimatic/helpers-js 1.5.2 → 1.5.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/count_down.js +46 -48
- package/date_time.js +0 -1
- package/details_sub_array.js +65 -50
- package/flash_message.js +10 -6
- package/form_date.js +144 -153
- package/form_helper.js +283 -232
- package/google_charts.js +154 -144
- package/google_maps.js +1 -1
- package/import_from_csv.js +198 -160
- package/multi_files_input.js +44 -35
- package/multiple_action_in_table.js +123 -109
- package/package.json +1 -1
- package/paging.js +103 -84
- package/select_all.js +65 -70
- package/sortable_list.js +12 -13
- package/tests/count_down.test.js +131 -352
- package/tests/details_sub_array.test.js +213 -258
- package/tests/flash_message.test.js +21 -153
- package/tests/form_date.test.js +287 -961
- package/tests/form_helper.test.js +553 -673
- package/tests/google_charts.test.js +338 -339
- package/tests/google_maps.test.js +3 -15
- package/tests/import_from_csv.test.js +421 -640
- package/tests/multi_files_input.test.js +305 -737
- package/tests/multiple_action_in_table.test.js +442 -429
- package/tests/open_street_map.test.js +15 -23
- package/tests/paging.test.js +344 -475
- package/tests/select_all.test.js +232 -318
- package/tests/sortable_list.test.js +176 -500
- package/tests/user.test.js +163 -54
- package/user.js +35 -38
package/google_charts.js
CHANGED
|
@@ -3,90 +3,100 @@ class GoogleCharts {
|
|
|
3
3
|
// google.load("visualization", "1", {packages:["corechart"]});
|
|
4
4
|
google.charts.load('current', {'packages':['bar','line','corechart']});
|
|
5
5
|
// google.charts.load('current', {packages:['corechart']});
|
|
6
|
-
|
|
6
|
+
|
|
7
7
|
if (onLoadCallback !== 'undefined') {
|
|
8
8
|
google.charts.setOnLoadCallback(onLoadCallback);
|
|
9
|
-
}
|
|
9
|
+
}
|
|
10
10
|
}
|
|
11
11
|
|
|
12
12
|
static drawCharts(chartsList, onComplete) {
|
|
13
13
|
// on supprime du tableau la liste des graphiques dont l'id div n'a pas été trouvé (le graphique ne pourra pas être généré)
|
|
14
|
-
chartsList = chartsList.filter(chartData => typeof chartData.div_id != 'undefined' &&
|
|
14
|
+
chartsList = chartsList.filter(chartData => typeof chartData.div_id != 'undefined' && document.getElementById(chartData.div_id) !== null);
|
|
15
15
|
|
|
16
16
|
let nbChartsCompleted = 0;
|
|
17
17
|
chartsList.forEach(chartData => {
|
|
18
18
|
//console.log(chartData);
|
|
19
19
|
GoogleCharts.draw(
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
onComplete
|
|
36
|
-
|
|
20
|
+
document.getElementById(chartData.div_id),
|
|
21
|
+
{
|
|
22
|
+
chart_type: chartData.chart_type,
|
|
23
|
+
title: chartData.title,
|
|
24
|
+
abscissa_label: chartData.abscissa_label,
|
|
25
|
+
abscissa_data: chartData.abscissa_data,
|
|
26
|
+
ordinate_label: chartData.ordinate_label,
|
|
27
|
+
ordinate_data: chartData.ordinate_data,
|
|
28
|
+
colors: chartData.colors,
|
|
29
|
+
ordinate_format: chartData.ordinate_format,
|
|
30
|
+
height: chartData.height,
|
|
31
|
+
width: chartData.width,
|
|
32
|
+
onComplete: chart => {
|
|
33
|
+
nbChartsCompleted++;
|
|
34
|
+
// si tous les graphiques ont été chargés, on appelle le callback onComplete transmis en paramètre
|
|
35
|
+
if (chartsList.length === nbChartsCompleted && typeof onComplete == 'function') {
|
|
36
|
+
onComplete();
|
|
37
|
+
}
|
|
38
|
+
},
|
|
37
39
|
},
|
|
38
40
|
);
|
|
39
41
|
});
|
|
40
42
|
}
|
|
41
43
|
|
|
42
|
-
static draw(div,
|
|
43
|
-
|
|
44
|
+
static draw(div, options) {
|
|
45
|
+
const {
|
|
46
|
+
chart_type: chartType,
|
|
47
|
+
title: title,
|
|
48
|
+
abscissa_label: abscissaLabel,
|
|
49
|
+
abscissa_data: abscissaData,
|
|
50
|
+
ordinate_label: ordinateLabel,
|
|
51
|
+
ordinate_data: ordinateData,
|
|
52
|
+
colors: colors = [],
|
|
53
|
+
ordinate_format: formatData = null,
|
|
54
|
+
height: height = null,
|
|
55
|
+
width: width = null,
|
|
56
|
+
onComplete = null,
|
|
57
|
+
} = options;
|
|
58
|
+
|
|
59
|
+
if (typeof div == 'undefined' || !div) {
|
|
44
60
|
console.error('div not found');
|
|
45
61
|
return;
|
|
46
62
|
}
|
|
47
63
|
|
|
48
|
-
height = height || null;
|
|
49
|
-
width = width || null;
|
|
50
|
-
|
|
51
|
-
let htmlDomDiv = div[0];
|
|
52
|
-
|
|
53
|
-
let afficherLibelleOrd = false;
|
|
54
|
-
|
|
55
64
|
let isStacked = false;
|
|
56
|
-
|
|
57
|
-
|
|
65
|
+
let graphType = chartType;
|
|
66
|
+
if (graphType === 'stacked_bar_chart') {
|
|
67
|
+
graphType = 'bar_chart';
|
|
58
68
|
isStacked = true;
|
|
59
69
|
}
|
|
60
|
-
if (
|
|
61
|
-
|
|
70
|
+
if (graphType === 'stacked_column_chart') {
|
|
71
|
+
graphType = 'column_chart';
|
|
62
72
|
isStacked = true;
|
|
63
73
|
}
|
|
64
|
-
if (
|
|
65
|
-
|
|
74
|
+
if (graphType === 'stacked_combo_chart') {
|
|
75
|
+
graphType = 'combo_chart';
|
|
66
76
|
isStacked = true;
|
|
67
77
|
}
|
|
68
78
|
|
|
69
79
|
let isDualChart = false;
|
|
70
|
-
if (
|
|
71
|
-
|
|
80
|
+
if (graphType === 'dual_column_chart') {
|
|
81
|
+
graphType = 'column_chart';
|
|
72
82
|
isDualChart = true;
|
|
73
83
|
}
|
|
74
|
-
if (
|
|
75
|
-
|
|
84
|
+
if (graphType === 'dual_bar_chart') {
|
|
85
|
+
graphType = 'bar_chart';
|
|
76
86
|
isDualChart = true;
|
|
77
87
|
}
|
|
78
88
|
|
|
79
89
|
let data = null;
|
|
80
90
|
let nbCells = 0;
|
|
81
|
-
if (
|
|
91
|
+
if (graphType === 'pie_chart') {
|
|
82
92
|
//data = google.visualization.arrayToDataTable(tabDataAbsParam);
|
|
83
93
|
|
|
84
94
|
data = new google.visualization.DataTable();
|
|
85
|
-
data.addColumn('string',
|
|
95
|
+
data.addColumn('string', abscissaLabel);
|
|
86
96
|
data.addColumn('number', '');
|
|
87
97
|
|
|
88
98
|
let numRow = 0;
|
|
89
|
-
|
|
99
|
+
Object.entries(abscissaData).forEach(([idx, value]) => {
|
|
90
100
|
data.addRows(1);
|
|
91
101
|
data.setCell(numRow, 0, idx);
|
|
92
102
|
data.setCell(numRow, 1, value);
|
|
@@ -96,15 +106,15 @@ class GoogleCharts {
|
|
|
96
106
|
else {
|
|
97
107
|
// Déclaration du tableau de données
|
|
98
108
|
data = new google.visualization.DataTable();
|
|
99
|
-
data.addColumn('string',
|
|
100
|
-
|
|
109
|
+
data.addColumn('string', abscissaLabel);
|
|
110
|
+
ordinateLabel.forEach((libelleOrd) => {
|
|
101
111
|
data.addColumn('number', libelleOrd);
|
|
102
112
|
});
|
|
103
113
|
|
|
104
114
|
// Remplissage des données
|
|
105
115
|
nbCells = 0;
|
|
106
116
|
let numRow = 0;
|
|
107
|
-
|
|
117
|
+
abscissaData.forEach((dataAbs, idx) => {
|
|
108
118
|
// dataOrd = tabDataOrd[idx];
|
|
109
119
|
// data.addRow([dataAbs, dataOrd]);
|
|
110
120
|
data.addRows(1);
|
|
@@ -112,7 +122,7 @@ class GoogleCharts {
|
|
|
112
122
|
data.setCell(numRow, 0, dataAbs);
|
|
113
123
|
|
|
114
124
|
let numCell = 1;
|
|
115
|
-
|
|
125
|
+
ordinateData.forEach((tabDataOrd) => {
|
|
116
126
|
data.setCell(numRow, numCell, tabDataOrd[idx]);
|
|
117
127
|
//data.setCell(numRow, numCell, Math.round(tabDataOrd[idx], 2));
|
|
118
128
|
numCell++;
|
|
@@ -125,11 +135,11 @@ class GoogleCharts {
|
|
|
125
135
|
}
|
|
126
136
|
|
|
127
137
|
// console.log(data);
|
|
128
|
-
// console.log('drawGraph : '+div+' ; type : '+
|
|
138
|
+
// console.log('drawGraph : '+div+' ; type : '+graphType);
|
|
129
139
|
|
|
130
140
|
// Options générales
|
|
131
|
-
let
|
|
132
|
-
colors:
|
|
141
|
+
let chartOptions = {
|
|
142
|
+
colors: colors,
|
|
133
143
|
fontName: 'Trebuchet MS',
|
|
134
144
|
fontSize: 12,
|
|
135
145
|
hAxis: {maxAlternation: 1},
|
|
@@ -138,199 +148,199 @@ class GoogleCharts {
|
|
|
138
148
|
};
|
|
139
149
|
|
|
140
150
|
if (formatData != null) {
|
|
141
|
-
|
|
151
|
+
chartOptions.vAxis.format = formatData;
|
|
142
152
|
}
|
|
143
153
|
|
|
144
154
|
// Options sur le titre du graphique
|
|
145
|
-
|
|
146
|
-
if (
|
|
147
|
-
//
|
|
155
|
+
chartOptions.title = title;
|
|
156
|
+
if (graphType === 'pie_chart') {
|
|
157
|
+
// chartOptions.titlePosition = 'none';
|
|
148
158
|
}
|
|
149
159
|
else {
|
|
150
|
-
|
|
160
|
+
chartOptions.titlePosition = 'none';
|
|
151
161
|
}
|
|
152
162
|
|
|
153
163
|
// Options sur la taille du graphique
|
|
154
|
-
if (
|
|
155
|
-
|
|
156
|
-
//
|
|
157
|
-
//
|
|
164
|
+
if (graphType === 'bar_chart') {
|
|
165
|
+
chartOptions.chartArea = {left:120, top:30};
|
|
166
|
+
//chartOptions.chartArea = {left:"auto", top:"auto"};
|
|
167
|
+
//chartOptions.chartArea = {};
|
|
158
168
|
if (height != null) {
|
|
159
|
-
|
|
160
|
-
//
|
|
169
|
+
chartOptions.chartArea.height = (height - 60);
|
|
170
|
+
//chartOptions.chartArea.height = '100%';
|
|
161
171
|
}
|
|
162
|
-
|
|
163
|
-
//
|
|
172
|
+
chartOptions.chartArea.width = "85%";
|
|
173
|
+
//chartOptions.chartArea.width = "100%";
|
|
164
174
|
}
|
|
165
175
|
else {
|
|
166
|
-
|
|
176
|
+
chartOptions.chartArea = {left:"auto", top:"auto"};
|
|
167
177
|
if (height != null) {
|
|
168
|
-
|
|
178
|
+
chartOptions.chartArea.height = height+"%";
|
|
169
179
|
}
|
|
170
180
|
else {
|
|
171
|
-
|
|
181
|
+
chartOptions.chartArea.height = "80%";
|
|
172
182
|
}
|
|
173
|
-
|
|
183
|
+
chartOptions.chartArea.width = "85%";
|
|
174
184
|
}
|
|
175
|
-
//
|
|
176
|
-
//
|
|
177
|
-
//
|
|
185
|
+
// chartOptions.chartArea = {};
|
|
186
|
+
// chartOptions.chartArea.height = "100%";
|
|
187
|
+
// chartOptions.chartArea.width = "100%";
|
|
178
188
|
|
|
179
|
-
//
|
|
180
|
-
//
|
|
189
|
+
//chartOptions.width = width;
|
|
190
|
+
//chartOptions.width = "100%";
|
|
181
191
|
if (typeof height != 'undefined' && height != null) {
|
|
182
|
-
|
|
192
|
+
chartOptions.height = height;
|
|
183
193
|
}
|
|
184
194
|
//console.log(div);
|
|
185
195
|
//console.log(div.width());
|
|
186
|
-
//
|
|
196
|
+
//chartOptions.width = div.width();
|
|
187
197
|
|
|
188
198
|
// Options sur la légende
|
|
189
|
-
|
|
190
|
-
if (
|
|
191
|
-
|
|
199
|
+
chartOptions.legend = {};
|
|
200
|
+
if (graphType === 'pie_chart') {
|
|
201
|
+
chartOptions.legend.position = 'right';
|
|
192
202
|
}
|
|
193
|
-
else if (
|
|
194
|
-
|
|
203
|
+
else if (graphType === 'bar_chart') {
|
|
204
|
+
chartOptions.legend.position = 'bottom';
|
|
195
205
|
}
|
|
196
206
|
else {
|
|
197
|
-
|
|
207
|
+
chartOptions.legend.position = 'top';
|
|
198
208
|
}
|
|
199
209
|
|
|
200
210
|
// Options sur l'affichage des labels en absisse / ordonnée
|
|
201
|
-
if (
|
|
202
|
-
//
|
|
203
|
-
|
|
211
|
+
if (graphType === 'bar_chart') {
|
|
212
|
+
// chartOptions.hAxis.title = libelleOrd;
|
|
213
|
+
chartOptions.vAxis.title = abscissaLabel;
|
|
204
214
|
}
|
|
205
215
|
else {
|
|
206
|
-
|
|
207
|
-
//
|
|
216
|
+
chartOptions.hAxis.title = abscissaLabel;
|
|
217
|
+
// chartOptions.vAxis.title = libelleOrd;
|
|
208
218
|
}
|
|
209
219
|
|
|
210
220
|
// Options sur les graphiques "dual bar chart / dual column chart"
|
|
211
221
|
if (isDualChart) {
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
if (
|
|
215
|
-
|
|
216
|
-
|
|
222
|
+
chartOptions.series = {};
|
|
223
|
+
chartOptions.axes = {};
|
|
224
|
+
if (graphType === 'column_chart') {
|
|
225
|
+
chartOptions.axes.y = {};
|
|
226
|
+
chartOptions.vAxes = {};
|
|
217
227
|
}
|
|
218
228
|
else {
|
|
219
|
-
|
|
220
|
-
|
|
229
|
+
chartOptions.axes.x = {};
|
|
230
|
+
chartOptions.hAxes = {};
|
|
221
231
|
}
|
|
222
|
-
|
|
232
|
+
ordinateLabel.forEach((libelleOrd, idx) => {
|
|
223
233
|
// console.log(idx);
|
|
224
234
|
if (idx <= 1) {
|
|
225
235
|
// key = 'series_'+idx;
|
|
226
236
|
let key = idx;
|
|
227
|
-
//
|
|
228
|
-
|
|
229
|
-
if (
|
|
230
|
-
|
|
237
|
+
// chartOptions.series[idx] = {axis: key, targetAxisIndex: key};
|
|
238
|
+
chartOptions.series[idx] = {axis: key, targetAxisIndex: idx};
|
|
239
|
+
if (graphType === 'column_chart') {
|
|
240
|
+
chartOptions.axes.y[key] = {label: libelleOrd};
|
|
231
241
|
if (idx === 1) {
|
|
232
|
-
|
|
242
|
+
chartOptions.axes.y[key].side = 'right';
|
|
233
243
|
}
|
|
234
244
|
if (formatData != null) {
|
|
235
|
-
|
|
245
|
+
chartOptions.vAxes[key] = {format: formatData};
|
|
236
246
|
}
|
|
237
247
|
}
|
|
238
248
|
else {
|
|
239
|
-
|
|
249
|
+
chartOptions.axes.x[key] = {label: libelleOrd};
|
|
240
250
|
if (idx === 1) {
|
|
241
|
-
|
|
251
|
+
chartOptions.axes.x[key].side = 'top';
|
|
242
252
|
}
|
|
243
253
|
if (formatData != null) {
|
|
244
|
-
|
|
254
|
+
chartOptions.hAxes[key] = {format: formatData};
|
|
245
255
|
}
|
|
246
256
|
}
|
|
247
257
|
}
|
|
248
258
|
});
|
|
249
|
-
// console.log(
|
|
250
|
-
// console.log(
|
|
259
|
+
// console.log(chartOptions.series);
|
|
260
|
+
// console.log(chartOptions.vAxes);
|
|
251
261
|
}
|
|
252
262
|
|
|
253
263
|
// Options sur les graphiques "combo chart"
|
|
254
|
-
if (
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
264
|
+
if (graphType === 'combo_chart') {
|
|
265
|
+
chartOptions.seriesType = "bars";
|
|
266
|
+
chartOptions.series = {};
|
|
267
|
+
chartOptions.series[nbCells] = {type: "line"};
|
|
258
268
|
}
|
|
259
269
|
|
|
260
270
|
// Options sur le style des lignes pour les "line chart"
|
|
261
|
-
if (
|
|
262
|
-
|
|
263
|
-
|
|
271
|
+
if (graphType === 'line_chart') {
|
|
272
|
+
chartOptions.series = [{lineWidth: 3}, {lineWidth: 1.5}];
|
|
273
|
+
chartOptions.curveType = 'function';
|
|
264
274
|
}
|
|
265
275
|
|
|
266
276
|
// Options sur le style pour les "pie chart"
|
|
267
|
-
if (
|
|
268
|
-
|
|
269
|
-
|
|
277
|
+
if (graphType === 'pie_chart') {
|
|
278
|
+
chartOptions.is3D = false;
|
|
279
|
+
chartOptions.pieResidueSliceLabel = 'Autre';
|
|
270
280
|
}
|
|
271
281
|
|
|
272
|
-
if (
|
|
273
|
-
|
|
282
|
+
if (graphType === 'bar_chart') {
|
|
283
|
+
chartOptions.bars = 'horizontal';
|
|
274
284
|
}
|
|
275
285
|
|
|
276
286
|
if (isStacked) {
|
|
277
|
-
|
|
287
|
+
chartOptions.isStacked = true;
|
|
278
288
|
}
|
|
279
289
|
|
|
280
|
-
// console.log(
|
|
290
|
+
// console.log(chartOptions);
|
|
281
291
|
|
|
282
292
|
// Création du graphique
|
|
283
293
|
let chart = null;
|
|
284
|
-
if (
|
|
285
|
-
// chart = new google.visualization.ColumnChart(
|
|
286
|
-
chart = new google.charts.Bar(
|
|
294
|
+
if (graphType === 'column_chart') {
|
|
295
|
+
// chart = new google.visualization.ColumnChart(div);
|
|
296
|
+
chart = new google.charts.Bar(div);
|
|
287
297
|
}
|
|
288
|
-
else if (
|
|
289
|
-
// chart = new google.visualization.BarChart(
|
|
290
|
-
chart = new google.charts.Bar(
|
|
298
|
+
else if (graphType === 'bar_chart') {
|
|
299
|
+
// chart = new google.visualization.BarChart(div);
|
|
300
|
+
chart = new google.charts.Bar(div);
|
|
291
301
|
}
|
|
292
|
-
else if (
|
|
293
|
-
// chart = new google.visualization.LineChart(
|
|
294
|
-
chart = new google.charts.Line(
|
|
302
|
+
else if (graphType === 'line_chart') {
|
|
303
|
+
// chart = new google.visualization.LineChart(div);
|
|
304
|
+
chart = new google.charts.Line(div);
|
|
295
305
|
}
|
|
296
|
-
else if (
|
|
297
|
-
chart = new google.visualization.ComboChart(
|
|
306
|
+
else if (graphType === 'combo_chart') {
|
|
307
|
+
chart = new google.visualization.ComboChart(div);
|
|
298
308
|
}
|
|
299
|
-
else if (
|
|
300
|
-
chart = new google.visualization.PieChart(
|
|
309
|
+
else if (graphType === 'pie_chart') {
|
|
310
|
+
chart = new google.visualization.PieChart(div);
|
|
301
311
|
}
|
|
302
312
|
|
|
303
|
-
div.
|
|
313
|
+
div.classList.remove('loading');
|
|
304
314
|
|
|
305
315
|
if (chart === null) {
|
|
306
316
|
console.error('error during creating chart');
|
|
307
|
-
div.
|
|
308
|
-
|
|
317
|
+
div.classList.add('graphique_error');
|
|
318
|
+
div.innerHTML = 'Une erreur s\'est produite lors du chargement du graphique.';
|
|
309
319
|
return;
|
|
310
320
|
}
|
|
311
321
|
|
|
312
|
-
//div.
|
|
313
|
-
div.
|
|
314
|
-
|
|
322
|
+
//div.classList.add('graphique');
|
|
323
|
+
div.classList.add('chart');
|
|
324
|
+
div.innerHTML = '';
|
|
315
325
|
|
|
316
|
-
//
|
|
326
|
+
// div.style.display = 'block';
|
|
317
327
|
let tabPaneDiv = div;
|
|
318
|
-
if (!div.
|
|
328
|
+
if (!div.classList.contains('tab-pane')) {
|
|
319
329
|
tabPaneDiv = div.closest('.tab-pane');
|
|
320
330
|
}
|
|
321
331
|
|
|
322
|
-
let hasClassActive = tabPaneDiv.
|
|
332
|
+
let hasClassActive = tabPaneDiv?.classList.contains('active') ?? false;
|
|
323
333
|
if (!hasClassActive) {
|
|
324
|
-
tabPaneDiv.
|
|
334
|
+
tabPaneDiv?.classList.add('active');
|
|
325
335
|
}
|
|
326
336
|
|
|
327
337
|
google.visualization.events.addListener(chart, 'ready', function () {
|
|
328
338
|
//console.log('ready');
|
|
329
339
|
//console.log(chart);
|
|
330
|
-
//
|
|
340
|
+
// div.style.display = 'none';
|
|
331
341
|
// div.hide();
|
|
332
342
|
if (!hasClassActive) {
|
|
333
|
-
tabPaneDiv.
|
|
343
|
+
tabPaneDiv?.classList.remove('active');
|
|
334
344
|
}
|
|
335
345
|
|
|
336
346
|
if (typeof onComplete == 'function') {
|
|
@@ -339,9 +349,9 @@ class GoogleCharts {
|
|
|
339
349
|
});
|
|
340
350
|
|
|
341
351
|
// console.log($("ul li.ui-state-active").index()
|
|
342
|
-
//console.log(
|
|
352
|
+
//console.log(chartOptions);
|
|
343
353
|
|
|
344
|
-
chart.draw(data,
|
|
354
|
+
chart.draw(data, chartOptions);
|
|
345
355
|
}
|
|
346
356
|
|
|
347
357
|
}
|