-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathscene2.html
137 lines (120 loc) · 3.67 KB
/
scene2.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
<!DOCTYPE html>
<head>
<meta charset="utf-8">
<title>COVID Scenes</title>
<link rel="stylesheet" href="test.css">
<script src="https://d3js.org/d3.v4.js"></script>
</head>
<body>
<header>
<h1> COVID 19 Scenes</h1>
</header>
<main>
<div id="bar_chart_simple"></div>
</main>
<aside>
<div class="myDiv">
<h2>Total Deaths for Countries w/ Top 10 Population</h2>
<p>As you can see from the graph, </p>
</p>The United States is also leading the World in total COVID-19 Deaths.</p>
<p>Mouseover for details</p>
</div>
<a href="scene3.html">
<button type="submit" class="button"
style="vertical-align:middle"><span>Scene 3</span>
</button>
</a>
</aside>
</footer>
</body>
<script>
var margin = {top: 30, right: 30, bottom: 70, left: 60},
width = 560 - margin.left - margin.right,
height = 500 - margin.top - margin.bottom;
var svg = d3.select("#bar_chart_simple")
.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 + ")");
d3.csv("owid-covid-data.csv", function(data) {
data.sort(function(b, a) {
return a.total_deaths - b.total_deaths;
});
var x = d3.scaleBand()
.range([ 0, width ])
.domain(data.map(function(d) { return d.location; }))
.padding(0.2);
svg.append("g")
.attr("transform", "translate(0," + height + ")")
.call(d3.axisBottom(x))
.selectAll("text")
.attr("transform", "translate(-10,0)rotate(-45)")
.style("text-anchor", "end");
var y = d3.scaleLinear()
.domain([0, 160000])
.range([ height, 0]);
svg.append("g")
.call(d3.axisLeft(y));
var topData = data.sort(function(a, b) {
return d3.descending(+a.total_deaths, +b.total_deaths);
}).slice(0, 10);
var Tooltip = d3.select("#bar_chart_simple")
.append("div")
.style("opacity", 0)
.attr("class", "tooltip")
.style("background-color", "#590C0C")
.style("border", "solid")
.style("border-width", "2px")
.style("border-radius", "5px")
.style("padding", "5px")
var mouseover = function(d) {
Tooltip
.style("opacity", 1)
d3.select(this)
.style("stroke", "black")
.style("opacity", 1)
}
var mousemove = function(d) {
Tooltip
.html("There are a total of : " + d3.format(',')(d.total_deaths) + " Deaths")
.style("left", (d3.mouse(this)[0]+70) + "px")
.style("top", (d3.mouse(this)[1]) + "px")
}
var mouseleave = function(d) {
Tooltip
.style("opacity", 0)
d3.select(this)
.style("stroke", "none")
.style("opacity", 0.8)
}
svg.selectAll("mybar")
.data(topData)
.enter()
.append("rect")
.attr("x", function(d) { return x(d.location); })
.attr("y", function(d) { return y(d.total_deaths); })
.attr("width", x.bandwidth())
.attr("height", function(d) { return height - y(d.total_deaths); })
.attr("fill", "#590C0C")
.on("mouseover", mouseover)
.on("mousemove", mousemove)
.on("mouseleave", mouseleave)
svg.append("line")
.style("stroke", "black")
.style("stroke-width", 2)
.style("stroke-dasharray", "5,5")
.attr("x1", 0)
.attr("y1", 15)
.attr("x2", 500)
.attr("y2", 15);
svg.append("text")
.attr("transform",
"translate(" + (250) + " ," + (30) + ")")
.style("text-anchor", "middle")
.style("stroke", "Black")
.style("font-size", ".8em")
.text("United States's Deaths: 154,447");
})
</script>