Skip to content

Commit c33c92f

Browse files
committed
do not constrain legend (x,y) when margin.autoexpand:false
- when one sets autoexpand to false, fullLayout.margin are honoured no matter how big the legend gets. In this case, (I'd argue) the legend should NOT move from its provided (or default) (x,y) position to make it fit on the graph. - if some users want the legend to auto-expand the margin while keeping the provided/default (x,y), we could eventually add a `legend.fitinside` boolean attribute
1 parent 488cca1 commit c33c92f

File tree

3 files changed

+23
-2
lines changed

3 files changed

+23
-2
lines changed

src/components/legend/draw.js

+4-2
Original file line numberDiff line numberDiff line change
@@ -101,8 +101,10 @@ module.exports = function draw(gd) {
101101
var lx = gs.l + gs.w * opts.x - FROM_TL[getXanchor(opts)] * opts._width;
102102
var ly = gs.t + gs.h * (1 - opts.y) - FROM_TL[getYanchor(opts)] * opts._effHeight;
103103

104-
lx = Lib.constrain(lx, 0, fullLayout.width - opts._width);
105-
ly = Lib.constrain(ly, 0, fullLayout.height - opts._effHeight);
104+
if(fullLayout.margin.autoexpand) {
105+
lx = Lib.constrain(lx, 0, fullLayout.width - opts._width);
106+
ly = Lib.constrain(ly, 0, fullLayout.height - opts._effHeight);
107+
}
106108

107109
// Set size and position of all the elements that make up a legend:
108110
// legend, background and border, scroll box and scroll bar
Loading
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
{
2+
"data": [
3+
{
4+
"labels": [
5+
"hello",
6+
"this is a very long string and bad things are likely to happen",
7+
"short string",
8+
"moderately long string"
9+
],
10+
"values": [4, 4, 4, 4],
11+
"type": "pie"
12+
}
13+
],
14+
"layout": {
15+
"width": 400,
16+
"height": 400,
17+
"margin": {"autoexpand": false}
18+
}
19+
}

0 commit comments

Comments
 (0)