3
3
var dragElement = require ( '../../dragelement' ) ;
4
4
var dragHelpers = require ( '../../dragelement/helpers' ) ;
5
5
var drawMode = dragHelpers . drawMode ;
6
+ var selectMode = dragHelpers . selectMode ;
6
7
7
8
var Registry = require ( '../../../registry' ) ;
8
9
@@ -16,10 +17,11 @@ var handleOutline = require('../../selections/handle_outline');
16
17
var clearOutlineControllers = handleOutline . clearOutlineControllers ;
17
18
18
19
var helpers = require ( './helpers' ) ;
19
- var pointsShapeRectangle = helpers . pointsShapeRectangle ;
20
- var pointsShapeEllipse = helpers . pointsShapeEllipse ;
20
+ var pointsOnRectangle = helpers . pointsOnRectangle ;
21
+ var pointsOnEllipse = helpers . pointsOnEllipse ;
21
22
<
B41A
code class="diff-text syntax-highlighted-line">var writePaths = helpers . writePaths ;
22
23
var newShapes = require ( './newshapes' ) ;
24
+ var newSelections = require ( '../../selections/draw_newselection/newselections' ) ;
23
25
24
26
module . exports = function displayOutlines ( polygons , outlines , dragOptions , nCalls ) {
25
27
if ( ! nCalls ) nCalls = 0 ;
@@ -30,47 +32,64 @@ module.exports = function displayOutlines(polygons, outlines, dragOptions, nCall
30
32
// recursive call
31
33
displayOutlines ( polygons , outlines , dragOptions , nCalls ++ ) ;
32
34
33
- if ( pointsShapeEllipse ( polygons [ 0 ] ) ) {
35
+ if ( pointsOnEllipse ( polygons [ 0 ] ) ) {
34
36
update ( { redrawing : true } ) ;
35
37
}
36
38
}
37
39
38
40
function update ( opts ) {
39
- dragOptions . isActiveShape = false ; // i.e. to disable controllers
41
+ var updateObject = { } ;
42
+
43
+ if ( dragOptions . isActiveShape !== undefined ) {
44
+ dragOptions . isActiveShape = false ; // i.e. to disable shape controllers
45
+ updateObject = newShapes ( outlines , dragOptions ) ;
46
+ }
47
+
48
+ if ( dragOptions . isActiveSelection !== undefined ) {
49
+ dragOptions . isActiveSelection = false ; // i.e. to disable selection controllers
50
+ updateObject = newSelections ( outlines , dragOptions ) ;
51
+ }
40
52
41
- var updateObject = newShapes ( outlines , dragOptions ) ;
42
53
if ( Object . keys ( updateObject ) . length ) {
43
54
Registry . call ( ( opts || { } ) . redrawing ? 'relayout' : '_guiRelayout' , gd , updateObject ) ;
44
55
}
45
56
}
46
57
47
-
48
- var isActiveShape = dragOptions . isActiveShape ;
49
58
var fullLayout = gd . _fullLayout ;
50
59
var zoomLayer = fullLayout . _zoomlayer ;
51
60
52
61
var dragmode = dragOptions . dragmode ;
53
62
var isDrawMode = drawMode ( dragmode ) ;
54
-
55
- if ( isDrawMode ) gd . _fullLayout . _drawing = true ;
56
- else if ( gd . _fullLayout . _activeShapeIndex >= 0 ) clearOutlineControllers ( gd ) ;
63
+ var isSelectMode = selectMode ( dragmode ) ;
64
+
65
+ if ( isDrawMode || isSelectMode ) {
66
+ gd . _fullLayout . _outlining = true ;
67
+ } else if (
68
+ gd . _fullLayout . _activeShapeIndex >= 0 ||
69
+ gd . _fullLayout . _activeSelectionIndex >= 0
70
+ ) {
71
+ clearOutlineControllers ( gd ) ;
72
+ }
57
73
58
74
// make outline
59
75
outlines . attr ( 'd' , writePaths ( polygons ) ) ;
60
76
61
77
// add controllers
62
78
var vertexDragOptions ;
63
- var shapeDragOptions ;
79
+ var regionDragOptions ;
64
80
var indexI ; // cell index
65
81
var indexJ ; // vertex or cell-controller index
66
82
var copyPolygons ;
67
83
68
- if ( isActiveShape && ! nCalls ) {
84
+ if ( ! nCalls && (
85
+ dragOptions . isActiveShape ||
86
+ dragOptions . isActiveSelection
87
+ ) ) {
69
88
copyPolygons = recordPositions ( [ ] , polygons ) ;
<
10000
td data-grid-cell-id="diff-8d2586fdf8fd49d26a8bdaeebadf8b2187331b0a06f1664bdf7802e3769dda36-70-89-0" data-selected="false" role="gridcell" style="background-color:var(--bgColor-default);text-align:center" tabindex="-1" valign="top" class="focusable-grid-cell diff-line-number position-relative diff-line-number-neutral left-side">70
89
71
90
var g = zoomLayer . append ( 'g' ) . attr ( 'class' , 'outline-controllers' ) ;
72
91
addVertexControllers ( g ) ;
73
- addShapeControllers ( ) ;
92
+ addRegionControllers ( ) ;
74
93
}
75
94
76
95
function startDragVertex ( evt ) {
@@ -88,7 +107,7 @@ module.exports = function displayOutlines(polygons, outlines, dragOptions, nCall
88
107
89
108
var cell = polygons [ indexI ] ;
90
109
var len = cell . length ;
91
- if ( pointsShapeRectangle ( cell ) ) {
110
+ if ( pointsOnRectangle ( cell ) ) {
92
111
for ( var q = 0 ; q < len ; q ++ ) {
93
112
if ( q === indexJ ) continue ;
94
113
@@ -107,7 +126,7 @@ module.exports = function displayOutlines(polygons, outlines, dragOptions, nCall
107
126
cell [ indexJ ] [ 1 ] = x0 + dx ;
108
127
cell [ indexJ ] [ 2 ] = y0 + dy ;
109
128
110
- if ( ! pointsShapeRectangle ( cell ) ) {
129
+ if ( ! pointsOnRectangle ( cell ) ) {
111
130
// reject result to rectangles with ensure areas
112
131
for ( var j = 0 ; j < len ; j ++ ) {
113
132
for ( var k = 0 ; k < cell [ j ] . length ; k ++ ) {
@@ -162,8 +181,8 @@ module.exports = function displayOutlines(polygons, outlines, dragOptions, nCall
162
181
163
182
var cell = polygons [ indexI ] ;
164
183
if (
165
- ! pointsShapeRectangle ( cell ) &&
166
- ! pointsShapeEllipse ( cell )
184
+ ! pointsOnRectangle ( cell ) &&
185
+ ! pointsOnEllipse ( cell )
167
186
) {
168
187
removeVertex ( ) ;
169
188
}
@@ -176,8 +195,8 @@ module.exports = function displayOutlines(polygons, outlines, dragOptions, nCall
176
195
for ( var i = 0 ; i < polygons . length ; i ++ ) {
177
196
var cell = polygons [ i ] ;
178
197
179
- var onRect = pointsShapeRectangle ( cell ) ;
180
- var onEllipse = ! onRect && pointsShapeEllipse ( cell ) ;
198
+ var onRect = pointsOnRectangle ( cell ) ;
199
+ var onEllipse = ! onRect && pointsOnEllipse ( cell ) ;
181
200
182
201
vertexDragOptions [ i ] = [ ] ;
183
202
for ( var j = 0 ; j < cell . length ; j ++ ) {
@@ -222,7 +241,7 @@ module.exports = function displayOutlines(polygons, outlines, dragOptions, nCall
222
241
}
223
242
}
224
243
225
- function moveShape ( dx , dy ) {
244
+ function moveRegion ( dx , dy ) {
226
245
if ( ! polygons . length ) return ;
227
246
228
247
for ( var i = 0 ; i < polygons . length ; i ++ ) {
@@ -235,37 +254,37 @@ module.exports = function displayOutlines(polygons, outlines, dragOptions, nCall
235
254
}
236
255
}
237
256
238
- function moveShapeController ( dx , dy ) {
239
- moveShape ( dx , dy ) ;
257
+ function moveRegionController ( dx , dy ) {
258
+ moveRegion ( dx , dy ) ;
240
259
241
260
redraw ( ) ;
242
261
}
243
262
244
- function startDragShapeController ( evt ) {
263
+ function startDragRegionController ( evt ) {
245
264
indexI = + evt . srcElement . getAttribute ( 'data-i' ) ;
246
265
if ( ! indexI ) indexI = 0 ; // ensure non-existing move button get zero index
247
266
248
- shapeDragOptions [ indexI ] . moveFn = moveShapeController ;
267
+ regionDragOptions [ indexI ] . moveFn = moveRegionController ;
249
268
}
250
269
251
- function endDragShapeController ( ) {
270
+ function endDragRegionController ( ) {
252
271
update ( ) ;
253
272
}
254
273
255
- function addShapeControllers ( ) {
256
- shapeDragOptions = [ ] ;
274
+ function addRegionControllers ( ) {
275
+ regionDragOptions = [ ] ;
257
276
258
277
if ( ! polygons . length ) return ;
259
278
260
279
var i = 0 ;
261
- shapeDragOptions [ i ] = {
280
+ regionDragOptions [ i ] = {
262
281
element : outlines [ 0 ] [ 0 ] ,
263
282
gd : gd ,
264
- prepFn : startDragShapeController ,
265
- doneFn : endDragShapeController
283
+ prepFn : startDragRegionController ,
284
+ doneFn : endDragRegionController
266
285
} ;
267
286
268
- dragElement . init ( shapeDragOptions [ i ] ) ;
287
+ dragElement . init ( regionDragOptions [ i ] ) ;
269
288
}
270
289
} ;
271
290
0 commit comments