Skip to content

Commit d240902

Browse files
committed
remove mouse event details from global variables
1 parent 87209bd commit d240902

File tree

3 files changed

+25
-37
lines changed

3 files changed

+25
-37
lines changed

imagetagger/imagetagger/annotations/static/annotations/js/annotations.js

Lines changed: 9 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,6 @@ globals = {
44
imageScaleHeight: 1,
55
moveSelectionStepSize: 2,
66
drawAnnotations: true,
7-
mouseUpX: undefined,
8-
mouseUpY: undefined,
9-
mouseClickX: undefined,
10-
mouseClickY: undefined,
11-
mouseDownX: undefined,
12-
mouseDownY: undefined,
137
currentAnnotationsOfSelectedType: undefined,
148
stdColor: '#CC4444',
159
mutColor: '#CC0000'
@@ -418,18 +412,12 @@ function calculateImageScale() {
418412
existingAnnotations.removeClass('hidden');
419413
}
420414

421-
/**
422-
* Highlight one annotation in a different color
423-
* @param annotationTypeId
424-
* @param annotationId
425-
*/
426-
427415
function handleMouseClick(e) {
428416
if (e && (e.target.id === 'image' || e.target.id === 'image_canvas')) {
429417
let position = globals.image.offset();
430-
globals.mouseClickX = Math.round((e.pageX - position.left));
431-
globals.mouseClickY = Math.round((e.pageY - position.top));
432-
tool.handleMouseClick(e);
418+
let x = Math.round((e.pageX - position.left));
419+
let y = Math.round((e.pageY - position.top));
420+
tool.handleMouseClick(e, x, y);
433421
}
434422

435423
// remove any existing highlight
@@ -1047,9 +1035,9 @@ function calculateImageScale() {
10471035
displayFeedback($('#feedback_annotation_type_missing'));
10481036
return;
10491037
}
1050-
globals.mouseDownX = Math.round((event.pageX - position.left) * globals.imageScaleWidth);
1051-
globals.mouseDownY = Math.round((event.pageY - position.top) * globals.imageScaleHeight);
1052-
tool.handleMouseDown(event);
1038+
let x = Math.round((event.pageX - position.left) * globals.imageScaleWidth);
1039+
let y = Math.round((event.pageY - position.top) * globals.imageScaleHeight);
1040+
tool.handleMouseDown(event, x, y);
10531041
}
10541042
}
10551043

@@ -1058,12 +1046,12 @@ function calculateImageScale() {
10581046
return;
10591047

10601048
let position = globals.image.offset();
1061-
globals.mouseUpX = Math.round((event.pageX - position.left)/* * globals.imageScaleWidth*/);
1062-
globals.mouseUpY = Math.round((event.pageY - position.top)/* * globals.imageScaleHeight*/);
1049+
let x = Math.round((event.pageX - position.left)/* * globals.imageScaleWidth*/);
1050+
let y = Math.round((event.pageY - position.top)/* * globals.imageScaleHeight*/);
10631051

10641052
if (event.pageX > position.left && event.pageX < position.left + globals.image.width() &&
10651053
event.pageY > position.top && event.pageY < position.top + globals.image.height()) {
1066-
tool.handleMouseUp(event);
1054+
tool.handleMouseUp(event, x, y);
10671055
}
10681056
}
10691057

imagetagger/imagetagger/annotations/static/annotations/js/boundingboxes.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -338,11 +338,11 @@ class BoundingBoxes {
338338
this.clear();
339339
}
340340

341-
handleMouseDown(event) { }
342-
handleMouseUp(event) { }
341+
handleMouseDown() { }
342+
handleMouseUp() { }
343343
closeDrawing() { }
344344

345-
handleMouseClick(event) {
345+
handleMouseClick(event, x, y) {
346346
// get current annotation type id
347347
let annotationType = parseInt($('#annotation_type_id').val());
348348

@@ -363,7 +363,7 @@ class BoundingBoxes {
363363
let bottom = annotation.vector.y2 / globals.imageScaleHeight;
364364

365365
// check if we clicked inside that annotation
366-
if (globals.mouseClickX >= left && globals.mouseClickX <= right && globals.mouseClickY >= top && globals.mouseClickY <= bottom) {
366+
if (x >= left && x <= right && y >= top && y <= bottom) {
367367
matchingAnnotations.push(annotation);
368368
}
369369
}

imagetagger/imagetagger/annotations/static/annotations/js/canvas.js

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -332,11 +332,11 @@ class Canvas {
332332
}
333333
}
334334

335-
mouseTooClose() {
335+
mouseTooClose(x, y) {
336336
for (let drawing of this.drawings) {
337337
let points = drawing.getPointTuples();
338338
for (let point of points) {
339-
if (Math.abs(point[0] * globals.imageScaleWidth - globals.mouseDownX) < threshold && Math.abs(point[1] * globals.imageScaleHeight - globals.mouseDownY) < threshold) {
339+
if (Math.abs(point[0] * globals.imageScaleWidth - x) < threshold && Math.abs(point[1] * globals.imageScaleHeight - y) < threshold) {
340340
return true;
341341
}
342342
}
@@ -647,7 +647,7 @@ class Canvas {
647647
increaseSelectionSizeRight() {}
648648
increaseSelectionSizeUp() {}
649649

650-
handleMouseClick(event) {
650+
handleMouseClick(event, x, y) {
651651
let position = globals.image.offset();
652652
if (!(event.pageX > position.left && event.pageX < position.left + globals.image.width() &&
653653
event.pageY > position.top && event.pageY < position.top + globals.image.height()) &&
@@ -656,20 +656,20 @@ class Canvas {
656656
}
657657
}
658658

659-
handleMouseDown() {
659+
handleMouseDown(event, x, y) {
660660
// Check if we are close enough to move the point, not draw a new drawing
661661
// we use the variable locked which is checked when we can create a new line
662-
if (this.mouseTooClose()) {
662+
if (this.mouseTooClose(x, y)) {
663663
this.locked = true;
664664
}
665665
}
666666

667-
handleMouseUp() {
667+
handleMouseUp(event, x, y) {
668668
if (this.inline && this.currentDrawing) {
669669
// We are currently drawing a drawing
670670
// and we clicked inside of the canvas:
671671
// add a point
672-
this.currentDrawing.addPoint(globals.mouseUpX, globals.mouseUpY);
672+
this.currentDrawing.addPoint(x, y);
673673
} else if (this.locked) {
674674
// we do not create a drawing because we are
675675
// only moving an existing one
@@ -683,19 +683,19 @@ class Canvas {
683683
this.inline = true;
684684
switch (this.vector_type) {
685685
case 2: // Point
686-
this.drawPoint({x1: globals.mouseUpX, y1: globals.mouseUpY}, 0, true);
686+
this.drawPoint({x1: x, y1: y}, 0, true);
687687
break;
688688
case 3: // Line
689-
this.drawLine({x1: globals.mouseUpX, y1: globals.mouseUpY}, 0, true);
689+
this.drawLine({x1: x, y1: y}, 0, true);
690690
break;
691691
case 4: // Multiline
692-
this.drawMultiline({x1: globals.mouseUpX, y1: globals.mouseUpY}, 0, true);
692+
this.drawMultiline({x1: x, y1: y}, 0, true);
693693
break;
694694
case 5: // Polygon
695695
if (this.node_count === 0) {
696-
this.drawArbitraryPolygon({x1: globals.mouseUpX, y1: globals.mouseUpY}, 0, true, false);
696+
this.drawArbitraryPolygon({x1: x, y1: y}, 0, true, false);
697697
} else {
698-
this.drawPolygon({x1: globals.mouseUpX, y1: globals.mouseUpY}, 0, true, this.node_count, false);
698+
this.drawPolygon({x1: x, y1: y}, 0, true, this.node_count, false);
699699
}
700700
break;
701701
default:

0 commit comments

Comments
 (0)