-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex2.html
119 lines (110 loc) · 4.36 KB
/
index2.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
<!doctype html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<link href="css/style.css" rel="stylesheet">
</head>
<body>
<button type="button" onclick="actualiza()">actualiza</button>
<div id="chart"> </div>
<script src="https://d3js.org/d3.v4.min.js"></script>
<script src="https://d3js.org/d3-queue.v3.min.js"></script>
<script src="script/reusableRadar.js"></script>
<script>
var currentRegion = 0,
allData,
radar;
d3.csv("data/variables-potencial-industrial.csv",
function(error, vars){
if (error) throw error;
// Parse data as numbers
data = [];
vars.forEach(function(d) {
data.push({
id: d.id,
nom_ciudad: d.nom_ciudad,
zona: d.zona,
"Legal System": +d.sis_dere,
"Environment": +d.man_ambi,
"Inclusive Society": +d.soc_incl,
"Efficent Government": +d.gob_efic,
"Market Factors": +d.merc_fac,
"Economic Stability": +d.eco_esta,
"Infrastructure": +d.precur,
"International Relationships": +d.rela_inte,
"Economic Innovation": +d.inno_eco,
"Political System": +d.sis_poli
});
});
var imcoAvgs = {
"id": -1,
"nom_ciudad": "National Averages",
"zona": "National",
"Legal System": d3.mean(vars,function(d) {
return d.sis_dere;
}),
"Political System": d3.mean(vars,function(d) {
return d.man_ambi;
}),
"Environment": d3.mean(vars,function(d) {
return d.soc_incl;
}),
"Inclusive Society": d3.mean(vars,function(d) {
return d.sis_poli;
}),
"Efficient Government": d3.mean(vars,function(d) {
return d.gob_efic;
}),
"Market Factors": d3.mean(vars,function(d) {
return d.merc_fac;
}),
"Economic Stability": d3.mean(vars,function(d) {
return d.eco_esta;
}),
"Infrastructure": d3.mean(vars,function(d) {
return d.precur;
}),
"International Relationships": d3.mean(vars,function(d) {
return d.rela_inte;
}),
"Economic Innovation": d3.mean(vars,function(d) {
return d.inno_eco;
})
};
var cityNames = [];
vars.forEach(function(e) {
cityNames.push(e.nom_ciudad);
});
radar = radarChart()
.width(400)
.height(400)
.displayName("nom_ciudad")
.id("id")
.color(d3.scaleOrdinal()
.domain(cityNames).range(d3.schemeCategory20))
.legend({ title: '', translateX: 100, translateY: 0 });
data.push(imcoAvgs);
allData = data;
radar.data([imcoAvgs]); // bind data to chart object
d3.select("#chart")
.call(radar); // Draw chart in selected div
});
var idToName = {
1 : "Noreste",
2 : "Centro-Occidente",
3 : "Megalopolis",
4 : "Noroeste",
5 : "Golfo Oriente",
6 : "Centro Norte",
7 : "Peninsula"
};
function actualiza(){
currentRegion ++;
newData = allData.filter(function(el){
return el.zona === idToName[currentRegion] || el.zona === "National";
});
radar.data(newData);
}
</script>
</body>
</html>