-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathweather_pull.html
More file actions
353 lines (307 loc) · 9.85 KB
/
weather_pull.html
File metadata and controls
353 lines (307 loc) · 9.85 KB
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
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
<!DOCTYPE html>
<meta charset="utf-8">
<head>
<title>Melbourne Weather</title>
<script src="http://d3js.org/d3.v3.min.js" charset="utf-8"></script>
<script src="https://code.jquery.com/jquery-3.2.1.min.js"></script>
<style>
@import url(styles.css);
#chart3 {
width: 60%;
height: 60%;
position: absolute;
}
.axis path,
.axis line {
fill: none;
stroke: #555;
shape-rendering: crispEdges;
}
.axis text {
fill: #555;
}
.line {
fill: none;
stroke: #ef0d0c;
stroke-width: 1.5px;
}
.body {
font-family: "Helvetica Neue", Helvetica, sans-serif;
margin: 1em auto 4em auto;
width: 960px;
}
div.tooltip {
position: absolute;
text-align: center;
width: auto;
height: 28px;
padding: 2px;
font: 12px sans-serif;
background: lightsteelblue;
border: 0px;
border-radius: 8px;
pointer-events: none;}
.dropdown {
position: relative;
display: inline-block;
}
.dropdown-content {
display: none;
position: absolute;
background-color: #f9f9f9;
min-width: 160px;
box-shadow: 0px 8px 8px 0px rgba(0,0,0,0.2);
padding: 6px 6px;
z-index: 1;
}
.dropdown-content a {
color: black;
padding: 12px 16px;
text-decoration: none;
display: block;
}
.dropdown:hover .dropdown-content {
display: block;
}
.dropdown-content a:hover {background-color: #f1f1f1}
span {color:cadetblue;
margin-left:20px;}
circle{
stroke:#b7a1a1;
}
text {font-family: sans-serif ;}
div.tooltip {
position: absolute;
text-align: center;
width: automatic;
height: automatic;
padding: 20px;
font: 12px sans-serif;
background: lightsteelblue;
border: 0px;
border-radius: 8px;
pointer-events: none;
}
}
path {
stroke: #0FA4D6;
stroke-width: 2;
fill: none;
}
path2 {stroke:#4BDB93;
stroke-width:2;
fill: none;}
.axis path,
.axis line {
fill: none;
stroke: grey;
stroke-width: 1;
shape-rendering: crispEdges;
}
.d3thing{width:100%;height:100%;}
div.tooltip {
position: absolute;
text-align: left;
width: auto;
height:auto;
font-weight:bold;
padding: 2px 2px 2px 2px;
font: 14px sans-serif;
background: white;
border: 2px dotted black;
border-radius: 2px;
}
</style>
</head>
<div id="body">
<header>
<b><a href="./">Home</a></b><br>
Projects:
<a href="synchrotron-map.html">Synchroton Map | </a>
<a href="clustered_force_graph.html">Toy Popularity | </a>
<a href="atoms.html">A protein molecule | </a>
<a href="weather_pull.html"><b>Melbourne Weather</b> | </a>
<a href="stacked_bar.html">Stacked bar chart | </a>
<a href="responsive_bar_chart.html">Responsive bar chart </a><br>
<a href="resources.html">Data Viz Resources</a>
</header>
<body><h1>Current Weather Melbourne </h1><p>Select the weather station to view the past 72 hrs
worth of temperature recorded by the Bureau of Meteorology. Note that the BOM displays this
data as .shtml or JSON format. The code retrieves this data from the JSON page for the weather station selected - there
may be a short delay as the data is loaded.<h5></h5>
<div>
<select id="options">
<option value="95936">Melbourne (Olympic Park)</option>
<option value="94866">Melbourne Airport</option>
<option value="94854">Avalon</option>
<option value="95873">Bundoora</option>
<option value="94898">Cerberus</option>
<option value="94864">Coldstream</option>
<option value="94879">Cranbourne</option>
<option value="95866">Essendon Airport</option>
<option value="95872">Fawkner Beacon</option>
<option value="94872">Ferny Creek</option>
<option value="94871">Frankston</option>
<option value="94857">Geelong Race Course</option>
<option value="94865">Laverton</option>
<option value="94870">Moorabbin Airport</option>
<option value="94847">Point Wilson</option>
<option value="94892">Rhyll</option>
<option value="95867">Scoresby</option>
<option value="94863">Sheoaks</option>
<option value="94853">South Channel Island</option>
<option value="95864">St Kilda Harbour</option>
<option value="95874">Viewbank</option>
</select></div>
<svg id="svg" width=900 height=500 ></svg>
</body>
<script type="text/javascript">
var value=95936;
makeGraph(value);
d3.select("#options").on("change", function() {
d3.selectAll("g").remove();
d3.selectAll("text").remove();
var value=eval(d3.select(this).property('value'));
makeGraph(value);console.log(value);
})
function makeGraph(value){
var yql_url = 'https://query.yahooapis.com/v1/public/yql';
//var url = 'http://www.bom.gov.au/fwo/IDS60901/IDS60901.94672.json';
var url_front='http://www.bom.gov.au/fwo/IDV60901/IDV60901.';
//var num=94898;
// value=getObs(selection);
var url_end='.json';
var major_url=url_front.concat(value,url_end);console.log(major_url)
var times=[];var currT=[];var appT=[];var dd=[];var dd2=[];
$.ajax({
'async':true,
'url': yql_url,
'data': {
'q': 'SELECT * FROM json WHERE url="' + major_url + '"',
'format': 'json',
'jsonCompat': 'new',
},
'dataType': 'jsonp',
'success': function (response) {
dd=response.query.results.observations.data;
dd2=response.query.results.observations.header;
for(i=0;i<dd.length;i++)
{times.push(dd[i].local_date_time_full);
appT.push(dd[i].apparent_t);
currT.push(dd[i].air_temp)
;
}
create_graph(times,appT);textViz(dd2);
function textViz(dd2){
dd2.forEach(function(d){
d.name=d.name;
d.time_retrieved=d.refresh_message;})
d3.select("h5").selectAll("h5")
.data(dd2)
.enter()
.append("text")
.text(function(d){return d.name + ", data "+d.time_retrieved;});
}
}});
function create_graph(times,appT){
var data=[];
var arrData=d3.zip(times,appT);
var parseTime = d3.time.format("%Y%m%d%H%M%S").parse;
var viewTime=d3.time.format("%d/%m %H:%M");
var data = arrData.map(function(d) {
return {
date: parseTime(d[0]),
close: d[1]
};
});
console.log(data);
var max_temp=d3.max(data,function(d){return d.close;});
var min_temp=d3.min(data,function(d){return d.close;});
var tooltip = d3.select("body").append("div")
.attr("class", "tooltip")
.style("opacity", 0);
var color = d3.scale.ordinal()
.range(["#98abc5", "#8a89a6", "#7b6888", "#6b486b", "#a05d56", "#d0743c", "#ff8c00"]);
// Set the dimensions of the canvas / graph
var width=900;var height=300;
var margin = {top: 40, right: 80, bottom: 80, left: 80},
w = width - margin.left - margin.right,
h = height- margin.top - margin.bottom;
var x = d3.time.scale()
.nice(d3.time.day)
.range([0, 0.85*width])
var y = d3.scale.linear()
.range([height, 0]);
var xAxis = d3.svg.axis()
.scale(x)
.orient("bottom");
var yAxis = d3.svg.axis()
.scale(y)
.orient("left");
var line = d3.svg.line()
.x(function(d) { return x(d.date); })
.y(function(d) { return y(d.close); });
var svg = d3.select("svg")
.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 + ")");
x.domain(d3.extent(data, function(d) { return d.date; }));
y.domain([d3.min(data,function(d){return d.close-5;}),d3.max(data, function(d) { return d.close+5; })]);
svg.append("g")
.attr("class", "x axis")
.attr("transform", "translate(0," + height + ")")
.attr("font-size","11pt")
.call(xAxis);
svg.append("g")
.attr("class", "y axis")
.attr("font-size","11pt")
.call(yAxis)
.append("text")
.attr("transform", "rotate(-90)")
.attr("y", 6)
.attr("dy", ".71em")
.style("text-anchor", "end");
svg.append("path")
.datum(data)
.attr("class", "line")
.style("stroke","#f4c842")
.style("stroke-width","1.5px")
.attr("d", line)
svg.selectAll("dot")
.data(data)
.enter().append("circle")
.attr("r", 3)
.style("fill","#00b39a")
.attr("cx", function(d) { return x(d.date); })
.attr("cy", function(d) { return y(d.close); })
.on("mouseover", function(d) {
tooltip.transition()
.duration(500)
.style("opacity",1);
tooltip.transition()
.duration(100)
.style("opacity", .9);
tooltip.html('Date-time: '+viewTime(d.date)+'<br>Temp: '+d.close)
.style("left", (d3.event.pageX) + "px")
.style("top", (d3.event.pageY) + "px");
})
.on("mouseout", function(d) {
tooltip.transition()
.duration(500)
.style("opacity", 0);});
//state high and low
svg.append("text")
.attr("x", (width / 2))
.attr("y", 0 - (margin.top / 2))
.attr("font-size","12pt")
.text("High: "+max_temp);
svg.append("text")
.attr("x",(width/2))
.attr("y",0-(margin.top/2)+20)
.attr("font-size","12pt")
.text("Low: "+min_temp);
}}
</script>
</html>