-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.html
371 lines (286 loc) · 9.44 KB
/
main.html
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
366
367
368
369
370
371
<!DOCTYPE html>
<html>
<head>
<title>COVID-19 Map Dashboard with Leaflet.js and Chart.js</title>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<link rel="stylesheet" href="https://unpkg.com/leaflet@1.7.1/dist/leaflet.css" />
<script src="https://unpkg.com/leaflet@1.7.1/dist/leaflet.js"></script>
<script src="https://code.jquery.com/jquery-1.11.3.min.js"></script>
<script type="text/javascript" src="http://www.chartjs.org/assets/Chart.js"> </script>
<script type="text/javascript" src="https://www.chartjs.org/samples/latest/utils.js"> </script>
<script src="https://www.chartjs.org/dist/2.9.3/Chart.min.js"></script>
<style>
#top {
width: 100%;
height: 40px;
float:top;
}
#map {
width: 50%;
height: 550px;
float:left;
}
#chartDiv {
width: 50%;
height: 500px;
float:left;
}
p,ol {
font: 12px/14px Arial, Helvetica, sans-serif;
}
.info {
padding: 16px 10px;
font: 14px/16px Arial, Helvetica, sans-serif;
background: white;
background: rgba(255,255,255,0.8);
box-shadow: 0 0 15px rgba(0,0,0,0.2);
border-radius: 5px;
}
.info h4 {
margin: 0 0 5px;
color: 'white';
}
.legend {
text-align: left;
line-height: 18px;
color: #555;
}
.legend i {
width: 18px;
height: 18px;
float: left;
margin-right: 8px;
opacity: 0.7;
}
</style>
</head>
<body>
<!--<div id="top">
<p align="center"><b>COVID-19 Dashboard with <a href="https://leafletjs.com/" target="new">Leaflet.js</a> and <a href="https://www.chartjs.org/" target="new">Chart.js</a> <br/>
<a href="dashboard_info.html" target="new">Project Details</a></b><br/> <b><a href="https://uem.edu.in/uem-kolkata/"> UEM, Kolkata </a></b></p>
</div>-->
<div id="map"></div>
<div id="chartDiv">
<canvas id="barChartCanvas" height="130"></canvas>
<canvas id="ScatterCanvas" height="130"></canvas>
</div>
<script src="https://unpkg.com/leaflet@1.0.1/dist/leaflet.js"></script>
<script type="text/javascript">
var scatterData = [];
var scatterLabels = [];
var color = Chart.helpers.color;
//bar chart that updates when the map is interacted with
var newChart = function(labels, data) {
var dataLength = labels ? labels.length : 0;
//will select colors to use based on the number of data points
var backgroundColors = ['rgba(255,255,153, 0.9)', //confirmed
'rgba(127,201,127, 0.9)', //discharged
'rgba(228,26,28, 0.9)' //death
];
var colors = [];
for (var i = 0; i < dataLength; i++) {
colors.push(backgroundColors[i]);
};
//'newChart colors', colors
var ctx = document.getElementById("barChartCanvas");
var barChartCanvas = new Chart(ctx, {
type: 'bar',
data: {
labels: labels,
datasets: [{
label: 'Info',
data: data,
backgroundColor: colors,
borderColor: colors,
borderWidth: 1
}]
},
options: {
scales: {
yAxes: [{
ticks: {
beginAtZero:true
}
}]
}
}
});
};// var newChart = function(labels, data) {
//scatter plot chart
var scatterChartData = {
labels: scatterLabels,
datasets: [{
label: 'Confirmed Cases (X-axis) vs. Discharged (Y-axis)',
data: scatterData
}]
};
//will draw the scatter plot
window.onload = function() {
//intialize the bar chart with nothing
newChart([], []);
var ctxScatter = document.getElementById('ScatterCanvas').getContext('2d');
//scatterChartData
window.myScatter = Chart.Scatter(ctxScatter, {
data: scatterChartData,
options: {
title: {
display: true,
text: 'Scatterplot: Mouse Over Data Points to See Individual Values'
},
tooltips: {
callbacks: {
title: function(tooltipItem, data) {
//will get the name of ths state
return data['labels'][tooltipItem[0]['index']];
},
label: function(tooltipItem, data) {
//will get the values
label_string = "Confirmed Cases: " + tooltipItem.xLabel + " Discharged: " + tooltipItem.yLabel;
return label_string;
}
},//callbacks: {
backgroundColor: '#FFF',
titleFontSize: 14,
titleFontColor: '#0066ff',
bodyFontColor: '#000',
bodyFontSize: 12,
displayColors: true
}//tooltips: {
} //options: {
});//window.myScatter = Chart.Scatter(ctxScatter, {
window.myScatter.update();
};//window.onload = function() {
//create the leaflet.js map, centered on Nigeria
var map = L.map('map', {
zoomControl: true, maxZoom: 28, minZoom: 1
}).fitBounds([[6.58213214121, -4.23063744871], [16.6848032876, 13.6705868633]]);
L.tileLayer('http://{s}.google.com/vt/lyrs=m&x={x}&y={y}&z={z}', {
maxZoom: 20,
subdomains: ['mt0', 'mt1', 'mt2', 'mt3']
}).addTo(map);
var info = L.control();
info.onAdd = function(map) {
this._div = L.DomUtil.create('div', 'info');
this.update();
return this._div;
};
info.update = function(props) {
if (props) {
var labels = ['Confirmed Cases', 'Discharged', 'Deaths'];
var data = [props.NigeriaCases_Confirmed, props.NigeriaCases_Discharged, props.NigeriaCases_Deaths];
//will add a floating DIV tage over the map
var overview = '<h4>Data for: ' + props.NAME_1 + ' State</h4>' + "<br/>";
overview += 'Confirmed Cases: ' + props.NigeriaCases_Confirmed + "<br/>";
overview += 'Discharged: ' + props.NigeriaCases_Discharged + "<br/>";
overview += 'Deaths: ' + props.NigeriaCases_Deaths + "<br/>";
this._div.innerHTML = overview;
//send this data to the bar chart
newChart(labels, data);
}
};
info.addTo(map);
//sets the color ramp for the map shape
//5 class natural using colorbrewer colors
function getColor(b) {
return b >= 0.0 & b <= 499 ? '#ffffcc' :
b >= 500 & b <= 999 ? '#c7e9b4':
b >= 1000 & b <= 2999 ? '#7fcdbb':
b >= 3000 & b <= 5999 ? '#41b6c4':
b >= 6000 & b <= 10999 ? '#2c7fb8' :
b >= 11000 & b <= 17999 ? '#253494' :
'grey' ;
}
function style_1(feature){
return{
weight: 1,
opacity: 1,
color: 'white',
};
}
//sets the intial look of the map using the confirmed cases
function style(feature) {
return {
weight: 0.6,
opacity: 0.4,
color: 'white',
fillOpacity: 0.8,
fillColor: getColor(feature.properties.NigeriaCases_Confirmed)
};
}
function highlightFeature(e) {
//highlightFeature was entered;
var layer = e.target;
layer.setStyle({
weight: 1.5,
color: 'black',
dashArray: '',
fillOpacity: 0.7
});
if (!L.Browser.ie && !L.Browser.opera) {
layer.bringToFront();
}
//data contained in the map feature will be sent to update the bar chart
info.update(layer.feature.properties);
}
var geojson;
function resetHighlight(e) {
geojson.resetStyle(e.target);
//comment the line below if you don't want the data to reset when the mouse moves away
info.update();
}
function onEachFeature(feature, layer) {
//get all the data for adding to the scatter plot
if (feature.properties) {
//no null values
if (feature.properties.NigeriaCases_Confirmed != null) {
scatterData.push ({x: feature.properties.NigeriaCases_Confirmed, y:feature.properties.NigeriaCases_Discharged} );
//get the statename for labeling in the scatterplot
scatterLabels.push(feature.properties.NAME_1);
} else {
console.log("null");
}
//force the scatter plot to draw when the page loads
window.myScatter.update();
}
layer.on({
mouseover: highlightFeature,
mouseout: resetHighlight
});
}
//this is where the GeoJSON created in QGIS is loaded into the map
$.getJSON ("./data/NigeriaStateData.geojson", function(data) {
//geojson retrieved
geojson = L.geoJson(data, {
style: style,
onEachFeature: onEachFeature
}).addTo(map);
});
map.attributionControl.addAttribution('COVID-19 Data Nigeria © <a href="https://www.mohfw.gov.in/">Ministry of Health and Family Welfare</a>');
var legend = L.control({position: 'bottomright'});
legend.onAdd = function (map) {
var div = L.DomUtil.create('div', 'info legend'),
grades = [0, 86, 400, 1084, 1893, 3651],
labels = ['<strong>Confirmed Cases</strong>'],
from, to;
var x=1;
var y=1;
for (var i = 0; i < grades.length - 1; i++) {
from = grades[i];
to = grades[i + 1];
y++;
//"x" + from + " " + to
/*labels.push(
'<i style="background:' + getColor(x,x+1) + '"></i> ' + from + (' to ' + to)
);*/
labels.push(
'<i style="background:' + getColor(from) + '"></i> ' + from + (' to ' + to)
);
}
div.innerHTML = labels.join('<br>');
return div;
};
legend.addTo(map);
</script>
</body>
</html>