Skip to content

Commit

Permalink
Cleanly handle unavailable entities
Browse files Browse the repository at this point in the history
  • Loading branch information
davet2001 committed Oct 28, 2024
1 parent 8acdc2a commit 0358c58
Showing 1 changed file with 5 additions and 4 deletions.
9 changes: 5 additions & 4 deletions src/elec-sankey.ts
Original file line number Diff line number Diff line change
Expand Up @@ -580,21 +580,22 @@ export class ElecSankey extends LitElement {
const divArray: TemplateResult[] = [];

const startTerminatorY = 0;

let phantomRate = 0;
const routes = structuredClone(this.generationInRoutes);
if (this._phantomGenerationInRoute !== undefined) {
routes.phantom = this._phantomGenerationInRoute;
phantomRate = this._phantomGenerationInRoute.rate;
}
let i = 0;
// eslint-disable-next-line guard-for-in
for (const key in routes) {
if (Object.prototype.hasOwnProperty.call(routes, key)) {
// const friendlyName = routes.text;
let width = 0;
const rate = routes[key].rate;
const rate = routes[key].rate || 0; // Handle undefined (NaN) rates.
// Most of the time, if the rate is zero, we don't want to draw it.
// Exception is if we have > phantom source.
if (rate || routes.phantom.rate > 0) {
// Exception is if we have a >0 phantom source.
if (rate || phantomRate > 0) {
width = this._rateToWidth(rate);
svgArray.push(
renderFlowByCorners(
Expand Down

0 comments on commit 0358c58

Please sign in to comment.