Weather dashboard https://natronics.org/weather/
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

45 lines
1.6 KiB

5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
  1. var d3 = require('d3')
  2. import {readxml} from './data.js'
  3. import {render_calendar, render_nights, render_astronomy, render_temperature, render_clouds, render_rain} from './render.js'
  4. import './style.sass'
  5. const canvas = d3.select('svg')
  6. const url = 'https://forecast.weather.gov/MapClick.php?lat=39.9243509&lon=-75.1696126&FcstType=digitalDWML'
  7. //const url = '/forcast.xml'
  8. const render = function (data) {
  9. data.beginTime = new Date(
  10. data.startTimes[0].getFullYear(),
  11. data.startTimes[0].getMonth(),
  12. data.startTimes[0].getDate(),
  13. 0,0,0
  14. )
  15. data.endTime = new Date(
  16. data.endTimes[data.endTimes.length - 1].getFullYear(),
  17. data.endTimes[data.endTimes.length - 1].getMonth(),
  18. data.endTimes[data.endTimes.length - 1].getDate(),
  19. 23,59,59
  20. )
  21. const width = canvas.node().getBoundingClientRect().width
  22. const height = canvas.node().getBoundingClientRect().height
  23. const calHeight = 20
  24. const astroHeight = 45
  25. const tempHeight = 200
  26. const cloudHeight = 300
  27. const rainHeight = height - (calHeight + astroHeight + tempHeight + cloudHeight)
  28. render_calendar(canvas, width, calHeight, 0, data)
  29. render_nights(canvas, width, height - calHeight, calHeight, data)
  30. render_astronomy(canvas, width, astroHeight, calHeight, data)
  31. render_temperature(canvas, width, tempHeight, calHeight + astroHeight, data)
  32. render_clouds(canvas, width, cloudHeight, calHeight + astroHeight + tempHeight, data)
  33. render_rain(canvas, width, rainHeight, calHeight + astroHeight + tempHeight + cloudHeight, data)
  34. }
  35. d3.xml(url).then(function(xmldoc) {
  36. let data = readxml(xmldoc)
  37. render(data)
  38. })