-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtornado.html
213 lines (177 loc) · 6.53 KB
/
tornado.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
<!DOCTYPE html>
<html>
<head>
<link rel="stylesheet" type="text/css" href="tornadocss.css">
<script src="https://ajax.aspnetcdn.com/ajax/jQuery/jquery-3.1.1.min.js"></script>
<script src="tornadojs.js"></script>
</head>
<body>
<br />
<hr>
<br />
<h1 style="text-align:center";>Quality of Life, 2017 to 2021</h1>
<br />
<hr>
<br />
<div class="popup">
<div class="message_box">
<p>Hey there! </p>
<p>Great to see you here. On this page, you will find a visualization demonstrating the percentage change of multiple categories over 5 years. </p>
<p>We hope you enjoy the experience!</p>
<div class="button" id="close_popup">Let's Go</div>
</div>
</div>
<!--Hello! this is our first draft visualization attempt
This file includes an interactive bar chart that changes as you press the buttons
we will use this for interactive reference
code is taken from https://d3-graph-gallery.com/graph/barplot_button_data_simple.html -->
<!-- Load d3.js -->
<script src="https://d3js.org/d3.v4.js"></script>
<p style="text-align: center";>Group Members: Dina, Carson, Danielle, Trent, Adrienne</p>
<br />
<br />
<div class="instructions">
<p style="text-align: center;">Instructions</p>
<p>When first observing the webpage, the first thing the user will notice is a bar chart that has details on demand when hovering over the individual bars. These details will show the exact percentage change over a time period that the user will be able to select themselves by using the interactive buttons located above the visualization section.
The user will also be able to access on-click data for the individual categories, where there will be a pop-up static chart showing more in-depth data on the selected category. The user will be able to repeat these steps for each category by either hovering or clicking on each bar.</p>
</div>
<br />
<br />
<br />
<container id="buttons">
<!-- Add 2 buttons -->
<button onclick="update(data1)">2017-2018</button>
<button onclick="update(data2)">2018-2019</button>
<button onclick="update(data3)">2019-2020</button>
<button onclick="update(data4)">2020-2021</button>
</container>
<br />
<br />
<br />
<!-- Create a div where the graph will take place -->
<div id="my_dataviz"></div>
<div id="singular_viz"></div>
<script>
// create 2 data_set
var data1 = [
{group: "Marriage", value: 2.31},
{group: "Death", value: 3.42},
{group: "Birth", value: -0.65},
{group: "Unemployment", value: 0.49},
{group: "Crime", value: 9.04},
{group: "Suicide", value: 5.34}
];
var data2 = [
{group: "Marriage", value: -0.05},
{group: "Death", value: 3.68},
{group: "Birth", value: -0.86},
{group: "Unemployment", value: 1.23},
{group: "Crime", value: 13.42},
{group: "Suicide", value: 3.47}
];
var data3 = [
{group: "Marriage", value: -35.06},
{group: "Death", value: 11.57},
{group: "Birth", value: -3.65},
{group: "Unemployment", value: -3.69},
{group: "Crime", value: 1.37},
{group: "Suicide", value: 4.2}
];
var data4 = [
{group: "Marriage", value: -16.72},
{group: "Death", value: 12.93},
{group: "Birth", value: -0.74},
{group: "Unemployment", value: -0.12},
{group: "Crime", value: 5.55},
{group: "Suicide", value: 0}
];
// set the dimensions and margins of the graph
var margin = {top: 100, right: 30, bottom: 60, left: 100},
width = 700 - margin.left - margin.right,
height = 640 - margin.top - margin.bottom;
// Define the div for the tooltip
var div = d3.select("#my_dataviz").append("div")
.attr("class", "tooltip")
.style("opacity", 0);
// append the svg object to the body of the page
var svg = d3.select("#my_dataviz")
.append("svg")
.attr("width", width + margin.left + margin.right)
.attr("height", height + margin.top + margin.bottom)
.append("g")
.attr("transform",
"translate(" + margin.left + "," + margin.top + ")")
// X axis
var x = d3.scaleBand()
.range([ 0, width ]) // where the x axis starts on the left side
.domain(data1.map(function(d) { return d.group; }))
.padding(0.6);
svg.append("g")
.attr("transform", "translate(0," + height + ")")
.call(d3.axisBottom(x))
// Add Y axis
var y = d3.scaleLinear()
.domain([-40, 15])
.range([ height, 1]);
svg.append("g")
.attr("class", "myYaxis")
.call(d3.axisLeft(y));
// add labels to graph
svg.append("text") // Title
.attr("x", (width / 2))
.attr("y", 0 - (margin.top / 2))
.attr("text-anchor", "middle")
.style("font-size", "20px")
.style("text-decoration", "underline")
.text("Quality of Life in Ontario from 2017 to 2021");
svg.append("text") // x axis
.attr("class", "x label")
.attr("text-anchor", "end")
.attr("x", (width / 2) + 120)
.attr("y", height + 50)
.text("Nominal variables affecting quality of life");
svg.append("text") // y axis
.attr("class", "y label")
.attr("text-anchor", "end")
.attr("x", -150)
.attr("y", -50)
.attr("dy", ".35em")
.attr("transform", "rotate(-90)")
.text("Percentage Change (%)");
// A function that create / update the plot for a given variable:
function update(data) {
var u = svg.selectAll("rect")
.data(data)
u
.enter()
.append("rect")
.merge(u)
.transition()
.duration(1000)
.attr("x", function(d) { return x(d.group); })
.attr("y", function(d) { return y(d.value); })
.attr("width", x.bandwidth())
.attr("height", function(d) { return height - y(d.value); })
.attr("fill", "#69b3a2")
.on("mouseover", function(d) {
div.transition()
.duration(200)
.style("opacity", .9);
div.html(d.group + "<br />" + d.value)
.style("left", (d3.event.pageX) + "px")
.style("top", (d3.event.pageY - 28) + "px");
})
.on("mouseout", function(d) {
div.transition()
.duration(500)
.style("opacity", 0);
});
}
// Initialize the plot with the first dataset
update(data1)
</script>
<br />
<br />
<br />
</body>
</html>