Skip to content

Commit 6b2c637

Browse files
authored
Merge pull request #6094 from plotly/fix6089-group-height-in-row
Fix vertical spacing of legend items in horizontal mode
2 parents 26b1436 + 9bc66b9 commit 6b2c637

File tree

4 files changed

+35
-1
lines changed

4 files changed

+35
-1
lines changed

draftlogs/6094_fix.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
- Fix vertical spacing of legend items in horizontal mode [[#6094](https://github.com/plotly/plotly.js/pull/6094)]

src/components/legend/draw.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -714,7 +714,6 @@ function computeLegendDimensions(gd, groups, traces, legendObj) {
714714
offsetY += h;
715715
maxWidthInGroup = Math.max(maxWidthInGroup, textGap + w);
716716
});
717-
maxGroupHeightInRow = Math.max(maxGroupHeightInRow, offsetY);
718717

719718
var next = maxWidthInGroup + itemGap;
720719

@@ -730,6 +729,8 @@ function computeLegendDimensions(gd, groups, traces, legendObj) {
730729
groupOffsetX = 0;
731730
groupOffsetY += maxGroupHeightInRow + traceGroupGap;
732731
maxGroupHeightInRow = offsetY;
732+
} else {
733+
maxGroupHeightInRow = Math.max(maxGroupHeightInRow, offsetY);
733734
}
734735

735736
Drawing.setTranslate(this, groupOffsetX, groupOffsetY);
21.8 KB
Loading
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
{
2+
"data": [
3+
{
4+
"legendgroup": "A",
5+
"name": "Long label in group A",
6+
"y": [1, 2, 3, 4]
7+
},
8+
{
9+
"legendgroup": "B",
10+
"name": "b1",
11+
"y": [2, 3, 4, 1]
12+
},
13+
{
14+
"legendgroup": "B",
15+
"name": "Very long label in another group",
16+
"y": [3, 4, 1, 2]
17+
},
18+
{
19+
"legendgroup": "B",
20+
"name": "b3",
21+
"y": [4, 1, 2, 3]
22+
}
23+
],
24+
"layout": {
25+
"paper_bgcolor": "lightblue",
26+
"height": 350,
27+
"width": 350,
28+
"legend": {
29+
"orientation": "h"
30+
}
31+
}
32+
}

0 commit comments

Comments
 (0)