Skip to content

Commit 7bef64e

Browse files
authored
Merge pull request #3329 from plotly/rangeslider-top-axis
Fix rangeslider + automargin on side:'top' axes
2 parents 713c6fe + 1a9949d commit 7bef64e

File tree

7 files changed

+99
-3
lines changed

7 files changed

+99
-3
lines changed

src/components/rangeslider/draw.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@ module.exports = function(gd) {
100100
var margin = fullLayout.margin;
101101
var graphSize = fullLayout._size;
102102
var domain = axisOpts.domain;
103-
var tickHeight = (axisOpts._boundingBox || {}).height || 0;
103+
var tickHeight = opts._tickHeight;
104104

105105
var oppBottom = opts._oppBottom;
106106

src/components/rangeslider/helpers.js

+1
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@ exports.autoMarginOpts = function(gd, ax) {
5454
opts._oppBottom = oppBottom;
5555

5656
var tickHeight = (ax.side === 'bottom' && ax._boundingBox.height) || 0;
57+
opts._tickHeight = tickHeight;
5758

5859
return {
5960
x: 0,

src/plot_api/plot_api.js

+13-2
Original file line numberDiff line numberDiff line change
@@ -1937,8 +1937,19 @@ function addAxRangeSequence(seq, rangesAltered) {
19371937
// subroutine of its own so that finalDraw always gets
19381938
// executed after drawData
19391939
var drawAxes = rangesAltered ?
1940-
function(gd) { return Axes.draw(gd, Object.keys(rangesAltered), {skipTitle: true}); } :
1941-
function(gd) { return Axes.draw(gd, 'redraw'); };
1940+
function(gd) {
1941+
var opts = {skipTitle: true};
1942+
for(var id in rangesAltered) {
1943+
if(Axes.getFromId(gd, id).automargin) {
1944+
opts = {};
1945+
break;
1946+
}
1947+
}
1948+
return Axes.draw(gd, Object.keys(rangesAltered), opts);
1949+
} :
1950+
function(gd) {
1951+
return Axes.draw(gd, 'redraw');
1952+
};
19421953

19431954
seq.push(
19441955
subroutines.doAutoRangeAndConstraints,
-260 Bytes
Loading
21.3 KB
Loading
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
{
2+
"data": [
3+
{
4+
"x": [
5+
"a",
6+
"b",
7+
"c",
8+
"d",
9+
"long category",
10+
"another even longer",
11+
"the longest one yet!!!!!!"
12+
],
13+
"y": [
14+
0,
15+
10,
16+
20,
17+
30,
18+
40,
19+
50,
20+
60
21+
]
22+
}
23+
],
24+
"layout": {
25+
"xaxis": {
26+
"title": {
27+
"text": "Top X Axis",
28+
"font": {"size": 24}
29+
},
30+
"rangeslider": {
31+
"visible": true
32+
},
33+
"side": "top",
34+
"automargin": true
35+
},
36+
"width": 400,
37+
"height": 400
38+
}
39+
}

test/jasmine/tests/range_slider_test.js

+45
Original file line numberDiff line numberDiff line change
@@ -352,6 +352,51 @@ describe('Visible rangesliders', function() {
352352
.catch(failTest)
353353
.then(done);
354354
});
355+
356+
it('should automargin correctly with a top or bottom x axis', function(done) {
357+
var topMock = require('@mocks/range_slider_top_axis');
358+
359+
function assertTop(hasExtra) {
360+
var op = hasExtra ? 'toBeGreaterThan' : 'toBeLessThan';
361+
expect(gd._fullLayout._size.t)[op](102);
362+
expect(gd._fullLayout._size.b).toBeWithin(128, 5);
363+
}
364+
365+
function assertBottom(val) {
366+
expect(gd._fullLayout._size.t).toBe(100);
367+
expect(gd._fullLayout._size.b).toBeWithin(val, 10);
368+
}
369+
370+
Plotly.plot(gd, topMock)
371+
.then(function() {
372+
assertTop(true);
373+
return Plotly.relayout(gd, 'xaxis.range', [-0.5, 1.5]);
374+
})
375+
.then(function() {
376+
assertTop(false);
377+
return Plotly.relayout(gd, 'xaxis.range', [-0.5, 6.5]);
378+
})
379+
.then(function() {
380+
assertTop(true);
381+
// rangeslider automargins even without automargin turned on
382+
// axis.automargin only affects automargin directly from labels,
383+
// not when the rangeslider is pushed down by labels.
384+
return Plotly.relayout(gd, {'xaxis.side': 'bottom', 'xaxis.automargin': false});
385+
})
386+
.then(function() {
387+
assertBottom(210);
388+
return Plotly.relayout(gd, 'xaxis.range', [-0.5, 1.5]);
389+
})
390+
.then(function() {
391+
assertBottom(145);
392+
return Plotly.relayout(gd, 'xaxis.range', [-0.5, 6.5]);
393+
})
394+
.then(function() {
395+
assertBottom(210);
396+
})
397+
.catch(failTest)
398+
.then(done);
399+
});
355400
});
356401

357402
describe('Rangeslider visibility property', function() {

0 commit comments

Comments
 (0)