From 146c7224ab963d18ccfbda9052acebe0190985c4 Mon Sep 17 00:00:00 2001 From: Luis Fernando Molina Date: Sun, 2 Feb 2020 12:36:29 +0100 Subject: [PATCH] Improvements handling scales --- CanvasApp/ChartsSpace/PlottersManager.js | 41 ++++++++++--------- CanvasApp/ChartsSpace/TimelineChart.js | 7 +++- CanvasApp/Plotter.js | 21 +--------- CanvasApp/Scales/RateScale.js | 15 ++++++- CanvasApp/Scales/TimeFrameScale.js | 15 ++++++- .../BollingerBands.js | 4 +- 6 files changed, 56 insertions(+), 47 deletions(-) diff --git a/CanvasApp/ChartsSpace/PlottersManager.js b/CanvasApp/ChartsSpace/PlottersManager.js index 007969d77..3b245cf99 100644 --- a/CanvasApp/ChartsSpace/PlottersManager.js +++ b/CanvasApp/ChartsSpace/PlottersManager.js @@ -4,8 +4,6 @@ function newPlottersManager () { const logger = newWebDebugLog() logger.fileName = MODULE_NAME - let connectors = [] - let timeFrame = INITIAL_TIME_PERIOD let datetime = NEW_SESSION_INITIAL_DATE @@ -13,6 +11,7 @@ function newPlottersManager () { fitFunction: undefined, container: undefined, payload: undefined, + connectors: [], setDatetime: setDatetime, setTimeFrame: setTimeFrame, setCoordinateSystem: setCoordinateSystem, @@ -22,6 +21,8 @@ function newPlottersManager () { finalize: finalize } + thisObject.connectors = [] + let initializationReady = false let layersPanel let onLayerStatusChangedEventSuscriptionId @@ -39,8 +40,8 @@ function newPlottersManager () { layersPanel.container.eventHandler.stopListening(onLayerStatusChangedEventSuscriptionId) layersPanel = undefined - for (let i = 0; i < connectors.length; i++) { - let connector = connectors[i] + for (let i = 0; i < thisObject.connectors.length; i++) { + let connector = thisObject.connectors[i] /* Then the panels. */ for (let j = 0; j < connector.panels.length; j++) { canvas.panelsSpace.destroyPanel(connector.panels[j]) @@ -61,7 +62,7 @@ function newPlottersManager () { connector = undefined } - connectors = [] + thisObject.connectors = [] coordinateSystem = undefined thisObject.container.finalize() @@ -210,7 +211,7 @@ function newPlottersManager () { connector.layer.panels = connector.panels } - connectors.push(connector) + thisObject.connectors.push(connector) } catch (err) { if (ERROR_LOG === true) { logger.write('[ERROR] initializePlotter -> onProductStorageInitialized -> onPlotterInizialized -> err = ' + err.stack) } } @@ -229,8 +230,8 @@ function newPlottersManager () { if (layer.status === LAYER_STATUS.LOADING) { /* Lets see if we can find the Plotter of this card on our Active Plotters list, other wise we will initialize it */ let found = false - for (let i = 0; i < connectors.length; i++) { - let connector = connectors[i] + for (let i = 0; i < thisObject.connectors.length; i++) { + let connector = thisObject.connectors[i] if (connector.layer.payload.node.id === layer.payload.node.id) { found = true } @@ -244,8 +245,8 @@ function newPlottersManager () { } if (layer.status === LAYER_STATUS.OFF) { /* If the plotter of this card is not on our Active Plotters list, then we remove it. */ - for (let i = 0; i < connectors.length; i++) { - let connector = connectors[i] + for (let i = 0; i < thisObject.connectors.length; i++) { + let connector = thisObject.connectors[i] if (connector.layer.payload.node.id === layer.payload.node.id) { /* Then the panels. */ for (let j = 0; j < connector.panels.length; j++) { @@ -259,7 +260,7 @@ function newPlottersManager () { connector.plotter.finalize() } finalizeStorage(connector.storage) - connectors.splice(i, 1) // Delete item from array. + thisObject.connectors.splice(i, 1) // Delete item from array. return // We already found the product woth changes and processed it. } } @@ -268,8 +269,8 @@ function newPlottersManager () { function setTimeFrame (pTimeFrame) { timeFrame = pTimeFrame - for (let i = 0; i < connectors.length; i++) { - let connector = connectors[i] + for (let i = 0; i < thisObject.connectors.length; i++) { + let connector = thisObject.connectors[i] connector.layer.setTimeFrame(timeFrame) connector.storage.setTimeFrame(timeFrame) connector.plotter.setTimeFrame(timeFrame) @@ -278,8 +279,8 @@ function newPlottersManager () { function setDatetime (pDatetime) { datetime = pDatetime - for (let i = 0; i < connectors.length; i++) { - let connector = connectors[i] + for (let i = 0; i < thisObject.connectors.length; i++) { + let connector = thisObject.connectors[i] connector.layer.setDatetime(pDatetime) connector.storage.setDatetime(pDatetime) connector.plotter.setDatetime(pDatetime) @@ -288,8 +289,8 @@ function newPlottersManager () { function setCoordinateSystem (pCoordinateSystem) { coordinateSystem = pCoordinateSystem - for (let i = 0; i < connectors.length; i++) { - let connector = connectors[i] + for (let i = 0; i < thisObject.connectors.length; i++) { + let connector = thisObject.connectors[i] connector.plotter.setCoordinateSystem(coordinateSystem) } } @@ -298,10 +299,10 @@ function newPlottersManager () { } function draw () { - if (connectors === undefined) { return } // We need to wait + if (thisObject.connectors === undefined) { return } // We need to wait /* First the Product Plotters. */ - for (let i = 0; i < connectors.length; i++) { - let connector = connectors[connectors.length - i - 1] + for (let i = 0; i < thisObject.connectors.length; i++) { + let connector = thisObject.connectors[thisObject.connectors.length - i - 1] connector.plotter.draw() } } diff --git a/CanvasApp/ChartsSpace/TimelineChart.js b/CanvasApp/ChartsSpace/TimelineChart.js index 7eeeeee52..fa6b444aa 100644 --- a/CanvasApp/ChartsSpace/TimelineChart.js +++ b/CanvasApp/ChartsSpace/TimelineChart.js @@ -199,7 +199,10 @@ function newTimelineChart () { } function rateScaleOffsetChanged (event) { - thisObject.container.frame.offset.y = event.offset + if (thisObject.container.frame.offset.y !== event.offset) { + thisObject.container.frame.offset.y = event.offset + thisObject.container.eventHandler.raiseEvent('onDisplace') + } } function rateScaleValueChanged (event) { @@ -358,9 +361,11 @@ function newTimelineChart () { function childrenPhysics () { if (thisObject.rateScale !== undefined) { + thisObject.rateScale.layersOn = thisObject.plotterManager.connectors.length thisObject.rateScale.physics() } if (thisObject.timeFrameScale !== undefined) { + thisObject.timeFrameScale.layersOn = thisObject.plotterManager.connectors.length thisObject.timeFrameScale.physics() } } diff --git a/CanvasApp/Plotter.js b/CanvasApp/Plotter.js index 8df54aa92..97b818a28 100644 --- a/CanvasApp/Plotter.js +++ b/CanvasApp/Plotter.js @@ -23,7 +23,6 @@ function newPlotter () { thisObject.container = container let coordinateSystem - let slotCoordinateSystem // Needed to be able to plot on a slot over the timeline. let plotterModuleConfig let slotHeight = (canvas.chartSpace.viewport.visibleArea.bottomRight.y - canvas.chartSpace.viewport.visibleArea.topLeft.y) / 10 // This is the amount of slots available let mustRecalculateDataPoints = false @@ -81,7 +80,6 @@ function newPlotter () { finalizeCoordinateSystem() coordinateSystem = undefined - slotCoordinateSystem = undefined plotterModuleConfig = undefined slotHeight = undefined mustRecalculateDataPoints = undefined @@ -482,23 +480,6 @@ function newPlotter () { thisObject.container.frame.width, thisObject.container.frame.height ) - - /* In case the plotter is configured to a certain slot, we calculate the slot coordinate system too. */ - if (productDefinition.referenceParent.code === undefined) { return } - plotterModuleConfig = productDefinition.referenceParent.code - if (plotterModuleConfig.slot === undefined) { return } - - slotCoordinateSystem = newCoordinateSystem() - - minValue.y = plotterModuleConfig.slot.minValue - maxValue.y = plotterModuleConfig.slot.maxValue - - slotCoordinateSystem.initialize( - minValue, - maxValue, - thisObject.container.frame.width, - slotHeight - ) } catch (err) { if (ERROR_LOG === true) { logger.write('[ERROR] recalculateScale -> err = ' + err.stack) } } @@ -602,7 +583,7 @@ function newPlotter () { if (plotterModuleConfig !== undefined) { if (plotterModuleConfig.slot !== undefined) { /* We reset the y coordinate since it will be transformed with another coordinate system to fit into a slot. */ - dataPoint.y = (-1) * y * slotCoordinateSystem.scale.y + (plotterModuleConfig.slot.number - 1) * slotHeight + canvas.chartSpace.viewport.visibleArea.topLeft.y + dataPoint.y = (-1) * y * coordinateSystem.scale.y + (plotterModuleConfig.slot.number - 1) * slotHeight + canvas.chartSpace.viewport.visibleArea.topLeft.y } } } diff --git a/CanvasApp/Scales/RateScale.js b/CanvasApp/Scales/RateScale.js index 907c8f484..9536a0b82 100644 --- a/CanvasApp/Scales/RateScale.js +++ b/CanvasApp/Scales/RateScale.js @@ -11,6 +11,7 @@ function newRateScale () { minValue: undefined, maxValue: undefined, isVisible: true, + layersOn: undefined, setScale: setScale, onMouseOverSomeTimeMachineContainer: onMouseOverSomeTimeMachineContainer, physics: physics, @@ -323,13 +324,17 @@ function newRateScale () { if (thisObject.payload.parentNode.type === 'Timeline Chart') { if (thisObject.payload.parentNode.payload.parentNode !== undefined) { if (thisObject.payload.parentNode.payload.parentNode.rateScale !== undefined) { - displaceFactor++ + if (thisObject.payload.parentNode.payload.parentNode.rateScale.payload.isVisible === true) { + displaceFactor++ + } } for (let i = 0; i < thisObject.payload.parentNode.payload.parentNode.timelineCharts.length; i++) { let timelineChart = thisObject.payload.parentNode.payload.parentNode.timelineCharts[i] if (timelineChart.rateScale !== undefined) { if (thisObject.payload.node.id !== timelineChart.rateScale.id) { - displaceFactor++ + if (timelineChart.rateScale.payload.isVisible === true) { + displaceFactor++ + } } else { break } @@ -366,11 +371,17 @@ function newRateScale () { thisObject.container.frame.position.x = ratePoint.x - thisObject.container.frame.width thisObject.isVisible = true + thisObject.payload.isVisible = true if (thisObject.container.frame.position.y + thisObject.container.frame.height * 2 > bottonCorner.y || thisObject.container.frame.position.y - thisObject.container.frame.height * 1 < upCorner.y || thisObject.container.frame.position.x < upCorner.x ) { thisObject.isVisible = false + thisObject.payload.isVisible = false + } + if (thisObject.layersOn === 0) { + thisObject.isVisible = false + thisObject.payload.isVisible = false } } diff --git a/CanvasApp/Scales/TimeFrameScale.js b/CanvasApp/Scales/TimeFrameScale.js index 7354b7a8f..444a2c6e5 100644 --- a/CanvasApp/Scales/TimeFrameScale.js +++ b/CanvasApp/Scales/TimeFrameScale.js @@ -7,6 +7,7 @@ function newTimeFrameScale () { fitFunction: undefined, payload: undefined, isVisible: true, + layersOn: undefined, onMouseOverSomeTimeMachineContainer: onMouseOverSomeTimeMachineContainer, draw: draw, drawForeground: drawForeground, @@ -144,13 +145,17 @@ function newTimeFrameScale () { if (thisObject.payload.parentNode.type === 'Timeline Chart') { if (thisObject.payload.parentNode.payload.parentNode !== undefined) { if (thisObject.payload.parentNode.payload.parentNode.timeFrameScale !== undefined) { - displaceFactor++ + if (thisObject.payload.parentNode.payload.parentNode.timeFrameScale.payload.isVisible === true) { + displaceFactor++ + } } for (let i = 0; i < thisObject.payload.parentNode.payload.parentNode.timelineCharts.length; i++) { let timelineChart = thisObject.payload.parentNode.payload.parentNode.timelineCharts[i] if (timelineChart.timeFrameScale !== undefined) { if (thisObject.payload.node.id !== timelineChart.timeFrameScale.id) { - displaceFactor++ + if (timelineChart.timeFrameScale.payload.isVisible === true) { + displaceFactor++ + } } else { break } @@ -179,9 +184,15 @@ function newTimeFrameScale () { thisObject.container.frame.position.y = timePoint.y - thisObject.container.frame.height thisObject.isVisible = true + thisObject.payload.isVisible = true if (thisObject.container.frame.position.y + thisObject.container.frame.height > bottonCorner.y || thisObject.container.frame.position.y - thisObject.container.frame.height * 3 < upCorner.y) { thisObject.isVisible = false + thisObject.payload.isVisible = false + } + if (thisObject.layersOn === 0) { + thisObject.isVisible = false + thisObject.payload.isVisible = false } } diff --git a/Legacy-Code/AAMasters/plotters/Plotters-Bollinger-Bands/BollingerBands.js b/Legacy-Code/AAMasters/plotters/Plotters-Bollinger-Bands/BollingerBands.js index 2132ef906..b233d428e 100644 --- a/Legacy-Code/AAMasters/plotters/Plotters-Bollinger-Bands/BollingerBands.js +++ b/Legacy-Code/AAMasters/plotters/Plotters-Bollinger-Bands/BollingerBands.js @@ -522,7 +522,7 @@ continue; } - let diffA = bandPoint2.y - canvas.chartSpace.viewport.visibleArea.bottomLeft.y + let diffA = bandPoint1.y - canvas.chartSpace.viewport.visibleArea.bottomLeft.y if (diffA > 0) { bandPoint1.y = bandPoint1.y - diffA bandPoint2.y = bandPoint2.y - diffA @@ -532,7 +532,7 @@ bandPoint6.y = bandPoint6.y - diffA } - let diffB = bandPoint1.y - canvas.chartSpace.viewport.visibleArea.topLeft.y + let diffB = bandPoint2.y - canvas.chartSpace.viewport.visibleArea.topLeft.y if (diffB < 0) { bandPoint1.y = bandPoint1.y - diffB bandPoint2.y = bandPoint2.y - diffB