From 1e4238ea3ccda90aa973e978be169be6b0e22493 Mon Sep 17 00:00:00 2001 From: Luis Fernando Molina Date: Thu, 30 Jan 2020 23:28:40 +0100 Subject: [PATCH] changes in ratescale working --- ChartsSpace/CoordinateSystem.js | 21 +++++----- ChartsSpace/TimeMachine.js | 14 +++++-- Scales/RateScale.js | 21 +++------- Utilities.js | 74 +++++++-------------------------- 4 files changed, 40 insertions(+), 90 deletions(-) diff --git a/ChartsSpace/CoordinateSystem.js b/ChartsSpace/CoordinateSystem.js index e99fedc33..5fc9728fe 100644 --- a/ChartsSpace/CoordinateSystem.js +++ b/ChartsSpace/CoordinateSystem.js @@ -11,6 +11,8 @@ function newCoordinateSystem () { let thisObject = { min: undefined, max: undefined, + maxHeight: undefined, + maxWidth: undefined, scale: undefined, recalculateScale: recalculateScale, transformThisPoint: transformThisPoint, @@ -35,9 +37,6 @@ function newCoordinateSystem () { y: 0 } - let maxHeight - let maxWidth - return thisObject function initialize (minValue, maxValue, pMaxWidth, pMaxHeight) { @@ -48,23 +47,23 @@ function newCoordinateSystem () { thisObject.min.y = minValue.y // * 0.999; // 0.1% less thisObject.max.y = maxValue.y // * 1.001; // 0.1% more - maxWidth = pMaxWidth - maxHeight = pMaxHeight + thisObject.maxWidth = pMaxWidth + thisObject.maxHeight = pMaxHeight recalculateScale() } function recalculateScale () { /* Defines the initial Zoom level at center position. */ - thisObject.scale.x = maxWidth / (thisObject.max.x - thisObject.min.x) - thisObject.scale.y = maxHeight / (thisObject.max.y - thisObject.min.y) + thisObject.scale.x = thisObject.maxWidth / (thisObject.max.x - thisObject.min.x) + thisObject.scale.y = thisObject.maxHeight / (thisObject.max.y - thisObject.min.y) } function initializeX (minValue, maxValue, maxWidth) { thisObject.min.x = minValue.x // * 0.999; // 0.1% less thisObject.max.x = maxValue.x // * 1.001; // 0.1% more - thisObject.scale.x = maxWidth / (thisObject.max.x - thisObject.min.x) + thisObject.scale.x = thisObject.maxWidth / (thisObject.max.x - thisObject.min.x) } function initializeY (minValue, maxValue, pMaxHeight) { @@ -73,7 +72,7 @@ function newCoordinateSystem () { thisObject.scale.y = pMaxHeight / (thisObject.max.y - thisObject.min.y) - maxHeight = pMaxHeight + thisObject.maxHeight = pMaxHeight } function transformThisPoint (point) { @@ -92,7 +91,7 @@ function newCoordinateSystem () { point = { x: (point.x - thisObject.min.x) * thisObject.scale.x, - y: maxHeight - (point.y - thisObject.min.y) * thisObject.scale.y + y: thisObject.maxHeight - (point.y - thisObject.min.y) * thisObject.scale.y } return point @@ -101,7 +100,7 @@ function newCoordinateSystem () { function transformThisPoint2 (point) { point = { x: (point.x - thisObject.min.x) * thisObject.scale.x, - y: (maxHeight - point.y - thisObject.min.y) * thisObject.scale.y + y: (thisObject.maxHeight - point.y - thisObject.min.y) * thisObject.scale.y } return point diff --git a/ChartsSpace/TimeMachine.js b/ChartsSpace/TimeMachine.js index c8c5be462..6b9246f10 100644 --- a/ChartsSpace/TimeMachine.js +++ b/ChartsSpace/TimeMachine.js @@ -194,7 +194,7 @@ function newTimeMachine () { thisObject.container.frame.width = TIME_MACHINE_WIDTH + TIME_MACHINE_WIDTH * event.scale recalculateCoordinateSystem() if (event.isUserAction === true) { - moveToUserPosition(thisObject.container, timeMachineCoordinateSystem, false, true, event.mousePosition, true) + // moveToUserPosition(thisObject.container, previousCoordinateSystem, timeMachineCoordinateSystem, false, true, event.mousePosition, true) } thisObject.container.eventHandler.raiseEvent('Dimmensions Changed', event) } @@ -213,10 +213,16 @@ function newTimeMachine () { thisObject.rateScale.initialize(timeMachineCoordinateSystem, thisObject.container, thisObject.container) function rateScaleValueChanged (event) { - thisObject.container.frame.height = TIME_MACHINE_HEIGHT + TIME_MACHINE_HEIGHT * event.scale - recalculateCoordinateSystem() if (event.isUserAction === true) { - moveToUserPosition(thisObject.container, timeMachineCoordinateSystem, true, false, event.mousePosition, true) + let currentDate = getDateFromPoint(event.mousePosition, thisObject.container, timeMachineCoordinateSystem) + let currentRate = getRateFromPoint(event.mousePosition, thisObject.container, timeMachineCoordinateSystem) + + thisObject.container.frame.height = TIME_MACHINE_HEIGHT + TIME_MACHINE_HEIGHT * event.scale + recalculateCoordinateSystem() + moveToUserPosition(thisObject.container, currentDate, currentRate, timeMachineCoordinateSystem, true, false, event.mousePosition, true) + } else { + thisObject.container.frame.height = TIME_MACHINE_HEIGHT + TIME_MACHINE_HEIGHT * event.scale + recalculateCoordinateSystem() } thisObject.container.eventHandler.raiseEvent('Dimmensions Changed', event) thisObject.container.eventHandler.raiseEvent('Upstream Rate Scale Value Changed', event) diff --git a/Scales/RateScale.js b/Scales/RateScale.js index 21a749462..9d367f1ca 100644 --- a/Scales/RateScale.js +++ b/Scales/RateScale.js @@ -177,26 +177,17 @@ function newRateScale () { if (thisObject.scale > MAX_SCALE) { thisObject.scale = MAX_SCALE } } - if ( - thisObject.scale <= DEFAULT_SCALE + SNAP_THRESHOLD_SCALE && - thisObject.scale >= DEFAULT_SCALE - SNAP_THRESHOLD_SCALE - ) { - event.scale = DEFAULT_SCALE - } else { - event.scale = thisObject.scale - } - - event.isUserAction = true - thisObject.container.eventHandler.raiseEvent('Rate Scale Value Changed', event) - - saveObjectState() - offsetTimer = 0 - scaleTimer = 100 + finishScaleChange(event) } } function setScale (scale) { thisObject.scale = scale + let event = {} + finishScaleChange(event) + } + + function finishScaleChange (event) { if ( thisObject.scale <= DEFAULT_SCALE + SNAP_THRESHOLD_SCALE && thisObject.scale >= DEFAULT_SCALE - SNAP_THRESHOLD_SCALE diff --git a/Utilities.js b/Utilities.js index 7749bc532..77f3bc643 100644 --- a/Utilities.js +++ b/Utilities.js @@ -188,76 +188,30 @@ function getUserPosition (coordinateSystem) { return userPosition } -function moveToUserPosition (container, coordinateSystem, ignoreX, ignoreY, center, moveContainer) { - let userPosition = getUserPosition(coordinateSystem) - - INITIAL_TIME_PERIOD = recalculatePeriod(userPosition.zoom) - NEW_SESSION_INITIAL_DATE = new Date(userPosition.date) - +function moveToUserPosition (container, currentDate, currentRate, coordinateSystem, ignoreX, ignoreY, mousePosition) { let targetPoint = { - x: (new Date(userPosition.date)).valueOf(), - y: userPosition.rate + x: currentDate.valueOf(), + y: currentRate } - /* Put this po int in the coordinate system of the canvas.chartSpace.viewport */ - + /* Put this point in the coordinate system of the canvas.chartSpace.viewport */ targetPoint = coordinateSystem.transformThisPoint(targetPoint) targetPoint = transformThisPoint(targetPoint, container) - let centerPoint - if (center !== undefined) { - centerPoint = { - x: center.x, - y: center.y - } - } else { - centerPoint = { - x: (canvas.chartSpace.viewport.visibleArea.bottomRight.x - canvas.chartSpace.viewport.visibleArea.topLeft.x) / 2, - y: (canvas.chartSpace.viewport.visibleArea.bottomRight.y - canvas.chartSpace.viewport.visibleArea.topLeft.y) / 2 - } - } - - /* 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 - if (moveContainer === true) { - let targetCopy = { - x: targetPoint.x, - y: targetPoint.y - } - let targetNoZoom - targetNoZoom = canvas.chartSpace.viewport.unTransformThisPoint(targetCopy) + let targetNoZoom = canvas.chartSpace.viewport.unTransformThisPoint(targetPoint) + let mouseNoZoom = canvas.chartSpace.viewport.unTransformThisPoint(mousePosition) - let centerCopy = { - x: centerPoint.x, - y: centerPoint.y - } - - let centerNoZoom - centerNoZoom = canvas.chartSpace.viewport.unTransformThisPoint(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 } - - canvas.chartSpace.viewport.displace(displaceVector) + displaceVector = { + x: mouseNoZoom.x - targetNoZoom.x, + y: mouseNoZoom.y - targetNoZoom.y } + + if (ignoreX) { displaceVector.x = 0 } + if (ignoreY) { displaceVector.y = 0 } + + container.displace(displaceVector) } function removeTime (datetime) {