-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathscene3.html
128 lines (108 loc) · 3.46 KB
/
scene3.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
<!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="scatter"></div>
</main>
<aside>
<div class="myDiv">
<h2>Total Cases compared to Deaths</h2>
<p>Surpisingly you can see from the chart that Mexico has a higher Fatality Rate then the United States</p>
<p>Mouseover for details</p>
</div>
<a href="index.html">
<button type="submit" class="button"
style="vertical-align:middle"><span>Restart</span>
</button>
</a>
</aside>
<footer>
</footer>
</body>
<script>
var margin = {top: 10, right: 30, bottom: 30, left: 60},
width = 500 - margin.left - margin.right,
height = 420 - margin.top - margin.bottom;
var svg = d3.select("#scatter")
.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) {
var x = d3.scaleLinear()
.domain([0, 160000])
.range([ 0, width ]);
svg.append("g")
.attr("transform", "translate(0," + height + ")")
.call(d3.axisBottom(x));
var y = d3.scaleLinear()
.domain([0, 5000000])
.range([ height, 0]);
svg.append("g")
.call(d3.axisLeft(y));
var tooltip = d3.select("#scatter")
.append("div")
.style("opacity", 0)
.attr("class", "tooltip")
.style("background-color", "#590C0C")
.style("border", "solid")
.style("border-width", "1px")
.style("border-radius", "5px")
.style("padding", "10px")
var mouseover = function(d) {
tooltip
.style("opacity", 1)
}
var mousemove = function(d) {
tooltip
.html("Country: "+d.location+"<br>Total Cases: " + d3.format(',')(d.total_cases)+"<br>Total Deaths: "+d3.format(',')(d.total_deaths)+"<br>Total Population: "+d3.format(',')(d.population)+"<br>Fatality Rate: "+d.total_rate)
.style("left", (d3.mouse(this)[0]+90) + "px")
.style("top", (d3.mouse(this)[1]) + "px")
}
var mouseleave = function(d) {
tooltip
.transition()
.duration(200)
.style("opacity", 0)
}
svg.append("line")
.style("stroke", "black")
.style("stroke-width", 2)
.style("stroke-dasharray", "5,5")
.attr("x1", 121.5)
.attr("y1", 0)
.attr("x2", 121.5)
.attr("y2", 380);
svg.append("text")
.attr("transform",
"translate(" + (200) + " ," + (350) + ")")
.style("text-anchor", "middle")
.style("stroke", "Black")
.style("font-size", ".8em")
.text("Mexico's 11% Fatality Rate");
svg.append('g')
.selectAll("dot")
.data(data.filter(function(d,i){return i<5000000}))
.enter()
.append("circle")
.attr("cx", function (d) { return x(d.total_deaths); } )
.attr("cy", function (d) { return y(d.total_cases); } )
.attr("r", 7)
.style("fill", "#590C0C")
.style("opacity", 0.3)
.style("stroke", "white")
.on("mouseover", mouseover )
.on("mousemove", mousemove )
.on("mouseleave", mouseleave )
})
</script>