From c3577f15e51c37799b0b59ad121da8fcf02b6ca6 Mon Sep 17 00:00:00 2001 From: Ricky Reusser Date: Thu, 18 May 2017 07:18:02 -0400 Subject: [PATCH] Add `execute` flag to components #1695 --- src/components/sliders/attributes.js | 11 +++++++++++ src/components/sliders/defaults.js | 1 + src/components/sliders/draw.js | 4 +++- src/components/updatemenus/attributes.js | 11 +++++++++++ src/components/updatemenus/defaults.js | 1 + src/components/updatemenus/draw.js | 4 +++- test/image/mocks/sliders.json | 3 ++- test/jasmine/tests/sliders_test.js | 11 ++++++++--- 8 files changed, 40 insertions(+), 6 deletions(-) diff --git a/src/components/sliders/attributes.js b/src/components/sliders/attributes.js index 8e584a2455f..b1e2b1d1e51 100644 --- a/src/components/sliders/attributes.js +++ b/src/components/sliders/attributes.js @@ -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(' ') } }; diff --git a/src/components/sliders/defaults.js b/src/components/sliders/defaults.js index b2fed316c7b..ac79a8ad392 100644 --- a/src/components/sliders/defaults.js +++ b/src/components/sliders/defaults.js @@ -103,6 +103,7 @@ function stepsDefaults(sliderIn, sliderOut) { coerce('args'); coerce('label', 'step-' + i); coerce('value', valueOut.label); + coerce('execute'); valuesOut.push(valueOut); } diff --git a/src/components/sliders/draw.js b/src/components/sliders/draw.js index 3965237d2ce..46f317e5142 100644 --- a/src/components/sliders/draw.js +++ b/src/components/sliders/draw.js @@ -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; diff --git a/src/components/updatemenus/attributes.js b/src/components/updatemenus/attributes.js index 9dd9f9b155d..21aa1550e46 100644 --- a/src/components/updatemenus/attributes.js +++ b/src/components/updatemenus/attributes.js @@ -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(' ') } }; diff --git a/src/components/updatemenus/defaults.js b/src/components/updatemenus/defaults.js index 2d4eeae7faa..43afe3f27ba 100644 --- a/src/components/updatemenus/defaults.js +++ b/src/components/updatemenus/defaults.js @@ -83,6 +83,7 @@ function buttonsDefaults(menuIn, menuOut) { coerce('method'); coerce('args'); coerce('label'); + coerce('execute'); buttonOut._index = i; buttonsOut.push(buttonOut); diff --git a/src/components/updatemenus/draw.js b/src/components/updatemenus/draw.js index 558c4148a2d..adf32f1f486 100644 --- a/src/components/updatemenus/draw.js +++ b/src/components/updatemenus/draw.js @@ -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}); }); diff --git a/test/image/mocks/sliders.json b/test/image/mocks/sliders.json index 4fb9035f17c..c250b96208d 100644 --- a/test/image/mocks/sliders.json +++ b/test/image/mocks/sliders.json @@ -115,7 +115,8 @@ }, { "label": "purple", "method": "restyle", - "args": [{"marker.color": "purple"}] + "args": [{"marker.color": "purple"}], + "execute": false }], "visible": true, "x": 0.5, diff --git a/test/jasmine/tests/sliders_test.js b/test/jasmine/tests/sliders_test.js index 377c82d70aa..39384e8213c 100644 --- a/test/jasmine/tests/sliders_test.js +++ b/test/jasmine/tests/sliders_test.js @@ -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 }]); }); @@ -131,6 +134,7 @@ describe('sliders defaults', function() { args: ['title', 'Hello World'], label: 'step-1', value: 'step-1', + execute: true }); }); @@ -155,6 +159,7 @@ describe('sliders defaults', function() { args: ['title', 'Hello World'], label: 'step-1', value: 'step-1', + execute: true }); });