From 8c7cdce253f0400adca1a2544c58eb2a4b8557f6 Mon Sep 17 00:00:00 2001 From: Luis Fernando Molina Date: Sat, 7 Mar 2020 17:54:19 +0100 Subject: [PATCH] viewport cleaned --- ChartingSpace/EdgeEditor.js | 34 ++++++++++++++++++++++++++++++++++ ChartingSpace/Viewport.js | 25 +------------------------ Globals.js | 3 +++ 3 files changed, 38 insertions(+), 24 deletions(-) diff --git a/ChartingSpace/EdgeEditor.js b/ChartingSpace/EdgeEditor.js index 17cb15c48..c321cb84d 100644 --- a/ChartingSpace/EdgeEditor.js +++ b/ChartingSpace/EdgeEditor.js @@ -56,6 +56,9 @@ function newEdgeEditor () { width: 0, height: 0 } + + let doubleClickCounter = 0 + return thisObject function finalize () { @@ -101,7 +104,26 @@ function newEdgeEditor () { thisObject.isMouseOver = false } + function onDoubleClick () { + doubleClickCounter = 0 + + // canvas.chartingSpace.viewport.displaceToContainer(thisObject.container.parentContainer) + + if (canvas.chartingSpace.viewport.zoomLevel === DOUBLE_CLICK_ZOOM_IN_LEVEL) { + canvas.chartingSpace.viewport.zoomAtCenter(DOUBLE_CLICK_ZOOM_OUT_LEVEL) + } else { + canvas.chartingSpace.viewport.zoomAtCenter(DOUBLE_CLICK_ZOOM_IN_LEVEL) + } + } + function onDragStarted (event) { + if (doubleClickCounter > 0) { + onDoubleClick() + return + } else { + doubleClickCounter = 50 + } + mouseWhenDragStarted = { position: { x: event.x, @@ -204,6 +226,18 @@ function newEdgeEditor () { } function physics () { + draggingPhysics() + doubleClickPhysics() + } + + function doubleClickPhysics () { + doubleClickCounter-- + if (doubleClickCounter < 0) { + doubleClickCounter = 0 + } + } + + function draggingPhysics () { if (thisObject.container.frame.position.x === 0 && thisObject.container.frame.position.y === 0) { return } let mouseNoZoom = canvas.chartingSpace.viewport.unTransformThisPoint(mouse.position) diff --git a/ChartingSpace/Viewport.js b/ChartingSpace/Viewport.js index 76b6c6528..9a5132919 100644 --- a/ChartingSpace/Viewport.js +++ b/ChartingSpace/Viewport.js @@ -50,14 +50,7 @@ function newViewport () { x: 0, y: 0 } - let targetPosition = { - x: 0, - y: 0 - } - let positionIncrement = { - x: 0, - y: 0 - } + thisObject.mousePosition = { x: 0, y: 0 @@ -169,14 +162,6 @@ function newViewport () { thisObject.zoomLevel = thisObject.zoomLevel - ANIMATION_INCREMENT changeZoom(thisObject.zoomLevel + ANIMATION_INCREMENT, thisObject.zoomLevel) } - - if (positionIncrement.y !== 0) { - if (Math.trunc(Math.abs(targetPosition.y - position.y) * 1000) >= Math.trunc(Math.abs(positionIncrement.y) * 1000)) { - position.y = position.y + positionIncrement.y - } else { - positionIncrement.y = 0 - } - } } function onMouseWheel (event) { @@ -290,14 +275,6 @@ function newViewport () { saveObjectState() - targetPosition.x = position.x - targetPosition.y = position.y - - positionIncrement = { - x: 0, - y: 0 - } - thisObject.eventHandler.raiseEvent('Zoom Changed') } diff --git a/Globals.js b/Globals.js index 57706701e..075f36207 100644 --- a/Globals.js +++ b/Globals.js @@ -168,6 +168,9 @@ const _3_MINUTES_IN_MILISECONDS = 3 * 60 * 1000; const _2_MINUTES_IN_MILISECONDS = 2 * 60 * 1000; const _1_MINUTE_IN_MILISECONDS = 1 * 60 * 1000; +const DOUBLE_CLICK_ZOOM_OUT_LEVEL = 0 +const DOUBLE_CLICK_ZOOM_IN_LEVEL = 2 + let NEW_SESSION_INITIAL_DATE = new Date(); // This value will be overwritten at the canvas.chartingSpace.viewport.initialize if the user had a prevous session with this same browser. let INITIAL_ZOOM_LEVEL = -28.25 // This is the zoom level at the view port in which the APP starts. let INITIAL_TIME_PERIOD = ONE_DAY_IN_MILISECONDS // This value will be overwritten at the canvas.chartingSpace.viewport.initialize if the user had a prevous session with this same browser.