-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdynamic.js
80 lines (67 loc) · 1.74 KB
/
dynamic.js
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
function numberToColorHsl(num, min, max) {
rgb = {0:0, 1:0, 2:0};
if (num > 0) {
foo = 255 - ((num/max) * 255);
rgb[0] = foo
rgb[1] = 255;
rgb[2] = foo;
}
else {
foo = 255 - ((num/min) * 255);
rgb[0] = 255;
rgb[1] = foo;
rgb[2] = foo;
}
return 'rgb(' + rgb[0] + ',' + rgb[1] + ',' + rgb[2] + ')';
}
function start(data) {
var map = new Datamap({
element: document.getElementById('map_container'),
scope: 'usa',
data: data,
fills: {
defaultFill: '#fff'
},
geographyConfig: {
borderWidth: 0.2,
highlightFillColor: '#999',
borderColor: 'black',
popupTemplate: function(geography, data) {
return '<div class="hoverinfo"><b>' + geography.properties.name + '</b><br />' +
'<br/><b>Minimum Wage:</b> ' + data['MinWage'] +
'<br/><b>Cost Of Living:</b> $' + data['CostOfLiving'] +
'<br/><b>Money Remaining:</b> $' + data['MoneyRemaining'] +
'</div>';
},
},
done: function() {
}
});
rawData = map.options.data;
colorData = {};
biggest = -Infinity;
lowest = Infinity;
allMrs = [];
for (var index in rawData) {
state = rawData[index];
allMrs.push(parseFloat(state['MoneyRemaining']));
}
max = Math.max.apply(null, allMrs);
min = Math.min.apply(null, allMrs);
$("#min").text(min);
$("#max").text(max);
for (var index in rawData) {
state = rawData[index];
if(state['MoneyRemaining'] > 0) {
colorData[index] = '#0000ff';
}
else {
colorData[index] = '#ff0000';
}
colorData[index] = numberToColorHsl(state['MoneyRemaining'], min, max);
}
setTimeout(function(){
map.updateChoropleth(colorData)
}, 100);
map.labels();
}