@osimatic/helpers-js 1.5.3 → 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/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' && $('#'+chartData.div_id).length);
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
- $('#'+chartData.div_id),
21
- chartData.chart_type,
22
- chartData.title,
23
- chartData.abscissa_label,
24
- chartData.abscissa_data,
25
- chartData.ordinate_label,
26
- chartData.ordinate_data,
27
- chartData.colors,
28
- chartData.ordinate_format,
29
- chartData.height,
30
- chartData.width,
31
- chart => {
32
- nbChartsCompleted++;
33
- // si tous les graphiques ont été chargés, on appelle le callback onComplete transmis en paramètre
34
- if (chartsList.length === nbChartsCompleted && typeof onComplete == 'function') {
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, typeGraph, titre, libelleAbs, tabDataAbsParam, listeLibelleOrd, listeTabDataOrd, tabColor, formatData, height, width, onComplete) {
43
- if (typeof div == 'undefined' || !div.length) {
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
- if (typeGraph === 'stacked_bar_chart') {
57
- typeGraph = 'bar_chart';
65
+ let graphType = chartType;
66
+ if (graphType === 'stacked_bar_chart') {
67
+ graphType = 'bar_chart';
58
68
  isStacked = true;
59
69
  }
60
- if (typeGraph === 'stacked_column_chart') {
61
- typeGraph = 'column_chart';
70
+ if (graphType === 'stacked_column_chart') {
71
+ graphType = 'column_chart';
62
72
  isStacked = true;
63
73
  }
64
- if (typeGraph === 'stacked_combo_chart') {
65
- typeGraph = 'combo_chart';
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 (typeGraph === 'dual_column_chart') {
71
- typeGraph = 'column_chart';
80
+ if (graphType === 'dual_column_chart') {
81
+ graphType = 'column_chart';
72
82
  isDualChart = true;
73
83
  }
74
- if (typeGraph === 'dual_bar_chart') {
75
- typeGraph = 'bar_chart';
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 (typeGraph === 'pie_chart') {
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', libelleAbs);
95
+ data.addColumn('string', abscissaLabel);
86
96
  data.addColumn('number', '');
87
97
 
88
98
  let numRow = 0;
89
- $.each(tabDataAbsParam, function(idx, value) {
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', libelleAbs);
100
- $.each(listeLibelleOrd, function(idx, libelleOrd) {
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
- $.each(tabDataAbsParam, function(idx, dataAbs) {
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
- $.each(listeTabDataOrd, function(idx2, tabDataOrd) {
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 : '+typeGraph);
138
+ // console.log('drawGraph : '+div+' ; type : '+graphType);
129
139
 
130
140
  // Options générales
131
- let options = {
132
- colors: tabColor,
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
- options.vAxis.format = formatData;
151
+ chartOptions.vAxis.format = formatData;
142
152
  }
143
153
 
144
154
  // Options sur le titre du graphique
145
- options.title = titre;
146
- if (typeGraph === 'pie_chart') {
147
- // options.titlePosition = 'none';
155
+ chartOptions.title = title;
156
+ if (graphType === 'pie_chart') {
157
+ // chartOptions.titlePosition = 'none';
148
158
  }
149
159
  else {
150
- options.titlePosition = 'none';
160
+ chartOptions.titlePosition = 'none';
151
161
  }
152
162
 
153
163
  // Options sur la taille du graphique
154
- if (typeGraph === 'bar_chart') {
155
- options.chartArea = {left:120, top:30};
156
- //options.chartArea = {left:"auto", top:"auto"};
157
- //options.chartArea = {};
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
- options.chartArea.height = (height - 60);
160
- //options.chartArea.height = '100%';
169
+ chartOptions.chartArea.height = (height - 60);
170
+ //chartOptions.chartArea.height = '100%';
161
171
  }
162
- options.chartArea.width = "85%";
163
- //options.chartArea.width = "100%";
172
+ chartOptions.chartArea.width = "85%";
173
+ //chartOptions.chartArea.width = "100%";
164
174
  }
165
175
  else {
166
- options.chartArea = {left:"auto", top:"auto"};
176
+ chartOptions.chartArea = {left:"auto", top:"auto"};
167
177
  if (height != null) {
168
- options.chartArea.height = height+"%";
178
+ chartOptions.chartArea.height = height+"%";
169
179
  }
170
180
  else {
171
- options.chartArea.height = "80%";
181
+ chartOptions.chartArea.height = "80%";
172
182
  }
173
- options.chartArea.width = "85%";
183
+ chartOptions.chartArea.width = "85%";
174
184
  }
175
- // options.chartArea = {};
176
- // options.chartArea.height = "100%";
177
- // options.chartArea.width = "100%";
185
+ // chartOptions.chartArea = {};
186
+ // chartOptions.chartArea.height = "100%";
187
+ // chartOptions.chartArea.width = "100%";
178
188
 
179
- //options.width = width;
180
- //options.width = "100%";
189
+ //chartOptions.width = width;
190
+ //chartOptions.width = "100%";
181
191
  if (typeof height != 'undefined' && height != null) {
182
- options.height = height;
192
+ chartOptions.height = height;
183
193
  }
184
194
  //console.log(div);
185
195
  //console.log(div.width());
186
- //options.width = div.width();
196
+ //chartOptions.width = div.width();
187
197
 
188
198
  // Options sur la légende
189
- options.legend = {};
190
- if (typeGraph === 'pie_chart') {
191
- options.legend.position = 'right';
199
+ chartOptions.legend = {};
200
+ if (graphType === 'pie_chart') {
201
+ chartOptions.legend.position = 'right';
192
202
  }
193
- else if (typeGraph === 'bar_chart') {
194
- options.legend.position = 'bottom';
203
+ else if (graphType === 'bar_chart') {
204
+ chartOptions.legend.position = 'bottom';
195
205
  }
196
206
  else {
197
- options.legend.position = 'top';
207
+ chartOptions.legend.position = 'top';
198
208
  }
199
209
 
200
210
  // Options sur l'affichage des labels en absisse / ordonnée
201
- if (typeGraph === 'bar_chart') {
202
- // options.hAxis.title = libelleOrd;
203
- options.vAxis.title = libelleAbs;
211
+ if (graphType === 'bar_chart') {
212
+ // chartOptions.hAxis.title = libelleOrd;
213
+ chartOptions.vAxis.title = abscissaLabel;
204
214
  }
205
215
  else {
206
- options.hAxis.title = libelleAbs;
207
- // options.vAxis.title = libelleOrd;
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
- options.series = {};
213
- options.axes = {};
214
- if (typeGraph === 'column_chart') {
215
- options.axes.y = {};
216
- options.vAxes = {};
222
+ chartOptions.series = {};
223
+ chartOptions.axes = {};
224
+ if (graphType === 'column_chart') {
225
+ chartOptions.axes.y = {};
226
+ chartOptions.vAxes = {};
217
227
  }
218
228
  else {
219
- options.axes.x = {};
220
- options.hAxes = {};
229
+ chartOptions.axes.x = {};
230
+ chartOptions.hAxes = {};
221
231
  }
222
- $.each(listeLibelleOrd, function(idx, libelleOrd) {
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
- // options.series[idx] = {axis: key, targetAxisIndex: key};
228
- options.series[idx] = {axis: key, targetAxisIndex: idx};
229
- if (typeGraph === 'column_chart') {
230
- options.axes.y[key] = {label: libelleOrd};
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
- options.axes.y[key].side = 'right';
242
+ chartOptions.axes.y[key].side = 'right';
233
243
  }
234
244
  if (formatData != null) {
235
- options.vAxes[key] = {format: formatData};
245
+ chartOptions.vAxes[key] = {format: formatData};
236
246
  }
237
247
  }
238
248
  else {
239
- options.axes.x[key] = {label: libelleOrd};
249
+ chartOptions.axes.x[key] = {label: libelleOrd};
240
250
  if (idx === 1) {
241
- options.axes.x[key].side = 'top';
251
+ chartOptions.axes.x[key].side = 'top';
242
252
  }
243
253
  if (formatData != null) {
244
- options.hAxes[key] = {format: formatData};
254
+ chartOptions.hAxes[key] = {format: formatData};
245
255
  }
246
256
  }
247
257
  }
248
258
  });
249
- // console.log(options.series);
250
- // console.log(options.vAxes);
259
+ // console.log(chartOptions.series);
260
+ // console.log(chartOptions.vAxes);
251
261
  }
252
262
 
253
263
  // Options sur les graphiques "combo chart"
254
- if (typeGraph === 'combo_chart') {
255
- options.seriesType = "bars";
256
- options.series = {};
257
- options.series[nbCells] = {type: "line"};
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 (typeGraph === 'line_chart') {
262
- options.series = [{lineWidth: 3}, {lineWidth: 1.5}];
263
- options.curveType = 'function';
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 (typeGraph === 'pie_chart') {
268
- options.is3D = false;
269
- options.pieResidueSliceLabel = 'Autre';
277
+ if (graphType === 'pie_chart') {
278
+ chartOptions.is3D = false;
279
+ chartOptions.pieResidueSliceLabel = 'Autre';
270
280
  }
271
281
 
272
- if (typeGraph === 'bar_chart') {
273
- options.bars = 'horizontal';
282
+ if (graphType === 'bar_chart') {
283
+ chartOptions.bars = 'horizontal';
274
284
  }
275
285
 
276
286
  if (isStacked) {
277
- options.isStacked = true;
287
+ chartOptions.isStacked = true;
278
288
  }
279
289
 
280
- // console.log(options);
290
+ // console.log(chartOptions);
281
291
 
282
292
  // Création du graphique
283
293
  let chart = null;
284
- if (typeGraph === 'column_chart') {
285
- // chart = new google.visualization.ColumnChart(htmlDomDiv);
286
- chart = new google.charts.Bar(htmlDomDiv);
294
+ if (graphType === 'column_chart') {
295
+ // chart = new google.visualization.ColumnChart(div);
296
+ chart = new google.charts.Bar(div);
287
297
  }
288
- else if (typeGraph === 'bar_chart') {
289
- // chart = new google.visualization.BarChart(htmlDomDiv);
290
- chart = new google.charts.Bar(htmlDomDiv);
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 (typeGraph === 'line_chart') {
293
- // chart = new google.visualization.LineChart(htmlDomDiv);
294
- chart = new google.charts.Line(htmlDomDiv);
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 (typeGraph === 'combo_chart') {
297
- chart = new google.visualization.ComboChart(htmlDomDiv);
306
+ else if (graphType === 'combo_chart') {
307
+ chart = new google.visualization.ComboChart(div);
298
308
  }
299
- else if (typeGraph === 'pie_chart') {
300
- chart = new google.visualization.PieChart(htmlDomDiv);
309
+ else if (graphType === 'pie_chart') {
310
+ chart = new google.visualization.PieChart(div);
301
311
  }
302
312
 
303
- div.removeClass('loading');
313
+ div.classList.remove('loading');
304
314
 
305
315
  if (chart === null) {
306
316
  console.error('error during creating chart');
307
- div.addClass('graphique_error');
308
- htmlDomDiv.innerHTML = 'Une erreur s\'est produite lors du chargement du graphique.';
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.addClass('graphique');
313
- div.addClass('chart');
314
- htmlDomDiv.innerHTML = '';
322
+ //div.classList.add('graphique');
323
+ div.classList.add('chart');
324
+ div.innerHTML = '';
315
325
 
316
- // htmlDomDiv.style.display = 'block';
326
+ // div.style.display = 'block';
317
327
  let tabPaneDiv = div;
318
- if (!div.hasClass('tab-pane')) {
328
+ if (!div.classList.contains('tab-pane')) {
319
329
  tabPaneDiv = div.closest('.tab-pane');
320
330
  }
321
331
 
322
- let hasClassActive = tabPaneDiv.hasClass('active');
332
+ let hasClassActive = tabPaneDiv?.classList.contains('active') ?? false;
323
333
  if (!hasClassActive) {
324
- tabPaneDiv.addClass('active');
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
- // htmlDomDiv.style.display = 'none';
340
+ // div.style.display = 'none';
331
341
  // div.hide();
332
342
  if (!hasClassActive) {
333
- tabPaneDiv.removeClass('active');
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(options);
352
+ //console.log(chartOptions);
343
353
 
344
- chart.draw(data, options);
354
+ chart.draw(data, chartOptions);
345
355
  }
346
356
 
347
357
  }
package/google_maps.js CHANGED
@@ -5,7 +5,7 @@ class GoogleMap {
5
5
  this.locations = [];
6
6
  this.mapId = mapId;
7
7
 
8
- if (!$('#'+mapId).length) {
8
+ if (!document.getElementById(mapId)) {
9
9
  return;
10
10
  }
11
11