Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix rangeslider + automargin on side:'top' axes #3329

Merged
merged 3 commits into from
Dec 12, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/components/rangeslider/draw.js
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ module.exports = function(gd) {
var margin = fullLayout.margin;
var graphSize = fullLayout._size;
var domain = axisOpts.domain;
var tickHeight = (axisOpts._boundingBox || {}).height || 0;
var tickHeight = opts._tickHeight;

var oppBottom = opts._oppBottom;

Expand Down
1 change: 1 addition & 0 deletions src/components/rangeslider/helpers.js
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ exports.autoMarginOpts = function(gd, ax) {
opts._oppBottom = oppBottom;

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

return {
x: 0,
Expand Down
15 changes: 13 additions & 2 deletions src/plot_api/plot_api.js
Original file line number Diff line number Diff line change
Expand Up @@ -1937,8 +1937,19 @@ function addAxRangeSequence(seq, rangesAltered) {
// subroutine of its own so that finalDraw always gets
// executed after drawData
var drawAxes = rangesAltered ?
function(gd) { return Axes.draw(gd, Object.keys(rangesAltered), {skipTitle: true}); } :
function(gd) { return Axes.draw(gd, 'redraw'); };
function(gd) {
var opts = {skipTitle: true};
for(var id in rangesAltered) {
if(Axes.getFromId(gd, id).automargin) {
opts = {};
break;
}
}
return Axes.draw(gd, Object.keys(rangesAltered), opts);
} :
function(gd) {
return Axes.draw(gd, 'redraw');
};

seq.push(
subroutines.doAutoRangeAndConstraints,
Expand Down
Binary file modified test/image/baselines/range_slider_multiple.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added test/image/baselines/range_slider_top_axis.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
39 changes: 39 additions & 0 deletions test/image/mocks/range_slider_top_axis.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
{
"data": [
{
"x": [
"a",
"b",
"c",
"d",
"long category",
"another even longer",
"the longest one yet!!!!!!"
],
"y": [
0,
10,
20,
30,
40,
50,
60
]
}
],
"layout": {
"xaxis": {
"title": {
"text": "Top X Axis",
"font": {"size": 24}
},
"rangeslider": {
"visible": true
},
"side": "top",
"automargin": true
},
"width": 400,
"height": 400
}
}
45 changes: 45 additions & 0 deletions test/jasmine/tests/range_slider_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -352,6 +352,51 @@ describe('Visible rangesliders', function() {
.catch(failTest)
.then(done);
});

it('should automargin correctly with a top or bottom x axis', function(done) {
var topMock = require('@mocks/range_slider_top_axis');

function assertTop(hasExtra) {
var op = hasExtra ? 'toBeGreaterThan' : 'toBeLessThan';
expect(gd._fullLayout._size.t)[op](102);
expect(gd._fullLayout._size.b).toBeWithin(128, 5);
}

function assertBottom(val) {
expect(gd._fullLayout._size.t).toBe(100);
expect(gd._fullLayout._size.b).toBeWithin(val, 10);
}

Plotly.plot(gd, topMock)
.then(function() {
assertTop(true);
return Plotly.relayout(gd, 'xaxis.range', [-0.5, 1.5]);
})
.then(function() {
assertTop(false);
return Plotly.relayout(gd, 'xaxis.range', [-0.5, 6.5]);
})
.then(function() {
assertTop(true);
// rangeslider automargins even without automargin turned on
// axis.automargin only affects automargin directly from labels,
// not when the rangeslider is pushed down by labels.
return Plotly.relayout(gd, {'xaxis.side': 'bottom', 'xaxis.automargin': false});
})
.then(function() {
assertBottom(210);
return Plotly.relayout(gd, 'xaxis.range', [-0.5, 1.5]);
})
.then(function() {
assertBottom(145);
return Plotly.relayout(gd, 'xaxis.range', [-0.5, 6.5]);
})
.then(function() {
assertBottom(210);
})
.catch(failTest)
.then(done);
});
});

describe('Rangeslider visibility property', function() {
Expand Down