Mercurial > personal > weather-server
comparison weather_server/static/graph.js @ 47:d200755e0930 v0.1.5
go back to fahrenheit
| author | Paul Fisher <paul@pfish.zone> |
|---|---|
| date | Sat, 03 May 2025 20:12:28 -0400 |
| parents | 4af79d69b12e |
| children |
comparison
equal
deleted
inserted
replaced
| 46:74b57044b2bd | 47:d200755e0930 |
|---|---|
| 50 const readings = data.readings; | 50 const readings = data.readings; |
| 51 if (readings.length === 0) | 51 if (readings.length === 0) |
| 52 return; | 52 return; |
| 53 root.classList.remove('plain'); | 53 root.classList.remove('plain'); |
| 54 root.classList.add('fancy'); | 54 root.classList.add('fancy'); |
| 55 const tempsF = readings.map(s => [s.sample_time, (0, math_1.cToK)(s.temp_c)]); | 55 const tempsK = readings.map(s => [s.sample_time, (0, math_1.cToK)(s.temp_c)]); |
| 56 const dewPointsF = readings.map(s => [s.sample_time, (0, math_1.cToK)((0, math_1.dewPointC)(s.temp_c, s.rh_pct))]); | 56 const dewPointsK = readings.map(s => [s.sample_time, (0, math_1.cToK)((0, math_1.dewPointC)(s.temp_c, s.rh_pct))]); |
| 57 setUpElement(tempElement, [startTS, nowTS], tempsF); | 57 setUpElement(tempElement, [startTS, nowTS], tempsK); |
| 58 setUpElement(dewPointElement, [startTS, nowTS], dewPointsF); | 58 setUpElement(dewPointElement, [startTS, nowTS], dewPointsK); |
| 59 }); | 59 }); |
| 60 } | 60 } |
| 61 exports.setUp = setUp; | 61 exports.setUp = setUp; |
| 62 function setUpElement(element, timeRange, data) { | 62 function setUpElement(element, timeRange, data) { |
| 63 if (data.length === 0) | 63 if (data.length === 0) |
| 72 const FONT_SIZE = '40px'; | 72 const FONT_SIZE = '40px'; |
| 73 class Chart { | 73 class Chart { |
| 74 constructor(element, timeRange, data, timezone) { | 74 constructor(element, timeRange, data, timezone) { |
| 75 this.element = element; | 75 this.element = element; |
| 76 this.timeRange = timeRange; | 76 this.timeRange = timeRange; |
| 77 this.data = data; | |
| 78 this.timezone = timezone; | 77 this.timezone = timezone; |
| 79 this.canvas = document.createElement('canvas'); | 78 this.canvas = document.createElement('canvas'); |
| 80 this.element.insertBefore(this.canvas, element.firstChild); | 79 this.element.insertBefore(this.canvas, element.firstChild); |
| 81 const unit = element.getElementsByClassName('unit')[0]; | 80 const unit = element.getElementsByClassName('unit')[0]; |
| 82 this.unit = unit && unit.textContent || ''; | 81 this.unit = unit && unit.textContent || ''; |
| 82 const conversionText = unit.dataset.fromK || 'k'; | |
| 83 this.conversion = eval(`k => ${conversionText}`); | |
| 84 this.data = data.map(([ts, k]) => [ts, this.conversion(k)]); | |
| 83 } | 85 } |
| 84 resize() { | 86 resize() { |
| 85 const dpr = self.devicePixelRatio || 1; | 87 const dpr = self.devicePixelRatio || 1; |
| 86 const [w, h] = this.size(); | 88 const [w, h] = this.size(); |
| 87 const pxSize = [w * dpr, h * dpr]; | 89 const pxSize = [w * dpr, h * dpr]; |
