Skip to content

Commit 5420911

Browse files
committed
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
1 parent 711b563 commit 5420911

File tree

1 file changed

+6
-1
lines changed

1 file changed

+6
-1
lines changed

src/plotly-graph-card.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,12 @@ function patchLonelyDatapoints(xs: Datum[], ys: Datum[]) {
3636
see: https://github.com/dbuezas/lovelace-plotly-graph-card/issues/103
3737
and: https://github.com/dbuezas/lovelace-plotly-graph-card/issues/124
3838
*/
39-
for (let i = 0; i < xs.length; i++) {
39+
if (ys.length === 1) {
40+
// A single lonely point won't create ghosts, and this fix breaks bar charts with a single bar
41+
// see: https://github.com/dbuezas/lovelace-plotly-graph-card/issues/129#issuecomment-1312730979
42+
return;
43+
}
44+
for (let i = 0; i < ys.length; i++) {
4045
if (!isNumber(ys[i - 1]) && isNumber(ys[i]) && !isNumber(ys[i + 1])) {
4146
ys.splice(i, 0, ys[i]);
4247
xs.splice(i, 0, xs[i]);

0 commit comments

Comments
 (0)