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

Add execute flag to components #1700

Merged
merged 4 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
12 changes: 12 additions & 0 deletions src/components/sliders/attributes.js
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,18 @@ var stepsAttrs = {
'Sets the value of the slider step, used to refer to the step programatically.',
'Defaults to the slider label if not provided.'
].join(' ')
},
execute: {
valType: 'boolean',
role: 'info',
dflt: true,
description: [
'When true, the API method is executed. When false, all other behaviors are the same',
'and command execution is skipped. This may be useful when hooking into, for example,',
'the `plotly_sliderchange` method and executing the API command manually without losing',
'the benefit of the slider automatically binding to the state of the plot through the',
'specification of `method` and `args`.'
].join(' ')
}
};

Expand Down
1 change: 1 addition & 0 deletions src/components/sliders/defaults.js
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,7 @@ function stepsDefaults(sliderIn, sliderOut) {
coerce('args');
coerce('label', 'step-' + i);
coerce('value', valueOut.label);
coerce('execute');

valuesOut.push(valueOut);
}
Expand Down
4 changes: 3 additions & 1 deletion src/components/sliders/draw.js
Original file line number Diff line number Diff line change
Expand Up @@ -409,7 +409,9 @@ function setActive(gd, sliderGroup, sliderOpts, index, doCallback, doTransition)
var _step = sliderGroup._nextMethod.step;
if(!_step.method) return;

Plots.executeAPICommand(gd, _step.method, _step.args);
if(_step.execute) {
Plots.executeAPICommand(gd, _step.method, _step.args);
}

sliderGroup._nextMethod = null;
sliderGroup._nextMethodRaf = null;
Expand Down
12 changes: 12 additions & 0 deletions src/components/updatemenus/attributes.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,18 @@ var buttonsAttrs = {
role: 'info',
dflt: '',
description: 'Sets the text label to appear on the button.'
},
execute: {
valType: 'boolean',
role: 'info',
dflt: true,
description: [
'When true, the API method is executed. When false, all other behaviors are the same',
'and command execution is skipped. This may be useful when hooking into, for example,',
'the `plotly_buttonclicked` method and executing the API command manually without losing',
'the benefit of the updatemenu automatically binding to the state of the plot through the',
'specification of `method` and `args`.'
].join(' ')
}
};

Expand Down
1 change: 1 addition & 0 deletions src/components/updatemenus/defaults.js
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,7 @@ function buttonsDefaults(menuIn, menuOut) {

coerce('args');
coerce('label');
coerce('execute');

buttonOut._index = i;
buttonsOut.push(buttonOut);
Expand Down
4 changes: 3 additions & 1 deletion src/components/updatemenus/draw.js
Original file line number Diff line number Diff line change
Expand Up @@ -331,7 +331,9 @@ function drawButtons(gd, gHeader, gButton, scrollBox, menuOpts) {

setActive(gd, menuOpts, buttonOpts, gHeader, gButton, scrollBox, buttonIndex);

Plots.executeAPICommand(gd, buttonOpts.method, buttonOpts.args);
if(buttonOpts.execute) {
Plots.executeAPICommand(gd, buttonOpts.method, buttonOpts.args);
}

gd.emit('plotly_buttonclicked', {menu: menuOpts, button: buttonOpts, active: menuOpts.active});
});
Expand Down
3 changes: 2 additions & 1 deletion test/image/mocks/sliders.json
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,8 @@
}, {
"label": "purple",
"method": "restyle",
"args": [{"marker.color": "purple"}]
"args": [{"marker.color": "purple"}],
"execute": false
}],
"visible": true,
"x": 0.5,
Expand Down
13 changes: 10 additions & 3 deletions test/jasmine/tests/sliders_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -99,15 +99,18 @@ describe('sliders defaults', function() {
expect(layoutOut.sliders[0].steps).toEqual([{
method: 'relayout',
label: 'Label #1',
value: 'label-1'
value: 'label-1',
execute: true
}, {
method: 'update',
label: 'Label #2',
value: 'Label #2'
value: 'Label #2',
execute: true
}, {
method: 'animate',
label: 'step-2',
value: 'lacks-label'
value: 'lacks-label',
execute: true
}]);
});

Expand All @@ -131,6 +134,7 @@ describe('sliders defaults', function() {
args: ['title', 'Hello World'],
label: 'step-1',
value: 'step-1',
execute: true
});
});

Expand All @@ -155,6 +159,7 @@ describe('sliders defaults', function() {
args: ['title', 'Hello World'],
label: 'step-1',
value: 'step-1',
execute: true
});
});

Expand All @@ -175,11 +180,13 @@ describe('sliders defaults', function() {
method: 'skip',
label: 'step-0',
value: 'step-0',
execute: true,
}, {
method: 'skip',
args: ['title', 'Hello World'],
label: 'step-1',
value: 'step-1',
execute: true,
});
});

Expand Down
30 changes: 30 additions & 0 deletions test/jasmine/tests/updatemenus_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,7 @@ describe('update menus defaults', function() {
expect(layoutOut.updatemenus[0].buttons[0]).toEqual({
method: 'relayout',
args: ['title', 'Hello World'],
execute: true,
label: '',
_index: 1
});
Expand All @@ -135,6 +136,7 @@ describe('update menus defaults', function() {
expect(layoutOut.updatemenus[0].buttons[0]).toEqual({
method: 'relayout',
args: ['title', 'Hello World'],
execute: true,
label: '',
_index: 1
});
Expand All @@ -156,11 +158,13 @@ describe('update menus defaults', function() {
expect(layoutOut.updatemenus[0].buttons[0]).toEqual({
method: 'skip',
label: '',
execute: true,
_index: 0
}, {
method: 'skip',
args: ['title', 'Hello World'],
label: '',
execute: true,
_index: 1
});
});
Expand Down Expand Up @@ -444,6 +448,32 @@ describe('update menus interactions', function() {
});
});

it('should execute the API command when execute = true', function(done) {
expect(gd.data[0].line.color).toEqual('blue');

click(selectHeader(0)).then(function() {
return click(selectButton(2));
}).then(function() {
// Has been changed:
expect(gd.data[0].line.color).toEqual('green');
}).catch(fail).then(done);
});

it('should not execute the API command when execute = false', function(done) {
// This test is identical to the one above, except that it disables
// the command by setting execute = false first:
expect(gd.data[0].line.color).toEqual('blue');

Plotly.relayout(gd, 'updatemenus[0].buttons[2].execute', false).then(function() {
return click(selectHeader(0));
}).then(function() {
return click(selectButton(2));
}).then(function() {
// Is unchanged:
expect(gd.data[0].line.color).toEqual('blue');
}).catch(fail).then(done);
});

it('should emit an event on button click', function(done) {
var clickCnt = 0;
var data = [];
Expand Down