From 9d84be843a28ef1efc2586ac402ae3df8de1aa15 Mon Sep 17 00:00:00 2001 From: Luis Fernando Molina Date: Wed, 12 Feb 2020 13:47:31 +0100 Subject: [PATCH] peace restored --- ChartsSpace/EdgeEditor.js | 106 +++++++++++++++---------------------- ChartsSpace/TimeMachine.js | 23 ++------ Plotter.js | 10 ++-- Scales/RateScale.js | 2 +- Scales/TimeScale.js | 12 ++--- Utilities.js | 34 +++++++++++- 6 files changed, 91 insertions(+), 96 deletions(-) diff --git a/ChartsSpace/EdgeEditor.js b/ChartsSpace/EdgeEditor.js index 649ec2538..a9dfee62b 100644 --- a/ChartsSpace/EdgeEditor.js +++ b/ChartsSpace/EdgeEditor.js @@ -134,53 +134,6 @@ function newEdgeEditor () { y: thisObject.container.frame.position.y } - /* Calculating the Direct Position, that will be needed to manipulate the coordinate system */ - thisObject.container.frame.position.x = 0 + dragVector.x - thisObject.container.frame.position.y = 0 + dragVector.y - - let directPositionA = { - x: thisObject.container.frame.position.x, - y: thisObject.container.frame.position.y - } - - directPositionA = transformThisPoint(directPositionA, thisObject.container) - - thisObject.container.frame.position.x = 0 + dragVector.x / 2 - thisObject.container.frame.position.y = 0 + dragVector.y / 2 - - let directPositionB = { - x: thisObject.container.frame.position.x, - y: thisObject.container.frame.position.y - } - - directPositionB = transformThisPoint(directPositionB, thisObject.container) - - /* Calculating the Inverted Position, that will be needed to manipulate the coordinate system */ - thisObject.container.frame.position.x = 0 - dragVector.x - thisObject.container.frame.position.y = 0 - dragVector.y - - let invertedPositionA = { - x: thisObject.container.frame.position.x, - y: thisObject.container.frame.position.y - } - - invertedPositionA = transformThisPoint(invertedPositionA, thisObject.container) - - /* Calculating the Inverted Position, that will be needed to manipulate the coordinate system */ - thisObject.container.frame.position.x = 0 - dragVector.x / 2 - thisObject.container.frame.position.y = 0 - dragVector.y / 2 - - let invertedPositionB = { - x: thisObject.container.frame.position.x, - y: thisObject.container.frame.position.y - } - - invertedPositionB = transformThisPoint(invertedPositionB, thisObject.container) - - /* Finally we reset this */ - thisObject.container.frame.position.x = 0 - thisObject.container.frame.position.y = 0 - const MIN_WIDTH = 100 const MIN_HEIGHT = 50 @@ -194,8 +147,12 @@ function newEdgeEditor () { break } case 'right mouse button': { - let newMinDate = getDateFromPoint(invertedPositionB, thisObject.container.parentContainer, coordinateSystem) - let newMaxRate = getRateFromPoint(invertedPositionB, thisObject.container.parentContainer, coordinateSystem) + let point = { + x: -thisObject.container.frame.position.x, + y: -thisObject.container.frame.position.y + } + let newMinDate = getDateFromPointAtContainer(point, thisObject.container.parentContainer, coordinateSystem) + let newMaxRate = getRateFromPointAtContainer(point, thisObject.container.parentContainer, coordinateSystem) let xDifferenceMaxMin = coordinateSystem.max.x - coordinateSystem.min.x let yDifferenceMaxMin = coordinateSystem.max.y - coordinateSystem.min.y coordinateSystem.min.x = newMinDate.valueOf() @@ -212,13 +169,18 @@ function newEdgeEditor () { if (thisObject.container.parentContainer.frame.height - dragVector.y < MIN_HEIGHT) { return } + + let point = { + x: thisObject.container.frame.position.x, + y: thisObject.container.frame.position.y + } + let newMaxRate = getRateFromPointAtContainer(point, thisObject.container.parentContainer, coordinateSystem) + thisObject.container.parentContainer.frame.position.y = thisObject.container.parentContainer.frame.position.y + dragVector.y thisObject.container.parentContainer.frame.height = thisObject.container.parentContainer.frame.height - dragVector.y - thisObject.container.parentContainer.eventHandler.raiseEvent('Dimmensions Changed', event) switch (buttonUsedForDragging) { case 'left mouse button': { - let newMaxRate = getRateFromPoint(directPositionB, thisObject.container.parentContainer, coordinateSystem) coordinateSystem.max.y = newMaxRate coordinateSystem.maxHeight = thisObject.container.parentContainer.frame.height coordinateSystem.recalculateScale() @@ -230,19 +192,25 @@ function newEdgeEditor () { break } } + thisObject.container.parentContainer.eventHandler.raiseEvent('Dimmensions Changed', event) break } case 'bottom' : { if (thisObject.container.parentContainer.frame.height + dragVector.y < MIN_HEIGHT) { return } + + let point = { + x: thisObject.container.frame.position.x, + y: thisObject.container.frame.position.y + thisObject.container.frame.height + } + let newMinRate = getRateFromPointAtContainer(point, thisObject.container.parentContainer, coordinateSystem) + thisObject.container.parentContainer.frame.height = thisObject.container.parentContainer.frame.height + dragVector.y - thisObject.container.parentContainer.eventHandler.raiseEvent('Dimmensions Changed', event) switch (buttonUsedForDragging) { case 'left mouse button': { - let newMaxRate = getRateFromPoint(directPositionA, thisObject.container.parentContainer, coordinateSystem) - coordinateSystem.min.y = coordinateSystem.min.y - (coordinateSystem.max.y - newMaxRate) + coordinateSystem.min.y = newMinRate coordinateSystem.maxHeight = thisObject.container.parentContainer.frame.height coordinateSystem.recalculateScale() break @@ -253,47 +221,54 @@ function newEdgeEditor () { break } } + thisObject.container.parentContainer.eventHandler.raiseEvent('Dimmensions Changed', event) break } case 'left' : { if (thisObject.container.parentContainer.frame.width - dragVector.x < MIN_WIDTH) { return } + let point = { + x: thisObject.container.frame.position.x, + y: thisObject.container.frame.position.y + } + let newMinDate = getDateFromPointAtContainer(point, thisObject.container.parentContainer, coordinateSystem) + thisObject.container.parentContainer.frame.position.x = thisObject.container.parentContainer.frame.position.x + dragVector.x thisObject.container.parentContainer.frame.width = thisObject.container.parentContainer.frame.width - dragVector.x - thisObject.container.parentContainer.eventHandler.raiseEvent('Dimmensions Changed', event) switch (buttonUsedForDragging) { case 'left mouse button': { - let newMinDate = getDateFromPoint(directPositionA, thisObject.container.parentContainer, coordinateSystem) coordinateSystem.min.x = newMinDate.valueOf() coordinateSystem.maxWidth = thisObject.container.parentContainer.frame.width coordinateSystem.recalculateScale() break } case 'right mouse button': { - let newMinDate = getDateFromPoint(directPositionB, thisObject.container.parentContainer, coordinateSystem) - coordinateSystem.min.x = newMinDate.valueOf() coordinateSystem.maxWidth = thisObject.container.parentContainer.frame.width coordinateSystem.recalculateScale() break } } + thisObject.container.parentContainer.eventHandler.raiseEvent('Dimmensions Changed', event) break } case 'right' : { if (thisObject.container.parentContainer.frame.width + dragVector.x < MIN_WIDTH) { return } - thisObject.container.parentContainer.frame.width = thisObject.container.parentContainer.frame.width + dragVector.x - thisObject.container.parentContainer.eventHandler.raiseEvent('Dimmensions Changed', event) + let point = { + x: thisObject.container.frame.position.x + thisObject.container.frame.width, + y: thisObject.container.frame.position.y + } + let newMaxDate = getDateFromPointAtContainer(point, thisObject.container.parentContainer, coordinateSystem) + + thisObject.container.parentContainer.frame.width = thisObject.container.parentContainer.frame.width + dragVector.x switch (buttonUsedForDragging) { case 'left mouse button': { - let newMinDate = getDateFromPoint(invertedPositionB, thisObject.container.parentContainer, coordinateSystem) - let xDifferenceMaxMin = coordinateSystem.min.x - newMinDate.valueOf() - coordinateSystem.max.x = coordinateSystem.max.x + xDifferenceMaxMin + coordinateSystem.max.x = newMaxDate.valueOf() coordinateSystem.maxWidth = thisObject.container.parentContainer.frame.width coordinateSystem.recalculateScale() break @@ -304,9 +279,14 @@ function newEdgeEditor () { break } } + thisObject.container.parentContainer.eventHandler.raiseEvent('Dimmensions Changed', event) break } } + + /* Finally we reset this */ + thisObject.container.frame.position.x = 0 + thisObject.container.frame.position.y = 0 } function drawForeground () { diff --git a/ChartsSpace/TimeMachine.js b/ChartsSpace/TimeMachine.js index 1c7767c10..0a2d68f58 100644 --- a/ChartsSpace/TimeMachine.js +++ b/ChartsSpace/TimeMachine.js @@ -50,7 +50,6 @@ function newTimeMachine () { let onViewportZoomChangedEventSuscriptionId let onMouseOverEventSuscriptionId let onMouseNotOverEventSuscriptionId - let timeScaleValueEventSuscriptionId let timeScaleMouseOverEventSuscriptionId let rateScaleValueEventSuscriptionId let rateScaleMouseOverEventSuscriptionId @@ -114,7 +113,6 @@ function newTimeMachine () { function finalizeTimeScale () { if (thisObject.timeScale === undefined) { return } - thisObject.timeScale.container.eventHandler.stopListening(timeScaleValueEventSuscriptionId) thisObject.timeScale.container.eventHandler.stopListening(timeScaleMouseOverEventSuscriptionId) thisObject.timeScale.finalize() thisObject.timeScale = undefined @@ -142,6 +140,9 @@ function newTimeMachine () { timeFrame = INITIAL_TIME_PERIOD loadFrame(thisObject.payload, thisObject.container.frame) + // thisObject.container.frame.position.x = 0 + // thisObject.container.frame.position.y = 0 + recalculateCoordinateSystem() recalculateCurrentDatetime() @@ -194,23 +195,9 @@ function newTimeMachine () { thisObject.timeScale.fitFunction = thisObject.fitFunction thisObject.timeScale.payload = thisObject.payload.node.timeScale.payload - timeScaleValueEventSuscriptionId = thisObject.timeScale.container.eventHandler.listenToEvent('Time Scale Value Changed', timeScaleValueChanged) timeScaleMouseOverEventSuscriptionId = thisObject.timeScale.container.eventHandler.listenToEvent('onMouseOverScale', timeScaleMouseOver) thisObject.timeScale.initialize(timeMachineCoordinateSystem, thisObject.container) - function timeScaleValueChanged (event) { - if (event.isUserAction === true) { - let currentDate = getDateFromPoint(event.mousePosition, thisObject.container, timeMachineCoordinateSystem) - let currentRate = getRateFromPoint(event.mousePosition, thisObject.container, timeMachineCoordinateSystem) - // thisObject.container.frame.width = TIME_MACHINE_WIDTH + TIME_MACHINE_WIDTH * event.scale - recalculateCoordinateSystem() - moveToUserPosition(thisObject.container, currentDate, currentRate, timeMachineCoordinateSystem, false, true, event.mousePosition) - } else { - // thisObject.container.frame.width = TIME_MACHINE_WIDTH + TIME_MACHINE_WIDTH * event.scale - recalculateCoordinateSystem() - } - thisObject.container.eventHandler.raiseEvent('Dimmensions Changed', event) - } function timeScaleMouseOver (event) { thisObject.container.eventHandler.raiseEvent('onMouseOver', event) } @@ -227,8 +214,8 @@ function newTimeMachine () { function rateScaleValueChanged (event) { if (event.isUserAction === true) { - let currentDate = getDateFromPoint(event.mousePosition, thisObject.container, timeMachineCoordinateSystem) - let currentRate = getRateFromPoint(event.mousePosition, thisObject.container, timeMachineCoordinateSystem) + let currentDate = getDateFromPointAtBrowserCanvas(event.mousePosition, thisObject.container, timeMachineCoordinateSystem) + let currentRate = getRateFromPointAtBrowserCanvas(event.mousePosition, thisObject.container, timeMachineCoordinateSystem) // thisObject.container.frame.height = TIME_MACHINE_HEIGHT + TIME_MACHINE_HEIGHT * event.scale recalculateCoordinateSystem() diff --git a/Plotter.js b/Plotter.js index 97b818a28..0f90ee3c5 100644 --- a/Plotter.js +++ b/Plotter.js @@ -146,7 +146,7 @@ function newPlotter () { } function onMouseOver (event) { - let userPosition = getDateFromPoint(event, thisObject.container, coordinateSystem) + let userPosition = getDateFromPointAtBrowserCanvas(event, thisObject.container, coordinateSystem) userPositionDate = userPosition.valueOf() } @@ -374,8 +374,8 @@ function newPlotter () { let daysOnSides = getSideDays(timeFrame) - let leftDate = getDateFromPoint(canvas.chartSpace.viewport.visibleArea.topLeft, thisObject.container, coordinateSystem) - let rightDate = getDateFromPoint(canvas.chartSpace.viewport.visibleArea.topRight, thisObject.container, coordinateSystem) + let leftDate = getDateFromPointAtBrowserCanvas(canvas.chartSpace.viewport.visibleArea.topLeft, thisObject.container, coordinateSystem) + let rightDate = getDateFromPointAtBrowserCanvas(canvas.chartSpace.viewport.visibleArea.topRight, thisObject.container, coordinateSystem) let dateDiff = rightDate.valueOf() - leftDate.valueOf() @@ -427,8 +427,8 @@ function newPlotter () { let daysOnSides = getSideDays(timeFrame) - let leftDate = getDateFromPoint(canvas.chartSpace.viewport.visibleArea.topLeft, thisObject.container, coordinateSystem) - let rightDate = getDateFromPoint(canvas.chartSpace.viewport.visibleArea.topRight, thisObject.container, coordinateSystem) + let leftDate = getDateFromPointAtBrowserCanvas(canvas.chartSpace.viewport.visibleArea.topLeft, thisObject.container, coordinateSystem) + let rightDate = getDateFromPointAtBrowserCanvas(canvas.chartSpace.viewport.visibleArea.topRight, thisObject.container, coordinateSystem) let dateDiff = rightDate.valueOf() - leftDate.valueOf() diff --git a/Scales/RateScale.js b/Scales/RateScale.js index c3793b8c7..ece23b55e 100644 --- a/Scales/RateScale.js +++ b/Scales/RateScale.js @@ -362,7 +362,7 @@ function newRateScale () { y: mouse.position.y + thisObject.offset } - thisObject.rate = getRateFromPoint(ratePoint, rateCalculationsContainer, coordinateSystem) + thisObject.rate = getRateFromPointAtBrowserCanvas(ratePoint, rateCalculationsContainer, coordinateSystem) /* rateScale Positioning */ ratePoint = { diff --git a/Scales/TimeScale.js b/Scales/TimeScale.js index e3a45b031..6e59aa2c0 100644 --- a/Scales/TimeScale.js +++ b/Scales/TimeScale.js @@ -86,7 +86,6 @@ function newTimeScale () { let event = {} event.scale = thisObject.scale - thisObject.container.eventHandler.raiseEvent('Time Scale Value Changed', event) } function onMouseOverSomeTimeMachineContainer (event) { @@ -133,7 +132,7 @@ function newTimeScale () { } coordinateSystem.zoomX(factor, event, limitingContainer) - + saveObjectState() return if ( thisObject.scale <= DEFAULT_SCALE + SNAP_THRESHOLD_SCALE && @@ -145,7 +144,6 @@ function newTimeScale () { } event.isUserAction = true - thisObject.container.eventHandler.raiseEvent('Time Scale Value Changed', event) saveObjectState() scaleTimer = 100 @@ -162,8 +160,8 @@ function newTimeScale () { let code = JSON.parse(thisObject.payload.node.code) code.scale = thisObject.scale / MAX_SCALE * 100 code.scale = code.scale.toFixed(0) - code.fromDate = (new Date(thisObject.fromDate)).toISOString() - code.toDate = (new Date(thisObject.toDate)).toISOString() + code.fromDate = (new Date(coordinateSystem.min.x)).toISOString() + code.toDate = (new Date(coordinateSystem.max.x)).toISOString() thisObject.payload.node.code = JSON.stringify(code, null, 4) } catch (err) { // we ignore errors here since most likely they will be parsing errors. @@ -171,6 +169,7 @@ function newTimeScale () { } function readObjectState () { + return try { let code = JSON.parse(thisObject.payload.node.code) @@ -192,7 +191,6 @@ function newTimeScale () { } else { event.scale = thisObject.scale } - thisObject.container.eventHandler.raiseEvent('Time Scale Value Changed', event) } } @@ -247,7 +245,7 @@ function newTimeScale () { y: 0 } - let mouseDate = getDateFromPoint(timePoint, limitingContainer, coordinateSystem) + let mouseDate = getDateFromPointAtBrowserCanvas(timePoint, limitingContainer, coordinateSystem) thisObject.date = new Date(mouseDate) diff --git a/Utilities.js b/Utilities.js index ddf1f302a..6bf221203 100644 --- a/Utilities.js +++ b/Utilities.js @@ -141,7 +141,7 @@ function pad (str, max) { return str.length < max ? pad('0' + str, max) : str } -function getDateFromPoint (point, container, coordinateSystem) { +function getDateFromPointAtBrowserCanvas (point, container, coordinateSystem) { point = unTransformThisPoint(point, container) point = coordinateSystem.unInverseTransform(point, container.frame.height) @@ -150,13 +150,43 @@ function getDateFromPoint (point, container, coordinateSystem) { return date } -function getRateFromPoint (point, container, coordinateSystem) { +function getDateFromPointAtChartsSpace (point, container, coordinateSystem) { + point = container.frame.unframeThisPoint(point) + point = coordinateSystem.unInverseTransform(point, container.frame.height) + + let date = new Date(point.x) + + return date +} + +function getDateFromPointAtContainer (point, container, coordinateSystem) { + point = coordinateSystem.unInverseTransform(point, container.frame.height) + + let date = new Date(point.x) + + return date +} + +function getRateFromPointAtBrowserCanvas (point, container, coordinateSystem) { point = unTransformThisPoint(point, container) point = coordinateSystem.unInverseTransform(point, container.frame.height) return point.y } +function getRateFromPointAtChartSpace (point, container, coordinateSystem) { + point = container.frame.unframeThisPoint(point) + point = coordinateSystem.unInverseTransform(point, container.frame.height) + + return point.y +} + +function getRateFromPointAtContainer (point, container, coordinateSystem) { + point = coordinateSystem.unInverseTransform(point, container.frame.height) + + return point.y +} + function getMilisecondsFromPoint (point, container, coordinateSystem) { point = unTransformThisPoint(point, container) point = coordinateSystem.unInverseTransform(point, container.frame.height)