@osimatic/helpers-js 1.0.5 → 1.0.8
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/{todos/google_charts.js → google_charts.js} +11 -8
- package/index.js +4 -2
- package/network.js +4 -12
- package/package.json +1 -1
- package/string.js +1 -2
- package/todos/google_charts_mytime.js +0 -295
|
@@ -1,12 +1,14 @@
|
|
|
1
|
+
class GoogleCharts {
|
|
2
|
+
static init(onLoadCallback) {
|
|
3
|
+
// google.load("visualization", "1", {packages:["corechart"]});
|
|
4
|
+
google.charts.load('current', {'packages':['bar','line','corechart']});
|
|
5
|
+
// google.charts.load('current', {packages:['corechart']});
|
|
6
|
+
|
|
7
|
+
if (onLoadCallback !== 'undefined') {
|
|
8
|
+
google.charts.setOnLoadCallback(onLoadCallback);
|
|
9
|
+
}
|
|
10
|
+
}
|
|
1
11
|
|
|
2
|
-
// google.load("visualization", "1", {packages:["corechart"]});
|
|
3
|
-
google.charts.load('current', {'packages':['bar','line','corechart']});
|
|
4
|
-
// google.charts.load('current', {packages:['corechart']});
|
|
5
|
-
|
|
6
|
-
google.charts.setOnLoadCallback(drawAllCharts);
|
|
7
|
-
|
|
8
|
-
class GoogleCharts
|
|
9
|
-
{
|
|
10
12
|
static drawCharts(chartsList, onComplete) {
|
|
11
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é)
|
|
12
14
|
chartsList = chartsList.filter(chartData => typeof chartData.div_id != 'undefined' && $('#'+chartData.div_id).length);
|
|
@@ -342,3 +344,4 @@ class GoogleCharts
|
|
|
342
344
|
|
|
343
345
|
}
|
|
344
346
|
|
|
347
|
+
module.exports = { GoogleCharts };
|
package/index.js
CHANGED
|
@@ -21,15 +21,17 @@ const { COUNTRIES_LIST, Country, PostalAddress, Location } = require('./location
|
|
|
21
21
|
const { SocialNetwork } = require('./social_network');
|
|
22
22
|
const { getValuesByKeyInArrayOfArrays, renameKeys, renameKeysByCallback } = require('./array');
|
|
23
23
|
const { NumberValue } = require('./number');
|
|
24
|
-
const { selectionnerContenuNode, copierTexte } = require('./string');
|
|
24
|
+
const { selectionnerContenuNode, copierTexte, truncateString } = require('./string');
|
|
25
25
|
const { addBookmark, sleep, refresh } = require('./util');
|
|
26
26
|
const { chr, ord, trim, empty } = require('./php.min');
|
|
27
27
|
const { Pagination, activateTab } = require('./paging');
|
|
28
|
+
const { GoogleCharts } = require('./google_charts');
|
|
28
29
|
|
|
29
30
|
module.exports = {
|
|
30
31
|
HTTPRequest, Cookie, UrlAndQueryString, IBAN, AudioMedia, PersonName, Email, TelephoneNumber, CountDown, DataTable,
|
|
31
32
|
DateTime, TimestampUnix, SqlDate, SqlTime, SqlDateTime, InputPeriod, DetailsSubArray, Duration, File, CSV, Img,
|
|
32
33
|
FlashMessage, FormHelper, GoogleMap, ImportFromCsv, JwtToken, JwtSession, ListBox, COUNTRIES_LIST, Country, PostalAddress,
|
|
33
34
|
Location, SocialNetwork, Array, Object, getValuesByKeyInArrayOfArrays, renameKeys, renameKeysByCallback, Number, NumberValue,
|
|
34
|
-
String, selectionnerContenuNode, copierTexte, addBookmark, sleep, refresh, chr, ord, trim, empty, Pagination,
|
|
35
|
+
String, selectionnerContenuNode, copierTexte, truncateString, addBookmark, sleep, refresh, chr, ord, trim, empty, Pagination,
|
|
36
|
+
activateTab, GoogleCharts
|
|
35
37
|
};
|
package/network.js
CHANGED
|
@@ -1,13 +1,5 @@
|
|
|
1
1
|
|
|
2
2
|
class HTTPRequest {
|
|
3
|
-
static getHttpHeaders() {
|
|
4
|
-
if (!JwtSession.isAnonymous()) { //on ne définit pas ce header si on ne trouve pas d'access_token
|
|
5
|
-
httpHeaders['Authorization'] = 'Bearer ' + JwtSession.getToken();
|
|
6
|
-
}
|
|
7
|
-
|
|
8
|
-
return httpHeaders;
|
|
9
|
-
}
|
|
10
|
-
|
|
11
3
|
static async get(url, data, successCallback, errorCallback) {
|
|
12
4
|
if (data == null) {
|
|
13
5
|
data = '';
|
|
@@ -56,7 +48,7 @@ class HTTPRequest {
|
|
|
56
48
|
$.ajax({
|
|
57
49
|
type: 'GET',
|
|
58
50
|
url: url + (!url.includes('?') ? '?' : '') + data,
|
|
59
|
-
headers:
|
|
51
|
+
headers: httpHeaders,
|
|
60
52
|
dataType: 'json',
|
|
61
53
|
cache: false,
|
|
62
54
|
success: (data) => successCallback(data),
|
|
@@ -124,7 +116,7 @@ class HTTPRequest {
|
|
|
124
116
|
$.ajax({
|
|
125
117
|
type: 'GET',
|
|
126
118
|
url: url + (!url.includes('?') ? '?' : '') + data,
|
|
127
|
-
headers:
|
|
119
|
+
headers: httpHeaders,
|
|
128
120
|
cache: false,
|
|
129
121
|
xhrFields: {
|
|
130
122
|
responseType: 'blob'
|
|
@@ -191,7 +183,7 @@ class HTTPRequest {
|
|
|
191
183
|
$.ajax({
|
|
192
184
|
type: 'POST',
|
|
193
185
|
url: url,
|
|
194
|
-
headers:
|
|
186
|
+
headers: httpHeaders,
|
|
195
187
|
dataType: 'json', // 22/09/2020 : à voir si cette ligne pose pb (utilisé pour requete import et peut être d'autres
|
|
196
188
|
data: formData,
|
|
197
189
|
cache: false,
|
|
@@ -549,4 +541,4 @@ class UrlAndQueryString {
|
|
|
549
541
|
|
|
550
542
|
}
|
|
551
543
|
|
|
552
|
-
module.exports = { HTTPRequest, Cookie, UrlAndQueryString };
|
|
544
|
+
module.exports = { HTTPRequest, Cookie, UrlAndQueryString };
|
package/package.json
CHANGED
package/string.js
CHANGED
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
|
|
2
1
|
function selectionnerContenuNode(node) {
|
|
3
2
|
if (window.getSelection) {
|
|
4
3
|
var selection = window.getSelection();
|
|
@@ -117,4 +116,4 @@ if (!String.format) {
|
|
|
117
116
|
};
|
|
118
117
|
}
|
|
119
118
|
|
|
120
|
-
module.exports = { selectionnerContenuNode, copierTexte };
|
|
119
|
+
module.exports = { selectionnerContenuNode, copierTexte, truncateString };
|
|
@@ -1,295 +0,0 @@
|
|
|
1
|
-
// /!\
|
|
2
|
-
// /!\ Jérôme : à mon avis celui-ci n'est pas à jour et il ne faut plus l'utiliser (provient du projet mytime/admin_osi/audioconf.),
|
|
3
|
-
// /!\ ou alors il faut le retirer des helpers et créer une classe spécifique dans chaque projet (si comportements différents)
|
|
4
|
-
// /!\
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
// google.load("visualization", "1", {packages:["corechart"]});
|
|
9
|
-
google.charts.load('current', {'packages':['bar','line','corechart']});
|
|
10
|
-
// google.charts.load('current', {packages:['corechart']});
|
|
11
|
-
|
|
12
|
-
google.charts.setOnLoadCallback(drawAllCharts);
|
|
13
|
-
|
|
14
|
-
function drawAllCharts() {
|
|
15
|
-
if (typeof(listCharts) != 'undefined' && listCharts.length > 0) {
|
|
16
|
-
loadListCharts(listCharts);
|
|
17
|
-
}
|
|
18
|
-
}
|
|
19
|
-
|
|
20
|
-
function loadListCharts(listCharts) {
|
|
21
|
-
$.each(listCharts, function(idx, chartData) {
|
|
22
|
-
// console.log('drawChart'+chartData.id);
|
|
23
|
-
drawChart(chartData.type_graph, chartData.id, chartData.title, chartData.libelle_abs, chartData.tab_data_abs, chartData.liste_libelle_ord, chartData.liste_tab_data_ord, chartData.list_color, chartData.format_ord, chartData.height, chartData.width);
|
|
24
|
-
|
|
25
|
-
/*
|
|
26
|
-
if (typeof(initWidth) == 'undefined' || initWidth) {
|
|
27
|
-
var width = 0;
|
|
28
|
-
$.each(listGraphStats, function(idx, tabGraph) {
|
|
29
|
-
if ($('#'+tabGraph.id).length) {
|
|
30
|
-
if ($('#'+tabGraph.id).width() > 0) {
|
|
31
|
-
width = $('#'+tabGraph.id).width();
|
|
32
|
-
}
|
|
33
|
-
}
|
|
34
|
-
});
|
|
35
|
-
}
|
|
36
|
-
|
|
37
|
-
$.each(listGraphStats, function(idx, tabGraph) {
|
|
38
|
-
drawChart(tabGraph.type_graph, tabGraph.id, tabGraph.title, tabGraph.libelle_abs, tabGraph.tab_data_abs, tabGraph.liste_libelle_ord, tabGraph.liste_tab_data_ord, tabGraph.list_color, tabGraph.format_ord, tabGraph.height, width);
|
|
39
|
-
});
|
|
40
|
-
*/
|
|
41
|
-
});
|
|
42
|
-
}
|
|
43
|
-
|
|
44
|
-
function drawChart(typeGraph, idDiv, titre, libelleAbs, tabDataAbsParam, listeLibelleOrd, listeTabDataOrd, tabColor, formatData, height, width) {
|
|
45
|
-
if ($('#'+idDiv).length == 0) {
|
|
46
|
-
return;
|
|
47
|
-
}
|
|
48
|
-
|
|
49
|
-
var afficherLibelleOrd = false;
|
|
50
|
-
|
|
51
|
-
isStacked = false;
|
|
52
|
-
if (typeGraph == 'stacked_bar_chart') {
|
|
53
|
-
typeGraph = 'bar_chart';
|
|
54
|
-
isStacked = true;
|
|
55
|
-
}
|
|
56
|
-
if (typeGraph == 'stacked_column_chart') {
|
|
57
|
-
typeGraph = 'column_chart';
|
|
58
|
-
isStacked = true;
|
|
59
|
-
}
|
|
60
|
-
if (typeGraph == 'stacked_combo_chart') {
|
|
61
|
-
typeGraph = 'combo_chart';
|
|
62
|
-
isStacked = true;
|
|
63
|
-
}
|
|
64
|
-
|
|
65
|
-
isDualChart = false;
|
|
66
|
-
if (typeGraph == 'dual_column_chart') {
|
|
67
|
-
typeGraph = 'column_chart';
|
|
68
|
-
isDualChart = true;
|
|
69
|
-
}
|
|
70
|
-
if (typeGraph == 'dual_bar_chart') {
|
|
71
|
-
typeGraph = 'bar_chart';
|
|
72
|
-
isDualChart = true;
|
|
73
|
-
}
|
|
74
|
-
|
|
75
|
-
// Déclaration du tableau de données
|
|
76
|
-
var data = new google.visualization.DataTable();
|
|
77
|
-
data.addColumn('string', libelleAbs);
|
|
78
|
-
$.each(listeLibelleOrd, function(idx, libelleOrd) {
|
|
79
|
-
data.addColumn('number', libelleOrd);
|
|
80
|
-
});
|
|
81
|
-
|
|
82
|
-
// Remplissage des données
|
|
83
|
-
var nbCells = 0;
|
|
84
|
-
var numRow = 0;
|
|
85
|
-
$.each(tabDataAbsParam, function(idx, dataAbs) {
|
|
86
|
-
// dataOrd = tabDataOrd[idx];
|
|
87
|
-
// data.addRow([dataAbs, dataOrd]);
|
|
88
|
-
data.addRows(1);
|
|
89
|
-
|
|
90
|
-
data.setCell(numRow, 0, dataAbs);
|
|
91
|
-
|
|
92
|
-
var numCell = 1;
|
|
93
|
-
$.each(listeTabDataOrd, function(idx2, tabDataOrd) {
|
|
94
|
-
data.setCell(numRow, numCell, tabDataOrd[idx]);
|
|
95
|
-
numCell++;
|
|
96
|
-
});
|
|
97
|
-
|
|
98
|
-
nbCells = numCell;
|
|
99
|
-
numRow++;
|
|
100
|
-
});
|
|
101
|
-
nbCells -= 2;
|
|
102
|
-
|
|
103
|
-
// console.log(data);
|
|
104
|
-
// console.log('drawGraph : '+idDiv+' ; type : '+typeGraph);
|
|
105
|
-
|
|
106
|
-
// Options générales
|
|
107
|
-
var options = {
|
|
108
|
-
colors: tabColor,
|
|
109
|
-
fontName: 'Trebuchet MS',
|
|
110
|
-
fontSize: 12,
|
|
111
|
-
hAxis: {maxAlternation: 1},
|
|
112
|
-
vAxis: {minValue: 0, textPosition: 'out'},
|
|
113
|
-
//gridlines: {color: '#333', count: 1}
|
|
114
|
-
};
|
|
115
|
-
|
|
116
|
-
if (formatData != null) {
|
|
117
|
-
options.vAxis.format = formatData;
|
|
118
|
-
}
|
|
119
|
-
|
|
120
|
-
// Options sur le titre du graphique
|
|
121
|
-
options.title = titre;
|
|
122
|
-
if (typeGraph == 'pie_chart') {
|
|
123
|
-
// options.titlePosition = 'none';
|
|
124
|
-
}
|
|
125
|
-
else {
|
|
126
|
-
options.titlePosition = 'none';
|
|
127
|
-
}
|
|
128
|
-
|
|
129
|
-
// Options sur la taille du graphique
|
|
130
|
-
if (typeGraph == 'bar_chart') {
|
|
131
|
-
options.chartArea = {left:120, top:30};
|
|
132
|
-
options.chartArea.height = (height-60);
|
|
133
|
-
options.chartArea.width = "85%";
|
|
134
|
-
}
|
|
135
|
-
else {
|
|
136
|
-
options.chartArea = {left:"auto", top:"auto"};
|
|
137
|
-
if (height != null) {
|
|
138
|
-
options.chartArea.height = height+"%";
|
|
139
|
-
}
|
|
140
|
-
else {
|
|
141
|
-
options.chartArea.height = "80%";
|
|
142
|
-
}
|
|
143
|
-
options.chartArea.width = "85%";
|
|
144
|
-
}
|
|
145
|
-
// options.chartArea = {};
|
|
146
|
-
// options.chartArea.height = "100%";
|
|
147
|
-
// options.chartArea.width = "100%";
|
|
148
|
-
|
|
149
|
-
options.width = width;
|
|
150
|
-
|
|
151
|
-
// Options sur la légende
|
|
152
|
-
options.legend = {};
|
|
153
|
-
if (typeGraph == 'pie_chart') {
|
|
154
|
-
options.legend.position = 'right';
|
|
155
|
-
}
|
|
156
|
-
else {
|
|
157
|
-
options.legend.position = 'top';
|
|
158
|
-
}
|
|
159
|
-
|
|
160
|
-
// Options sur l'affichage des labels en absisse / ordonnée
|
|
161
|
-
if (typeGraph == 'bar_chart') {
|
|
162
|
-
// options.hAxis.title = libelleOrd;
|
|
163
|
-
options.vAxis.title = libelleAbs;
|
|
164
|
-
}
|
|
165
|
-
else {
|
|
166
|
-
options.hAxis.title = libelleAbs;
|
|
167
|
-
// options.vAxis.title = libelleOrd;
|
|
168
|
-
}
|
|
169
|
-
|
|
170
|
-
// Options sur les graphiques "dual bar chart / dual column chart"
|
|
171
|
-
if (isDualChart) {
|
|
172
|
-
options.series = {};
|
|
173
|
-
options.axes = {};
|
|
174
|
-
if (typeGraph == 'column_chart') {
|
|
175
|
-
options.axes.y = {};
|
|
176
|
-
options.vAxes = {};
|
|
177
|
-
}
|
|
178
|
-
else {
|
|
179
|
-
options.axes.x = {};
|
|
180
|
-
options.hAxes = {};
|
|
181
|
-
}
|
|
182
|
-
$.each(listeLibelleOrd, function(idx, libelleOrd) {
|
|
183
|
-
// console.log(idx);
|
|
184
|
-
if (idx <= 1) {
|
|
185
|
-
// key = 'series_'+idx;
|
|
186
|
-
key = idx;
|
|
187
|
-
// options.series[idx] = {axis: key, targetAxisIndex: key};
|
|
188
|
-
options.series[idx] = {axis: key, targetAxisIndex: idx};
|
|
189
|
-
if (typeGraph == 'column_chart') {
|
|
190
|
-
options.axes.y[key] = {label: libelleOrd};
|
|
191
|
-
if (idx == 1) {
|
|
192
|
-
options.axes.y[key].side = 'right';
|
|
193
|
-
}
|
|
194
|
-
if (formatData != null) {
|
|
195
|
-
options.vAxes[key] = {format: formatData};
|
|
196
|
-
}
|
|
197
|
-
}
|
|
198
|
-
else {
|
|
199
|
-
options.axes.x[key] = {label: libelleOrd};
|
|
200
|
-
if (idx == 1) {
|
|
201
|
-
options.axes.x[key].side = 'top';
|
|
202
|
-
}
|
|
203
|
-
if (formatData != null) {
|
|
204
|
-
options.hAxes[key] = {format: formatData};
|
|
205
|
-
}
|
|
206
|
-
}
|
|
207
|
-
}
|
|
208
|
-
});
|
|
209
|
-
// console.log(options.series);
|
|
210
|
-
// console.log(options.vAxes);
|
|
211
|
-
}
|
|
212
|
-
|
|
213
|
-
// Options sur les graphiques "combo chart"
|
|
214
|
-
if (typeGraph == 'combo_chart') {
|
|
215
|
-
options.seriesType = "bars";
|
|
216
|
-
options.series = {};
|
|
217
|
-
options.series[nbCells] = {type: "line"};
|
|
218
|
-
}
|
|
219
|
-
|
|
220
|
-
// Options sur le style des lignes pour les "line chart"
|
|
221
|
-
if (typeGraph == 'line_chart') {
|
|
222
|
-
options.series = [{lineWidth: 3}, {lineWidth: 1.5}];
|
|
223
|
-
options.curveType = 'function';
|
|
224
|
-
}
|
|
225
|
-
|
|
226
|
-
// Options sur le style pour les "pie chart"
|
|
227
|
-
if (typeGraph == 'pie_chart') {
|
|
228
|
-
options.is3D = false;
|
|
229
|
-
options.pieResidueSliceLabel = 'Autre';
|
|
230
|
-
}
|
|
231
|
-
|
|
232
|
-
if (typeGraph == 'bar_chart') {
|
|
233
|
-
options.bars = 'horizontal';
|
|
234
|
-
}
|
|
235
|
-
|
|
236
|
-
if (isStacked) {
|
|
237
|
-
options.isStacked = true;
|
|
238
|
-
}
|
|
239
|
-
|
|
240
|
-
// console.log(options);
|
|
241
|
-
|
|
242
|
-
// Création du graphique
|
|
243
|
-
var errorChart = false;
|
|
244
|
-
if (typeGraph == 'column_chart') {
|
|
245
|
-
// var chart = new google.visualization.ColumnChart(document.getElementById(idDiv));
|
|
246
|
-
var chart = new google.charts.Bar(document.getElementById(idDiv));
|
|
247
|
-
}
|
|
248
|
-
else if (typeGraph == 'bar_chart') {
|
|
249
|
-
// var chart = new google.visualization.BarChart(document.getElementById(idDiv));
|
|
250
|
-
var chart = new google.charts.Bar(document.getElementById(idDiv));
|
|
251
|
-
}
|
|
252
|
-
else if (typeGraph == 'line_chart') {
|
|
253
|
-
// var chart = new google.visualization.LineChart(document.getElementById(idDiv));
|
|
254
|
-
var chart = new google.charts.Line(document.getElementById(idDiv));
|
|
255
|
-
}
|
|
256
|
-
else if (typeGraph == 'combo_chart') {
|
|
257
|
-
var chart = new google.visualization.ComboChart(document.getElementById(idDiv));
|
|
258
|
-
}
|
|
259
|
-
else if (typeGraph == 'pie_chart') {
|
|
260
|
-
var chart = new google.visualization.PieChart(document.getElementById(idDiv));
|
|
261
|
-
}
|
|
262
|
-
else {
|
|
263
|
-
errorChart = true;
|
|
264
|
-
}
|
|
265
|
-
|
|
266
|
-
$('#'+idDiv).removeClass('ajaxLoader');
|
|
267
|
-
$('#'+idDiv).removeClass('graphique_load');
|
|
268
|
-
|
|
269
|
-
if (errorChart) {
|
|
270
|
-
console.log('erreur graphique');
|
|
271
|
-
$('#'+idDiv).addClass('graphique_error');
|
|
272
|
-
document.getElementById(idDiv).innerHTML = 'Une erreur s\'est produite lors du chargement du graphique.';
|
|
273
|
-
}
|
|
274
|
-
else {
|
|
275
|
-
$('#'+idDiv).addClass('graphique');
|
|
276
|
-
document.getElementById(idDiv).innerHTML = '';
|
|
277
|
-
|
|
278
|
-
// $('#'+idDiv).
|
|
279
|
-
// document.getElementById(idDiv).style.display = 'block';
|
|
280
|
-
var hasClassActive = $('#'+idDiv).hasClass('active');
|
|
281
|
-
if (!hasClassActive) {
|
|
282
|
-
$('#'+idDiv).addClass('active');
|
|
283
|
-
}
|
|
284
|
-
google.visualization.events.addListener(chart, 'ready', function () {
|
|
285
|
-
// document.getElementById(idDiv).style.display = 'none';
|
|
286
|
-
// $('#'+idDiv).hide();
|
|
287
|
-
if (!hasClassActive) {
|
|
288
|
-
$('#'+idDiv).removeClass('active');
|
|
289
|
-
}
|
|
290
|
-
});
|
|
291
|
-
// console.log($("ul li.ui-state-active").index()
|
|
292
|
-
|
|
293
|
-
chart.draw(data, options);
|
|
294
|
-
}
|
|
295
|
-
}
|