-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.html
156 lines (136 loc) · 3.75 KB
/
index.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
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Tree Map</title>
<script src="https://d3plus.org/js/d3.js"></script>
<script src="https://d3plus.org/js/d3plus.js"></script>
<style>
*, *:before, *:after {
box-sizing: border-box;
margin: 0;
padding: 0;
font: Geneva, sans-serif !important;
color: black;
}
#wrapper {
width: 100vw;
height: 100vh;
background: black;
}
#treeMapAreaCtn, #treeMapValueCtn {
position: absolute;
top: 12.5%;
left: 0;
width: 70vw;
height: 75vh;
opacity: 0;
background: black;
}
#treeMapAreaCtn.active, #treeMapValueCtn.active {
opacity: 1;
transition: opacity 1.5s ;
transition-timing-function: ease-in;
}
#treeMapCtlCtn {
position: absolute;
top: 12.5%;
left: 70%;
width: 30vw;
height: 75vh;
background: tan;
color: white;
font-size: 1.5rem;
font-family: Menlo;
display: flex;
flex-direction: column;
justify-content: center;
align-items: flex-start;
padding: 1.5rem;
}
#treeMapCtlCtn #header {
font-size: 2rem;
display: flex;
flex-direction: column;
justify-content: center;
align-items: center;
margin-bottom: 3rem;
width: 100%;
}
#treeMapCtlCtn label {
margin-bottom: 1rem;
}
#treeMapCtlCtn label input {
margin-right: 0.5rem;
vertical-align: middle;
}
</style>
</head>
<body>
<div id="wrapper">
<div id="treeMapAreaCtn"> </div>
<div class="active" id="treeMapValueCtn"> </div>
<div id="treeMapCtlCtn">
<div id="header">
<p>Crops in Ghana</p>
<p> - 2005 - </p>
</div>
<label>
<input type="radio" id="js-Value" checked="true" name="checkbox" value="value">Crops by Production Value
</label>
<label>
<input type="radio" id="js-Area" name="checkbox" value="value">Crops by Harvested Area
</label>
</div>
</div>
<script>
let cropsData = [];
// read csv data
d3.csv("Crops.csv", function(data) {
data.forEach(function(d) {
d.crop_name = d.crop_name;
d.harvested_area = +d.harvested_area;
d.value_of_production = +d.value_of_production;
cropsData.push(
{ "name": d.crop_name,
"area": d.harvested_area,
"production_value": d.value_of_production
});
});
var valueMap = d3plus.viz()
.container("#treeMapValueCtn")
.data(cropsData)
.type("tree_map")
.id("name")
.size("production_value")
.draw();
var areaMap = d3plus.viz()
.container("#treeMapAreaCtn")
.data(cropsData)
.type("tree_map")
.id("name")
.size("area")
.draw();
});
////////////////////////////////////////////////////////////
// toggle betweeen area and value
////////////////////////////////////////////////////////////
let areaTextEl = document.querySelector('#js-Area');
let valueTextEl = document.querySelector('#js-Value');
areaTextEl.addEventListener("change",
function() {
if(this.checked === true) {
document.querySelector('#treeMapAreaCtn').classList.add("active");
document.querySelector('#treeMapValueCtn').classList.remove("active");
};
});
valueTextEl.addEventListener("change",
function() {
if(this.checked === true) {
document.querySelector('#treeMapAreaCtn').classList.remove("active");
document.querySelector('#treeMapValueCtn').classList.add("active");
};
});
</script>
</body>
</html>