-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathny.html
220 lines (194 loc) · 5.17 KB
/
ny.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
214
215
216
217
218
219
220
<!DOCTYPE html>
<link
href="https://fonts.googleapis.com/css2?family=Lato&display=swap"
rel="stylesheet"
/>
<style>
body {
font-family: "Lato", sans-serif;
}
.pagination a {
color: black;
padding: 8px 16px;
text-decoration: none;
transition: background-color 0.3s;
}
/* Style the active/current link */
.pagination a.active {
background-color: blue;
color: white;
}
/* Add a grey background color on mouse-over */
.pagination a:hover:not(.active) {
background-color: #ddd;
}
.annotation path {
stroke: blue;
fill: none;
}
.annotation path.connector-arrow,
.title text,
.annotation text,
.annotation.callout.circle .annotation-subject path {
fill: black;
}
.title text,
.annotation text {
font-size: 14px;
}
.annotation-note-bg {
fill: rgba(255, 255, 255, 0);
}
.annotation-note-title {
font-weight: bold;
}
.annotation.xythreshold {
cursor: move;
}
.hidden {
display: none;
}
text.hover {
font-size: 0.7em;
}
text.title {
font-size: 1.1em;
}
</style>
<div align="center">
<h1>New York</h1>
<p>New York's first case was on <b>March 1, 2020</b>.</p>
<p>New York's population is <b>19.45 million</b>.</p>
<p>
Although New York saw the biggest influx of initial cases,<br />
the state has been successfully flattening the curve, even after
stay-at-home ended.
</p>
<div id="container"></div>
<div class="pagination">
<a href="index.html">«</a>
<a href="index.html">1</a>
<a class="active" href="ny.html">2</a>
<a href="cali.html">3</a>
<a href="illinois.html">4</a>
<a href="resources.html">5</a>
<a href="cali.html">»</a>
</div>
</div>
<!-- Load d3.js -->
<script src="https://d3js.org/d3.v4.js"></script>
<script src="https://rawgit.com/susielu/d3-annotation/master/d3-annotation.min.js"></script>
<script src="helperFunctions.js"></script>
<script>
// LOAD & STRUCTURE DATA
const dateParser = d3.timeParse("%Y-%m-%d");
d3.csv(
"us-states.csv",
function (d) {
if (d.state === "New York") {
return { date: dateParser(d.date), cases: +d.cases };
}
},
function (data) {
// CONSTRUCT GRAPH CONTAINER
const margin = { top: 80, right: 120, bottom: 60, left: 100 };
const width = 700 - margin.left - margin.right;
const height = 500 - margin.top - margin.bottom;
let svg = d3
.select("#container")
.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 + ")");
// CONSTRUCT AXES
const xScale = d3
.scaleTime()
.domain(d3.extent(data, (d) => d.date))
.range([0, width]);
svg
.append("g")
.attr("transform", "translate(0," + height + ")")
.call(d3.axisBottom(xScale));
const yScale = d3
.scaleLinear()
.domain([0, d3.max(data, (d) => d.cases)])
.nice()
.range([height, 0]);
svg.append("g").call(d3.axisLeft(yScale));
svg
.append("text")
.attr("transform", "rotate(-90)")
.attr("y", -75)
.attr("x", -height / 2)
.attr("dy", "1em")
.style("text-anchor", "middle")
.text("# Cases")
.style("font-family", "Lato")
.style("font-size", "14px");
// CONSTRUCT LINE GRAPH
let line = d3
.line()
.x((d) => xScale(d.date))
.y((d) => yScale(d.cases));
svg
.append("path")
.attr("fill", "none")
.attr("stroke", "blue")
.attr("stroke-width", 1.5)
.attr("class", "line")
.attr("d", line(data));
// CONSTRUCT ANNOTATION
const labels = [
{
note: {
label: "2020-03-22",
title: "Stay at home begins",
},
dy: -5,
dx: 50,
data: {
x: "2020-03-22",
y: 15188,
},
subject: { radius: 5 },
},
{
note: {
label: "2020-05-15",
title: "Stay at home ends",
},
dy: 0,
dx: 50,
data: {
x: "2020-05-15",
y: 350951,
},
subject: { radius: 5 },
},
];
const makeAnnotations = d3
.annotation()
.annotations(labels)
.type(d3.annotationCalloutCircle)
.accessors({
x: (d) => xScale(dateParser(d.x)),
y: (d) => yScale(d.y),
})
.on("subjectover", function (annotation) {
annotation.type.a
.selectAll("g.annotation-connector, g.annotation-note")
.classed("hidden", false);
})
.on("subjectout", function (annotation) {
annotation.type.a
.selectAll("g.annotation-connector, g.annotation-note")
.classed("hidden", true);
});
svg.append("g").attr("class", "annotation-test").call(makeAnnotations);
svg
.selectAll("g.annotation-connector, g.annotation-note")
.classed("hidden", true);
}
);
</script>