Skip to content

Commit

Permalink
Added more-info link to ppfd bubble
Browse files Browse the repository at this point in the history
  • Loading branch information
maziggy committed Nov 3, 2024
1 parent 4dcd274 commit 355bf17
Showing 1 changed file with 21 additions and 9 deletions.
30 changes: 21 additions & 9 deletions dist/ppfdChart.min.js
Original file line number Diff line number Diff line change
Expand Up @@ -204,17 +204,29 @@ class PPFDCustomCard extends LitElement {
const marker = this.shadowRoot.querySelector(".marker");
const chartBar = this.shadowRoot.querySelector(".chart-bar");

const minPPFD = 100;
const maxPPFD = 1200;
const barWidth = chartBar ? chartBar.offsetWidth : 0;
if (!chartBar) return;

let position = ((currentPPFD - minPPFD) / (maxPPFD - minPPFD)) * barWidth;
position = Math.max(0, Math.min(position, barWidth));
clearTimeout(this._throttleTimeout);
this._throttleTimeout = setTimeout(() => {
const minPPFD = 100;
const maxPPFD = 1200;
const barWidth = chartBar.offsetWidth;

if (marker) {
marker.style.left = `${position}px`;
marker.innerText = `${currentPPFD}`;
}
let position = ((currentPPFD - minPPFD) / (maxPPFD - minPPFD)) * barWidth;
position = Math.max(0, Math.min(position, barWidth));

if (marker) {
marker.style.left = `${position}px`;
marker.innerText = `${currentPPFD}`;

// Add an onclick event to open the more-info dialog
marker.onclick = () => {
const event = new Event('hass-more-info', { bubbles: true, composed: true });
event.detail = { entityId: this.entity };
this.dispatchEvent(event);
};
}
}, 100);
}

updateLastUpdated(lastUpdated) {
Expand Down

0 comments on commit 355bf17

Please sign in to comment.