Skip to content

Commit a154ab9

Browse files
authored
Merge pull request #6285 from plotly/config-editSelection-option
Add `editSelection` option to config
2 parents 08f621b + a8c7fa8 commit a154ab9

File tree

4 files changed

+23
-1
lines changed

4 files changed

+23
-1
lines changed

draftlogs/6285_add.md

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
- Add `editSelection` option to config [[#6285](https://github.com/plotly/plotly.js/pull/6285)]

src/components/selections/draw.js

+11-1
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,10 @@ function draw(gd) {
4646
}
4747
}
4848

49+
function couldHaveActiveSelection(gd) {
50+
return gd._context.editSelection;
51+
}
52+
4953
function drawOne(gd, index) {
5054
// remove the existing selection if there is one.
5155
// because indices can change, we need to look in all selection layers
@@ -82,7 +86,7 @@ function drawOne(gd, index) {
8286
lineDash = 'solid';
8387
}
8488

85-
var isActiveSelection =
89+
var isActiveSelection = couldHaveActiveSelection(gd) &&
8690
gd._fullLayout._activeSelectionIndex === index;
8791

8892
if(isActiveSelection) {
@@ -149,6 +153,8 @@ function setClipPath(selectionPath, gd, selectionOptions) {
149153

150154

151155
function activateSelection(gd, path) {
156+
if(!couldHaveActiveSelection(gd)) return;
157+
152158
var element = path.node();
153159
var id = +element.getAttribute('data-index');
154160
if(id >= 0) {
@@ -165,13 +171,17 @@ function activateSelection(gd, path) {
165171
}
166172

167173
function activateLastSelection(gd) {
174+
if(!couldHaveActiveSelection(gd)) return;
175+
168176
var id = gd._fullLayout.selections.length - 1;
169177
gd._fullLayout._activeSelectionIndex = id;
170178
gd._fullLayout._deactivateSelection = deactivateSelection;
171179
draw(gd);
172180
}
173181

174182
function deactivateSelection(gd) {
183+
if(!couldHaveActiveSelection(gd)) return;
184+
175185
var id = gd._fullLayout._activeSelectionIndex;
176186
if(id >= 0) {
177187
clearOutlineControllers(gd);

src/plot_api/plot_config.js

+6
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,12 @@ var configAttributes = {
114114
}
115115
},
116116

117+
editSelection: {
118+
valType: 'boolean',
119+
dflt: true,
120+
description: 'Enables moving selections.'
121+
},
122+
117123
autosizable: {
118124
valType: 'boolean',
119125
dflt: false,

test/plot-schema.json

+5
Original file line numberDiff line numberDiff line change
@@ -199,6 +199,11 @@
199199
"valType": "boolean"
200200
}
201201
},
202+
"editSelection": {
203+
"description": "Enables moving selections.",
204+
"dflt": true,
205+
"valType": "boolean"
206+
},
202207
"fillFrame": {
203208
"description": "When `layout.autosize` is turned on, determines whether the graph fills the container (the default) or the screen (if set to *true*).",
204209
"dflt": false,

0 commit comments

Comments
 (0)