Skip to content
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

Allow the skip api method for sliders and udpatemenus #1699

Merged
merged 2 commits into from
May 18, 2017
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
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'],
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A little note on 'skip' in the description would've been nice. We can get to that later though.

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