From da3e8184de549d2e7f7728e3edfae71c964875d4 Mon Sep 17 00:00:00 2001 From: Luis Fernando Molina Date: Thu, 13 Feb 2020 16:29:35 +0100 Subject: [PATCH] Autoscaling working --- ChartsSpace/CoordinateSystem.js | 29 ++++++++++++++++++++++++++++- ChartsSpace/TimeMachine.js | 1 + Scales/RateScale.js | 1 + 3 files changed, 30 insertions(+), 1 deletion(-) diff --git a/ChartsSpace/CoordinateSystem.js b/ChartsSpace/CoordinateSystem.js index 18e51602f..d302b080e 100644 --- a/ChartsSpace/CoordinateSystem.js +++ b/ChartsSpace/CoordinateSystem.js @@ -15,6 +15,9 @@ function newCoordinateSystem () { maxWidth: undefined, scale: undefined, eventHandler: undefined, + autosScale: true, + physics: physics, + reportValue: reportValue, zoomX: zoomX, zoomY: zoomY, recalculateScale: recalculateScale, @@ -44,6 +47,9 @@ function newCoordinateSystem () { thisObject.eventHandler = newEventHandler() thisObject.eventHandler.name = 'Coordinate System' + let newMax = -VERY_LARGE_NUMBER + let newMin = VERY_LARGE_NUMBER + return thisObject function finalize () { @@ -65,6 +71,28 @@ function newCoordinateSystem () { recalculateScale() } + function physics () { + if (thisObject.autosScale === true) { + if (thisObject.max.y !== newMax || thisObject.min.y !== newMin) { + thisObject.min.y = newMin + thisObject.max.y = newMax + + thisObject.scale.x = thisObject.maxWidth / (thisObject.max.x - thisObject.min.x) + thisObject.scale.y = thisObject.maxHeight / (thisObject.max.y - thisObject.min.y) + } + + newMax = -VERY_LARGE_NUMBER + newMin = VERY_LARGE_NUMBER + } + } + + function reportValue (value) { + if (thisObject.autosScale === true) { + if (value > newMax) { newMax = value } + if (value < newMin) { newMin = value } + } + } + function zoomX (factor, mousePosition, container) { let mouseAtCointainer = unTransformThisPoint(mousePosition, container) let leftDistance = mouseAtCointainer.x @@ -96,7 +124,6 @@ function newCoordinateSystem () { } function recalculateScale (event) { - /* Defines the initial Zoom level at center position. */ thisObject.scale.x = thisObject.maxWidth / (thisObject.max.x - thisObject.min.x) thisObject.scale.y = thisObject.maxHeight / (thisObject.max.y - thisObject.min.y) diff --git a/ChartsSpace/TimeMachine.js b/ChartsSpace/TimeMachine.js index 170dd6d3a..64e5d2246 100644 --- a/ChartsSpace/TimeMachine.js +++ b/ChartsSpace/TimeMachine.js @@ -365,6 +365,7 @@ function newTimeMachine () { function physics () { thisObject.edgeEditor.physics() + timeMachineCoordinateSystem.physics() saveFrame(thisObject.payload, thisObject.container.frame) if (thisObject.container.frame.isInViewPort()) { diff --git a/Scales/RateScale.js b/Scales/RateScale.js index 687fa4c73..150a65fc3 100644 --- a/Scales/RateScale.js +++ b/Scales/RateScale.js @@ -163,6 +163,7 @@ function newRateScale () { } function readObjectState () { + return try { let code = JSON.parse(thisObject.payload.node.code)