Skip to content

Commit

Permalink
Merge pull request #6094 from plotly/fix6089-group-height-in-row
Browse files Browse the repository at this point in the history
Fix vertical spacing of legend items in horizontal mode
  • Loading branch information
archmoj committed Feb 1, 2022
2 parents 26b1436 + 9bc66b9 commit 6b2c637
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 1 deletion.
1 change: 1 addition & 0 deletions draftlogs/6094_fix.md
@@ -0,0 +1 @@
- Fix vertical spacing of legend items in horizontal mode [[#6094](https://github.com/plotly/plotly.js/pull/6094)]
3 changes: 2 additions & 1 deletion src/components/legend/draw.js
Expand Up @@ -714,7 +714,6 @@ function computeLegendDimensions(gd, groups, traces, legendObj) {
offsetY += h;
maxWidthInGroup = Math.max(maxWidthInGroup, textGap + w);
});
maxGroupHeightInRow = Math.max(maxGroupHeightInRow, offsetY);

var next = maxWidthInGroup + itemGap;

Expand All @@ -730,6 +729,8 @@ function computeLegendDimensions(gd, groups, traces, legendObj) {
groupOffsetX = 0;
groupOffsetY += maxGroupHeightInRow + traceGroupGap;
maxGroupHeightInRow = offsetY;
} else {
maxGroupHeightInRow = Math.max(maxGroupHeightInRow, offsetY);
}

Drawing.setTranslate(this, groupOffsetX, groupOffsetY);
Expand Down
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
32 changes: 32 additions & 0 deletions test/image/mocks/z-legend-row-group-height.json
@@ -0,0 +1,32 @@
{
"data": [
{
"legendgroup": "A",
"name": "Long label in group A",
"y": [1, 2, 3, 4]
},
{
"legendgroup": "B",
"name": "b1",
"y": [2, 3, 4, 1]
},
{
"legendgroup": "B",
"name": "Very long label in another group",
"y": [3, 4, 1, 2]
},
{
"legendgroup": "B",
"name": "b3",
"y": [4, 1, 2, 3]
}
],
"layout": {
"paper_bgcolor": "lightblue",
"height": 350,
"width": 350,
"legend": {
"orientation": "h"
}
}
}

0 comments on commit 6b2c637

Please sign in to comment.