-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.html
185 lines (156 loc) · 5.49 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
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
<!doctype html>
<head>
<meta charset="utf-8">
<title>Final Project for CS 498 - Data Visualization Course</title>
<meta name="author" content="Pratyush Kumar">
<meta name="description" content="">
<link rel="stylesheet" href="css/reset.css">
<link rel="stylesheet" href="css/stepper.css">
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js"></script>
<script src="js/stepper.js"></script>
<script src="//d3js.org/d3.v3.min.js"></script>
</head>
<body>
<div id="container">
<h1>Carbon dioxide release studies alongside Vehicle Horsepower</h1>
<h2 class="subtitle">Visualization is based on data from the Environment Protection Agency of vehicles manufactured in 2017.</h2>
<div id="vis-nav">
<a href="#" id="step1" class="step-link active">Scene 1</a>
<a href="#" id="step2" class="step-link">Scene 2</a>
<a href="#" id="step3" class="step-link">Scene 3</a>
<a href="https://github.com/pratyushkr9420/CS498-Narrative-visualization/blob/master/README.md" target="_blank" class="desc-link">About the Visualization</a>
</div>
<div id="vis-container">
<div id="annotation-steps">
<div class="annotation-step" id="step1-annotation" style="display:block;">
<div class="annotation" id="step1-high-annotation" >
<h4>There is a direct positive correlation between CO2 and horsepower. For all vehicles increase in horsepower led to more carbon dioxide emission from them.</h4>
</div>
</div>
<div class="annotation-step" id="step2-annotation">
<div class="annotation" id="step2-high-annotation" >
<h4>Mouseover the data to see the individual trends for Cars, Trucks or both.</h4>
</div>
</div>
<div class="annotation-step" id="step3-annotation">
<div class="annotation" id="step3-high-annotation" >
<h4>The visuals indicates that lower horsepower vehciles are more sustainable</h4>
</div>
</div>
</div>
<div id="vis-canvas">
<style>
.axis path,
.axis line {
fill: none;
stroke: #000;
shape-rendering: crispEdges;
}
.dot {
stroke: #000;
}
</style>
<script>
// Set the dimensions of the canvas / graph
var margin = {top: 50, right: 20, bottom: 30, left: 80},
width = 940 - margin.left - margin.right,
height = 500 - margin.top - margin.bottom;
// Set the ranges
var x = d3.scale.linear()
.range([0, width]);
var y = d3.scale.linear()
.range([height, 0]);
var color = d3.scale.category20();
// Define the axes
var xAxis = d3.svg.axis()
.scale(x)
.orient("bottom");
var yAxis = d3.svg.axis()
.scale(y)
.orient("left");
// Add the svg canvas
var svg = d3.select("#vis-canvas").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 + ")");
// Get the data
d3.csv("https://raw.githubusercontent.com/pratyushkr9420/CS498-Narrative-visualization/master/data/epa2017_revised.csv", function(error, data) {
if (error) throw error;
data.forEach(function(d) {
d.CO2 = +d.CO2;
d.horse = +d.horse;
});
// Scale the range of the data
x.domain(d3.extent(data, function(d) { return d.horse; })).nice();
y.domain(d3.extent(data, function(d) { return d.CO2; })).nice();
// Add the X Axis
svg.append("g")
.attr("class", "x axis")
.attr("transform", "translate(0," + height + ")")
.call(xAxis)
.append("text")
.attr("class", "label")
.attr("x", width)
.attr("y", -6)
.style("text-anchor", "end")
.text("Rated Horsepower (foot-pounds per second)");
// Add the Y Axis
svg.append("g")
.attr("class", "y axis")
.call(yAxis)
.append("text")
.attr("class", "label")
.attr("transform", "rotate(-90)")
.attr("y", 6)
.attr("dy", ".71em")
.style("text-anchor", "end")
.text("Carbon dioxide Emissions (grams per mile)")
// Add the Scatterplot
svg.selectAll(".dot")
.data(data)
.enter().append("circle")
.attr("class", "dot")
.attr("r", 3.5)
.attr("cx", function(d) { return x(d.horse); })
.attr("cy", function(d) { return y(d.CO2); })
.style("fill", function(d) { return color(d.type); })
.on("mouseover", function(d){
d3.selectAll('.dot')
.filter(function(dot){
return (dot.type != d.type)
})
.transition()
.style("opacity", 0.01)
})
.on("mouseout", function(d){
d3.selectAll('.dot')
.filter(function(dot){
return (dot.type != d.type)
})
.transition()
.style("opacity", 1)
});
// Add the Legend
var legend = svg.selectAll(".legend")
.data(color.domain())
.enter().append("g")
.attr("class", "legend")
.attr("transform", function(d, i) { return "translate(0," + i * 20 + ")"; });
legend.append("rect")
.attr("x", width - 18)
.attr("width", 18)
.attr("height", 18)
.style("fill", color);
legend.append("text")
.attr("x", width - 24)
.attr("y", 9)
.attr("dy", ".35em")
.style("text-anchor", "end")
.text(function(d) { return d; });
});
</script>
</div>
</div>
</div>
</body>