Skip to content

Commit

Permalink
Add execute flag to components #1695
Browse files Browse the repository at this point in the history
  • Loading branch information
rreusser committed May 18, 2017
1 parent fab0ba4 commit c3577f1
Show file tree
Hide file tree
Showing 8 changed files with 40 additions and 6 deletions.
11 changes: 11 additions & 0 deletions src/components/sliders/attributes.js
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,17 @@ 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',
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 @@ -103,6 +103,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
11 changes: 11 additions & 0 deletions src/components/updatemenus/attributes.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,17 @@ var buttonsAttrs = {
role: 'info',
dflt: '',
description: 'Sets the text label to appear on the button.'
},
execute: {
valType: 'boolean',
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 @@ -83,6 +83,7 @@ function buttonsDefaults(menuIn, menuOut) {
coerce('method');
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
11 changes: 8 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 Down

0 comments on commit c3577f1

Please sign in to comment.