Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions draftlogs/6285_add.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
- Add `editSelection` option to config [[#6285](https://github.com/plotly/plotly.js/pull/6285)]
12 changes: 11 additions & 1 deletion src/components/selections/draw.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -82,7 +86,7 @@ function drawOne(gd, index) {
lineDash = 'solid';
}

var isActiveSelection =
var isActiveSelection = couldHaveActiveSelection(gd) &&
gd._fullLayout._activeSelectionIndex === index;

if(isActiveSelection) {
Expand Down Expand Up @@ -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) {
Expand All @@ -165,13 +171,17 @@ 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;
draw(gd);
}

function deactivateSelection(gd) {
if(!couldHaveActiveSelection(gd)) return;

var id = gd._fullLayout._activeSelectionIndex;
if(id >= 0) {
clearOutlineControllers(gd);
Expand Down
6 changes: 6 additions & 0 deletions src/plot_api/plot_config.js
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,12 @@ var configAttributes = {
}
},

editSelection: {
valType: 'boolean',
dflt: true,
description: 'Disables moving selections.'
},

autosizable: {
valType: 'boolean',
dflt: false,
Expand Down
5 changes: 5 additions & 0 deletions test/plot-schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down