Skip to content

Commit 9cd1ba1

Browse files
committed
simplify vertex buttons
1 parent d017bb7 commit 9cd1ba1

File tree

1 file changed

+9
-66
lines changed

1 file changed

+9
-66
lines changed

src/components/shapes/draw_newshape/display_outlines.js

Lines changed: 9 additions & 66 deletions
Original file line numberDiff line numberDiff line change
@@ -193,18 +193,6 @@ module.exports = function displayOutlines(polygons, outlines, dragOptions, nCall
193193
var onRect = pointsShapeRectangle(cell);
194194
var onEllipse = !onRect && pointsShapeEllipse(cell);
195195

196-
var minX;
197-
var minY;
198-
var maxX;
199-
var maxY;
200-
if(onRect) {
201-
// compute bounding box
202-
minX = calcMin(cell, 1);
203-
minY = calcMin(cell, 2);
204-
maxX = calcMax(cell, 1);
205-
maxY = calcMax(cell, 2);
206-
}
207-
208196
vertexDragOptions[i] = [];
209197
for(var j = 0; j < cell.length; j++) {
210198
if(cell[j][0] === 'Z') continue;
@@ -222,57 +210,28 @@ module.exports = function displayOutlines(polygons, outlines, dragOptions, nCall
222210
var y = cell[j][2];
223211

224212
var rIcon = 3;
225-
var button = g.append(onRect ? 'rect' : 'circle')
213+
g.append('circle')
214+
.attr('cx', x)
215+
.attr('cy', y)
216+
.attr('r', rIcon)
226217
.style({
227218
'mix-blend-mode': 'luminosity',
228219
fill: 'black',
229220
stroke: 'white',
230221
'stroke-width': 1
231222
});
232223

233-
if(onRect) {
234-
button
235-
.attr('x', x - rIcon)
236-
.attr('y', y - rIcon)
237-
.attr('width', 2 * rIcon)
238-
.attr('height', 2 * rIcon);
239-
} else {
240-
button
224+
var vertex = g.append('circle')
225+
.classed('cursor-grab', true)
226+
.attr('data-i', i)
227+
.attr('data-j', j)
241228
.attr('cx', x)
242229
.attr('cy', y)
243-
.attr('r', rIcon);
244-
}
245-
246-
var vertex = g.append(onRect ? 'rect' : 'circle')
247-
.attr('data-i', i)
248-
.attr('data-j', j)
230+
.attr('r', rVertexController)
249231
.style({
250232
opacity: 0
251233
});
252234

253-
if(onRect) {
254-
var ratioX = (x - minX) / (maxX - minX);
255-
var ratioY = (y - minY) / (maxY - minY);
256-
if(isFinite(ratioX) && isFinite(ratioY)) {
257-
setCursor(
258-
vertex,
259-
dragElement.getCursor(ratioX, 1 - ratioY)
260-
);
261-
}
262-
263-
vertex
264-
.attr('x', x - rVertexController)
265-
.attr('y', y - rVertexController)
266-
.attr('width', 2 * rVertexController)
267-
.attr('height', 2 * rVertexController);
268-
} else {
269-
vertex
270-
.classed('cursor-grab', true)
271-
.attr('cx', x)
272-
.attr('cy', y)
273-
.attr('r', rVertexController);
274-
}
275-
276235
vertexDragOptions[i][j] = {
277236
element: vertex.node(),
278237
gd: gd,
@@ -333,22 +292,6 @@ module.exports = function displayOutlines(polygons, outlines, dragOptions, nCall
333292
}
334293
};
335294

336-
function calcMin(cell, dim) {
337-
var v = Infinity;
338-
for(var i = 0; i < cell.length; i++) {
339-
v = Math.min(v, cell[i][dim]);
340-
}
341-
return v;
342-
}
343-
344-
function calcMax(cell, dim) {
345-
var v = -Infinity;
346-
for(var i = 0; i < cell.length; i++) {
347-
v = Math.max(v, cell[i][dim]);
348-
}
349-
return v;
350-
}
351-
352295
function recordPositions(polygonsOut, polygonsIn) {
353296
for(var i = 0; i < polygonsIn.length; i++) {
354297
var cell = polygonsIn[i];

0 commit comments

Comments
 (0)