From 4fc824ac2d9d563a77436539876b84e3b7166c2c Mon Sep 17 00:00:00 2001 From: Luis Fernando Molina Date: Wed, 1 Apr 2020 12:01:42 +0200 Subject: [PATCH] Improving in coordinate System with Margins --- ChartingSpace/CoordinateSystem.js | 24 ++++++++++++++---------- ChartingSpace/EdgeEditor.js | 5 +++-- 2 files changed, 17 insertions(+), 12 deletions(-) diff --git a/ChartingSpace/CoordinateSystem.js b/ChartingSpace/CoordinateSystem.js index 4e28a1716..653004e23 100644 --- a/ChartingSpace/CoordinateSystem.js +++ b/ChartingSpace/CoordinateSystem.js @@ -19,6 +19,10 @@ function newCoordinateSystem () { autoMaxXScale: true, autoMinYScale: true, autoMaxYScale: true, + HORIZONTAL_MARGIN_FACTOR: 0.80, + VERTICAL_MARGIN_FACTOR: 0.90, + HORIZONTAL_MARGIN_INVERSE_FACTOR: 0.20, + VERTICAL_MARGIN_INVERSE_FACTOR: 0.10, physics: physics, reportXValue: reportXValue, reportYValue: reportYValue, @@ -193,8 +197,8 @@ function newCoordinateSystem () { } function recalculateScale (event) { - thisObject.scale.x = thisObject.maxWidth / (thisObject.max.x - thisObject.min.x) - thisObject.scale.y = thisObject.maxHeight / (thisObject.max.y - thisObject.min.y) + thisObject.scale.x = thisObject.maxWidth * thisObject.HORIZONTAL_MARGIN_FACTOR / (thisObject.max.x - thisObject.min.x) + thisObject.scale.y = thisObject.maxHeight * thisObject.VERTICAL_MARGIN_FACTOR / (thisObject.max.y - thisObject.min.y) thisObject.eventHandler.raiseEvent('Scale Changed', event) } @@ -230,8 +234,8 @@ function newCoordinateSystem () { */ point = { - x: (point.x - thisObject.min.x) * thisObject.scale.x, - y: thisObject.maxHeight - (point.y - thisObject.min.y) * thisObject.scale.y + x: (point.x - thisObject.min.x) * thisObject.scale.x + thisObject.maxWidth * thisObject.HORIZONTAL_MARGIN_INVERSE_FACTOR / 2, + y: thisObject.maxHeight - (point.y - thisObject.min.y) * thisObject.scale.y - thisObject.maxHeight * thisObject.VERTICAL_MARGIN_INVERSE_FACTOR / 2 } return point @@ -239,8 +243,8 @@ function newCoordinateSystem () { function transformThisPoint2 (point) { point = { - x: (point.x - thisObject.min.x) * thisObject.scale.x, - y: (thisObject.maxHeight - point.y - thisObject.min.y) * thisObject.scale.y + x: (point.x - thisObject.min.x) * thisObject.scale.x + thisObject.maxWidth * thisObject.HORIZONTAL_MARGIN_INVERSE_FACTOR / 2, + y: (thisObject.maxHeight - point.y - thisObject.min.y) * thisObject.scale.y - thisObject.maxHeight * thisObject.VERTICAL_MARGIN_INVERSE_FACTOR / 2 } return point @@ -248,8 +252,8 @@ function newCoordinateSystem () { function unInverseTransform (point, inverseY) { point = { - x: (point.x / thisObject.scale.x) + thisObject.min.x, - y: (inverseY - point.y) / thisObject.scale.y + thisObject.min.y + x: ((point.x - thisObject.maxWidth * thisObject.HORIZONTAL_MARGIN_INVERSE_FACTOR / 2) / thisObject.scale.x) + thisObject.min.x, + y: (inverseY * thisObject.VERTICAL_MARGIN_FACTOR - point.y + thisObject.maxHeight * thisObject.VERTICAL_MARGIN_INVERSE_FACTOR / 2) / thisObject.scale.y + thisObject.min.y } return point @@ -257,8 +261,8 @@ function newCoordinateSystem () { function inverseTransformUncappedY (point, inverseY) { point = { - x: (point.x - thisObject.min.x) * thisObject.scale.x, - y: (inverseY - point.y) * thisObject.scale.y + x: (point.x - thisObject.min.x) * thisObject.scale.x + thisObject.maxWidth * thisObject.HORIZONTAL_MARGIN_INVERSE_FACTOR / 2, + y: (inverseY * thisObject.VERTICAL_MARGIN_FACTOR - point.y) * thisObject.scale.y - thisObject.maxHeight * thisObject.VERTICAL_MARGIN_INVERSE_FACTOR / 2 } return point diff --git a/ChartingSpace/EdgeEditor.js b/ChartingSpace/EdgeEditor.js index 02af47f99..df338ece4 100644 --- a/ChartingSpace/EdgeEditor.js +++ b/ChartingSpace/EdgeEditor.js @@ -268,6 +268,7 @@ function newEdgeEditor () { } function draggingPhysics () { + if (coordinateSystemWhenDragStarted === undefined) { return } if (thisObject.container.frame.position.x === 0 && thisObject.container.frame.position.y === 0) { return } let mouseNoZoom = canvas.chartingSpace.viewport.unTransformThisPoint(mouse.position) @@ -324,7 +325,7 @@ function newEdgeEditor () { break case 'left or right arrow key pressed': { let point = { - x: -dragVector.x, + x: -dragVector.x + thisObject.container.frame.width * coordinateSystem.HORIZONTAL_MARGIN_INVERSE_FACTOR / 2, y: 0 } @@ -342,7 +343,7 @@ function newEdgeEditor () { case 'up or down arrow key pressed': { let point = { x: 0, - y: -dragVector.y + y: -dragVector.y + thisObject.container.frame.height * coordinateSystem.VERTICAL_MARGIN_INVERSE_FACTOR / 2 } let newMaxRate = getRateFromPointAtContainer(point, thisObject.container.parentContainer, coordinateSystem)