From 504afdc89a758cb6da6a6b6e1369934d9196780b Mon Sep 17 00:00:00 2001 From: Luis Fernando Molina Date: Sat, 11 Jan 2020 18:38:02 +0100 Subject: [PATCH] fit function at time machine --- ChartsSpace/TimeMachine.js | 36 +++++++++++++++++++++++++++++++++++- ChartsSpace/TimelineChart.js | 6 ++---- Spaces/ChartSpace.js | 6 ++---- Spaces/PanelsSpace.js | 6 +++--- 4 files changed, 42 insertions(+), 12 deletions(-) diff --git a/ChartsSpace/TimeMachine.js b/ChartsSpace/TimeMachine.js index d30d1a737..9e32904fd 100644 --- a/ChartsSpace/TimeMachine.js +++ b/ChartsSpace/TimeMachine.js @@ -20,9 +20,9 @@ function newTimeMachine () { container: undefined, timeScale: undefined, rateScale: undefined, - fitFunction: undefined, payload: undefined, timelineCharts: [], + fitFunction: fitFunction, physics: physics, draw: draw, drawBackground: drawBackground, @@ -60,6 +60,7 @@ function newTimeMachine () { function setupContainer () { thisObject.container = newContainer() thisObject.container.initialize(MODULE_NAME) + thisObject.container.fitFunction = thisObject.fitFunction thisObject.container.isDraggeable = true thisObject.container.insideViewport = true thisObject.container.detectMouseOver = true @@ -281,6 +282,38 @@ function newTimeMachine () { } } + function fitFunction (point, fullVisible) { + /* We prevent a point to be out of the container AND out of the Chart Space in general */ + + let returnPoint = { + x: point.x, + y: point.y + } + + let upCorner = { + x: 0, + y: 0 + } + + let bottonCorner = { + x: thisObject.container.frame.width, + y: thisObject.container.frame.height + } + + upCorner = transformThisPoint(upCorner, thisObject.container) + bottonCorner = transformThisPoint(bottonCorner, thisObject.container) + + /* Checking against the container limits. */ + if (returnPoint.x < upCorner.x) { returnPoint.x = upCorner.x } + if (returnPoint.x > bottonCorner.x) { returnPoint.x = bottonCorner.x } + if (returnPoint.y < upCorner.y) { returnPoint.y = upCorner.y } + if (returnPoint.y > bottonCorner.y) { returnPoint.y = bottonCorner.y } + + returnPoint = canvas.chartSpace.fitFunction(returnPoint, fullVisible) + + return returnPoint + } + function physics () { thisObjectPhysics() childrenPhysics() @@ -359,6 +392,7 @@ function newTimeMachine () { /* Setting up the new timeline timelineChart. */ timelineChart.container.connectToParent(thisObject.container, true, true, false, true, true, true, false, false, true) timelineChart.container.fitFunction = thisObject.container.fitFunction + timelineChart.fitFunction = thisObject.fitFunction timelineChart.container.frame.height = thisObject.container.frame.height timelineChart.container.frame.position.x = thisObject.container.frame.width / 2 - timelineChart.container.frame.width / 2 timelineChart.container.frame.position.y = 0 diff --git a/ChartsSpace/TimelineChart.js b/ChartsSpace/TimelineChart.js index 3f9fcc83d..2e823c21c 100644 --- a/ChartsSpace/TimelineChart.js +++ b/ChartsSpace/TimelineChart.js @@ -26,8 +26,6 @@ function newTimelineChart () { finalize: finalize } - thisObject.fitFunction = canvas.chartSpace.fitIntoVisibleArea - let timeMachineCoordinateSystem let timelineChartCoordinateSystem = newCoordinateSystem() @@ -410,8 +408,8 @@ function newTimelineChart () { fromPoint = transformThisPoint(fromPoint, thisObject.container) toPoint = transformThisPoint(toPoint, thisObject.container) - fromPoint = canvas.chartSpace.fitIntoVisibleArea(fromPoint) - toPoint = canvas.chartSpace.fitIntoVisibleArea(toPoint) + fromPoint = thisObject.fitFunction(fromPoint) + toPoint = thisObject.fitFunction(toPoint) browserCanvasContext.beginPath() diff --git a/Spaces/ChartSpace.js b/Spaces/ChartSpace.js index a4ba0f45b..789e36d45 100644 --- a/Spaces/ChartSpace.js +++ b/Spaces/ChartSpace.js @@ -20,7 +20,7 @@ function newChartSpace () { oneScreenDown: oneScreenDown, oneScreenLeft: oneScreenLeft, oneScreenRight: oneScreenRight, - fitIntoVisibleArea: fitIntoVisibleArea, + fitFunction: fitFunction, isThisPointVisible: isThisPointVisible, physics: physics, draw: draw, @@ -144,7 +144,7 @@ function newChartSpace () { viewPort.displace(displaceVector, true) } - function fitIntoVisibleArea (point, fullVisible) { + function fitFunction (point, fullVisible) { /* Here we check the boundaries of the resulting points, so they dont go out of the visible area. */ let returnPoint = { @@ -250,8 +250,6 @@ function newChartSpace () { /* Setting up the new time machine. */ timeMachine.container.frame.position.x = thisObject.container.frame.width / 2 - timeMachine.container.frame.width / 2 timeMachine.container.frame.position.y = thisObject.container.frame.height / 2 - timeMachine.container.frame.height / 2 - timeMachine.container.fitFunction = fitIntoVisibleArea - timeMachine.fitFunction = fitIntoVisibleArea timeMachine.initialize(onTimeMachineInitialized) function onTimeMachineInitialized (err) { diff --git a/Spaces/PanelsSpace.js b/Spaces/PanelsSpace.js index ce0aa8a59..1539238e4 100644 --- a/Spaces/PanelsSpace.js +++ b/Spaces/PanelsSpace.js @@ -42,7 +42,7 @@ function newPanelsSpace () { case 'Products Panel': { panel = newProductsPanel() - panel.fitFunction = canvas.chartSpace.fitIntoVisibleArea + panel.fitFunction = canvas.chartSpace.fitFunction panel.container.isVisibleFunction = canvas.chartSpace.isThisPointVisible break } @@ -50,13 +50,13 @@ function newPanelsSpace () { { if (pPanelCode !== undefined) { panel = newPlotterPanel() - panel.fitFunction = canvas.chartSpace.fitIntoVisibleArea + panel.fitFunction = canvas.chartSpace.fitFunction panel.container.isVisibleFunction = canvas.chartSpace.isThisPointVisible panel.session = pSession panel.initialize(pPanelCode) } else { panel = getNewPlotterPanel(pParameters.dataMine, pParameters.plotterCodeName, pParameters.moduleCodeName, pParameters.panelCodeName) - panel.fitFunction = canvas.chartSpace.fitIntoVisibleArea + panel.fitFunction = canvas.chartSpace.fitFunction panel.container.isVisibleFunction = canvas.chartSpace.isThisPointVisible panel.session = pSession panel.initialize()