Skip to content

Commit 0f27ecc

Browse files
author
David Buezas
committed
Only add legendgroup if show_value to reduce legend spacing when unused
1 parent b923624 commit 0f27ecc

File tree

1 file changed

+6
-4
lines changed

1 file changed

+6
-4
lines changed

src/plotly-graph-card.ts

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -290,10 +290,10 @@ export class PlotlyGraph extends HTMLElement {
290290
}
291291
}
292292

293-
const schemeName = this.config.color_scheme ?? "category10" 
294-
let colorScheme =
293+
const schemeName = this.config.color_scheme ?? "category10";
294+
let colorScheme =
295295
colorSchemes[schemeName] ||
296-
colorSchemes[Object.keys(colorSchemes)[schemeName]]||
296+
colorSchemes[Object.keys(colorSchemes)[schemeName]] ||
297297
colorSchemes.category10;
298298
const mergedTrace = merge(
299299
{
@@ -306,7 +306,6 @@ export class PlotlyGraph extends HTMLElement {
306306
shape: "hv",
307307
color: colorScheme[traceIdx % colorScheme.length],
308308
},
309-
legendgroup: "group" + traceIdx,
310309
x: xs,
311310
y: ys,
312311
yaxis: "y" + (yaxis_idx == 0 ? "" : yaxis_idx + 1),
@@ -316,6 +315,9 @@ export class PlotlyGraph extends HTMLElement {
316315
);
317316
const traces: Plotly.Data[] = [mergedTrace];
318317
if (mergedTrace.show_value) {
318+
merge(mergedTrace, {
319+
legendgroup: "group" + traceIdx,
320+
});
319321
traces.push({
320322
...mergedTrace,
321323
mode: "text+markers",

0 commit comments

Comments
 (0)