1010'use strict' ;
1111
1212var polygon = require ( '../../lib/polygon' ) ;
13+ var color = require ( '../../components/color' ) ;
1314
1415var axes = require ( './axes' ) ;
1516var constants = require ( './constants' ) ;
1617
1718var filteredPolygon = polygon . filter ;
1819var polygonTester = polygon . tester ;
20+ var MINDRAG = constants . MINDRAG ;
1921
2022function getAxId ( ax ) { return ax . _id ; }
2123
@@ -43,6 +45,16 @@ module.exports = function prepSelect(e, startX, startY, dragOptions, mode) {
4345 . attr ( 'class' , function ( d ) { return 'select-outline select-outline-' + d ; } )
4446 . attr ( 'd' , path0 + 'Z' ) ;
4547
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+
4658 // find the traces to search for selection points
4759 var searchTraces = [ ] ,
4860 gd = dragOptions . gd ,
@@ -73,9 +85,35 @@ module.exports = function prepSelect(e, startX, startY, dragOptions, mode) {
7385 x1 = Math . max ( 0 , Math . min ( pw , dx0 + x0 ) ) ;
7486 y1 = Math . max ( 0 , Math . min ( ph , dy0 + y0 ) ) ;
7587
88+ var dx = Math . abs ( x1 - x0 ) ,
89+ dy = Math . abs ( y1 - y0 ) ;
90+
7691 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' ) ;
79117 }
80118 else if ( mode === 'lasso' ) {
81119 pts . addPt ( [ x1 , y1 ] ) ;
@@ -99,6 +137,7 @@ module.exports = function prepSelect(e, startX, startY, dragOptions, mode) {
99137 dragOptions . gd . emit ( 'plotly_selected' , eventData ) ;
100138 }
101139 outlines . remove ( ) ;
140+ corners . remove ( ) ;
102141 for ( i = 0 ; i < searchTraces . length ; i ++ ) {
103142 searchInfo = searchTraces [ i ] ;
104143 searchInfo . selectPoints ( searchInfo , false ) ;
0 commit comments