-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.html
174 lines (152 loc) · 4.39 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
<!DOCTYPE html>
<meta charset="utf-8">
<link href='https://fonts.googleapis.com/css?family=Titillium+Web:400,700' rel='stylesheet' type='text/css'>
<style>
body {
font-family: 'Titillium Web', sans-serif;
font-size: 18px;
shape-rendering: crispEdges;
width:550px;
padding-top: 120px;
}
p {
margin:0px;
padding:0px;
}
.day {
fill: #fff;
}
.month {
fill: none;
stroke: #000;
stroke-width: 1px;
}
#key div {
float: left;
padding: 5px;
margin: 5px;
font-weight:700;
}
#key { background: rgb(255,255,255);
background: rgba(255,255,255, .8);
padding:5px;
position:fixed;
top:0;
width:100%;
z-index:100;}
#temp9 {background-color:rgb(158,1,66);}
#temp8 {background-color:rgb(213,62,79)}
#temp7 {background-color:rgb(244,109,67)}
#temp6 {background-color:rgb(253,174,97)}
#temp5 {background-color:rgb(254,224,139)}
#temp4 {background-color:rgb(230,245,152)}
#temp3 {background-color:rgb(171,221,164)}
#temp2 {background-color:rgb(102,194,165)}
#temp1 {background-color:rgb(50,136,189)}
#temp0 {background-color:rgb(94,79,162)}
.RdYlGn .q9-10{fill:rgb(158,1,66)}
.RdYlGn .q8-10{fill:rgb(213,62,79)}
.RdYlGn .q7-10{fill:rgb(244,109,67)}
.RdYlGn .q6-10{fill:rgb(253,174,97)}
.RdYlGn .q5-10{fill:rgb(254,224,139)}
.RdYlGn .q4-10{fill:rgb(230,245,152)}
.RdYlGn .q3-10{fill:rgb(171,221,164)}
.RdYlGn .q2-10{fill:rgb(102,194,165)}
.RdYlGn .q1-10{fill:rgb(50,136,189)}
.RdYlGn .q0-10{fill:rgb(94,79,162)}
</style>
<body>
<div id="key" class="RdYlGn">
<h2 style="margin:0px">Daily minimum temperatures</h2>
<div id="temp0">
<p>Less than 0°F</p>
</div>
<div id="temp1">
<p>0°to 10°</p>
</div>
<div id="temp2">
<p>10°to 20°</p>
</div>
<div id="temp3">
<p>20°to 30°</p>
</div>
<div id="temp4">
<p>30°to 40°</p>
</div>
<div id="temp5">
<p>40°to 50°</p>
</div>
<div id="temp6">
<p>50°to 60°</p>
</div>
<div id="temp7">
<p>60°to 70°</p>
</div>
<div id="temp8">
<p>70°to 80°</p>
</div>
<div id="temp9">
<p>Above 80°</p>
</div>
</div>
</div>
<script src="https://d3js.org/d3.v3.min.js"></script>
<script>
var width = 550,
height = 100,
cellSize = 9.5; // cell size
var day = d3.time.format("%w"),
week = d3.time.format("%U"),
format = d3.time.format("%Y%m%d");
var color = d3.scale.quantize()
.domain([-10, 90])
.range(d3.range(10).map(function(d) { return "q" + d + "-10"; }));
var svg = d3.select("body").selectAll("svg")
.data(d3.range(1984, 2015))
.enter().append("svg")
.attr("width", width)
.attr("height", height)
.attr("class", "RdYlGn")
.append("g")
.attr("transform", "translate(" + ((width - cellSize * 53) / 2) + "," + (height - cellSize * 7 - 1) + ")");
svg.append("text")
.attr("transform", "translate(-6," + cellSize * 3.5 + ")rotate(-90)")
.style("text-anchor", "middle")
.text(function(d) { return d; });
var rect = svg.selectAll(".day")
.data(function(d) { return d3.time.days(new Date(d, 0, 1), new Date(d + 1, 0, 1)); })
.enter().append("rect")
.attr("class", "day")
.attr("width", cellSize)
.attr("height", cellSize)
.attr("x", function(d) { return week(d) * cellSize; })
.attr("y", function(d) { return day(d) * cellSize; })
.datum(format);
rect.append("title")
.text(function(d) { return d; });
svg.selectAll(".month")
.data(function(d) { return d3.time.months(new Date(d, 0, 1), new Date(d + 1, 0, 1)); })
.enter().append("path")
.attr("class", "month")
.attr("d", monthPath);
d3.csv("data/1983_2013weatherdatadaily.csv", function(error, csv) {
var data = d3.nest()
.key(function(d) { return d.DATE; })
.rollup(function(d) { return d3.round(d[0].TMIN * .18 + 32,0); })
.map(csv);
rect.filter(function(d) { return d in data; })
.attr("class", function(d) { return "day " + color(data[d]); })
.select("title")
.text(function(d) { return d.substring(0,4) + "-" + d.substring(4,6) + "-" + d.substring(6,8) + ": " + data[d] + "\260 F"; });
});
function monthPath(t0) {
var t1 = new Date(t0.getFullYear(), t0.getMonth() + 1, 0),
d0 = +day(t0), w0 = +week(t0),
d1 = +day(t1), w1 = +week(t1);
return "M" + (w0 + 1) * cellSize + "," + d0 * cellSize
+ "H" + w0 * cellSize + "V" + 7 * cellSize
+ "H" + w1 * cellSize + "V" + (d1 + 1) * cellSize
+ "H" + (w1 + 1) * cellSize + "V" + 0
+ "H" + (w0 + 1) * cellSize + "Z";
}
</script>