-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPlotlyCode
More file actions
365 lines (285 loc) · 13.5 KB
/
PlotlyCode
File metadata and controls
365 lines (285 loc) · 13.5 KB
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
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
function init_salesCustomersMap() {
geocoder = new L.Control.Geocoder.Nominatim();
var a = true;
var LayerMarker;
var bol = true;
var tempD1;
var tempD2;
var info = L.control();
var RegViewValue = 'a';
$("#casablanca").click(function() {
RegViewValue = 'CasaBlanca';
if (bol) GrabDrawGraphMap('City', 'SaleAmount', 'CompanyName', '1996-07-16', '1996-07-31', RegViewValue);
else GrabDrawGraphMap2('City', 'SaleAmount', 'CompanyName', tempD1, tempD2, RegViewValue);
$("#vgms").text('Totale des ventes par GMS - CasaBlanca');
});
$("#fes").click(function() {
RegViewValue = 'Fes';
if (bol) GrabDrawGraphMap('City', 'SaleAmount', 'CompanyName', '1996-07-16', '1996-07-31', RegViewValue);
else GrabDrawGraphMap2('City', 'SaleAmount', 'CompanyName', tempD1, tempD2, RegViewValue);
$("#vgms").text('Totale des ventes par GMS - Fes');
});
$("#tanger").click(function() {
RegViewValue = 'Tanger';
if (bol) GrabDrawGraphMap('City', 'SaleAmount', 'CompanyName', '1996-07-16', '1996-07-31', RegViewValue);
else GrabDrawGraphMap2('City', 'SaleAmount', 'CompanyName', tempD1, tempD2, RegViewValue);
$("#vgms").text('Totale des ventes par GMS - Tanger');
});
$("#Marrakech").click(function() {
RegViewValue = 'Marrackech';
if (bol) GrabDrawGraphMap('City', 'SaleAmount', 'CompanyName', '1996-07-16', '1996-07-31', RegViewValue);
else GrabDrawGraphMap2('City', 'SaleAmount', 'CompanyName', tempD1, tempD2, RegViewValue);
$("#vgms").text('Totale des ventes par GMS - Marrackech');
});
$("#meknes").click(function() {
RegViewValue = 'Meknes';
if (bol) GrabDrawGraphMap('City', 'SaleAmount', 'CompanyName', '1996-07-16', '1996-07-31', RegViewValue);
else GrabDrawGraphMap2('City', 'SaleAmount', 'CompanyName', tempD1, tempD2, RegViewValue);
$("#vgms").text('Totale des ventes par GMS - Meknes');
});
$("#rabat").click(function() {
RegViewValue = 'Rabat';
if (bol) GrabDrawGraphMap('City', 'SaleAmount', 'CompanyName', '1996-07-16', '1996-07-31', RegViewValue);
else GrabDrawGraphMap2('City', 'SaleAmount', 'CompanyName', tempD1, tempD2, RegViewValue);
$("#vgms").text('Totale des ventes par GMS - Rabat');
});
$("#vis_gen").click(function() {
RegViewValue = 'a';
if (bol) GrabDrawGraphMap('City', 'SaleAmount', 'CompanyName', '1996-07-16', '1996-07-31', RegViewValue);
else GrabDrawGraphMap2('City', 'SaleAmount', 'CompanyName', tempD1, tempD2, RegViewValue);
$("#vgms").text('Totale des ventes par GMS (Maroc)');
});
if ($('#salesCustmersMapContainer').length) {
function buildMap() {
document.getElementById('salesCustmersMapContainer').innerHTML = "<div id='map' style='width: 100%; height: 100%;'></div>";
var mymap = L.map('map').setView([33.589886, -7.603869], 8);
L.tileLayer('https://api.tiles.mapbox.com/v4/{id}/{z}/{x}/{y}.png?access_token=pk.eyJ1IjoibWFwcGF0aHphYiIsImEiOiJjamlkNHU4eGEwNGsyM3BsaW1zMHN0dDhtIn0.O6cKzkUUydISZX7bvXOA9A', {
attribution: 'Map data © <a href="https://www.openstreetmap.org/">OpenStreetMap</a> contributors, <a href="https://creativecommons.org/licenses/by-sa/2.0/">CC-BY-SA</a>, Imagery © <a href="https://www.mapbox.com/">Mapbox</a>',
maxZoom: 18,
id: 'mapbox.streets',
accessToken: 'pk.eyJ1IjoibWFwcGF0aHphYiIsImEiOiJjamlkNHU4eGEwNGsyM3BsaW1zMHN0dDhtIn0.O6cKzkUUydISZX7bvXOA9A'
}).addTo(mymap);
return mymap;
}
function GrabDrawGraphMap(c1, c2, c3, d1, d2, c4) {
$.when(salesAdress(c1, d1, d2, c4),
CompanySale(c2, d1, d2, c4),
salesCompanyName(c3, d1, d2, c4)).done(function() {
mymap = buildMap();
info.onAdd = function(mymap) {
this._div = L.DomUtil.create('div', 'infoMapSales');
return this._div;
};
function GraphDrawer() {
var data1 = [],
data2 = [];
objsalesAdress.forEach(function(el, indx) {
data2.push(el);
data1.push(parseFloat(objCompanySale[indx]));
/*var data1 = [20, 14, 23];
var data2 = ['giraffes', 'orangutans', 'monkeys'];*/
});
//setTimeout(function() {
$('.infoMapSales').attr('id', 'SC');
var data = [{
type: 'bar',
x: data1,
y: data2,
orientation: 'h'
}];
//('thus data :');
//(data);
Plotly.react('SC', data, {
paper_bgcolor: 'rgba(0,0,0,0)',
plot_bgcolor: 'rgba(0,0,0,0)',
width: 400,
height: 200,
margin: {
l: 200,
r: 0,
b: 30,
t: 40,
pad: 4
},
}, {
displayModeBar: true
});
}
info.addTo(mymap);
var JsonDataArray = [];
var JsonData = {
"type": "Feature",
"properties": {
"name": null,
"Ventes": null
},
"geometry": {
"type": "Point",
"coordinates": null
}
};
JsonDataArray = [];
//mymap=buildMap();
var datax = [];
var datay = [];
objsalesAdress.forEach(function(el, indx) {
geocoder.geocode(el, function(results) {
JsonData['properties']['name'] = objCompanyName[indx];
JsonData['properties']['Ventes'] = objCompanySale[indx];
if (typeof results[0] != 'undefined') {
JsonData['geometry']['coordinates'] = [results[0].center.lat, results[0].center.lng];
}
JsonDataArray.push(JsonData);
console.log("JsonDataArray");
console.log(JsonDataArray);
if (JsonData['geometry']['coordinates'] != null) L.circleMarker(JsonData['geometry']['coordinates'], {
color: "red",
fillColor: '#f03',
fillOpacity: 0.5,
radius: (JsonData['properties']['Ventes']) * 0.01
})
.bindPopup(el + "</br>" + "</br>" + parseFloat(JsonData['properties']['Ventes']) + " MAD")
.addTo(mymap);
//L.marker(JsonData['geometry']['coordinates']).addTo(mymap);
}); //geocode
}); //getting the elements of an objectArray
//mymap.remove();
GraphDrawer();
//(JsonDataArray);
}); //This Function Calls another function To get data from a php file .
} //END fUNCTION GRAB&Draw
var MapConfig = function() {
if (bol) GrabDrawGraphMap('City', 'SaleAmount', 'CompanyName', '1996-07-16', '1996-07-31', RegViewValue);
else GrabDrawGraphMap2('City', 'SaleAmount', 'CompanyName', tempD1, tempD2, RegViewValue);
}
//Date Variation partition :
function GrabDrawGraphMap2(c1, c2, c3, d1, d2, c4) {
var mymap2 = buildMap()
info.onAdd = function(mymap2) {
this._div = L.DomUtil.create('div', 'infoMapSales');
return this._div;
};
info.addTo(mymap2);
a = false;
//LayerMarker.clearLayers();
$.when(salesAdress('City', d1, d2, c4),
CompanySale('SaleAmount', d1, d2, c4),
salesCompanyName('CompanyName', d1, d2, c4)).done(function() {
var data1 = [],
data2 = [];
objsalesAdress.forEach(function(el, indx) {
data2.push(el);
data1.push(parseFloat(objCompanySale[indx]));
});
$('.infoMapSales').attr('id', 'SC');
var data = [{
type: 'bar',
x: data1,
y: data2,
orientation: 'h'
}];
//('thus data :');
//(data);
Plotly.react('SC', data, {
paper_bgcolor: 'rgba(0,0,0,0)',
plot_bgcolor: 'rgba(0,0,0,0)',
width: 400,
height: 200,
margin: {
l: 200,
r: 0,
b: 30,
t: 0,
pad: 4
},
}, {
displayModeBar: true
});
var JsonDataArray2 = [];
var JsonData2 = {
"type": "Feature",
"properties": {
"name": null,
"Ventes": null
},
"geometry": {
"type": "Point",
"coordinates": null
}
};
//(JsonData2);
//mymap.removeLayer(LayerMarker);
objsalesAdress.forEach(function(el, indx) {
geocoder.geocode(el, function(results) {
JsonData2['properties']['name'] = objCompanyName[indx];
JsonData2['properties']['Ventes'] = objCompanySale[indx];
if (typeof results[0] != 'undefined') JsonData2['geometry']['coordinates'] = [results[0].center.lat, results[0].center.lng];
JsonDataArray2.push(JsonData2);
if (JsonData2['geometry']['coordinates'] != null) {
L.circleMarker(JsonData2['geometry']['coordinates'], {
color: "red",
fillColor: '#f03',
fillOpacity: 0.5,
radius: (JsonData2['properties']['Ventes']) * 0.01
})
.bindPopup(el + "</br>" + parseFloat(JsonData2['properties']['Ventes']) + " MAD")
.addTo(mymap2);
}
//L.marker(JsonData['geometry']['coordinates']).addTo(mymap);
});
});
//('Upadddate date :::');
//(JsonDataArray2);
});
}
$('#reportrange').on('apply.daterangepicker', function(ev, picker) {
bol = false;
tempD1 = picker.startDate.format('YYYY-MM-DD');
tempD2 = picker.endDate.format('YYYY-MM-DD');
GrabDrawGraphMap2('City', 'SaleAmount', 'CompanyName', tempD1, tempD2, RegViewValue);
}); //This Function make sure to send the new Date to the function that calls another function that calls a php file
function salesAdress(Adrss, beginDateRevenu, endDateRevenu, RegV) {
return $.post("http://localhost/gentelella-master/production/CustomersSalesMap.php", {
totalSales: Adrss,
beginDate: beginDateRevenu,
endDate: endDateRevenu,
RegionView: RegV
}, function(data) {
objsalesAdress = $.parseJSON(data);
//('Cities');
//(objsalesAdress);
});
}
function salesCompanyName(CmpName, beginDateRevenu, endDateRevenu, RegV) {
return $.post("http://localhost/gentelella-master/production/CustomersSalesMap.php", {
totalSales: CmpName,
beginDate: beginDateRevenu,
endDate: endDateRevenu,
RegionView: RegV
}, function(data) {
objCompanyName = $.parseJSON(data);
//(objCompanyName);
});
}
function CompanySale(CmpSale, beginDateRevenu, endDateRevenu, RegV) {
return $.post("http://localhost/gentelella-master/production/CustomersSalesMap.php", {
totalSales: CmpSale,
beginDate: beginDateRevenu,
endDate: endDateRevenu,
RegionView: RegV
}, function(data) {
objCompanySale = $.parseJSON(data);
//(objCompanySale);
});
}
var MapResize;
$(window).on("resize", function() {
/*E-Chart Resize*/
clearTimeout(MapResize);
MapResize = setTimeout(MapConfig, 200);
}).resize();
/*****Resize function end*****/
/*****Function Call start*****/
MapConfig();
} //end if make sure it's loaded befor doing anything
} //End sakesCusomersMap