From 7288db19088f38e1cc9dc199d1b58f3ed8cc37ec Mon Sep 17 00:00:00 2001 From: Shivam Dave Date: Wed, 2 Sep 2015 13:37:17 -0700 Subject: [PATCH] [Mobile] Comments Added comments to the MCTPinch file. --- .../plot-reborn/src/directives/MCTPlot.js | 29 ++++++++++++++----- 1 file changed, 21 insertions(+), 8 deletions(-) diff --git a/platform/features/plot-reborn/src/directives/MCTPlot.js b/platform/features/plot-reborn/src/directives/MCTPlot.js index c1809aa555..e52aadd106 100644 --- a/platform/features/plot-reborn/src/directives/MCTPlot.js +++ b/platform/features/plot-reborn/src/directives/MCTPlot.js @@ -304,12 +304,12 @@ define( firstTouch = trackTouchPosition(touch, bounds).positionAsPlotPoint; } - //Receives the emit of single touch pan start + // Receives the emit of single touch pan start function onPanStart(event, touch) { startPan(touch.touch, touch.bounds); } - //Receives the emit of single touch pan change + // Receives the emit of single touch pan change function onPanChange(event, touch) { updatePan(touch.touch, touch.bounds); } @@ -381,16 +381,17 @@ define( } // Starts the zoom by emitting that viewport will be changed - // also sets the first touch variable (midpoint) if panning will happen - // and sets the distance between the first touches occurring - function startZoom(midpoint, bounds, touches, distance) { + // also sets the first touch variable (midpoint) if panning will + // happen and sets the distance between the first touches occurring + function startZoom(midpoint, bounds, distance) { $scope.$emit('user:viewport:change:start'); firstTouchDistance = distance; firstTouch = trackTouchPosition(midpoint, bounds).positionAsPlotPoint; } + // Receives the emit of the start of pinch touch function onPinchStart(event, touch) { - startZoom(touch.midpoint, touch.bounds, touch.touches, touch.distance); + startZoom(touch.midpoint, touch.bounds, touch.distance); } function comparePinchDrag(distance, prevDistance) { @@ -398,17 +399,29 @@ define( ((prevDistance - PINCH_DRAG_AMT) <= distance); } + // Receives the emit of the change of pinch touch, + // differentiates between a pan and zoom function onPinchChange(event, touch) { + + // Will pan if change in distance is within PINCH_DRAG_AMT + // range relative to the previous distance if(comparePinchDrag(Math.round(touch.distance), Math.round(prevTouchDistance || firstTouchDistance))) { updatePan(touch.midpoint, touch.bounds); - } else { + } + // Will pinch in any other situation that the distance between + // pinching touches is increasing or decreasing by more than + // PINCH_DRAG_AMT + else { updateZoom(touch.midpoint, touch.bounds, touch.distance); } + + // Sets previous touch distance to current touch.distance prevTouchDistance = touch.distance; } - // + // Receives emit for touch event ending and emits that the + // viewport has stopped changing. function onTouchEnd() { $scope.$emit('user:viewport:change:end', $scope.viewport); }