Skip to content

Commit

Permalink
- fixed request bug
Browse files Browse the repository at this point in the history
- fixed triangle bug
  • Loading branch information
mentalilll committed Apr 1, 2024
1 parent a801f5b commit a026856
Show file tree
Hide file tree
Showing 2 changed files with 52 additions and 40 deletions.
88 changes: 48 additions & 40 deletions dist/bar.js
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ export const bar = {
this.content.appendChild(card);
});
}

this.updateBars();

},
Expand All @@ -98,47 +99,55 @@ export const bar = {
bar.querySelector('.vpd-value').innerText = `${vpd} kPa`;
bar.querySelector('.vpd-rh').innerText = `${this.rh_text}: ${humidity}%`;
bar.querySelector('.vpd-temp').innerText = `${this.air_text}: ${temperature}°C`;

if (this.enable_ghostmap) {
this.renderMiniHistory(sensor).then((data) => {
const canvas = bar.querySelector('canvas');
const ctx = canvas.getContext('2d');
ctx.reset();
canvas.width = 80;
canvas.height = 20;

const padding = 0;
const pointRadius = 1;
const width = canvas.width - 2 * padding;
const height = canvas.height - 2 * padding;
const sensorData = data['sensor-' + index];
const maxY = Math.max(...sensorData.map(data => parseFloat(data.vpd)));
const minY = Math.min(...sensorData.map(data => parseFloat(data.vpd)));
const scaleX = width / (sensorData.length - 1);
const scaleY = height / (maxY - minY);

var previousX;
var previousY;

sensorData.forEach((data, index) => {
const x = index * scaleX + padding;
const y = padding + height - (parseFloat(data.vpd) - minY) * scaleY;
var color = this.getColorForVpd(parseFloat(data.vpd));

ctx.beginPath();
ctx.moveTo(x, y);
ctx.lineTo(previousX, previousY);
ctx.strokeStyle = color;
ctx.stroke();

ctx.beginPath();
ctx.arc(x, y, pointRadius, 0, Math.PI * 2);
ctx.fillStyle = color;
ctx.fill();

previousX = x;
previousY = y;
if(!this.updateRunning) {

this.renderMiniHistory(sensor).then((data) => {
this.updateRunning = true;
const canvas = bar.querySelector('canvas');
const ctx = canvas.getContext('2d');
ctx.reset();
canvas.width = 80;
canvas.height = 20;

const padding = 0;
const pointRadius = 1;
const width = canvas.width - 2 * padding;
const height = canvas.height - 2 * padding;
const sensorData = data['sensor-' + index];
const maxY = Math.max(...sensorData.map(data => parseFloat(data.vpd)));
const minY = Math.min(...sensorData.map(data => parseFloat(data.vpd)));
const scaleX = width / (sensorData.length - 1);
const scaleY = height / (maxY - minY);

var previousX;
var previousY;

sensorData.forEach((data, index) => {
const x = index * scaleX + padding;
const y = padding + height - (parseFloat(data.vpd) - minY) * scaleY;
var color = this.getColorForVpd(parseFloat(data.vpd));

ctx.beginPath();
ctx.moveTo(x, y);
ctx.lineTo(previousX, previousY);
ctx.strokeStyle = color;
ctx.stroke();

ctx.beginPath();
ctx.arc(x, y, pointRadius, 0, Math.PI * 2);
ctx.fillStyle = color;
ctx.fill();

previousX = x;
previousY = y;
});
setTimeout(() => {
this.updateRunning = false;
}, 15000);
});
});
}
}
let vpdState = bar.querySelector('.vpd-state');
vpdState.className = `vpd-state ${this.getPhaseClass(vpd)} tooltip`;
Expand All @@ -160,7 +169,6 @@ export const bar = {
async renderMiniHistory(sensor) {

const data = [];

for (const [index, sensor] of this.config.sensors.entries()) {
data['sensor-'+index] = [];
const temperaturesPromise = this.getEntityHistory(sensor.temperature);
Expand Down
4 changes: 4 additions & 0 deletions dist/ha-vpd-chart.js
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ class HaVpdChart extends HTMLElement {
this.enable_axes = true;
this.enable_ghostmap = true;
this.enable_triangle = false;
this.updateRunning = false;
}

set hass(hass) {
Expand Down Expand Up @@ -101,6 +102,9 @@ class HaVpdChart extends HTMLElement {
if('enable_ghostmap' in config) {
this.enable_ghostmap = config.enable_ghostmap;
}
if('enable_triangle' in config) {
this.enable_triangle = config.enable_triangle;
}
if('enable_tooltip' in config) {
this.enable_tooltip = config.enable_tooltip;
}
Expand Down

0 comments on commit a026856

Please sign in to comment.