diff --git a/ChartsSpace/TimeMachine.js b/ChartsSpace/TimeMachine.js index 37024081d..0f268f8b1 100644 --- a/ChartsSpace/TimeMachine.js +++ b/ChartsSpace/TimeMachine.js @@ -92,7 +92,7 @@ function newTimeMachine () { thisObject.timeScale.container.eventHandler.listenToEvent('Lenght Percentage Changed', function (event) { thisObject.container.frame.width = TIME_MACHINE_WIDTH * event.lenghtPercentage / 100 recalculateScale() - moveToUserPosition(thisObject.container, timeLineCoordinateSystem, false, true, event.mousePosition) + moveToUserPosition(thisObject.container, timeLineCoordinateSystem, false, true, event.mousePosition, false, true) thisObject.container.eventHandler.raiseEvent('Dimmensions Changed', event) }) diff --git a/Utilities.js b/Utilities.js index 37ee16d97..52f02cbf4 100644 --- a/Utilities.js +++ b/Utilities.js @@ -105,7 +105,7 @@ function getUserPosition (timeLineCoordinateSystem) { return userPosition } -function moveToUserPosition (container, timeLineCoordinateSystem, ignoreX, ignoreY, center, considerZoom) { +function moveToUserPosition (container, timeLineCoordinateSystem, ignoreX, ignoreY, center, considerZoom, moveContainer) { let userPosition = getUserPosition(timeLineCoordinateSystem) if (considerZoom === true) { @@ -138,17 +138,47 @@ function moveToUserPosition (container, timeLineCoordinateSystem, ignoreX, ignor } } - /* Lets calculate the displace vector, from the point we want at the center, to the current center. */ + /* When we are moving the container, it needs to consider the zooming of the viewport */ + /* Lets calculate the displace vector, from the point we want at the center, to the current center. */ - let displaceVector = { - x: centerPoint.x - targetPoint.x, - y: centerPoint.y - targetPoint.y + let displaceVector + if (moveContainer === true) { + let targetCopy = { + x: targetPoint.x, + y: targetPoint.y + } + + let targetNoZoom + targetNoZoom = viewPort.unzoomThisPoint(targetCopy) + + let centerCopy = { + x: centerPoint.x, + y: centerPoint.y + } + + let centerNoZoom + centerNoZoom = viewPort.unzoomThisPoint(centerCopy) + + displaceVector = { + x: centerNoZoom.x - targetNoZoom.x, + y: centerNoZoom.y - targetNoZoom.y + } + + if (ignoreX) { displaceVector.x = 0 } + if (ignoreY) { displaceVector.y = 0 } + + container.displace(displaceVector) + } else { + displaceVector = { + x: centerPoint.x - targetPoint.x, + y: centerPoint.y - targetPoint.y + } + + if (ignoreX) { displaceVector.x = 0 } + if (ignoreY) { displaceVector.y = 0 } + + viewPort.displace(displaceVector) } - - if (ignoreX) { displaceVector.x = 0 } - if (ignoreY) { displaceVector.y = 0 } - - viewPort.displace(displaceVector) } function removeTime (datetime) {