10
10
'use strict' ;
11
11
12
12
var polygon = require ( '../../lib/polygon' ) ;
13
+ var color = require ( '../../components/color' ) ;
13
14
14
15
var axes = require ( './axes' ) ;
15
16
var constants = require ( './constants' ) ;
16
17
17
18
var filteredPolygon = polygon . filter ;
18
19
var polygonTester = polygon . tester ;
20
+ var MINDRAG = constants . MINDRAG ;
19
21
20
22
function getAxId ( ax ) { return ax . _id ; }
21
23
@@ -43,6 +45,16 @@ module.exports = function prepSelect(e, startX, startY, dragOptions, mode) {
43
45
. attr ( 'class' , function ( d ) { return 'select-outline select-outline-' + d ; } )
44
46
. attr ( 'd' , path0 + 'Z' ) ;
45
47
48
+ var corners = plot . append ( 'path' )
49
+ . attr ( 'class' , 'zoombox-corners' )
50
+ . style ( {
51
+ fill : color . background ,
52
+ stroke : color . defaultLine ,
53
+ 'stroke-width' : 1
54
+ } )
55
+ . attr ( 'd' , 'M0,0Z' ) ;
56
+
57
+
46
58
// find the traces to search for selection points
47
59
var searchTraces = [ ] ,
48
60
gd = dragOptions . gd ,
@@ -73,9 +85,35 @@ module.exports = function prepSelect(e, startX, startY, dragOptions, mode) {
73
85
x1 = Math . max ( 0 , Math . min ( pw , dx0 + x0 ) ) ;
74
86
y1 = Math . max ( 0 , Math . min ( ph , dy0 + y0 ) ) ;
75
87
88
+ var dx = Math . abs ( x1 - x0 ) ,
89
+ dy = Math . abs ( y1 - y0 ) ;
90
+
76
91
if ( mode === 'select' ) {
77
- poly = polygonTester ( [ [ x0 , y0 ] , [ x0 , y1 ] , [ x1 , y1 ] , [ x1 , y0 ] ] ) ;
78
- outlines . attr ( 'd' , path0 + 'H' + x1 + 'V' + y1 + 'H' + x0 + 'Z' ) ;
92
+ if ( dy < Math . min ( dx * 0.6 , MINDRAG ) ) {
93
+ // horizontal motion: make a vertical box
94
+ poly = polygonTester ( [ [ x0 , 0 ] , [ x0 , ph ] , [ x1 , ph ] , [ x1 , 0 ] ] ) ;
95
+ // extras to guide users in keeping a straight selection
96
+ corners . attr ( 'd' , 'M' + poly . xmin + ',' + ( y0 - MINDRAG ) +
97
+ 'h-4v' + ( 2 * MINDRAG ) + 'h4Z' +
98
+ 'M' + poly . xmax + ',' + ( y0 - MINDRAG ) +
99
+ 'h4v' + ( 2 * MINDRAG ) + 'h-4Z' ) ;
100
+
101
+ }
102
+ else if ( dx < Math . min ( dy * 0.6 , MINDRAG ) ) {
103
+ // vertical motion: make a horizontal box
104
+ poly = polygonTester ( [ [ 0 , y0 ] , [ 0 , y1 ] , [ pw , y1 ] , [ pw , y0 ] ] ) ;
105
+ corners . attr ( 'd' , 'M' + ( x0 - MINDRAG ) + ',' + poly . ymin +
106
+ 'v-4h' + ( 2 * MINDRAG ) + 'v4Z' +
107
+ 'M' + ( x0 - MINDRAG ) + ',' + poly . ymax +
108
+ 'v4h' + ( 2 * MINDRAG ) + 'v-4Z' ) ;
109
+ }
110
+ else {
111
+ // diagonal motion
112
+ poly = polygonTester ( [ [ x0 , y0 ] , [ x0 , y1 ] , [ x1 , y1 ] , [ x1 , y0 ] ] ) ;
113
+ corners . attr ( 'd' , 'M0,0Z' ) ;
114
+ }
115
+ outlines . attr ( 'd' , 'M' + poly . xmin + ',' + poly . ymin +
116
+ 'H' + poly . xmax + 'V' + poly . ymax + 'H' + poly . xmin + 'Z' ) ;
79
117
}
80
118
else if ( mode === 'lasso' ) {
81
119
pts . addPt ( [ x1 , y1 ] ) ;
@@ -99,6 +137,7 @@ module.exports = function prepSelect(e, startX, startY, dragOptions, mode) {
99
137
dragOptions . gd . emit ( 'plotly_selected' , eventData ) ;
100
138
}
101
139
outlines . remove ( ) ;
140
+ corners . remove ( ) ;
102
141
for ( i = 0 ; i < searchTraces . length ; i ++ ) {
103
142
searchInfo = searchTraces [ i ] ;
104
143
searchInfo . selectPoints ( searchInfo , false ) ;
0 commit comments