From f29986488f651dcfd84ec3be1f2ba80492df4107 Mon Sep 17 00:00:00 2001 From: Luis Fernando Molina Date: Sat, 18 Jan 2020 11:16:20 +0100 Subject: [PATCH] Viewport saving zoom level --- ChartsSpace/TimelineChart.js | 4 ++- ChartsSpace/ViewPort.js | 53 ++++++++++++++++++++---------------- 2 files changed, 32 insertions(+), 25 deletions(-) diff --git a/ChartsSpace/TimelineChart.js b/ChartsSpace/TimelineChart.js index 174507d59..b368f2f96 100644 --- a/ChartsSpace/TimelineChart.js +++ b/ChartsSpace/TimelineChart.js @@ -283,7 +283,9 @@ function newTimelineChart () { datetime = newDate - thisObject.plotterManager.setDatetime(datetime) + if (thisObject.plotterManager !== undefined) { + thisObject.plotterManager.setDatetime(datetime) + } } function getContainer (point, purpose) { diff --git a/ChartsSpace/ViewPort.js b/ChartsSpace/ViewPort.js index 7c8d3944a..f29d0c043 100644 --- a/ChartsSpace/ViewPort.js +++ b/ChartsSpace/ViewPort.js @@ -8,7 +8,7 @@ function newViewport () { logger.fileName = MODULE_NAME const CONSOLE_LOG = true - const MIN_ZOOM_LEVEL = -28.25 + const MIN_ZOOM_LEVEL = -28.04435 const MAX_ZOOM_LEVEL = 1000 let ANIMATION_INCREMENT = 0.25 @@ -85,6 +85,23 @@ function newViewport () { } function initialize () { + if (thisObject.payload !== undefined) { + /* Read the position from the frame structure */ + let frame = { + position: { + x: 0, + y: 0 + } + } + loadFrame(thisObject.payload, frame) + if (!isNaN(frame.position.x)) { + position.x = frame.position.x + } + if (!isNaN(frame.position.y)) { + position.y = frame.position.y + } + } + resize() readObjectState() } @@ -122,6 +139,16 @@ function newViewport () { function physics () { animationPhysics() + positioningphysics() + readObjectState() + } + + function positioningphysics () { + if (thisObject.payload === undefined) { return } + /* Save the position at the frame lavel */ + let frame = {} + frame.position = position + saveFrame(thisObject.payload, frame) } function animationPhysics () { @@ -451,31 +478,11 @@ function newViewport () { } catch (err) { // we ignore errors here since most likely they will be parsing errors. } - - /* Save the position at the frame lavel */ - let frame = {} - frame.position = position - saveFrame(thisObject.payload, frame) } function readObjectState () { if (thisObject.payload === undefined) { return } - /* Read the position from the frame structure */ - let frame = { - position: { - x: 0, - y: 0 - } - } - loadFrame(thisObject.payload, frame) - if (!isNaN(frame.position.x)) { - position.x = frame.position.x - } - if (!isNaN(frame.position.y)) { - position.y = frame.position.y - } - /* Read the zoom level from the node config */ try { let code = JSON.parse(thisObject.payload.node.code) @@ -489,9 +496,7 @@ function newViewport () { if (code.zoom > MAX_ZOOM_LEVEL) { code.zoom = MAX_ZOOM_LEVEL } if (code.zoom !== thisObject.zoomLevel) { - thisObject.zoomLevel = code.zoom - thisObject.zoomTargetLevel = code.zoom - INITIAL_TIME_PERIOD = recalculatePeriod(thisObject.zoomLevel) + newZoomLevel(code.zoom) } else { saveObjectState() }