Skip to content

Commit c764ec8

Browse files
committed
Fixed trace ghosting on lonely datapoints. Fixes #103
1 parent fcc4ebb commit c764ec8

File tree

1 file changed

+13
-0
lines changed

1 file changed

+13
-0
lines changed

src/plotly-graph-card.ts

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,18 @@ import { parseTimeDuration } from "./duration/duration";
3030

3131
const componentName = isProduction ? "plotly-graph" : "plotly-graph-dev";
3232

33+
function patchLonelyDatapoints(xs: Datum[], ys: Datum[]) {
34+
/* Ghost traces when data has single non-unavailable states sandwiched between unavailable ones
35+
see: https://github.com/dbuezas/lovelace-plotly-graph-card/issues/103
36+
*/
37+
for (let i = 1; i < xs.length - 1; i++) {
38+
if (ys[i - 1] === null && ys[i] !== null && ys[i + 1] === null) {
39+
ys.splice(i, 0, ys[i]);
40+
xs.splice(i, 0, xs[i]);
41+
}
42+
}
43+
}
44+
3345
console.info(
3446
`%c ${componentName.toUpperCase()} %c ${version} ${process.env.NODE_ENV}`,
3547
"color: orange; font-weight: bold; background: black",
@@ -429,6 +441,7 @@ export class PlotlyGraph extends HTMLElement {
429441
console.error(e);
430442
}
431443
}
444+
patchLonelyDatapoints(xs, ys);
432445
const customdatum = { unit_of_measurement: unit, name, attributes };
433446
const customdata = xs.map(() => customdatum);
434447
const mergedTrace = merge(

0 commit comments

Comments
 (0)