Nathan Bergey
6 years ago
4 changed files with 103 additions and 39 deletions
-
58src/data.js
-
16src/index.js
-
60src/render.js
-
8src/style.sass
@ -1,50 +1,72 @@ |
|||
var d3 = require('d3') |
|||
|
|||
export function readxml(xmldoc) { |
|||
let forcast = xmldoc.childNodes[0] |
|||
let data = forcast.children[1] |
|||
const forcast = xmldoc.childNodes[0] |
|||
const data = forcast.children[1] |
|||
|
|||
// Time
|
|||
let times = data.getElementsByTagName('time-layout')[0] |
|||
var startTimes = [] |
|||
const times = data.getElementsByTagName('time-layout')[0] |
|||
let startTimes = [] |
|||
for (let time of times.getElementsByTagName('start-valid-time')) { |
|||
let date = new Date(time.textContent) |
|||
const date = new Date(time.textContent) |
|||
startTimes.push(date) |
|||
} |
|||
var endTimes = [] |
|||
let endTimes = [] |
|||
for (let time of times.getElementsByTagName('end-valid-time')) { |
|||
let date = new Date(time.textContent) |
|||
const date = new Date(time.textContent) |
|||
endTimes.push(date) |
|||
} |
|||
|
|||
// Temperature
|
|||
var temperatures = [] |
|||
let temperatures = [] |
|||
for (let temp_type of data.getElementsByTagName('temperature')) { |
|||
if (temp_type.attributes.type.nodeValue === 'hourly') { |
|||
for (let temp of temp_type.getElementsByTagName('value')) { |
|||
let degC = (parseFloat(temp.textContent) - 32) * (5.0/9.0) |
|||
const degC = (parseFloat(temp.textContent) - 32) * (5.0/9.0) |
|||
temperatures.push(degC) |
|||
} |
|||
} |
|||
} |
|||
|
|||
// Cloud Cover
|
|||
let cloudCover = [] |
|||
const clouds = data.getElementsByTagName('cloud-amount')[0] |
|||
for (let cloud of clouds.getElementsByTagName('value')) { |
|||
cloudCover.push(parseFloat(cloud.textContent)) |
|||
} |
|||
|
|||
// Map
|
|||
let nElements = startTimes.length |
|||
var forcastData = [] |
|||
const nElements = startTimes.length |
|||
|
|||
let forcastData = [] |
|||
let cloudData = [] |
|||
cloudData.push({ |
|||
date: startTimes[0], |
|||
coverage: 0 |
|||
}) |
|||
for (var i = 0; i < nElements; i++) { |
|||
let midtimeScale = d3.scaleTime() |
|||
const midtimeScale = d3.scaleTime() |
|||
.domain([0, 1]) |
|||
.range([startTimes[i], endTimes[i]]) |
|||
let midpointTime = midtimeScale(0.5) |
|||
const midpointTime = midtimeScale(0.5) |
|||
forcastData.push({ |
|||
'date': midpointTime, |
|||
'temp': temperatures[i] |
|||
date: midpointTime, |
|||
temp: temperatures[i] |
|||
}) |
|||
cloudData.push({ |
|||
date: midpointTime, |
|||
coverage: cloudCover[i] |
|||
}) |
|||
} |
|||
cloudData.push({ |
|||
date: endTimes[endTimes.length - 1], |
|||
coverage: 0 |
|||
}) |
|||
|
|||
return { |
|||
'startTimes': startTimes, |
|||
'endTimes': endTimes, |
|||
'temperature': forcastData |
|||
startTimes: startTimes, |
|||
endTimes: endTimes, |
|||
temperature: forcastData, |
|||
clouds: cloudData |
|||
} |
|||
} |
Write
Preview
Loading…
Cancel
Save
Reference in new issue