Skip to content

ensure newRng stays in bounds #4448

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

Merged
merged 3 commits into from
Mar 14, 2023
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
9 changes: 9 additions & 0 deletions src/components/rangeslider/draw.js
Original file line number Diff line number Diff line change
Expand Up @@ -205,18 +205,27 @@ function setupDragElement(rangeSlider, gd, axisOpts, opts) {
switch(target) {
case slideBox:
cursor = 'ew-resize';
if(minVal + delta > axisOpts._length || maxVal + delta < 0) {
return;
}
pixelMin = minVal + delta;
pixelMax = maxVal + delta;
break;

case grabAreaMin:
cursor = 'col-resize';
if(minVal + delta > axisOpts._length) {
return;
}
pixelMin = minVal + delta;
pixelMax = maxVal;
break;

case grabAreaMax:
cursor = 'col-resize';
if(maxVal + delta < 0) {
return;
}
pixelMin = minVal;
pixelMax = maxVal + delta;
break;
Expand Down
44 changes: 40 additions & 4 deletions test/jasmine/tests/range_slider_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -190,12 +190,48 @@ describe('Visible rangesliders', function() {
return slide(start, sliderY, end, sliderY);
})
.then(function() {
var maskMax = getRangeSliderChild(3);
var handleMax = getRangeSliderChild(6);
var maskMin = getRangeSliderChild(3);
var handleMin = getRangeSliderChild(6);

expect(gd.layout.xaxis.range).toBeCloseToArray([0, 45.04], -0.5);
expect(+maskMax.getAttribute('width')).toBeCloseTo(-diff);
testTranslate1D(handleMax, dataMaxStart + diff);
expect(+maskMin.getAttribute('width')).toBeCloseTo(-diff);
testTranslate1D(handleMin, dataMaxStart + diff);
})
.catch(failTest)
.then(done);
});

it('should not exceed slider bounds left to right', function(done) {
var start = 940;
var end = 990;

plotMock().then(function() {
gd._fullLayout.xaxis.d2p(49);

expect(gd.layout.xaxis.range).toBeCloseToArray([0, 49]);

return slide(start, sliderY, end, sliderY);
})
.then(function() {
expect(gd.layout.xaxis.range).toBeCloseToArray([0, 49], -0.5);
})
.catch(failTest)
.then(done);
});

it('should not exceed slider bounds right to left', function(done) {
var start = 0;
var end = -50;

plotMock().then(function() {
gd._fullLayout.xaxis.d2p(-49);

expect(gd.layout.xaxis.range).toBeCloseToArray([0, 49]);

return slide(start, sliderY, end, sliderY);
})
.then(function() {
expect(gd.layout.xaxis.range).toBeCloseToArray([0, 49], -0.5);
})
.catch(failTest)
.then(done);
Expand Down