hourly graph uses image with internal canvas for drawing

This commit is contained in:
Matt Walsh 2022-12-08 09:23:26 -06:00
parent 64fb06d7b4
commit 69d14236f1
5 changed files with 52 additions and 49 deletions

View file

@ -42,18 +42,20 @@ class HourlyGraph extends WeatherDisplay {
} }
drawCanvas() { drawCanvas() {
if (!this.canvas) this.canvas = this.elem.querySelector('.chart canvas'); if (!this.image) this.image = this.elem.querySelector('.chart img');
// get available space // get available space
const boundingRect = this.canvas.getBoundingClientRect(); const availableWidth = 532;
const availableWidth = boundingRect.width; const availableHeight = 285;
const availableHeight = boundingRect.height;
this.canvas.width = availableWidth; this.image.width = availableWidth;
this.canvas.height = availableHeight; this.image.height = availableHeight;
// get context // get context
const ctx = this.canvas.getContext('2d'); const canvas = document.createElement('canvas');
canvas.width = availableWidth;
canvas.height = availableHeight;
const ctx = canvas.getContext('2d');
ctx.imageSmoothingEnabled = false; ctx.imageSmoothingEnabled = false;
// calculate time scale // calculate time scale
@ -97,6 +99,9 @@ class HourlyGraph extends WeatherDisplay {
this.elem.querySelector('.y-axis .l-2').innerHTML = midTemp; this.elem.querySelector('.y-axis .l-2').innerHTML = midTemp;
this.elem.querySelector('.y-axis .l-3').innerHTML = minTemp; this.elem.querySelector('.y-axis .l-3').innerHTML = minTemp;
// set the image source
this.image.src = canvas.toDataURL();
super.drawCanvas(); super.drawCanvas();
this.finishDraw(); this.finishDraw();
} }

View file

@ -367,8 +367,6 @@ class Radar extends WeatherDisplay {
} }
RadarContext.putImageData(RadarImageData, 0, 0); RadarContext.putImageData(RadarImageData, 0, 0);
// MapContext.drawImage(RadarContext.canvas, 0, 0);
} }
static mergeDopplerRadarImage(mapContext, radarContext) { static mergeDopplerRadarImage(mapContext, radarContext) {

View file

@ -89,7 +89,7 @@
top: 0px; top: 0px;
left: 50px; left: 50px;
canvas { img {
width: 532px; width: 532px;
height: 285px; height: 285px;
} }

View file

@ -11,7 +11,7 @@
<div class="label l-3">55</div> <div class="label l-3">55</div>
</div> </div>
<div class="chart"> <div class="chart">
<canvas id="chart-area"></canvas> <img id="chart-area"></img>
</div> </div>
<div class="x-axis"> <div class="x-axis">
<div class="label l-1">12a</div> <div class="label l-1">12a</div>