Skip to content

Commit 8c6d47a

Browse files
committed
Legend: set default position of horizontal legends
* Position horizontal legends on the bottom left, unless a range slider is present. * If a range slider is present, position the horizontal legend on the top left.
1 parent 65aa6c0 commit 8c6d47a

File tree

3 files changed

+26
-10
lines changed

3 files changed

+26
-10
lines changed

src/components/legend/defaults.js

Lines changed: 25 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,11 @@ module.exports = function legendDefaults(layoutIn, layoutOut, fullData) {
2121
containerOut = layoutOut.legend = {};
2222

2323
var visibleTraces = 0,
24-
defaultOrder = 'normal';
24+
defaultOrder = 'normal',
25+
defaultX,
26+
defaultY,
27+
defaultXAnchor,
28+
defaultYAnchor;
2529

2630
for(var i = 0; i < fullData.length; i++) {
2731
var trace = fullData[i];
@@ -57,14 +61,30 @@ module.exports = function legendDefaults(layoutIn, layoutOut, fullData) {
5761
coerce('bordercolor');
5862
coerce('borderwidth');
5963
Lib.coerceFont(coerce, 'font', layoutOut.font);
64+
6065
coerce('orientation');
66+
if(containerOut.orientation === 'h') {
67+
var xaxis = layoutIn.xaxis;
68+
if(xaxis && xaxis.rangeslider && xaxis.rangeslider.visible) {
69+
defaultX = 0;
70+
defaultXAnchor = 'left';
71+
defaultY = 1.1;
72+
defaultYAnchor = 'bottom';
73+
}
74+
else {
75+
defaultX = 0;
76+
defaultXAnchor = 'left';
77+
defaultY = -0.1;
78+
defaultYAnchor = 'top';
79+
}
80+
}
6181

6282
coerce('traceorder', defaultOrder);
6383
if(helpers.isGrouped(layoutOut.legend)) coerce('tracegroupgap');
6484

65-
coerce('x');
66-
coerce('xanchor');
67-
coerce('y');
68-
coerce('yanchor');
85+
coerce('x', defaultX);
86+
coerce('xanchor', defaultXAnchor);
87+
coerce('y', defaultY);
88+
coerce('yanchor', defaultYAnchor);
6989
Lib.noneOrAll(containerIn, containerOut, ['x', 'y']);
7090
};
312 Bytes
Loading

test/image/mocks/legend_horizontal.json

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -175,10 +175,6 @@
175175
},
176176
"legend": {
177177
"orientation": "h",
178-
"x": 0,
179-
"xanchor": "left",
180-
"y": -0.1,
181-
"yanchor": "top",
182178
"traceorder": "normal",
183179
"font": {
184180
"family": "",
@@ -187,7 +183,7 @@
187183
},
188184
"bgcolor": "#fff",
189185
"bordercolor": "#444",
190-
"borderwidth": 0
186+
"borderwidth": 1
191187
},
192188
"margin": {
193189
"l": 80,

0 commit comments

Comments
 (0)