@@ -19,6 +19,7 @@ var shapeHelpers = require('../shapes/helpers');
1919var shapeConstants = require ( '../shapes/constants' ) ;
2020
2121var displayOutlines = require ( '../shapes/display_outlines' ) ;
22+ var clearOutline = require ( '../shapes/handle_outline' ) . clearOutline ;
2223
2324var newShapeHelpers = require ( '../shapes/draw_newshape/helpers' ) ;
2425var handleEllipse = newShapeHelpers . handleEllipse ;
@@ -44,8 +45,6 @@ var MINSELECT = constants.MINSELECT;
4445var filteredPolygon = polygon . filter ;
4546var polygonTester = polygon . tester ;
4647
47- var clearOutline = require ( '../shapes/handle_outline' ) . clearOutline ;
48-
4948var helpers = require ( './helpers' ) ;
5049var p2r = helpers . p2r ;
5150var axValue = helpers . axValue ;
@@ -144,9 +143,43 @@ function prepSelect(evt, startX, startY, dragOptions, mode) {
144143 var searchTraces = determineSearchTraces ( gd , dragOptions . xaxes ,
145144 dragOptions . yaxes , dragOptions . subplot ) ;
146145
146+ if ( immediateSelect && ! evt . shiftKey ) {
147+ dragOptions . _clearSubplotSelections = function ( ) {
148+ var xRef = xAxis . _id ;
149+ var yRef = yAxis . _id ;
150+ deselectSubplot ( gd , xRef , yRef , searchTraces ) ;
151+
152+ var selections = ( gd . layout || { } ) . selections || [ ] ;
153+ var list = [ ] ;
154+ var selectionErased = false ;
155+ for ( var q = 0 ; q < selections . length ; q ++ ) {
156+ var s = fullLayout . selections [ q ] ;
157+ if (
158+ s . xref !== xRef ||
159+ s . yref !== yRef
160+ ) {
161+ list . push ( selections [ q ] ) ;
162+ } else {
163+ selectionErased = true ;
164+ }
165+ }
166+
167+ if ( selectionErased ) {
168+ Registry . call ( '_guiRelayout' , gd , {
169+ selections : list
170+ } ) ;
171+ }
172+ } ;
173+ }
174+
147175 var fillRangeItems = getFillRangeItems ( dragOptions ) ;
148176
149177 dragOptions . moveFn = function ( dx0 , dy0 ) {
178+ if ( dragOptions . _clearSubplotSelections ) {
179+ dragOptions . _clearSubplotSelections ( ) ;
180+ dragOptions . _clearSubplotSelections = undefined ;
181+ }
182+
150183 x1 = Math . max ( 0 , Math . min ( pw , scaleX * dx0 + x0 ) ) ;
151184 y1 = Math . max ( 0 , Math . min ( ph , scaleY * dy0 + y0 ) ) ;
152185
@@ -1176,34 +1209,8 @@ function reselect(gd, selectionTesters, searchTraces, dragOptions) {
11761209 xRef = deselect . xref ;
11771210 yRef = deselect . yref ;
11781211
1179- var foundSubplot = false ;
1180- for ( var q = 0 ; q < allSearchTraces . length ; q ++ ) {
1181- var a = allSearchTraces [ q ] ;
1182- if (
1183- ( a . xaxis && a . xaxis . _id === xRef ) &&
1184- ( a . yaxis && a . yaxis . _id === yRef )
1185- ) {
1186- foundSubplot = true ;
1187- break ;
1188- }
1189- }
1190-
1191- if ( ! foundSubplot ) {
1192- // deselect traces in this subplot
1193-
1194- searchTraces = determineSearchTraces (
1195- gd ,
1196- [ getFromId ( gd , xRef , 'x' ) ] ,
1197- [ getFromId ( gd , yRef , 'y' ) ] ,
1198- xRef + yRef
1199- ) ;
1200-
1201- for ( var k = 0 ; k < searchTraces . length ; k ++ ) {
1202- var searchInfo = searchTraces [ k ] ;
1203- searchInfo . _module . selectPoints ( searchInfo , false ) ;
1204- }
1205-
1206- updateSelectedState ( gd , searchTraces ) ;
1212+ if ( ! subplotSelected ( xRef , yRef , allSearchTraces ) ) {
1213+ deselectSubplot ( gd , xRef , yRef , searchTraces ) ;
12071214 }
12081215
12091216 if ( sendEvents ) {
@@ -1240,6 +1247,35 @@ function epmtySplomSelectionBatch(gd) {
12401247 }
12411248}
12421249
1250+ function subplotSelected ( xRef , yRef , searchTraces ) {
1251+ for ( var i = 0 ; i < searchTraces . length ; i ++ ) {
1252+ var s = searchTraces [ i ] ;
1253+ if (
1254+ ( s . xaxis && s . xaxis . _id === xRef ) &&
1255+ ( s . yaxis && s . yaxis . _id === yRef )
1256+ ) {
1257+ return true ;
1258+ }
1259+ }
1260+ return false ;
1261+ }
1262+
1263+ function deselectSubplot ( gd , xRef , yRef , searchTraces ) {
1264+ searchTraces = determineSearchTraces (
1265+ gd ,
1266+ [ getFromId ( gd , xRef , 'x' ) ] ,
1267+ [ getFromId ( gd , yRef , 'y' ) ] ,
1268+ xRef + yRef
1269+ ) ;
1270+
1271+ for ( var k = 0 ; k < searchTraces . length ; k ++ ) {
1272+ var searchInfo = searchTraces [ k ] ;
1273+ searchInfo . _module . selectPoints ( searchInfo , false ) ;
1274+ }
1275+
1276+ updateSelectedState ( gd , searchTraces ) ;
1277+ }
1278+
12431279function addTester ( layoutPolygons , xRef , yRef , selectionTesters ) {
12441280 var mergedPolygons ;
12451281
0 commit comments