diff --git a/TimeMachine.js b/TimeMachine.js index 75e11f84a..d046453af 100644 --- a/TimeMachine.js +++ b/TimeMachine.js @@ -43,6 +43,8 @@ function newTimeMachine () { let timeScale let rigthScale + let timeLineCoordinateSystem = newTimeLineCoordinateSystem() + return thisObject function finalize () { @@ -67,6 +69,13 @@ function newTimeMachine () { controlPanelHandle = canvas.panelsSpace.createNewPanel('Time Control Panel', undefined, panelOwner) let controlPanel = canvas.panelsSpace.getPanel(controlPanelHandle, panelOwner) + recalculateScale() + + thisObject.container.eventHandler.listenToEvent('Dimmensions Changed', function (event) { + recalculateScale() + moveToUserPosition(thisObject.container, timeLineCoordinateSystem, false, false, event.mousePosition) + }) + /* First, we initialize the market that we are going to show first on screen. Later all the other markets will be initialized on the background. */ let position = 0 // This defines the position of each chart respect to each other. @@ -82,7 +91,7 @@ function newTimeMachine () { position++ - timelineChart.initialize(DEFAULT_EXCHANGE, DEFAULT_MARKET, onDefaultInitialized) + timelineChart.initialize(DEFAULT_EXCHANGE, DEFAULT_MARKET, timeLineCoordinateSystem, onDefaultInitialized) function onDefaultInitialized (err) { if (err.result !== GLOBAL.DEFAULT_OK_RESPONSE.result) { @@ -158,7 +167,7 @@ function newTimeMachine () { position++ - timelineChart.initialize(exchange, market, finalSteps) + timelineChart.initialize(exchange, market, timeLineCoordinateSystem, finalSteps) function finalSteps () { if (INFO_LOG === true) { logger.write('[INFO] initialize -> initializeTheRest -> initializeTimelineChart -> finalSteps -> Entering function.') } @@ -228,4 +237,25 @@ function newTimeMachine () { } return this.container } + + function recalculateScale () { + if (INFO_LOG === true) { logger.write('[INFO] recalculateScale -> Entering function.') } + + let minValue = { + x: EARLIEST_DATE.valueOf(), + y: 0 + } + + let maxValue = { + x: MAX_PLOTABLE_DATE.valueOf(), + y: nextPorwerOf10(USDT_BTC_HTH) / 4 + } + + timeLineCoordinateSystem.initialize( + minValue, + maxValue, + thisObject.container.frame.width, + thisObject.container.frame.height + ) + } } diff --git a/TimelineChart.js b/TimelineChart.js index da21b21be..551d1f2a5 100644 --- a/TimelineChart.js +++ b/TimelineChart.js @@ -6,7 +6,7 @@ const logger = newWebDebugLog() logger.fileName = MODULE_NAME - let timeLineCoordinateSystem = newTimeLineCoordinateSystem() + let timeLineCoordinateSystem let timePeriod = INITIAL_TIME_PERIOD let datetime = INITIAL_DATE @@ -60,22 +60,18 @@ } } - function initialize (pExchange, pMarket, callBackFunction) { + function initialize (pExchange, pMarket, pTimeLineCoordinateSystem, callBackFunction) { try { if (INFO_LOG === true) { logger.write('[INFO] initialize -> Entering function.') } - thisObject.container.eventHandler.listenToEvent('Dimmensions Changed', function (event) { - recalculateScale() - moveToUserPosition(thisObject.container, timeLineCoordinateSystem, false, false, event.mousePosition) - }) - - thisObject.container.eventHandler.listenToEvent('onMouseOver', function (event) { - saveUserPosition(thisObject.container, timeLineCoordinateSystem, event) - }) - /* We load the logow we will need for the background. */ exchange = pExchange market = pMarket + timeLineCoordinateSystem = pTimeLineCoordinateSystem + + thisObject.container.eventHandler.listenToEvent('onMouseOver', function (event) { + saveUserPosition(thisObject.container, timeLineCoordinateSystem, event) + }) let panelOwner = exchange + ' ' + market.assetB + '/' + market.assetA productsPanelHandle = canvas.panelsSpace.createNewPanel('Products Panel', undefined, panelOwner) @@ -122,8 +118,6 @@ breakpointsBar = newBreakpointsBar() breakpointsBar.initialize(thisObject.container, timeLineCoordinateSystem) - recalculateScale() - moveToUserPosition(thisObject.container, timeLineCoordinateSystem) timePeriod = INITIAL_TIME_PERIOD datetime = INITIAL_DATE @@ -253,27 +247,6 @@ return container } - function recalculateScale () { - if (INFO_LOG === true) { logger.write('[INFO] recalculateScale -> Entering function.') } - - let minValue = { - x: EARLIEST_DATE.valueOf(), - y: 0 - } - - let maxValue = { - x: MAX_PLOTABLE_DATE.valueOf(), - y: nextPorwerOf10(USDT_BTC_HTH) / 4 - } - - timeLineCoordinateSystem.initialize( - minValue, - maxValue, - thisObject.container.frame.width, - thisObject.container.frame.height - ) - } - function tooTiny () { if (INTENSIVE_LOG === true) { logger.write('[INFO] tooTiny -> Entering function.') }