Skip to content

Commit 9998e35

Browse files
committed
Fix: #124. Ghosting when the gap is caused by other strings (e.g unknown)
Fix ghosting created by "unknown" values Remove converting unavailable to null, as plotly still interprets the axis as numerical
1 parent 44a7839 commit 9998e35

File tree

1 file changed

+5
-6
lines changed

1 file changed

+5
-6
lines changed

src/plotly-graph-card.ts

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -29,14 +29,15 @@ import { parseTimeDuration } from "./duration/duration";
2929

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

32-
const isDefined = (y: any) => y !== null && y !== undefined;
32+
const isNumber = (y: any) => !Number.isNaN(parseFloat(y));
3333

3434
function patchLonelyDatapoints(xs: Datum[], ys: Datum[]) {
35-
/* Ghost traces when data has single non-unavailable states sandwiched between unavailable ones
35+
/* Ghost traces when data has single numeric value sandwiched between unavailable, unknown, etc ones
3636
see: https://github.com/dbuezas/lovelace-plotly-graph-card/issues/103
37+
and: https://github.com/dbuezas/lovelace-plotly-graph-card/issues/124
3738
*/
3839
for (let i = 0; i < xs.length; i++) {
39-
if (!isDefined(ys[i - 1]) && isDefined(ys[i]) && !isDefined(ys[i + 1])) {
40+
if (!isNumber(ys[i - 1]) && isNumber(ys[i]) && !isNumber(ys[i + 1])) {
4041
ys.splice(i, 0, ys[i]);
4142
xs.splice(i, 0, xs[i]);
4243
}
@@ -567,9 +568,7 @@ export class PlotlyGraph extends HTMLElement {
567568
if (isEntityIdAttrConfig(trace)) name += ` (${trace.attribute}) `;
568569
if (isEntityIdStatisticsConfig(trace)) name += ` (${trace.statistic}) `;
569570
const xsIn = history.map(({ timestamp }) => new Date(timestamp));
570-
const ysIn: Datum[] = history.map(({ value }) =>
571-
value === "unavailable" ? null : value
572-
);
571+
const ysIn: Datum[] = history.map(({ value }) => value);
573572

574573
let xs: Datum[] = xsIn;
575574
let ys = ysIn;

0 commit comments

Comments
 (0)