From 5c4876df351cc79478567415133c6737b698b55b Mon Sep 17 00:00:00 2001 From: Luis Fernando Molina Date: Tue, 7 Jan 2020 17:50:43 +0100 Subject: [PATCH] Can have more than one time machine and drag it around --- Canvas.js | 42 +++++++++++++++++++++----------------- ChartsSpace/TimeMachine.js | 5 +++-- Container.js | 5 +++++ Globals.js | 3 ++- Spaces/ChartSpace.js | 8 +++++++- 5 files changed, 40 insertions(+), 23 deletions(-) diff --git a/Canvas.js b/Canvas.js index 9726c9d46..286cc81f5 100644 --- a/Canvas.js +++ b/Canvas.js @@ -850,30 +850,34 @@ function newCanvas () { thisObject.eventHandler.raiseEvent('Dragging', undefined) if (containerDragStarted || viewPortBeingDragged) { - /* The parameters received have been captured with zoom applied. We must remove the zoom in order to correctly modify the displacement. */ - - let downCopy = { - x: dragVector.downX, - y: dragVector.downY - } - - let downCopyNoTransf - downCopyNoTransf = viewPort.unzoomThisPoint(downCopy) - // downCopyNoTransf = containerBeingDragged.zoom.unzoomThisPoint(downCopyNoTransf); - - let upCopy = { - x: dragVector.upX, - y: dragVector.upY - } - - let upCopyNoTranf - upCopyNoTranf = viewPort.unzoomThisPoint(upCopy) - let displaceVector = { x: dragVector.upX - dragVector.downX, y: dragVector.upY - dragVector.downY } + if (containerBeingDragged !== undefined && containerBeingDragged.insideViewport === true) { + let downCopy = { + x: dragVector.downX, + y: dragVector.downY + } + + let downNoZoom + downNoZoom = viewPort.unzoomThisPoint(downCopy) + + let upCopy = { + x: dragVector.upX, + y: dragVector.upY + } + + let upNoZoom + upNoZoom = viewPort.unzoomThisPoint(upCopy) + + displaceVector = { + x: upNoZoom.x - downNoZoom.x, + y: upNoZoom.y - downNoZoom.y + } + } + if (viewPortBeingDragged) { viewPort.displace(displaceVector) } diff --git a/ChartsSpace/TimeMachine.js b/ChartsSpace/TimeMachine.js index 3c5f50b83..37024081d 100644 --- a/ChartsSpace/TimeMachine.js +++ b/ChartsSpace/TimeMachine.js @@ -48,7 +48,8 @@ function newTimeMachine () { function setupContainer () { thisObject.container = newContainer() thisObject.container.initialize(MODULE_NAME) - thisObject.container.isDraggeable = false + thisObject.container.isDraggeable = true + thisObject.container.insideViewport = true thisObject.container.detectMouseOver = true thisObject.container.frame.width = TIME_MACHINE_WIDTH @@ -329,7 +330,7 @@ function newTimeMachine () { if (thisObject.timeScale !== undefined) { thisObject.timeScale.draw() } if (thisObject.rateScale !== undefined) { thisObject.rateScale.draw() } - // thisObject.container.frame.draw(false, true, false) + thisObject.container.frame.draw(false, true, false, thisObject.fitFunction) } } diff --git a/Container.js b/Container.js index d94375bdd..0816953fd 100644 --- a/Container.js +++ b/Container.js @@ -211,6 +211,11 @@ function newContainer () { return true } break + case GET_CONTAINER_PURPOSE.DRAGGING: + if (thisObject.isDraggeable === true) { + return true + } + break default: { return false } } diff --git a/Globals.js b/Globals.js index 281a3da9e..f6db156ae 100644 --- a/Globals.js +++ b/Globals.js @@ -48,7 +48,8 @@ const MIN_ZOOM_LEVEL = -28.25 const GET_CONTAINER_PURPOSE = { MOUSE_OVER: 1, MOUSE_WHEEL: 2, - MOUSE_CLICK: 3 + MOUSE_CLICK: 3, + DRAGGING: 4 } /* User Interface Panels */ diff --git a/Spaces/ChartSpace.js b/Spaces/ChartSpace.js index 117f09d14..57bc80994 100644 --- a/Spaces/ChartSpace.js +++ b/Spaces/ChartSpace.js @@ -76,7 +76,13 @@ function newChartSpace () { for (let i = 0; i < thisObject.timeMachines.length; i++) { container = thisObject.timeMachines[i].getContainer(point, purpose) if (container !== undefined) { - if (container.isForThisPurpose(purpose)) { + if (purpose !== undefined) { + if (container.isForThisPurpose(purpose)) { + if (thisObject.container.frame.isThisPointHere(point, true) === true) { + return container + } + } + } else { if (thisObject.container.frame.isThisPointHere(point, true) === true) { return container }