Skip to content

Range slider data update fix #1350

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

Closed
wants to merge 3 commits into from
Closed
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/defaults.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ module.exports = function handleDefaults(layoutIn, layoutOut, axName) {
coerce('range');

// Expand slider range to the axis range
if(containerOut.range && !axOut.autorange) {
if(containerOut.range) {
// TODO: what if the ranges are reversed?
var outRange = containerOut.range,
axRange = axOut.range;
Expand Down
2 changes: 1 addition & 1 deletion src/components/rangeslider/draw.js
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ module.exports = function(gd) {
// compute new slider range using axis autorange if necessary
// copy back range to input range slider container to skip
// this step in subsequent draw calls
if(!opts.range) {
if(axisOpts._needsExpand && axisOpts._min.length && axisOpts._max.length) {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As the computed range slider range (i.e. opts.range here) is copied to the user layer container, Axes.getAutoRange would not get called on data array updates (unless one would delete gd.layout.xaxis.rangeslider.range).

Note that xaxis._min and xaxis._max are only defined when an update call passed through the calc step as setConvert clears them here in supplyDefaults.

opts._input.range = opts.range = Axes.getAutoRange(axisOpts);
}

Expand Down
84 changes: 84 additions & 0 deletions test/jasmine/tests/range_slider_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -536,6 +536,13 @@ describe('the range slider', function() {

describe('in general', function() {

// lower toBeCloseToArray precision for FF38 on CI
var precision = 1e-2;

beforeAll(function() {
jasmine.addMatchers(customMatchers);
});

beforeEach(function() {
gd = createGraphDiv();
});
Expand All @@ -561,6 +568,83 @@ describe('the range slider', function() {
})
.then(done);
});

it('should expand its range in accordance with new data arrays', function(done) {

function assertRange(expected) {
expect(gd.layout.xaxis.range).toBeCloseToArray(expected, precision);
expect(gd.layout.xaxis.rangeslider.range).toBeCloseToArray(expected, precision);
}

Plotly.plot(gd, [{
y: [2, 1, 2]
}], {
xaxis: { rangeslider: {} }
})
.then(function() {
assertRange([-0.13, 2.13]);

return Plotly.restyle(gd, 'y', [[2, 1, 2, 1]]);
})
.then(function() {
assertRange([-0.19, 3.19]);

return Plotly.extendTraces(gd, { y: [[2, 1]] }, [0]);
})
.then(function() {
assertRange([-0.32, 5.32]);

return Plotly.addTraces(gd, { x: [0, 10], y: [2, 1] });
})
.then(function() {
assertRange([-0.68, 10.68]);

return Plotly.deleteTraces(gd, [1]);
})
.then(function() {
assertRange([-0.31, 5.31]);
})
.then(done);
});

it('should not expand its range when range slider range is set', function(done) {
var rangeSliderRange = [-1, 11];

function assertRange(expected) {
expect(gd.layout.xaxis.range).toBeCloseToArray(expected, precision);
expect(gd.layout.xaxis.rangeslider.range).toEqual(rangeSliderRange, precision);
}

Plotly.plot(gd, [{
y: [2, 1, 2]
}], {
xaxis: { rangeslider: { range: [-1, 11]} }
})
.then(function() {
assertRange([-0.13, 2.13]);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A bit confusing, as it looks like this test is identical to the previous one until you squint at the details of assertRange. Nonblocking, but I might have made it explicit by saying assertRanges([-0.13, 2.13], [-1, 11]) or something.


return Plotly.restyle(gd, 'y', [[2, 1, 2, 1]]);
})
.then(function() {
assertRange([-0.19, 3.19]);

return Plotly.extendTraces(gd, { y: [[2, 1]] }, [0]);
})
.then(function() {
assertRange([-0.32, 5.32]);

return Plotly.addTraces(gd, { x: [0, 10], y: [2, 1] });
})
.then(function() {
assertRange([-0.68, 10.68]);

return Plotly.deleteTraces(gd, [1]);
})
.then(function() {
assertRange([-0.31, 5.31]);
})
.then(done);
});
});
});

Expand Down