Skip to content

Commit f27885d

Browse files
authored
Merge pull request #1699 from plotly/allow-skip-api-method
Allow the skip api method for sliders and udpatemenus
2 parents fab0ba4 + bdf96b8 commit f27885d

File tree

8 files changed

+108
-6
lines changed

8 files changed

+108
-6
lines changed

src/components/sliders/attributes.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ var stepsAttrs = {
2020

2121
method: {
2222
valType: 'enumerated',
23-
values: ['restyle', 'relayout', 'animate', 'update'],
23+
values: ['restyle', 'relayout', 'animate', 'update', 'skip'],
2424
dflt: 'restyle',
2525
role: 'info',
2626
description: [

src/components/sliders/defaults.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -95,11 +95,12 @@ function stepsDefaults(sliderIn, sliderOut) {
9595
valueIn = valuesIn[i];
9696
valueOut = {};
9797

98-
if(!Lib.isPlainObject(valueIn) || !Array.isArray(valueIn.args)) {
98+
coerce('method');
99+
100+
if(!Lib.isPlainObject(valueIn) || (valueOut.method !== 'skip' && !Array.isArray(valueIn.args))) {
99101
continue;
100102
}
101103

102-
coerce('method');
103104
coerce('args');
104105
coerce('label', 'step-' + i);
105106
coerce('value', valueOut.label);

src/components/updatemenus/attributes.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ var buttonsAttrs = {
1818

1919
method: {
2020
valType: 'enumerated',
21-
values: ['restyle', 'relayout', 'animate', 'update'],
21+
values: ['restyle', 'relayout', 'animate', 'update', 'skip'],
2222
dflt: 'restyle',
2323
role: 'info',
2424
description: [

src/components/updatemenus/defaults.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -76,11 +76,12 @@ function buttonsDefaults(menuIn, menuOut) {
7676
buttonIn = buttonsIn[i];
7777
buttonOut = {};
7878

79-
if(!Lib.isPlainObject(buttonIn) || !Array.isArray(buttonIn.args)) {
79+
coerce('method');
80+
81+
if(!Lib.isPlainObject(buttonIn) || (buttonOut.method !== 'skip' && !Array.isArray(buttonIn.args))) {
8082
continue;
8183
}
8284

83-
coerce('method');
8485
coerce('args');
8586
coerce('label');
8687

src/plots/command.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -262,6 +262,8 @@ function bindingValueHasChanged(gd, binding, cache) {
262262
* A list of arguments passed to the API command
263263
*/
264264
exports.executeAPICommand = function(gd, method, args) {
265+
if(method === 'skip') return Promise.resolve();
266+
265267
var apiMethod = Plotly[method];
266268

267269
var allArgs = [gd];

test/jasmine/tests/command_test.js

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,13 @@ describe('Plots.executeAPICommand', function() {
5858
});
5959

6060
});
61+
62+
describe('with the skip command', function() {
63+
it('resolves immediately', function(done) {
64+
Plots.executeAPICommand(gd, 'skip')
65+
.catch(fail).then(done);
66+
});
67+
});
6168
});
6269

6370
describe('Plots.hasSimpleAPICommandBindings', function() {
@@ -93,6 +100,14 @@ describe('Plots.hasSimpleAPICommandBindings', function() {
93100
});
94101
});
95102

103+
it('the skip method returns false', function() {
104+
var isSimple = Plots.hasSimpleAPICommandBindings(gd, [{
105+
method: 'skip',
106+
}]);
107+
108+
expect(isSimple).toEqual(false);
109+
});
110+
96111
it('return false when properties are not the same', function() {
97112
var isSimple = Plots.hasSimpleAPICommandBindings(gd, [{
98113
method: 'restyle',
@@ -187,6 +202,11 @@ describe('Plots.computeAPICommandBindings', function() {
187202
destroyGraphDiv(gd);
188203
});
189204

205+
it('the skip method returns no bindings', function() {
206+
var result = Plots.computeAPICommandBindings(gd, 'skip', ['marker.size', 7]);
207+
expect(result).toEqual([]);
208+
});
209+
190210
describe('restyle', function() {
191211
describe('with invalid notation', function() {
192212
it('with a scalar value', function() {

test/jasmine/tests/sliders_test.js

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -158,6 +158,32 @@ describe('sliders defaults', function() {
158158
});
159159
});
160160

161+
it('allow the `skip` method', function() {
162+
layoutIn.sliders = [{
163+
steps: [{
164+
method: 'skip',
165+
}, {
166+
method: 'skip',
167+
args: ['title', 'Hello World']
168+
}]
169+
}];
170+
171+
supply(layoutIn, layoutOut);
172+
173+
expect(layoutOut.sliders[0].steps.length).toEqual(2);
174+
expect(layoutOut.sliders[0].steps[0]).toEqual({
175+
method: 'skip',
176+
label: 'step-0',
177+
value: 'step-0',
178+
}, {
179+
method: 'skip',
180+
args: ['title', 'Hello World'],
181+
label: 'step-1',
182+
value: 'step-1',
183+
});
184+
});
185+
186+
161187
it('should keep ref to input update menu container', function() {
162188
layoutIn.sliders = [{
163189
steps: [{

test/jasmine/tests/updatemenus_test.js

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -140,6 +140,31 @@ describe('update menus defaults', function() {
140140
});
141141
});
142142

143+
it('allow the `skip` method', function() {
144+
layoutIn.updatemenus = [{
145+
buttons: [{
146+
method: 'skip',
147+
}, {
148+
method: 'skip',
149+
args: ['title', 'Hello World']
150+
}]
151+
}];
152+
153+
supply(layoutIn, layoutOut);
154+
155+
expect(layoutOut.updatemenus[0].buttons.length).toEqual(2);
156+
expect(layoutOut.updatemenus[0].buttons[0]).toEqual({
157+
method: 'skip',
158+
label: '',
159+
_index: 0
160+
}, {
161+
method: 'skip',
162+
args: ['title', 'Hello World'],
163+
label: '',
164+
_index: 1
165+
});
166+
});
167+
143168
it('should keep ref to input update menu container', function() {
144169
layoutIn.updatemenus = [{
145170
buttons: [{
@@ -444,6 +469,33 @@ describe('update menus interactions', function() {
444469
}).catch(fail).then(done);
445470
});
446471

472+
it('should still emit the event if method = skip', function(done) {
473+
var clickCnt = 0;
474+
var data = [];
475+
gd.on('plotly_buttonclicked', function(datum) {
476+
data.push(datum);
477+
clickCnt++;
478+
});
479+
480+
Plotly.relayout(gd, {
481+
'updatemenus[0].buttons[0].method': 'skip',
482+
'updatemenus[0].buttons[1].method': 'skip',
483+
'updatemenus[0].buttons[2].method': 'skip',
484+
'updatemenus[1].buttons[0].method': 'skip',
485+
'updatemenus[1].buttons[1].method': 'skip',
486+
'updatemenus[1].buttons[2].method': 'skip',
487+
'updatemenus[1].buttons[3].method': 'skip',
488+
}).then(function() {
489+
click(selectHeader(0)).then(function() {
490+
expect(clickCnt).toEqual(0);
491+
492+
return click(selectButton(2));
493+
}).then(function() {
494+
expect(clickCnt).toEqual(1);
495+
}).catch(fail).then(done);
496+
});
497+
});
498+
447499
it('should apply update on button click', function(done) {
448500
var header0 = selectHeader(0),
449501
header1 = selectHeader(1);

0 commit comments

Comments
 (0)