Skip to content

Commit 28fc880

Browse files
committed
add a minimum pixel for margins - add test with margins on both sides
1 parent 921e5a5 commit 28fc880

File tree

4 files changed

+64
-2
lines changed

4 files changed

+64
-2
lines changed

src/plots/plots.js

+8-2
Original file line numberDiff line numberDiff line change
@@ -1881,6 +1881,12 @@ function initMargins(fullLayout) {
18811881
*/
18821882
plots.autoMargin = function(gd, id, o) {
18831883
var fullLayout = gd._fullLayout;
1884+
var minFinalWidth = Math.max(0, fullLayout.width -
1885+
64 // TODO: could be exposed as layout.margin.minfinalwidth
1886+
);
1887+
var minFinalHeight = Math.max(0, fullLayout.height -
1888+
64 // TODO: could be exposed as layout.margin.minfinalheight
1889+
);
18841890

18851891
var pushMargin = fullLayout._pushmargin;
18861892
var pushMarginIds = fullLayout._pushmarginIds;
@@ -1900,11 +1906,11 @@ plots.autoMargin = function(gd, id, o) {
19001906

19011907
// if the item is too big, just give it enough automargin to
19021908
// make sure you can still grab it and bring it back
1903-
if(o.l + o.r > fullLayout.width) {
1909+
if(o.l + o.r > minFinalWidth) {
19041910
Lib.log('Margin push', id, 'is too big in x, dropping');
19051911
o.l = o.r = 0;
19061912
}
1907-
if(o.b + o.t > fullLayout.height) {
1913+
if(o.b + o.t > minFinalHeight) {
19081914
Lib.log('Margin push', id, 'is too big in y, dropping');
19091915
o.b = o.t = 0;
19101916
}
Loading
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
{
2+
"data": [{
3+
"name": "< D E A T H >",
4+
"marker": { "color": "red" },
5+
"y": [
6+
"Antonio Vivaldi",
7+
"Johann Sebastian Bach",
8+
"Wolfgang Amadeus Mozart",
9+
"Ludwig van Beethoven"
10+
],
11+
"x": [
12+
"1741",
13+
"1750",
14+
"1791",
15+
"1827"
16+
]
17+
},
18+
{
19+
"name": "< B I R T H >",
20+
"marker": { "color": "blue" },
21+
"y": [
22+
"Antonio Vivaldi",
23+
"Johann Sebastian Bach",
24+
"Wolfgang Amadeus Mozart",
25+
"Ludwig van Beethoven"
26+
],
27+
"x": [
28+
"1678",
29+
"1685",
30+
"1756",
31+
"1770"
32+
]
33+
}],
34+
"layout": {
35+
"title": {
36+
"text": "Longest and shortest<br>names and time periods"
37+
},
38+
"width": 200,
39+
"height": 200,
40+
"margin": {
41+
"t": 80,
42+
"b": 20,
43+
"l": 20,
44+
"r": 20
45+
},
46+
"xaxis": {
47+
"type": "date",
48+
"automargin": true
49+
},
50+
"yaxis": {
51+
"automargin": true
52+
}
53+
}
54+
}

test/jasmine/tests/mock_test.js

+2
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ var list = [
4040
'annotations-autorange',
4141
'arrow-markers',
4242
'automargin-large-margins',
43+
'automargin-large-margins-both-sides',
4344
'automargin-large-margins-horizontal',
4445
'automargin-mirror-all',
4546
'automargin-mirror-allticks',
@@ -1106,6 +1107,7 @@ figs['animation_bar'] = require('@mocks/animation_bar');
11061107
// figs['annotations-autorange'] = require('@mocks/annotations-autorange');
11071108
figs['arrow-markers'] = require('@mocks/arrow-markers');
11081109
figs['automargin-large-margins'] = require('@mocks/automargin-large-margins');
1110+
figs['automargin-large-margins-both-sides'] = require('@mocks/automargin-large-margins-both-sides');
11091111
figs['automargin-large-margins-horizontal'] = require('@mocks/automargin-large-margins-horizontal');
11101112
figs['automargin-mirror-all'] = require('@mocks/automargin-mirror-all');
11111113
figs['automargin-mirror-allticks'] = require('@mocks/automargin-mirror-allticks');

0 commit comments

Comments
 (0)