Browse Source

Precipitation chart

master
Nathan Bergey 6 years ago
parent
commit
a7c77ba5de
  1. 23
      src/data.js
  2. 13
      src/render.js
  3. 5
      src/style.sass

23
src/data.js

@ -35,15 +35,27 @@ export function readxml(xmldoc) {
cloudCover.push(parseFloat(cloud.textContent)) cloudCover.push(parseFloat(cloud.textContent))
} }
// Precipitation
let precip = []
const probabilityOfPrecipitation = data.getElementsByTagName('probability-of-precipitation')[0]
for (let prop of probabilityOfPrecipitation.getElementsByTagName('value')) {
precip.push(parseFloat(prop.textContent))
}
// Map // Map
const nElements = startTimes.length const nElements = startTimes.length
let forcastData = [] let forcastData = []
let cloudData = [] let cloudData = []
let precipData = []
cloudData.push({ cloudData.push({
date: startTimes[0], date: startTimes[0],
coverage: 0 coverage: 0
}) })
precipData.push({
date: startTimes[0],
probability: 0
})
for (var i = 0; i < nElements; i++) { for (var i = 0; i < nElements; i++) {
const midtimeScale = d3.scaleTime() const midtimeScale = d3.scaleTime()
.domain([0, 1]) .domain([0, 1])
@ -57,16 +69,25 @@ export function readxml(xmldoc) {
date: midpointTime, date: midpointTime,
coverage: cloudCover[i] coverage: cloudCover[i]
}) })
precipData.push({
date: midpointTime,
probability: precip[i]
})
} }
cloudData.push({ cloudData.push({
date: endTimes[endTimes.length - 1], date: endTimes[endTimes.length - 1],
coverage: 0 coverage: 0
}) })
precipData.push({
date: endTimes[endTimes.length - 1],
probability: 0
})
return { return {
startTimes: startTimes, startTimes: startTimes,
endTimes: endTimes, endTimes: endTimes,
temperature: forcastData, temperature: forcastData,
clouds: cloudData
clouds: cloudData,
precip: precipData
} }
} }

13
src/render.js

@ -330,11 +330,15 @@ export function render_clouds(canvas, width, height, offset, data) {
const yrange = [0, 100] const yrange = [0, 100]
const chart = new Chart(canvas, width, height, offset, margin, data, yrange) const chart = new Chart(canvas, width, height, offset, margin, data, yrange)
const line = d3.line()
const cloudLine = d3.line()
.x(function(d) { return chart.xRange(d.date) }) .x(function(d) { return chart.xRange(d.date) })
.y(function(d) { return chart.yRange(d.coverage) }) .y(function(d) { return chart.yRange(d.coverage) })
.curve(d3.curveBasis) .curve(d3.curveBasis)
const precipLine = d3.line()
.x(function(d) { return chart.xRange(d.date) })
.y(function(d) { return chart.yRange(d.probability) })
chart.set_yAxisTic( 0, '0%') chart.set_yAxisTic( 0, '0%')
chart.set_yAxisTic( 50, '50%') chart.set_yAxisTic( 50, '50%')
chart.draw_xGrid( 50, 'guide') chart.draw_xGrid( 50, 'guide')
@ -344,6 +348,11 @@ export function render_clouds(canvas, width, height, offset, data) {
canvas.append('path') canvas.append('path')
.data([data.clouds]) .data([data.clouds])
.attr('class', 'clouds') .attr('class', 'clouds')
.attr('d', line)
.attr('d', cloudLine)
canvas.append('path')
.data([data.precip])
.attr('class', 'precip')
.attr('d', precipLine)
chart.draw_xAxisLineBottom() chart.draw_xAxisLineBottom()
} }

5
src/style.sass

@ -76,6 +76,11 @@ path.clouds
stroke: #bbb stroke: #bbb
fill: #ddd fill: #ddd
path.precip
opacity: 0.7
stroke: #99c
fill: #aae
line.now line.now
stroke: #f5f stroke: #f5f
stroke-width: 1px stroke-width: 1px

Loading…
Cancel
Save