Skip to content

Commit

Permalink
Merge pull request #1699 from plotly/allow-skip-api-method
Browse files Browse the repository at this point in the history
Allow the skip api method for sliders and udpatemenus
  • Loading branch information
rreusser committed May 18, 2017
2 parents fab0ba4 + bdf96b8 commit f27885d
Show file tree
Hide file tree
Showing 8 changed files with 108 additions and 6 deletions.
2 changes: 1 addition & 1 deletion src/components/sliders/attributes.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ var stepsAttrs = {

method: {
valType: 'enumerated',
values: ['restyle', 'relayout', 'animate', 'update'],
values: ['restyle', 'relayout', 'animate', 'update', 'skip'],
dflt: 'restyle',
role: 'info',
description: [
Expand Down
5 changes: 3 additions & 2 deletions src/components/sliders/defaults.js
Original file line number Diff line number Diff line change
Expand Up @@ -95,11 +95,12 @@ function stepsDefaults(sliderIn, sliderOut) {
valueIn = valuesIn[i];
valueOut = {};

if(!Lib.isPlainObject(valueIn) || !Array.isArray(valueIn.args)) {
coerce('method');

if(!Lib.isPlainObject(valueIn) || (valueOut.method !== 'skip' && !Array.isArray(valueIn.args))) {
continue;
}

coerce('method');
coerce('args');
coerce('label', 'step-' + i);
coerce('value', valueOut.label);
Expand Down
2 changes: 1 addition & 1 deletion src/components/updatemenus/attributes.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ var buttonsAttrs = {

method: {
valType: 'enumerated',
values: ['restyle', 'relayout', 'animate', 'update'],
values: ['restyle', 'relayout', 'animate', 'update', 'skip'],
dflt: 'restyle',
role: 'info',
description: [
Expand Down
5 changes: 3 additions & 2 deletions src/components/updatemenus/defaults.js
Original file line number Diff line number Diff line change
Expand Up @@ -76,11 +76,12 @@ function buttonsDefaults(menuIn, menuOut) {
buttonIn = buttonsIn[i];
buttonOut = {};

if(!Lib.isPlainObject(buttonIn) || !Array.isArray(buttonIn.args)) {
coerce('method');

if(!Lib.isPlainObject(buttonIn) || (buttonOut.method !== 'skip' && !Array.isArray(buttonIn.args))) {
continue;
}

coerce('method');
coerce('args');
coerce('label');

Expand Down
2 changes: 2 additions & 0 deletions src/plots/command.js
Original file line number Diff line number Diff line change
Expand Up @@ -262,6 +262,8 @@ function bindingValueHasChanged(gd, binding, cache) {
* A list of arguments passed to the API command
*/
exports.executeAPICommand = function(gd, method, args) {
if(method === 'skip') return Promise.resolve();

var apiMethod = Plotly[method];

var allArgs = [gd];
Expand Down
20 changes: 20 additions & 0 deletions test/jasmine/tests/command_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,13 @@ describe('Plots.executeAPICommand', function() {
});

});

describe('with the skip command', function() {
it('resolves immediately', function(done) {
Plots.executeAPICommand(gd, 'skip')
.catch(fail).then(done);
});
});
});

describe('Plots.hasSimpleAPICommandBindings', function() {
Expand Down Expand Up @@ -93,6 +100,14 @@ describe('Plots.hasSimpleAPICommandBindings', function() {
});
});

it('the skip method returns false', function() {
var isSimple = Plots.hasSimpleAPICommandBindings(gd, [{
method: 'skip',
}]);

expect(isSimple).toEqual(false);
});

it('return false when properties are not the same', function() {
var isSimple = Plots.hasSimpleAPICommandBindings(gd, [{
method: 'restyle',
Expand Down Expand Up @@ -187,6 +202,11 @@ describe('Plots.computeAPICommandBindings', function() {
destroyGraphDiv(gd);
});

it('the skip method returns no bindings', function() {
var result = Plots.computeAPICommandBindings(gd, 'skip', ['marker.size', 7]);
expect(result).toEqual([]);
});

describe('restyle', function() {
describe('with invalid notation', function() {
it('with a scalar value', function() {
Expand Down
26 changes: 26 additions & 0 deletions test/jasmine/tests/sliders_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,32 @@ describe('sliders defaults', function() {
});
});

it('allow the `skip` method', function() {
layoutIn.sliders = [{
steps: [{
method: 'skip',
}, {
method: 'skip',
args: ['title', 'Hello World']
}]
}];

supply(layoutIn, layoutOut);

expect(layoutOut.sliders[0].steps.length).toEqual(2);
expect(layoutOut.sliders[0].steps[0]).toEqual({
method: 'skip',
label: 'step-0',
value: 'step-0',
}, {
method: 'skip',
args: ['title', 'Hello World'],
label: 'step-1',
value: 'step-1',
});
});


it('should keep ref to input update menu container', function() {
layoutIn.sliders = [{
steps: [{
Expand Down
52 changes: 52 additions & 0 deletions test/jasmine/tests/updatemenus_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,31 @@ describe('update menus defaults', function() {
});
});

it('allow the `skip` method', function() {
layoutIn.updatemenus = [{
buttons: [{
method: 'skip',
}, {
method: 'skip',
args: ['title', 'Hello World']
}]
}];

supply(layoutIn, layoutOut);

expect(layoutOut.updatemenus[0].buttons.length).toEqual(2);
expect(layoutOut.updatemenus[0].buttons[0]).toEqual({
method: 'skip',
label: '',
_index: 0
}, {
method: 'skip',
args: ['title', 'Hello World'],
label: '',
_index: 1
});
});

it('should keep ref to input update menu container', function() {
layoutIn.updatemenus = [{
buttons: [{
Expand Down Expand Up @@ -444,6 +469,33 @@ describe('update menus interactions', function() {
}).catch(fail).then(done);
});

it('should still emit the event if method = skip', function(done) {
var clickCnt = 0;
var data = [];
gd.on('plotly_buttonclicked', function(datum) {
data.push(datum);
clickCnt++;
});

Plotly.relayout(gd, {
'updatemenus[0].buttons[0].method': 'skip',
'updatemenus[0].buttons[1].method': 'skip',
'updatemenus[0].buttons[2].method': 'skip',
'updatemenus[1].buttons[0].method': 'skip',
'updatemenus[1].buttons[1].method': 'skip',
'updatemenus[1].buttons[2].method': 'skip',
'updatemenus[1].buttons[3].method': 'skip',
}).then(function() {
click(selectHeader(0)).then(function() {
expect(clickCnt).toEqual(0);

return click(selectButton(2));
}).then(function() {
expect(clickCnt).toEqual(1);
}).catch(fail).then(done);
});
});

it('should apply update on button click', function(done) {
var header0 = selectHeader(0),
header1 = selectHeader(1);
Expand Down

0 comments on commit f27885d

Please sign in to comment.