MCPcopy
hub / github.com/automeris-io/WebPlotDigitizer / Tool

Function Tool

app/javascript/tools/axesCalibrationTools.js:24–105  ·  view source on GitHub ↗
(calibration, reloadTool)

Source from the content-addressed store, hash-verified

22
23wpd.AxesCornersTool = (function() {
24 var Tool = function(calibration, reloadTool) {
25 var pointCount = 0,
26 _calibration = calibration,
27 isCapturingCorners = true;
28
29 if (reloadTool) {
30 pointCount = _calibration.maxPointCount;
31 isCapturingCorners = false;
32 } else {
33 pointCount = 0;
34 isCapturingCorners = true;
35 wpd.graphicsWidget.resetData();
36 }
37
38 this.onMouseClick = function(ev, pos, imagePos) {
39 if (isCapturingCorners) {
40 pointCount = pointCount + 1;
41
42 _calibration.addPoint(imagePos.x, imagePos.y, 0, 0);
43 _calibration.unselectAll();
44 _calibration.selectPoint(pointCount - 1);
45 wpd.graphicsWidget.forceHandlerRepaint();
46
47 if (pointCount === _calibration.maxPointCount) {
48 isCapturingCorners = false;
49 wpd.alignAxes.calibrationCompleted();
50 }
51
52 wpd.graphicsWidget.updateZoomOnEvent(ev);
53 } else {
54 _calibration.unselectAll();
55 // cal.selectNearestPoint(imagePos.x,
56 // imagePos.y, 15.0/wpd.graphicsWidget.getZoomRatio());
57 _calibration.selectNearestPoint(imagePos.x, imagePos.y);
58 wpd.graphicsWidget.forceHandlerRepaint();
59 wpd.graphicsWidget.updateZoomOnEvent(ev);
60 }
61 };
62
63 this.onKeyDown = function(ev) {
64 if (_calibration.getSelectedPoints().length === 0) {
65 return;
66 }
67
68 var selPoint = _calibration.getPoint(_calibration.getSelectedPoints()[0]),
69 pointPx = selPoint.px,
70 pointPy = selPoint.py,
71 stepSize = ev.shiftKey === true ? 5 / wpd.graphicsWidget.getZoomRatio() :
72 0.5 / wpd.graphicsWidget.getZoomRatio();
73
74 // rotate to current rotation
75 const currentRotation = wpd.graphicsWidget.getRotation();
76 let {
77 x,
78 y
79 } = wpd.graphicsWidget.getRotatedCoordinates(0, currentRotation, pointPx, pointPy);
80
81 if (wpd.keyCodes.isUp(ev.keyCode)) {

Callers

nothing calls this directly

Calls 11

addPointMethod · 0.80
selectPointMethod · 0.80
getSelectedPointsMethod · 0.80
getPointMethod · 0.80
getRotationMethod · 0.80
changePointPxMethod · 0.80
unselectAllMethod · 0.45
selectNearestPointMethod · 0.45
onRedrawMethod · 0.45
getCountMethod · 0.45
isPointSelectedMethod · 0.45

Tested by

no test coverage detected