diff --git a/draftlogs/6285_add.md b/draftlogs/6285_add.md new file mode 100644 index 00000000000..8f23b61862d --- /dev/null +++ b/draftlogs/6285_add.md @@ -0,0 +1 @@ + - Add `editSelection` option to config [[#6285](https://github.com/plotly/plotly.js/pull/6285)] diff --git a/src/components/selections/draw.js b/src/components/selections/draw.js index 9e3aea7a665..a58370985a2 100644 --- a/src/components/selections/draw.js +++ b/src/components/selections/draw.js @@ -46,6 +46,10 @@ function draw(gd) { } } +function couldHaveActiveSelection(gd) { + return gd._context.editSelection; +} + function drawOne(gd, index) { // remove the existing selection if there is one. // because indices can change, we need to look in all selection layers @@ -82,7 +86,7 @@ function drawOne(gd, index) { lineDash = 'solid'; } - var isActiveSelection = + var isActiveSelection = couldHaveActiveSelection(gd) && gd._fullLayout._activeSelectionIndex === index; if(isActiveSelection) { @@ -149,6 +153,8 @@ function setClipPath(selectionPath, gd, selectionOptions) { function activateSelection(gd, path) { + if(!couldHaveActiveSelection(gd)) return; + var element = path.node(); var id = +element.getAttribute('data-index'); if(id >= 0) { @@ -165,6 +171,8 @@ function activateSelection(gd, path) { } function activateLastSelection(gd) { + if(!couldHaveActiveSelection(gd)) return; + var id = gd._fullLayout.selections.length - 1; gd._fullLayout._activeSelectionIndex = id; gd._fullLayout._deactivateSelection = deactivateSelection; @@ -172,6 +180,8 @@ function activateLastSelection(gd) { } function deactivateSelection(gd) { + if(!couldHaveActiveSelection(gd)) return; + var id = gd._fullLayout._activeSelectionIndex; if(id >= 0) { clearOutlineControllers(gd); diff --git a/src/plot_api/plot_config.js b/src/plot_api/plot_config.js index cf843260731..577710ac3ac 100644 --- a/src/plot_api/plot_config.js +++ b/src/plot_api/plot_config.js @@ -114,6 +114,12 @@ var configAttributes = { } }, + editSelection: { + valType: 'boolean', + dflt: true, + description: 'Enables moving selections.' + }, + autosizable: { valType: 'boolean', dflt: false, diff --git a/test/plot-schema.json b/test/plot-schema.json index 8aed6ab4651..6528c0b899d 100644 --- a/test/plot-schema.json +++ b/test/plot-schema.json @@ -199,6 +199,11 @@ "valType": "boolean" } }, + "editSelection": { + "description": "Enables moving selections.", + "dflt": true, + "valType": "boolean" + }, "fillFrame": { "description": "When `layout.autosize` is turned on, determines whether the graph fills the container (the default) or the screen (if set to *true*).", "dflt": false,