Skip to content

Commit c3577f1

Browse files
committed
Add execute flag to components #1695
1 parent fab0ba4 commit c3577f1

File tree

8 files changed

+40
-6
lines changed

8 files changed

+40
-6
lines changed

src/components/sliders/attributes.js

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,17 @@ var stepsAttrs = {
5353
'Sets the value of the slider step, used to refer to the step programatically.',
5454
'Defaults to the slider label if not provided.'
5555
].join(' ')
56+
},
57+
execute: {
58+
valType: 'boolean',
59+
dflt: true,
60+
description: [
61+
'When true, the API method is executed. When false, all other behaviors are the same',
62+
'and command execution is skipped. This may be useful when hooking into, for example,',
63+
'the `plotly_sliderchange` method and executing the API command manually without losing',
64+
'the benefit of the slider automatically binding to the state of the plot through the',
65+
'specification of `method` and `args`.'
66+
].join(' ')
5667
}
5768
};
5869

src/components/sliders/defaults.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,7 @@ function stepsDefaults(sliderIn, sliderOut) {
103103
coerce('args');
104104
coerce('label', 'step-' + i);
105105
coerce('value', valueOut.label);
106+
coerce('execute');
106107

107108
valuesOut.push(valueOut);
108109
}

src/components/sliders/draw.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -409,7 +409,9 @@ function setActive(gd, sliderGroup, sliderOpts, index, doCallback, doTransition)
409409
var _step = sliderGroup._nextMethod.step;
410410
if(!_step.method) return;
411411

412-
Plots.executeAPICommand(gd, _step.method, _step.args);
412+
if(_step.execute) {
413+
Plots.executeAPICommand(gd, _step.method, _step.args);
414+
}
413415

414416
sliderGroup._nextMethod = null;
415417
sliderGroup._nextMethodRaf = null;

src/components/updatemenus/attributes.js

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,17 @@ var buttonsAttrs = {
4444
role: 'info',
4545
dflt: '',
4646
description: 'Sets the text label to appear on the button.'
47+
},
48+
execute: {
49+
valType: 'boolean',
50+
dflt: true,
51+
description: [
52+
'When true, the API method is executed. When false, all other behaviors are the same',
53+
'and command execution is skipped. This may be useful when hooking into, for example,',
54+
'the `plotly_buttonclicked` method and executing the API command manually without losing',
55+
'the benefit of the updatemenu automatically binding to the state of the plot through the',
56+
'specification of `method` and `args`.'
57+
].join(' ')
4758
}
4859
};
4960

src/components/updatemenus/defaults.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,7 @@ function buttonsDefaults(menuIn, menuOut) {
8383
coerce('method');
8484
coerce('args');
8585
coerce('label');
86+
coerce('execute');
8687

8788
buttonOut._index = i;
8889
buttonsOut.push(buttonOut);

src/components/updatemenus/draw.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -331,7 +331,9 @@ function drawButtons(gd, gHeader, gButton, scrollBox, menuOpts) {
331331

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

334-
Plots.executeAPICommand(gd, buttonOpts.method, buttonOpts.args);
334+
if(buttonOpts.execute) {
335+
Plots.executeAPICommand(gd, buttonOpts.method, buttonOpts.args);
336+
}
335337

336338
gd.emit('plotly_buttonclicked', {menu: menuOpts, button: buttonOpts, active: menuOpts.active});
337339
});

test/image/mocks/sliders.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,8 @@
115115
}, {
116116
"label": "purple",
117117
"method": "restyle",
118-
"args": [{"marker.color": "purple"}]
118+
"args": [{"marker.color": "purple"}],
119+
"execute": false
119120
}],
120121
"visible": true,
121122
"x": 0.5,

test/jasmine/tests/sliders_test.js

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -99,15 +99,18 @@ describe('sliders defaults', function() {
9999
expect(layoutOut.sliders[0].steps).toEqual([{
100100
method: 'relayout',
101101
label: 'Label #1',
102-
value: 'label-1'
102+
value: 'label-1',
103+
execute: true
103104
}, {
104105
method: 'update',
105106
label: 'Label #2',
106-
value: 'Label #2'
107+
value: 'Label #2',
108+
execute: true
107109
}, {
108110
method: 'animate',
109111
label: 'step-2',
110-
value: 'lacks-label'
112+
value: 'lacks-label',
113+
execute: true
111114
}]);
112115
});
113116

@@ -131,6 +134,7 @@ describe('sliders defaults', function() {
131134
args: ['title', 'Hello World'],
132135
label: 'step-1',
133136
value: 'step-1',
137+
execute: true
134138
});
135139
});
136140

@@ -155,6 +159,7 @@ describe('sliders defaults', function() {
155159
args: ['title', 'Hello World'],
156160
label: 'step-1',
157161
value: 'step-1',
162+
execute: true
158163
});
159164
});
160165

0 commit comments

Comments
 (0)