Skip to content

Commit 9070705

Browse files
authored
Merge pull request #2983 from plotly/2971-legend_large_margin
fix legend when figures has large margins
2 parents cfc720b + dbea03d commit 9070705

File tree

3 files changed

+42
-2
lines changed

3 files changed

+42
-2
lines changed

src/components/legend/draw.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -639,12 +639,12 @@ function computeLegendDimensions(gd, groups, traces) {
639639
});
640640

641641
// check if legend fits in one row
642-
oneRowLegend = (fullLayout.width - (fullLayout.margin.r + fullLayout.margin.l)) > borderwidth + fullTracesWidth - traceGap;
642+
oneRowLegend = fullLayout._size.w > borderwidth + fullTracesWidth - traceGap;
643643
traces.each(function(d) {
644644
var legendItem = d[0],
645645
traceWidth = oneRowLegend ? 40 + d[0].width : maxTraceWidth;
646646

647-
if((borderwidth + offsetX + traceGap + traceWidth) > (fullLayout.width - (fullLayout.margin.r + fullLayout.margin.l))) {
647+
if((borderwidth + offsetX + traceGap + traceWidth) > fullLayout._size.w) {
648648
offsetX = 0;
649649
rowHeight = rowHeight + maxTraceHeight;
650650
opts._height = opts._height + maxTraceHeight;
37 KB
Loading
+40
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
{
2+
"data": [{
3+
"x": [1, 2, 3, 4],
4+
"y": ["long y label long y label long y label", "a", "b", "c"],
5+
"name": "trace 1"
6+
},
7+
{
8+
"x": [1.1, 2.1, 3.1, 4.1],
9+
"y": ["long y label long y label long y label", "a", "b", "c"],
10+
"name": "trace 1"
11+
},
12+
{
13+
"x": [1.2, 2.2, 3.2, 4.2],
14+
"y": ["long y label long y label long y label", "a", "b", "c"],
15+
"name": "trace 1"
16+
},
17+
{
18+
"x": [1.3, 2.3, 3.3, 4.3],
19+
"y": ["long y label long y label long y label", "a", "b", "c"],
20+
"name": "trace 1"
21+
},
22+
{
23+
"x": [1.4, 2.4, 3.4, 4.4],
24+
"y": ["long y label long y label long y label", "a", "b", "c"],
25+
"name": "trace 1"
26+
}
27+
],
28+
"layout": {
29+
"width": 500,
30+
"height": 500,
31+
"legend": {
32+
"orientation": "h",
33+
"bgcolor": "#ffffff00"
34+
},
35+
"yaxis": {
36+
"automargin": true
37+
}
38+
39+
}
40+
}

0 commit comments

Comments
 (0)