Skip to content

Commit 1f8b47c

Browse files
authored
Merge pull request #6312 from plotly/automargin-zoom
Automargin zoom
2 parents 259c942 + 448d641 commit 1f8b47c

File tree

5 files changed

+86
-2
lines changed

5 files changed

+86
-2
lines changed

draftlogs/6312_fix.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Fix bug with automargin and axis titles [[#6312](https://github.com/plotly/plotly.js/pull/6312)]

src/plot_api/plot_api.js

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1888,8 +1888,6 @@ function addAxRangeSequence(seq, rangesAltered) {
18881888
}
18891889
}
18901890
}
1891-
1892-
if(ax.automargin) skipTitle = false;
18931891
}
18941892

18951893
return Axes.draw(gd, axIds, {skipTitle: skipTitle});
26.3 KB
Loading
Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
{"data": [{
2+
"showlegend": false,
3+
"type": "scatter",
4+
"x": [
5+
"@100000001",
6+
"@100000002",
7+
"@100000003",
8+
"@100000004",
9+
"@100000005",
10+
"@100000006",
11+
"@100000007",
12+
"@100000008",
13+
"@100000009",
14+
"@100000010",
15+
"@100000011",
16+
"@100000012",
17+
"@100000013",
18+
"@100000014",
19+
"@100000015",
20+
"@100000016",
21+
"@100000017",
22+
"@100000018",
23+
"@100000019"
24+
],
25+
"xaxis": "x",
26+
"y": [
27+
100,
28+
101,
29+
99,
30+
101,
31+
98,
32+
97,
33+
101,
34+
102,
35+
109,
36+
110,
37+
110,
38+
102,
39+
93,
40+
114,
41+
115,
42+
115,
43+
171,
44+
185,
45+
190
46+
],
47+
"yaxis": "y"
48+
}],
49+
"layout": {
50+
"height": 400,
51+
"width": 700,
52+
"xaxis": {
53+
"title": {"text": "Revision"},
54+
"automargin": true
55+
},
56+
"yaxis": {
57+
"automargin": true
58+
}
59+
}
60+
}

test/jasmine/tests/axes_test.js

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4376,6 +4376,31 @@ describe('Test axes', function() {
43764376
})
43774377
.then(done, done.fail);
43784378
});
4379+
it('should respect axis title placement on relayout', function(done) {
4380+
function getPos(gd, sel) {
4381+
return d3Select(gd).select(sel).node().getBoundingClientRect();
4382+
}
4383+
4384+
// Tick position is < title position since 0 is at the top of the graph,
4385+
// rather than at the bottom. We're checking that the ticks and title don't overlap
4386+
function assertLayout() {
4387+
var titleTop = getPos(gd, '.xtitle').top;
4388+
var tickBottom = getPos(gd, '.xtick').bottom;
4389+
expect(tickBottom).toBeLessThan(titleTop + 2); // allow two pixels tolerance
4390+
}
4391+
4392+
var fig = require('@mocks/z-automargin-zoom.json');
4393+
Plotly.newPlot(gd, fig)
4394+
4395+
.then(assertLayout)
4396+
.then(function() {
4397+
return Plotly.relayout(gd, {'xaxis.range': [6, 14]});
4398+
})
4399+
.then(function() {
4400+
assertLayout();
4401+
})
4402+
.then(done, done.fail);
4403+
});
43794404
});
43804405

43814406
describe('zeroline visibility logic', function() {

0 commit comments

Comments
 (0)