Skip to content

Commit be4932d

Browse files
committed
fix bugs in rangeslider with explicit range and relayout
the range_slider_multiple mock showed the first bug, but I updated it so neither bound matches the default [-1, 6] second bug was that impliedEdits were missing so some range updates wouldn't work
1 parent 564dff6 commit be4932d

File tree

6 files changed

+32
-41
lines changed

6 files changed

+32
-41
lines changed

src/components/rangeslider/attributes.js

+4-2
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ module.exports = {
3838
dflt: true,
3939
role: 'style',
4040
editType: 'calc',
41+
impliedEdits: {'range[0]': undefined, 'range[1]': undefined},
4142
description: [
4243
'Determines whether or not the range slider range is',
4344
'computed in relation to the input data.',
@@ -48,10 +49,11 @@ module.exports = {
4849
valType: 'info_array',
4950
role: 'info',
5051
items: [
51-
{valType: 'any', editType: 'calc'},
52-
{valType: 'any', editType: 'calc'}
52+
{valType: 'any', editType: 'calc', impliedEdits: {'^autorange': false}},
53+
{valType: 'any', editType: 'calc', impliedEdits: {'^autorange': false}}
5354
],
5455
editType: 'calc',
56+
impliedEdits: {'autorange': false},
5557
description: [
5658
'Sets the range of the range slider.',
5759
'If not set, defaults to the full xaxis range.',

src/components/rangeslider/defaults.js

-12
Original file line numberDiff line numberDiff line change
@@ -38,18 +38,6 @@ module.exports = function handleDefaults(layoutIn, layoutOut, axName) {
3838
coerce('autorange', !axOut.isValidRange(containerIn.range));
3939
coerce('range');
4040

41-
// Expand slider range to the axis range
42-
// TODO: what if the ranges are reversed?
43-
if(containerOut.range) {
44-
var outRange = containerOut.range,
45-
axRange = axOut.range;
46-
47-
outRange[0] = axOut.l2r(Math.min(axOut.r2l(outRange[0]), axOut.r2l(axRange[0])));
48-
outRange[1] = axOut.l2r(Math.max(axOut.r2l(outRange[1]), axOut.r2l(axRange[1])));
49-
}
50-
51-
axOut.cleanRange('rangeslider.range');
52-
5341
// to map back range slider (auto) range
5442
containerOut._input = containerIn;
5543
};

src/components/rangeslider/draw.js

+15
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,21 @@ module.exports = function(gd) {
8080
opts = axisOpts[constants.name],
8181
oppAxisOpts = fullLayout[Axes.id2name(axisOpts.anchor)];
8282

83+
// update range
84+
// Expand slider range to the axis range
85+
// TODO: what if the ranges are reversed?
86+
if(opts.range) {
87+
var outRange = opts.range;
88+
var axRange = axisOpts.range;
89+
90+
outRange[0] = axisOpts.l2r(Math.min(axisOpts.r2l(outRange[0]), axisOpts.r2l(axRange[0])));
91+
outRange[1] = axisOpts.l2r(Math.max(axisOpts.r2l(outRange[1]), axisOpts.r2l(axRange[1])));
92+
opts._input.range = outRange.slice();
93+
}
94+
95+
axisOpts.cleanRange('rangeslider.range');
96+
97+
8398
// update range slider dimensions
8499

85100
var margin = fullLayout.margin,
38 Bytes
Loading

test/image/mocks/range_slider_multiple.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626
"anchor": "y2",
2727
"domain": [ 0.55, 1 ],
2828
"rangeslider": {
29-
"range": [ -1, 4 ]
29+
"range": [ -2, 4 ]
3030
}
3131
},
3232
"yaxis": {

test/jasmine/tests/range_slider_test.js

+12-26
Original file line numberDiff line numberDiff line change
@@ -445,7 +445,7 @@ describe('the range slider', function() {
445445
it('should not mutate layoutIn', function() {
446446
var layoutIn = { xaxis: { rangeslider: { visible: true }} },
447447
layoutOut = { xaxis: { rangeslider: {}} },
448-
expected = { xaxis: { rangeslider: { visible: true }} };
448+
expected = { xaxis: { rangeslider: { visible: true}} };
449449

450450
_supply(layoutIn, layoutOut, 'xaxis');
451451
expect(layoutIn).toEqual(expected);
@@ -457,7 +457,6 @@ describe('the range slider', function() {
457457
expected = {
458458
visible: true,
459459
autorange: true,
460-
range: [-1, 6],
461460
thickness: 0.15,
462461
bgcolor: '#fff',
463462
borderwidth: 0,
@@ -475,7 +474,6 @@ describe('the range slider', function() {
475474
expected = {
476475
visible: true,
477476
autorange: true,
478-
range: [-1, 6],
479477
thickness: 0.15,
480478
bgcolor: '#fff',
481479
borderwidth: 0,
@@ -507,7 +505,6 @@ describe('the range slider', function() {
507505
expected = {
508506
visible: true,
509507
autorange: true,
510-
range: [-1, 6],
511508
thickness: 0.15,
512509
bgcolor: '#fff',
513510
borderwidth: 0,
@@ -519,34 +516,12 @@ describe('the range slider', function() {
519516
expect(layoutOut.xaxis.rangeslider).toEqual(expected);
520517
});
521518

522-
it('should expand the rangeslider range to axis range', function() {
523-
var layoutIn = { xaxis: { rangeslider: { range: [5, 6] } } },
524-
layoutOut = { xaxis: { range: [1, 10], type: 'linear'} },
525-
expected = {
526-
visible: true,
527-
autorange: false,
528-
range: [1, 10],
529-
thickness: 0.15,
530-
bgcolor: '#fff',
531-
borderwidth: 0,
532-
bordercolor: '#444',
533-
_input: layoutIn.xaxis.rangeslider
534-
};
535-
536-
_supply(layoutIn, layoutOut, 'xaxis');
537-
538-
// don't compare the whole layout, because we had to run setConvert which
539-
// attaches all sorts of other stuff to xaxis
540-
expect(layoutOut.xaxis.rangeslider).toEqual(expected);
541-
});
542-
543519
it('should set autorange to true when range input is invalid', function() {
544520
var layoutIn = { xaxis: { rangeslider: { range: 'not-gonna-work'}} },
545521
layoutOut = { xaxis: {} },
546522
expected = {
547523
visible: true,
548524
autorange: true,
549-
range: [-1, 6],
550525
thickness: 0.15,
551526
bgcolor: '#fff',
552527
borderwidth: 0,
@@ -729,6 +704,17 @@ describe('the range slider', function() {
729704
.then(function() {
730705
assertRange([-0.26, 4.26], [-0.26, 4.26]);
731706

707+
// smaller than xaxis.range - won't be accepted
708+
return Plotly.relayout(gd, {'xaxis.rangeslider.range': [0, 2]});
709+
})
710+
.then(function() {
711+
assertRange([-0.26, 4.26], [-0.26, 4.26]);
712+
713+
// will be accepted (and autorange is disabled by impliedEdits)
714+
return Plotly.relayout(gd, {'xaxis.rangeslider.range': [-2, 12]});
715+
})
716+
.then(function() {
717+
assertRange([-0.26, 4.26], [-2, 12]);
732718
})
733719
.then(done);
734720
});

0 commit comments

Comments
 (0)