diff --git a/ChartsSpace/TimeMachine.js b/ChartsSpace/TimeMachine.js index b5a373126..b511509aa 100644 --- a/ChartsSpace/TimeMachine.js +++ b/ChartsSpace/TimeMachine.js @@ -11,15 +11,15 @@ each one with it own charts, and each one positioned at an especific point in ti function newTimeMachine () { const MODULE_NAME = 'Time Machine' - const INFO_LOG = false const logger = newWebDebugLog() logger.fileName = MODULE_NAME let thisObject = { container: undefined, + charts: [], + physics: physics, drawBackground: drawBackground, draw: draw, - charts: [], getContainer: getContainer, // returns the inner most container that holds the point received by parameter. initialize: initialize, finalize: finalize @@ -41,28 +41,20 @@ function newTimeMachine () { const SEPARATION_BETWEEN_TIMELINE_CHARTS = 1.5 let timeScale - let rigthScale + let rateScale let timeLineCoordinateSystem = newTimeLineCoordinateSystem() return thisObject function finalize () { - try { - if (INFO_LOG === true) { logger.write('[INFO] finalize -> Entering function.') } - - for (let i = 0; i < thisObject.charts.length; i++) { - let chart = thisObject.charts[i] - chart.finalize() - } - } catch (err) { - if (ERROR_LOG === true) { logger.write('[ERROR] finalize -> err = ' + err.stack) } + for (let i = 0; i < thisObject.charts.length; i++) { + let chart = thisObject.charts[i] + chart.finalize() } } function initialize (callBackFunction) { - if (INFO_LOG === true) { logger.write('[INFO] initialize -> Entering function.') } - /* Each Time Machine has a Control Panel. */ let panelOwner = 'Global' @@ -114,21 +106,19 @@ function newTimeMachine () { timeScale.initialize(timeLineCoordinateSystem) - rigthScale = newRateScale() - rigthScale.container.connectToParent(thisObject.container, false, false, false, true, true, true) - rigthScale.container.eventHandler.listenToEvent('Height Percentage Changed', function (event) { + rateScale = newRateScale() + rateScale.container.connectToParent(thisObject.container, false, false, false, true, true, true) + rateScale.container.eventHandler.listenToEvent('Height Percentage Changed', function (event) { thisObject.container.frame.height = TIME_MACHINE_HEIGHT * event.heightPercentage / 100 thisObject.container.eventHandler.raiseEvent('Dimmensions Changed', event) }) - rigthScale.initialize(timeLineCoordinateSystem) + rateScale.initialize(timeLineCoordinateSystem) initializeTheRest() } function initializeTheRest () { - if (INFO_LOG === true) { logger.write('[INFO] initialize -> initializeTheRest -> Entering function.') } - let leftToInitialize = SUPPORTED_EXCHANGES.length * SUPPORTED_MARKETS.length - 1 // The default exchange and market was already initialized. let alreadyInitialized = 0 @@ -153,8 +143,6 @@ function newTimeMachine () { } function initializeTimelineChart (exchange, market) { - if (INFO_LOG === true) { logger.write('[INFO] initialize -> initializeTheRest -> initializeTimelineChart -> Entering function.') } - let timelineChart = newTimelineChart() timelineChart.container.connectToParent(thisObject.container, true, true, false, true, true, true) @@ -169,8 +157,6 @@ function newTimeMachine () { timelineChart.initialize(exchange, market, timeLineCoordinateSystem, finalSteps) function finalSteps () { - if (INFO_LOG === true) { logger.write('[INFO] initialize -> initializeTheRest -> initializeTimelineChart -> finalSteps -> Entering function.') } - thisObject.charts.push(timelineChart) controlPanel.container.eventHandler.listenToEvent('Datetime Changed', timelineChart.setDatetime, undefined) @@ -198,8 +184,8 @@ function newTimeMachine () { } } - if (rigthScale !== undefined) { - container = rigthScale.getContainer(point) + if (rateScale !== undefined) { + container = rateScale.getContainer(point) if (container !== undefined) { if (container.isForThisPurpose(purpose)) { return container @@ -228,6 +214,24 @@ function newTimeMachine () { } } + function physics () { + thisObjectPhysics() + childrenPhysics() + } + + function thisObjectPhysics () { + + } + + function childrenPhysics () { + timeScale.physics() + rateScale.physics() + for (let i = 0; i < thisObject.charts.length; i++) { + let chart = thisObject.charts[i] + chart.physics() + } + } + function drawBackground () { thisBackground() @@ -247,7 +251,7 @@ function newTimeMachine () { } if (timeScale !== undefined) { timeScale.draw() } - if (rigthScale !== undefined) { rigthScale.draw() } + if (rateScale !== undefined) { rateScale.draw() } // thisObject.container.frame.draw(false, true, false) } @@ -269,8 +273,6 @@ function newTimeMachine () { } function recalculateScale () { - if (INFO_LOG === true) { logger.write('[INFO] recalculateScale -> Entering function.') } - let minValue = { x: MIN_PLOTABLE_DATE.valueOf(), y: 0 diff --git a/ChartsSpace/TimelineChart.js b/ChartsSpace/TimelineChart.js index f9d1aad60..bce46cf18 100644 --- a/ChartsSpace/TimelineChart.js +++ b/ChartsSpace/TimelineChart.js @@ -14,6 +14,7 @@ function newTimelineChart () { let thisObject = { container: undefined, fitFunction: undefined, + physics: physics, setDatetime: setDatetime, drawBackground: drawBackground, draw: draw, @@ -239,6 +240,19 @@ function newTimelineChart () { return container } + function physics () { + thisObjectPhysics() + childrenPhysics() + } + + function thisObjectPhysics () { + + } + + function childrenPhysics () { + + } + function tooTiny () { if (viewPort.zoomLevel < Math.trunc(-28.25 * 100) / 100) { return true diff --git a/CockpitSpace/RestartSimulation.js b/CockpitSpace/RestartSimulation.js index ae5372145..8515fd996 100644 --- a/CockpitSpace/RestartSimulation.js +++ b/CockpitSpace/RestartSimulation.js @@ -71,11 +71,32 @@ function newRestartSimulation () { } async function onMouseClick (event) { + let dateAtScreenCorner = new Date(window.localStorage.getItem('Date @ Screen Corner')) + let currentTimePeriod = JSON.parse(window.localStorage.getItem('Current Time Period')) + + let timePeriodsMasterArray = [marketFilesPeriods, dailyFilePeriods] + let timePeriodArray = timePeriodsMasterArray[currentTimePeriod.filePeriodIndex] + let timePeriod = timePeriodArray[currentTimePeriod.timePeriodIndex][1] + + let timePeriodDailyArray = [] + let timePeriodMarketArray = [] + + switch (currentTimePeriod.filePeriodIndex) { + case 0: { + timePeriodMarketArray.push(timePeriod) + break + } + case 1: { + timePeriodDailyArray.push(timePeriod) + break + } + } + let simulationParams = { - beginDatetime: 1554087600, - resumeExecution: true, - timePeriodDailyArray: ['05-min', '10-min'], - timePeriodMarketArray: ['01-hs', '02-hs'] + beginDatetime: dateAtScreenCorner.valueOf() / 1000 | 0, + resumeExecution: false, + timePeriodDailyArray: timePeriodDailyArray, + timePeriodMarketArray: timePeriodMarketArray } let result = await graphQlRestartSimulation(simulationParams) @@ -136,3 +157,4 @@ function newRestartSimulation () { browserCanvasContext.fillText(label, labelPoint.x, labelPoint.y) } } + diff --git a/Scales/RateScale.js b/Scales/RateScale.js index 300587042..4d5a08252 100644 --- a/Scales/RateScale.js +++ b/Scales/RateScale.js @@ -2,11 +2,12 @@ function newRateScale () { const MODULE_NAME = 'Right Scale' let thisObject = { + heightPercentage: 100, container: undefined, + physics: physics, draw: draw, getContainer: getContainer, - initialize: initialize, - heightPercentage: 100 + initialize: initialize } const HEIGHT_PERCENTAGE_DEFAULT_VALUE = 50 @@ -101,6 +102,10 @@ function newRateScale () { } } + function physics () { + + } + function draw () { if (visible === false) { return } diff --git a/Scales/TimePeriodScale.js b/Scales/TimePeriodScale.js index 55ba9a6b8..705e4fafe 100644 --- a/Scales/TimePeriodScale.js +++ b/Scales/TimePeriodScale.js @@ -292,6 +292,7 @@ to be visible at the top of the viewPort. */ let event = {} event.timePeriod = thisObject.timePeriod thisObject.container.eventHandler.raiseEvent('Time Period Changed', event) + window.localStorage.setItem('Current Time Period', JSON.stringify({filePeriodIndex: filePeriodIndex, timePeriodIndex: timePeriodIndex})) } } diff --git a/Scales/TimeScale.js b/Scales/TimeScale.js index 5cc926436..631cdb697 100644 --- a/Scales/TimeScale.js +++ b/Scales/TimeScale.js @@ -2,11 +2,12 @@ function newTimeScale () { const MODULE_NAME = 'Time Scale' let thisObject = { + lenghtPercentage: undefined, container: undefined, + physics: physics, draw: draw, getContainer: getContainer, - initialize: initialize, - lenghtPercentage: undefined + initialize: initialize } const LENGHT_PERCENTAGE_DEFAULT_VALUE = 5 @@ -96,6 +97,17 @@ function newTimeScale () { } } + function physics () { + let point = { + x: 0, + y: 0 + } + + let date = getDateFromPoint(point, thisObject.container.parentContainer, timeLineCoordinateSystem) + date = new Date(date) + window.localStorage.setItem('Date @ Screen Corner', date.toUTCString()) + } + function draw () { if (visible === false) { return } @@ -206,3 +218,4 @@ to be visible at the top of the viewPort. */ browserCanvasContext.stroke() } } + diff --git a/Spaces/ChartSpace.js b/Spaces/ChartSpace.js index 2af37d1d0..96aaa7bbc 100644 --- a/Spaces/ChartSpace.js +++ b/Spaces/ChartSpace.js @@ -149,6 +149,11 @@ function newChartSpace () { } function physics () { + thisObjectPhysics() + childrenPhysics() + } + + function thisObjectPhysics () { thisObject.container.frame.height = COCKPIT_SPACE_POSITION if (thisObject.container.frame.height <= 0 / 100) { @@ -160,6 +165,13 @@ function newChartSpace () { viewPort.resize() } + function childrenPhysics () { + for (let i = 0; i < thisObject.timeMachines.length; i++) { + let timeMachine = thisObject.timeMachines[i] + timeMachine.physics() + } + } + function drawBackground () { if (thisObject.visible !== true) { return }