From 049dc9a3abe990fbea2dfc55a975b3d347640212 Mon Sep 17 00:00:00 2001 From: Mojtaba Samimi Date: Tue, 2 Aug 2022 12:28:21 -0400 Subject: [PATCH 1/3] add config.editSelection option --- src/components/selections/draw.js | 12 +++++++++++- src/plot_api/plot_config.js | 6 ++++++ test/plot-schema.json | 5 +++++ 3 files changed, 22 insertions(+), 1 deletion(-) 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..5147bdd5f8e 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: 'Disables moving selections.' + }, + autosizable: { valType: 'boolean', dflt: false, diff --git a/test/plot-schema.json b/test/plot-schema.json index 8aed6ab4651..732ee85acab 100644 --- a/test/plot-schema.json +++ b/test/plot-schema.json @@ -199,6 +199,11 @@ "valType": "boolean" } }, + "editSelection": { + "description": "Disables 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, From 64237371659cc09d81916326ad8e49712655f56f Mon Sep 17 00:00:00 2001 From: Mojtaba Samimi Date: Tue, 2 Aug 2022 13:10:40 -0400 Subject: [PATCH 2/3] draft log for PR 6285 --- draftlogs/6285_add.md | 1 + 1 file changed, 1 insertion(+) create mode 100644 draftlogs/6285_add.md 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)] From a8c7fa86dcff7c597260216fc306b99134a6ef4f Mon Sep 17 00:00:00 2001 From: Mojtaba Samimi Date: Tue, 2 Aug 2022 14:22:25 -0400 Subject: [PATCH 3/3] revise description --- src/plot_api/plot_config.js | 2 +- test/plot-schema.json | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/plot_api/plot_config.js b/src/plot_api/plot_config.js index 5147bdd5f8e..577710ac3ac 100644 --- a/src/plot_api/plot_config.js +++ b/src/plot_api/plot_config.js @@ -117,7 +117,7 @@ var configAttributes = { editSelection: { valType: 'boolean', dflt: true, - description: 'Disables moving selections.' + description: 'Enables moving selections.' }, autosizable: { diff --git a/test/plot-schema.json b/test/plot-schema.json index 732ee85acab..6528c0b899d 100644 --- a/test/plot-schema.json +++ b/test/plot-schema.json @@ -200,7 +200,7 @@ } }, "editSelection": { - "description": "Disables moving selections.", + "description": "Enables moving selections.", "dflt": true, "valType": "boolean" },