diff --git a/Animation.js b/Animation.js index d27dc114c..01ce1f6f5 100644 --- a/Animation.js +++ b/Animation.js @@ -1,7 +1,6 @@ function newAnimation () { const MODULE_NAME = 'Animation' - const INFO_LOG = false const ERROR_LOG = true const logger = newWebDebugLog() logger.fileName = MODULE_NAME @@ -29,75 +28,31 @@ function newAnimation () { return thisObject function finalize () { - try { - if (INFO_LOG === true) { logger.write('[INFO] finalize -> Entering function.') } - - thisObject.stop() - } catch (err) { - if (ERROR_LOG === true) { logger.write('[ERROR] finalize -> err = ' + err.stack) } - }s + thisObject.stop() } - function initialize (callBackFunction) { - try { - if (INFO_LOG === true) { logger.write('[INFO] initialize -> Entering function.') } + function initialize () { - /* Nothing to do here yet. */ - callBackFunction(GLOBAL.CUSTOM_OK_RESPONSE) - } catch (err) { - if (ERROR_LOG === true) { logger.write('[ERROR] initialize -> err = ' + err.stack) } - callBackFunction(GLOBAL.DEFAULT_FAIL_RESPONSE) - } } - function start (callBackFunction) { - try { - if (INFO_LOG === true) { logger.write('[INFO] start -> Entering function.') } - - animationLoop() // Inside this function the animation process is started, and at the same time it creates a loop. - } catch (err) { - if (ERROR_LOG === true) { logger.write('[ERROR] start -> err = ' + err.stack) } - callBackFunction(GLOBAL.DEFAULT_FAIL_RESPONSE) - } + function start () { + animationLoop() // Inside this function the animation process is started, and at the same time it creates a loop. } - function stop (callBackFunction) { - try { - if (INFO_LOG === true) { logger.write('[INFO] stop -> Entering function.') } - - window.cancelAnimationFrame(animationLoopHandle) - } catch (err) { - if (ERROR_LOG === true) { logger.write('[ERROR] stop -> err = ' + err.stack) } - callBackFunction(GLOBAL.DEFAULT_FAIL_RESPONSE) - } + function stop () { + window.cancelAnimationFrame(animationLoopHandle) } - function addCallBackFunction (key, callBack, callBackFunction) { - try { - if (INFO_LOG === true) { logger.write('[INFO] addCallBackFunction -> Entering function.') } - - callBackFunctions.set(key, callBack) - } catch (err) { - if (ERROR_LOG === true) { logger.write('[ERROR] addCallBackFunction -> err = ' + err.stack) } - callBackFunction(GLOBAL.DEFAULT_FAIL_RESPONSE) - } + function addCallBackFunction (key, callBack) { + callBackFunctions.set(key, callBack) } - function removeCallBackFunction (key, callBackFunction) { - try { - if (INFO_LOG === true) { logger.write('[INFO] removeCallBackFunction -> Entering function.') } - - callBackFunctions.delete(key) - } catch (err) { - if (ERROR_LOG === true) { logger.write('[ERROR] removeCallBackFunction -> err = ' + err.stack) } - callBackFunction(GLOBAL.DEFAULT_FAIL_RESPONSE) - } + function removeCallBackFunction (key) { + callBackFunctions.delete(key) } function animationLoop () { try { - if (INFO_LOG === true) { logger.write('[INFO] animationLoop -> Entering function.') } - if (window.canvasApp.visible === true) { /* We set the canvas to its normal width and height */ @@ -140,4 +95,3 @@ function newAnimation () { browserCanvasContext.fill() } } - diff --git a/Canvas.js b/Canvas.js index 3bc45b757..33e8e77d4 100644 --- a/Canvas.js +++ b/Canvas.js @@ -7,7 +7,6 @@ let splashScreenNeeded = true function newCanvas () { const MODULE_NAME = 'Canvas' - const INFO_LOG = false const ERROR_LOG = true const logger = newWebDebugLog() logger.fileName = MODULE_NAME @@ -52,8 +51,6 @@ function newCanvas () { function finalize () { try { - if (INFO_LOG === true) { logger.write('[INFO] finalize -> Entering function.') } - thisObject.chartSpace.finalize() thisObject.floatingSpace.finalize() @@ -78,10 +75,8 @@ function newCanvas () { } } - async function initialize (callBackFunction) { + async function initialize () { try { - if (INFO_LOG === true) { logger.write('[INFO] initialize -> Entering function.') } - initializeBrowserCanvas() addCanvasEvents() @@ -110,12 +105,9 @@ function newCanvas () { function onCharSpaceInitialized (err) { try { - if (INFO_LOG === true) { logger.write('[INFO] initialize -> onCharSpaceInitialized -> Entering function.') } - viewPort.raiseEvents() // These events will impacts on objects just initialized. } catch (err) { if (ERROR_LOG === true) { logger.write('[ERROR] initialize -> onCharSpaceInitialized -> err = ' + err.stack) } - callBackFunction(GLOBAL.DEFAULT_FAIL_RESPONSE) } } @@ -125,90 +117,32 @@ function newCanvas () { splashScreen.initialize() let animation = newAnimation() - animation.initialize(onAnimationInitialized) + animation.initialize() - function onAnimationInitialized (err) { - try { - if (INFO_LOG === true) { logger.write('[INFO] initialize -> onAnimationInitialized -> Entering function.') } - - thisObject.animation = animation + thisObject.animation = animation /* Here we add all the functions that will be called during the animation cycle. */ - animation.addCallBackFunction('Floating Space Draw', thisObject.floatingSpace.draw, onFunctionAdded) - animation.addCallBackFunction('Floating Space Physics', thisObject.floatingSpace.physics, onFunctionAdded) - animation.addCallBackFunction('Chart Space Background', thisObject.chartSpace.drawBackground, onFunctionAdded) - animation.addCallBackFunction('Chart Space Draw', thisObject.chartSpace.draw, onFunctionAdded) - animation.addCallBackFunction('Chart Space Physics', thisObject.chartSpace.physics, onFunctionAdded) - animation.addCallBackFunction('Panels Space', thisObject.panelsSpace.draw, onFunctionAdded) - animation.addCallBackFunction('ViewPort Animate', viewPort.animate, onFunctionAdded) - animation.addCallBackFunction('CockpitSpace Draw', thisObject.cockpitSpace.draw, onFunctionAdded) - animation.addCallBackFunction('CockpitSpace Physics', thisObject.cockpitSpace.physics, onFunctionAdded) - animation.addCallBackFunction('Top Space Draw', thisObject.topSpace.draw, onFunctionAdded) - animation.addCallBackFunction('Strategy Space Draw', thisObject.strategySpace.draw, onFunctionAdded) - animation.addCallBackFunction('Splash Screen Draw', splashScreen.draw, onFunctionAdded) - animation.start(onStart) - - function onFunctionAdded (err) { - try { - if (INFO_LOG === true) { logger.write('[INFO] initialize -> onAnimationInitialized -> onFunctionAdded -> Entering function.') } - - if (err.result === GLOBAL.DEFAULT_FAIL_RESPONSE.result) { - animation.stop() - - if (ERROR_LOG === true) { logger.write('[ERROR] initialize -> onAnimationInitialized -> onFunctionAdded -> Animation Stopped since a vital funtion could not be added.') } - - /* Display some Error Page here. */ - } - } catch (err) { - if (ERROR_LOG === true) { logger.write('[ERROR] initialize -> onAnimationInitialized -> onFunctionAdded -> err = ' + err.stack) } - callBackFunction(GLOBAL.DEFAULT_FAIL_RESPONSE) - } - } - - function onStart (err) { - try { - if (INFO_LOG === true) { logger.write('[INFO] initialize -> onAnimationInitialized -> onStart -> Entering function.') } - - switch (err.result) { - case GLOBAL.DEFAULT_OK_RESPONSE.result: { - if (INFO_LOG === true) { logger.write('[INFO] initialize -> onAnimationInitialized -> onStart -> Received OK Response.') } - callBackFunction(GLOBAL.DEFAULT_OK_RESPONSE) - return - } - - case GLOBAL.DEFAULT_FAIL_RESPONSE.result: { - if (INFO_LOG === true) { logger.write('[INFO] initialize -> onAnimationInitialized -> onStart -> Received FAIL Response.') } - callBackFunction(GLOBAL.DEFAULT_FAIL_RESPONSE) - return - } - - default: { - if (INFO_LOG === true) { logger.write('[INFO] initialize -> onAnimationInitialized -> onStart -> Received Unexpected Response.') } - callBackFunction(err) - return - } - } - } catch (err) { - if (ERROR_LOG === true) { logger.write('[ERROR] initialize -> onAnimationInitialized -> onStart -> err = ' + err.stack) } - callBackFunction(GLOBAL.DEFAULT_FAIL_RESPONSE) - } - } - } catch (err) { - if (ERROR_LOG === true) { logger.write('[ERROR] initialize -> onAnimationInitialized -> err = ' + err.stack) } - callBackFunction(GLOBAL.DEFAULT_FAIL_RESPONSE) - } - } + animation.addCallBackFunction('Floating Space Draw', thisObject.floatingSpace.draw) + animation.addCallBackFunction('Floating Space Physics', thisObject.floatingSpace.physics) + animation.addCallBackFunction('Chart Space Background', thisObject.chartSpace.drawBackground) + animation.addCallBackFunction('Chart Space Draw', thisObject.chartSpace.draw) + animation.addCallBackFunction('Chart Space Physics', thisObject.chartSpace.physics) + animation.addCallBackFunction('Panels Space', thisObject.panelsSpace.draw) + animation.addCallBackFunction('ViewPort Animate', viewPort.animate) + animation.addCallBackFunction('CockpitSpace Draw', thisObject.cockpitSpace.draw) + animation.addCallBackFunction('CockpitSpace Physics', thisObject.cockpitSpace.physics) + animation.addCallBackFunction('Top Space Draw', thisObject.topSpace.draw) + animation.addCallBackFunction('Strategy Space Draw', thisObject.strategySpace.draw) + animation.addCallBackFunction('Splash Screen Draw', splashScreen.draw) + animation.start() } catch (err) { if (ERROR_LOG === true) { logger.write('[ERROR] initialize -> err = ' + err.stack) } - callBackFunction(GLOBAL.DEFAULT_FAIL_RESPONSE) } } function initializeBrowserCanvas () { try { - if (INFO_LOG === true) { logger.write('[INFO] initializeBrowserCanvas -> Entering function.') } - browserCanvasContext = browserCanvas.getContext('2d') // browserCanvasContext.font = 'italic small-caps bold 12px Saira' browserCanvasContext.font = 'Saira' @@ -221,8 +155,6 @@ function newCanvas () { function addCanvasEvents () { try { - if (INFO_LOG === true) { logger.write('[INFO] addCanvasEvents -> Entering function.') } - /* Mouse down and up events to control the drag of the canvas. */ browserCanvas.addEventListener('mousedown', onMouseDown, false) @@ -253,21 +185,6 @@ function newCanvas () { function onMouseDown (event) { try { - if (INFO_LOG === true) { logger.write('[INFO] onMouseDown -> Entering function.') } - - /* - - There are four types of elements that can be dragged. - - 1. Panels. - 2. Floating Elements (Currently only FloatingObjects). - 3. Charts. - 4. The Viewport. - - We eveluate each space in order to see if they are holding the element being dragged, and we fallout at the Viewport. - - */ - let point = { x: event.pageX, y: event.pageY - window.canvasApp.topMargin @@ -362,8 +279,6 @@ function newCanvas () { function onMouseClick (event) { try { - if (INFO_LOG === true) { logger.write('[INFO] onMouseClick -> Entering function.') } - if (ignoreNextClick === true) { ignoreNextClick = false return @@ -611,8 +526,6 @@ function newCanvas () { function onMouseWheel (event) { try { - if (INFO_LOG === true) { logger.write('[INFO] onMouseWheel -> Entering function.') } - // cross-browser wheel delta var event = window.event || event // old IE support let delta = Math.max(-1, Math.min(1, event.wheelDelta || -event.detail)) 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/GraphQLRestartSimulation.js b/CockpitSpace/GraphQLRestartSimulation.js new file mode 100644 index 000000000..53c5d2e37 --- /dev/null +++ b/CockpitSpace/GraphQLRestartSimulation.js @@ -0,0 +1,39 @@ + +async function graphQlRestartSimulation (simulationParams) { + try { + const accessToken = window.localStorage.getItem(LOGGED_IN_ACCESS_TOKEN_LOCAL_STORAGE_KEY) + + if (accessToken === null) { + throw new Error('Can not restart the simulation because the user is not logged in. ') + } + + const graphQLServer = await axios({ + url: window.canvasApp.graphQL.masterAppApiUrl, + method: 'post', + data: { + query: ` + mutation operations_RunSimulation( + $simulation: operations_SimulationInput) + { + operations_RunSimulation(simulation: $simulation) + } + `, + variables: { + simulation: simulationParams + } + }, + headers: { + authorization: 'Bearer ' + accessToken + } + }) + + if (graphQLServer.data.errors) { + console.log(err.stack) + throw new Error(graphQLServer.data.errors[0].message) + } + } catch (err) { + console.log(err.stack) + throw new Error('There has been an error restarting the simulation. Error: ' + err.stack) + } +} + diff --git a/CockpitSpace/RestartSimulation.js b/CockpitSpace/RestartSimulation.js new file mode 100644 index 000000000..f82de480c --- /dev/null +++ b/CockpitSpace/RestartSimulation.js @@ -0,0 +1,216 @@ + +function newRestartSimulation () { + const MODULE_NAME = 'Restart Simulation' + + let thisObject = { + visible: true, + container: undefined, + status: undefined, + physics: physics, + draw: draw, + getContainer: getContainer, + initialize: initialize, + finalize: finalize + } + + thisObject.container = newContainer() + thisObject.container.initialize(MODULE_NAME) + + thisObject.container.isDraggeable = false + thisObject.container.isWheelable = false + thisObject.container.isClickeable = true + thisObject.container.detectMouseOver = true + + let selfMouseOverEventSubscriptionId + let selfMouseClickEventSubscriptionId + let selfMouseNotOverEventSubscriptionId + + let isMouseOver = false + let counterTillNextState = 0 + + return thisObject + + function finalize () { + thisObject.container.eventHandler.stopListening(selfMouseOverEventSubscriptionId) + thisObject.container.eventHandler.stopListening(selfMouseClickEventSubscriptionId) + thisObject.container.eventHandler.stopListening(selfMouseNotOverEventSubscriptionId) + + thisObject.container.finalize() + thisObject.container = undefined + } + + function initialize () { + thisObject.container.frame.position.x = thisObject.container.parentContainer.frame.width * 80 / 100 + thisObject.container.frame.position.y = 6 + thisObject.container.frame.width = 250 + thisObject.container.frame.height = COCKPIT_SPACE_HEIGHT - 12 + + selfMouseOverEventSubscriptionId = thisObject.container.eventHandler.listenToEvent('onMouseOver', onMouseOver) + selfMouseClickEventSubscriptionId = thisObject.container.eventHandler.listenToEvent('onMouseClick', onMouseClick) + selfMouseNotOverEventSubscriptionId = thisObject.container.eventHandler.listenToEvent('onMouseNotOver', onMouseNotOver) + + thisObject.status = 'Ready' + } + + function getContainer (point, purpose) { + if (thisObject.visible !== true || thisObject.status !== 'Ready') { return } + + if (thisObject.container.frame.isThisPointHere(point, true) === true) { + return thisObject.container + } else { + return undefined + } + } + + function onMouseOver (point) { + if (thisObject.container.frame.isThisPointHere(point, true, false) === true) { + isMouseOver = true + } else { + isMouseOver = false + } + } + + function onMouseNotOver (point) { + isMouseOver = false + } + + 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: dateAtScreenCorner.valueOf() / 1000 | 0, + resumeExecution: false, + timePeriodDailyArray: timePeriodDailyArray, + timePeriodMarketArray: timePeriodMarketArray + } + try { + thisObject.status = 'Restarting' + await graphQlRestartSimulation(simulationParams) + thisObject.status = 'Calculating' + counterTillNextState = 1000 + } catch (err) { + thisObject.status = 'Error' + counterTillNextState = 500 + } + } + + function physics () { + if (counterTillNextState > 0) { + counterTillNextState-- + + if (counterTillNextState === 0) { + switch (thisObject.status) { + case 'Ready': + + break + case 'Restarting': + + break + case 'Calculating': + thisObject.status = 'Ready' + break + case 'Error': + thisObject.status = 'Ready' + break + } + } + } + } + + function draw () { + if (thisObject.visible !== true) { return } + drawBackground() + drawText() + } + + function drawBackground () { + let params = { + cornerRadius: 3, + lineWidth: 0.01, + container: thisObject.container, + borderColor: UI_COLOR.DARK, + castShadow: false, + opacity: 1 + } + + switch (thisObject.status) { + case 'Ready': { + if (isMouseOver === true) { + params.backgroundColor = UI_COLOR.TURQUOISE + } else { + params.backgroundColor = UI_COLOR.DARK_TURQUOISE + } + break + } + case 'Restarting': + params.backgroundColor = UI_COLOR.GREY + break + case 'Calculating': + params.backgroundColor = UI_COLOR.TITANIUM_YELLOW + break + case 'Error': + params.backgroundColor = UI_COLOR.RUSTED_RED + break + } + + roundedCornersBackground(params) + } + + function drawText () { + let fontSize + let label + let xOffset + let yOffset + + const OPACITY = 1 + + /* We put the params.VALUE in the middle */ + + fontSize = 15 + + browserCanvasContext.font = 'bold ' + fontSize + 'px ' + UI_FONT.PRIMARY + + switch (thisObject.status) { + case 'Ready': + label = 'RESTART SIMULATION' + break + case 'Restarting': + label = 'RESTARTING...' + break + case 'Calculating': + label = 'CALCULATING...' + break + case 'Error': + label = 'NOT POSSIBLE NOW' + break + } + + let labelPoint = { + x: thisObject.container.frame.width / 2 - label.length / 2 * fontSize * FONT_ASPECT_RATIO - 15, + y: thisObject.container.frame.height - 9 + } + labelPoint = thisObject.container.frame.frameThisPoint(labelPoint) + + browserCanvasContext.fillStyle = 'rgba(' + UI_COLOR.WHITE + ', ' + OPACITY + ')' + browserCanvasContext.fillText(label, labelPoint.x, labelPoint.y) + } +} diff --git a/Dashboard.js b/Dashboard.js index cb57b4fe3..63e3176af 100644 --- a/Dashboard.js +++ b/Dashboard.js @@ -6,7 +6,6 @@ let viewPort = newViewPort() function newDashboard () { const MODULE_NAME = 'Dashboard' - const INFO_LOG = false const ERROR_LOG = true const INTENSIVE_LOG = false const logger = newWebDebugLog() @@ -25,8 +24,6 @@ function newDashboard () { function start () { try { - if (INFO_LOG === true) { logger.write('[INFO] start -> Entering function.') } - /* If this method is executed for a second time, it should finalize the current execution structure */ if (canvas !== undefined) { canvas.finalize() } @@ -40,8 +37,6 @@ function newDashboard () { loadImages(onImagesLoaded) function onImagesLoaded () { - if (INFO_LOG === true) { logger.write('[INFO] start -> onImagesLoaded -> Entering function.') } - /* Next we start the App */ setTimeout(delayedStart, DEBUG_START_UP_DELAY) @@ -53,8 +48,6 @@ function newDashboard () { function delayedStart () { try { - if (INFO_LOG === true) { logger.write('[INFO] delayedStart -> Entering function.') } - /* For now, we are supporting only one market. */ let market = { @@ -76,8 +69,6 @@ function newDashboard () { function userProfileChanged () { try { - if (INFO_LOG === true) { logger.write('[INFO] userProfileChanged -> Entering function.') } - canvas.topSpace.initialize() } catch (err) { if (ERROR_LOG === true) { logger.write('[ERROR] userProfileChanged -> err = ' + err.stack) } @@ -86,8 +77,6 @@ function newDashboard () { function browserResized () { try { - if (INFO_LOG === true) { logger.write('[INFO] browserResized -> Entering function.') } - browserCanvas = document.getElementById('canvas') browserCanvas.width = window.innerWidth @@ -101,8 +90,6 @@ function newDashboard () { function loadImages (callBack) { try { - if (INFO_LOG === true) { logger.write('[INFO] loadImages -> Entering function.') } - const accessToken = '' /* diff --git a/Globals.js b/Globals.js index 7fb404879..d25a99d1c 100644 --- a/Globals.js +++ b/Globals.js @@ -122,9 +122,17 @@ function convertTimePeriodToName(pTimePeriod) { window.AT_BREAKPOINT = false; +let testUser = window.localStorage.getItem("test_user") +let LOGGED_IN_USER_LOCAL_STORAGE_KEY +let LOGGED_IN_ACCESS_TOKEN_LOCAL_STORAGE_KEY -const LOGGED_IN_USER_LOCAL_STORAGE = "xuser" -const LOGGED_IN_ACCESS_TOKEN_LOCAL_STORAGE = "xaccess_token" +if (testUser !== null) { + LOGGED_IN_USER_LOCAL_STORAGE_KEY = "test_user" + LOGGED_IN_ACCESS_TOKEN_LOCAL_STORAGE_KEY = "test_access_token" +} else { + LOGGED_IN_USER_LOCAL_STORAGE_KEY = "user" + LOGGED_IN_ACCESS_TOKEN_LOCAL_STORAGE_KEY = "access_token" +} const USDT_BTC_HTH = 19900; // This is needed to know the scale of the market time line. 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 } diff --git a/Spaces/CockpitSpace.js b/Spaces/CockpitSpace.js index 29096fa78..36d5477ff 100644 --- a/Spaces/CockpitSpace.js +++ b/Spaces/CockpitSpace.js @@ -6,6 +6,7 @@ container: undefined, status: 'BOTTOM', assetBalances: undefined, + restartSimulation: undefined, draw: draw, physics: physics, getContainer: getContainer, @@ -16,6 +17,7 @@ thisObject.container = newContainer() thisObject.container.initialize(MODULE_NAME) thisObject.container.isClickeable = false + thisObject.container.detectMouseOver = true thisObject.container.isDraggeable = true thisObject.container.notDraggingOnX = true @@ -34,6 +36,7 @@ thisObject.container.finalize() thisObject.container = undefined thisObject.assetBalances = undefined + thisObject.restartSimulation = undefined } function initialize () { @@ -42,6 +45,10 @@ thisObject.assetBalances = newAssetBalances() thisObject.assetBalances.initialize() + + thisObject.restartSimulation = newRestartSimulation() + thisObject.restartSimulation.container.connectToParent(thisObject.container) + thisObject.restartSimulation.initialize() } function onMouseClick (event) { @@ -57,11 +64,19 @@ } function physics () { + thisObjectPhysics() + childrenPhysics() + } + + function childrenPhysics () { + thisObject.restartSimulation.physics() + } + function thisObjectPhysics () { /* Check the limits */ thisObject.status = 'MIDDLE' - let user = window.localStorage.getItem(LOGGED_IN_USER_LOCAL_STORAGE) + let user = window.localStorage.getItem(LOGGED_IN_USER_LOCAL_STORAGE_KEY) if (user !== null) { // Only if user is logged in thisObject.container.isDraggeable = true } else { @@ -89,6 +104,11 @@ } function getContainer (point) { + let container + + container = thisObject.restartSimulation.getContainer(point) + if (container !== undefined) { return container } + if (thisObject.container.frame.isThisPointHere(point, true) === true) { return thisObject.container } else { @@ -102,6 +122,7 @@ drawBackground() thisObject.assetBalances.draw() + thisObject.restartSimulation.draw() } function drawBackground () { @@ -134,7 +155,7 @@ browserCanvasContext.closePath() browserCanvasContext.fill() - let user = window.localStorage.getItem(LOGGED_IN_USER_LOCAL_STORAGE) + let user = window.localStorage.getItem(LOGGED_IN_USER_LOCAL_STORAGE_KEY) if (user !== null) { // Only if user is logged in arrow() } @@ -228,4 +249,3 @@ browserCanvasContext.stroke() } } - diff --git a/StrategySpace/Workspace.js b/StrategySpace/Workspace.js index d03cf2b35..d533d8c14 100644 --- a/StrategySpace/Workspace.js +++ b/StrategySpace/Workspace.js @@ -41,9 +41,9 @@ function newWorkspace () { async function saveToStrategyzer () { try { - const accessToken = window.localStorage.getItem(LOGGED_IN_ACCESS_TOKEN_LOCAL_STORAGE) + const accessToken = window.localStorage.getItem(LOGGED_IN_ACCESS_TOKEN_LOCAL_STORAGE_KEY) - let user = window.localStorage.getItem(LOGGED_IN_USER_LOCAL_STORAGE) + let user = window.localStorage.getItem(LOGGED_IN_USER_LOCAL_STORAGE_KEY) if (user === null) { if (ERROR_LOG === true) { logger.write('[ERROR] saveToStrategyzer -> Can not save because user is not logged in. ') } return @@ -91,7 +91,7 @@ function newWorkspace () { resolve(true) }) .catch(err => { - if (ERROR_LOG === true) { logger.write('[ERROR] saveToStrategyzer -> ApolloClient error getting user strategies -> err = ' + err.stack) } + if (ERROR_LOG === true) { logger.write('[ERROR] saveToStrategyzer -> ApolloClient error updating user strategies -> err = ' + err.stack) } reject(err) }) }) @@ -253,9 +253,9 @@ function newWorkspace () { async function loadFromStrategyzer () { try { - const accessToken = window.localStorage.getItem(LOGGED_IN_ACCESS_TOKEN_LOCAL_STORAGE) + const accessToken = window.localStorage.getItem(LOGGED_IN_ACCESS_TOKEN_LOCAL_STORAGE_KEY) - let user = window.localStorage.getItem(LOGGED_IN_USER_LOCAL_STORAGE) + let user = window.localStorage.getItem(LOGGED_IN_USER_LOCAL_STORAGE_KEY) if (user === null) { // if there is no user that means that we are logged off, which means this object can not be used. return