From 501dd6c05d7977a6282f08d8e9223799b317e16f Mon Sep 17 00:00:00 2001 From: David Buezas Date: Sun, 13 Nov 2022 14:36:36 +0100 Subject: [PATCH] Fix #129 for the case of a single bar being plotted If there is only 1 point to be plotted, patchLonelyDatapoints will duplicate it unnecessarily --- src/plotly-graph-card.ts | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/src/plotly-graph-card.ts b/src/plotly-graph-card.ts index e6eaaa4..24a0a6a 100644 --- a/src/plotly-graph-card.ts +++ b/src/plotly-graph-card.ts @@ -36,7 +36,12 @@ function patchLonelyDatapoints(xs: Datum[], ys: Datum[]) { see: https://github.com/dbuezas/lovelace-plotly-graph-card/issues/103 and: https://github.com/dbuezas/lovelace-plotly-graph-card/issues/124 */ - for (let i = 0; i < xs.length; i++) { + if (ys.length === 1) { + // A single lonely point won't create ghosts, and this fix breaks bar charts with a single bar + // see: https://github.com/dbuezas/lovelace-plotly-graph-card/issues/129#issuecomment-1312730979 + return; + } + for (let i = 0; i < ys.length; i++) { if (!isNumber(ys[i - 1]) && isNumber(ys[i]) && !isNumber(ys[i + 1])) { ys.splice(i, 0, ys[i]); xs.splice(i, 0, xs[i]);