Skip to content

Commit 10a655d

Browse files
committed
rangeselector: skip non-object buttons items
- making relayout(gd, 'xaxis.rangeselector.buttons[i]', 'remove'); clear to existing button
1 parent 6376166 commit 10a655d

File tree

2 files changed

+38
-1
lines changed

2 files changed

+38
-1
lines changed

src/components/rangeselector/defaults.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,8 @@ function buttonsDefaults(containerIn, containerOut) {
5757
buttonIn = buttonsIn[i];
5858
buttonOut = {};
5959

60+
if(!Lib.isPlainObject(buttonIn)) continue;
61+
6062
var step = coerce('step');
6163
if(step !== 'all') {
6264
coerce('stepmode');

test/jasmine/tests/range_selector_test.js

Lines changed: 36 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,26 @@ describe('range selector defaults:', function() {
6060
}]);
6161
});
6262

63+
it('should skip over non-object buttons', function() {
64+
var containerIn = {
65+
rangeselector: {
66+
buttons: [{
67+
label: 'button 0'
68+
}, null, {
69+
label: 'button 2'
70+
}, 'remove', {
71+
label: 'button 4'
72+
}]
73+
}
74+
};
75+
var containerOut = {};
76+
77+
supply(containerIn, containerOut);
78+
79+
expect(containerIn.rangeselector.buttons.length).toEqual(5);
80+
expect(containerOut.rangeselector.buttons.length).toEqual(3);
81+
});
82+
6383
it('should coerce all buttons present', function() {
6484
var containerIn = {
6585
rangeselector: {
@@ -421,6 +441,22 @@ describe('range selector interactions:', function() {
421441

422442
});
423443

444+
it('should be able to remove button(s) on `relayout`', function(done) {
445+
var len = mockCopy.layout.xaxis.rangeselector.buttons.length;
446+
447+
assertNodeCount('.button', len);
448+
449+
Plotly.relayout(gd, 'xaxis.rangeselector.buttons[0]', null).then(function() {
450+
assertNodeCount('.button', len - 1);
451+
452+
return Plotly.relayout(gd, 'xaxis.rangeselector.buttons[1]', 'remove');
453+
}).then(function() {
454+
assertNodeCount('.button', len - 2);
455+
456+
done();
457+
});
458+
});
459+
424460
it('should update range and active button when clicked', function() {
425461
var range0 = gd.layout.xaxis.range[0];
426462
var buttons = d3.selectAll('.button').select('rect');
@@ -482,5 +518,4 @@ describe('range selector interactions:', function() {
482518
done();
483519
});
484520
});
485-
486521
});

0 commit comments

Comments
 (0)