@@ -19,8 +19,11 @@ var shapeHelpers = require('../shapes/helpers');
19
19
var shapeConstants = require ( '../shapes/constants' ) ;
20
20
21
21
var displayOutlines = require ( '../shapes/display_outlines' ) ;
22
- var handleEllipse = require ( '../shapes/draw_newshape/helpers' ) . handleEllipse ;
23
- var readPaths = require ( '../shapes/draw_newshape/helpers' ) . readPaths ;
22
+
23
+ var newShapeHelpers = require ( '../shapes/draw_newshape/helpers' ) ;
24
+ var handleEllipse = newShapeHelpers . handleEllipse ;
25
+ var readPaths = newShapeHelpers . readPaths ;
26
+
24
27
var newShapes = require ( '../shapes/draw_newshape/newshapes' ) ;
25
28
26
29
var newSelections = require ( './draw_newselection/newselections' ) ;
@@ -281,7 +284,7 @@ function prepSelect(evt, startX, startY, dragOptions, mode) {
281
284
selection = _doSelect ( selectionTesters , searchTraces ) ;
282
285
283
286
eventData = { points : selection } ;
284
- fillRangeItems ( eventData , currentPolygon , filterPoly ) ;
287
+ fillRangeItems ( eventData , filterPoly ? filterPoly . filtered : currentPolygon ) ;
285
288
dragOptions . gd . emit ( 'plotly_selecting' , eventData ) ;
286
289
}
287
290
) ;
@@ -1110,6 +1113,28 @@ function reselect(gd, selectionTesters, searchTraces, dragOptions) {
1110
1113
var clickmode = fullLayout . clickmode ;
1111
1114
var sendEvents = clickmode . indexOf ( 'event' ) > - 1 ;
1112
1115
if ( sendEvents ) {
1116
+ var activePolygons = getLayoutPolygons ( gd , true ) ;
1117
+
1118
+ var xref = activePolygons [ 0 ] . xref ;
1119
+ var yref = activePolygons [ 0 ] . yref ;
1120
+ if ( xref && yref ) {
1121
+ var activePolygon = activePolygons [ 0 ] ;
1122
+ // handle active shape with multiple polygons
1123
+ for ( var n = 1 ; n < activePolygons . length ; n ++ ) {
1124
+ // close previous polygon
1125
+ activePolygon . push ( activePolygon [ 0 ] ) ;
1126
+ // add this polygon
1127
+ activePolygon = activePolygon . concat ( activePolygons [ n ] ) ;
1128
+ }
1129
+
1130
+ var fillRangeItems = makeFillRangeItems ( [
1131
+ getFromId ( gd , xref , 'x' ) ,
1132
+ getFromId ( gd , yref , 'y' )
1133
+ ] ) ;
1134
+
1135
+ fillRangeItems ( eventData , activePolygon ) ;
1136
+ }
1137
+
1113
1138
gd . emit ( 'plotly_selected' , eventData ) ;
1114
1139
}
1115
1140
}
@@ -1157,12 +1182,16 @@ function addTester(layoutPolygons, xRef, yRef, selectionTesters) {
1157
1182
return selectionTesters ;
1158
1183
}
1159
1184
1160
- function getLayoutPolygons ( gd ) {
1185
+ function getLayoutPolygons ( gd , onlyActiveOnes ) {
1161
1186
var allPolygons = [ ] ;
1162
- var allSelections = gd . _fullLayout . selections ;
1187
+
1188
+ var fullLayout = gd . _fullLayout ;
1189
+ var allSelections = fullLayout . selections ;
1163
1190
var len = allSelections . length ;
1164
1191
1165
1192
for ( var i = 0 ; i < len ; i ++ ) {
1193
+ if ( onlyActiveOnes && i !== fullLayout . _activeSelectionIndex ) continue ;
1194
+
1166
1195
var selection = allSelections [ i ] ;
1167
1196
if ( ! selection ) continue ;
1168
1197
@@ -1198,6 +1227,7 @@ function getLayoutPolygons(gd) {
1198
1227
polygon . yref = yref ;
1199
1228
1200
1229
polygon . subtract = false ;
1230
+ polygon . isRect = true ;
1201
1231
1202
1232
allPolygons . push ( polygon ) ;
1203
1233
} else if ( selection . type === 'path' ) {
@@ -1271,42 +1301,37 @@ function convert(ax, d) {
1271
1301
}
1272
1302
1273
1303
function makeFillRangeItems ( allAxes ) {
1274
- return function ( eventData , poly , filterPoly ) {
1275
- var range = { } ;
1276
- var ranges = { } ;
1277
-
1278
- var hasRange = false ;
1279
- var hasRanges = false ;
1304
+ return function ( eventData , poly ) {
1305
+ var range ;
1306
+ var lassoPoints ;
1280
1307
1281
1308
for ( var i = 0 ; i < allAxes . length ; i ++ ) {
1282
1309
var ax = allAxes [ i ] ;
1283
- var axLetter = ax . _id . charAt ( 0 ) ;
1310
+ var id = ax . _id ;
1311
+ var axLetter = id . charAt ( 0 ) ;
1284
1312
1313
+ if ( ! range ) range = { } ;
1285
1314
var min = poly [ axLetter + 'min' ] ;
1286
1315
var max = poly [ axLetter + 'max' ] ;
1287
1316
1288
1317
if ( min !== undefined && max !== undefined ) {
1289
- range [ ax . _id ] = [
1318
+ range [ id ] = [
1290
1319
p2r ( ax , min ) ,
1291
1320
p2r ( ax , max )
1292
1321
] . sort ( ascending ) ;
1293
-
1294
- hasRange = true ;
1295
1322
}
1296
-
1297
- if ( filterPoly && filterPoly . filtered ) {
1298
- ranges [ ax . _id ] = filterPoly . filtered . map ( axValue ( ax ) ) ;
1299
-
1300
- hasRanges = true ;
1323
+ if ( ! lassoPoints ) {
1324
+ lassoPoints = { } ;
1301
1325
}
1326
+ lassoPoints [ id ] = poly . map ( axValue ( ax ) ) ;
1302
1327
}
1303
1328
1304
- if ( hasRange ) {
1329
+ if ( range ) {
1305
1330
eventData . range = range ;
1306
1331
}
1307
1332
1308
- if ( hasRanges ) {
1309
- eventData . lassoPoints = ranges ;
1333
+ if ( lassoPoints ) {
1334
+ eventData . lassoPoints = lassoPoints ;
1310
1335
}
1311
1336
} ;
1312
1337
}
0 commit comments