From 8df97497df0a9194510ce313a4f415cc4415a107 Mon Sep 17 00:00:00 2001 From: Luis Fernando Molina Date: Thu, 11 Apr 2019 13:56:36 +0200 Subject: [PATCH] Adapted to new version of Canvas App --- Conditions.js | 30 +++++++-------- SimulationExecution.js | 2 +- TradingSimulation.js | 83 ++++++++++++++++++++---------------------- 3 files changed, 55 insertions(+), 60 deletions(-) diff --git a/Conditions.js b/Conditions.js index be917ba1c..cc703ee01 100644 --- a/Conditions.js +++ b/Conditions.js @@ -78,7 +78,7 @@ } catch (err) { - if (ERROR_LOG === true) { logger.write("[ERROR] finalize -> err.message = " + err.message); } + if (ERROR_LOG === true) { logger.write("[ERROR] finalize -> err = " + err.stack); } } } @@ -122,7 +122,7 @@ } catch (err) { - if (ERROR_LOG === true) { logger.write("[ERROR] initialize -> err.message = " + err.message); } + if (ERROR_LOG === true) { logger.write("[ERROR] initialize -> err = " + err.stack); } } } @@ -149,7 +149,7 @@ } catch (err) { - if (ERROR_LOG === true) { logger.write("[ERROR] getContainer -> err.message = " + err.message); } + if (ERROR_LOG === true) { logger.write("[ERROR] getContainer -> err = " + err.stack); } } } @@ -169,7 +169,7 @@ } catch (err) { - if (ERROR_LOG === true) { logger.write("[ERROR] onFilesUpdated -> err.message = " + err.message); } + if (ERROR_LOG === true) { logger.write("[ERROR] onFilesUpdated -> err = " + err.stack); } } } @@ -207,7 +207,7 @@ } catch (err) { - if (ERROR_LOG === true) { logger.write("[ERROR] setTimePeriod -> err.message = " + err.message); } + if (ERROR_LOG === true) { logger.write("[ERROR] setTimePeriod -> err = " + err.stack); } } } @@ -235,7 +235,7 @@ } catch (err) { - if (ERROR_LOG === true) { logger.write("[ERROR] onDailyFileLoaded -> err.message = " + err.message); } + if (ERROR_LOG === true) { logger.write("[ERROR] onDailyFileLoaded -> err = " + err.stack); } } } @@ -251,7 +251,7 @@ } catch (err) { - if (ERROR_LOG === true) { logger.write("[ERROR] draw -> err.message = " + err.message); } + if (ERROR_LOG === true) { logger.write("[ERROR] draw -> err = " + err.stack); } } } @@ -275,7 +275,7 @@ } catch (err) { - if (ERROR_LOG === true) { logger.write("[ERROR] recalculate -> err.message = " + err.message); } + if (ERROR_LOG === true) { logger.write("[ERROR] recalculate -> err = " + err.stack); } } } @@ -368,7 +368,7 @@ } catch (err) { - if (ERROR_LOG === true) { logger.write("[ERROR] recalculateUsingDailyFiles -> err.message = " + err.message); } + if (ERROR_LOG === true) { logger.write("[ERROR] recalculateUsingDailyFiles -> err = " + err.stack); } } } @@ -427,7 +427,7 @@ } catch (err) { - if (ERROR_LOG === true) { logger.write("[ERROR] recalculateUsingMarketFiles -> err.message = " + err.message); } + if (ERROR_LOG === true) { logger.write("[ERROR] recalculateUsingMarketFiles -> err = " + err.stack); } } } @@ -480,7 +480,7 @@ } catch (err) { - if (ERROR_LOG === true) { logger.write("[ERROR] recalculateScale -> err.message = " + err.message); } + if (ERROR_LOG === true) { logger.write("[ERROR] recalculateScale -> err = " + err.stack); } } } @@ -517,7 +517,7 @@ } catch (err) { - if (ERROR_LOG === true) { logger.write("[ERROR] plotChart -> err.message = " + err.message); } + if (ERROR_LOG === true) { logger.write("[ERROR] plotChart -> err = " + err.stack); } } } @@ -532,7 +532,7 @@ } catch (err) { - if (ERROR_LOG === true) { logger.write("[ERROR] onZoomChanged -> err.message = " + err.message); } + if (ERROR_LOG === true) { logger.write("[ERROR] onZoomChanged -> err = " + err.stack); } } } @@ -549,7 +549,7 @@ } catch (err) { - if (ERROR_LOG === true) { logger.write("[ERROR] onOffsetChanged -> err.message = " + err.message); } + if (ERROR_LOG === true) { logger.write("[ERROR] onOffsetChanged -> err = " + err.stack); } } } @@ -563,7 +563,7 @@ } catch (err) { - if (ERROR_LOG === true) { logger.write("[ERROR] onDragFinished -> err.message = " + err.message); } + if (ERROR_LOG === true) { logger.write("[ERROR] onDragFinished -> err = " + err.stack); } } } } diff --git a/SimulationExecution.js b/SimulationExecution.js index d912be97b..701d65563 100644 --- a/SimulationExecution.js +++ b/SimulationExecution.js @@ -78,7 +78,7 @@ } catch (err) { - if (ERROR_LOG === true) { logger.write("[ERROR] finalize -> err.message = " + err.message); } + if (ERROR_LOG === true) { logger.write("[ERROR] finalize -> err = " + err.stack); } } } diff --git a/TradingSimulation.js b/TradingSimulation.js index a80ab4e41..284937281 100644 --- a/TradingSimulation.js +++ b/TradingSimulation.js @@ -73,6 +73,7 @@ viewPort.eventHandler.stopListening("Offset Changed", onOffsetChanged); marketFiles.eventHandler.stopListening("Files Updated", onFilesUpdated); canvas.eventHandler.stopListening("Drag Finished", onDragFinished); + thisObject.container.eventHandler.stopListening('Dimmensions Changed') /* icons */ @@ -99,7 +100,7 @@ } catch (err) { - if (ERROR_LOG === true) { logger.write("[ERROR] finalize -> err.message = " + err.message); } + if (ERROR_LOG === true) { logger.write("[ERROR] finalize -> err = " + err.stack); } } } @@ -139,6 +140,13 @@ recalculate(); + /* Ready for when dimmension changes. */ + + thisObject.container.eventHandler.listenToEvent('Dimmensions Changed', function () { + recalculateScale() + recalculate(); + }) + /* Loading a few icons */ smileyHappy = loadEmoji("Smiley/Emoji Smiley-51.png"); @@ -171,7 +179,7 @@ } catch (err) { - if (ERROR_LOG === true) { logger.write("[ERROR] initialize -> err.message = " + err.message); } + if (ERROR_LOG === true) { logger.write("[ERROR] initialize -> err = " + err.stack); } } } @@ -198,7 +206,7 @@ } catch (err) { - if (ERROR_LOG === true) { logger.write("[ERROR] getContainer -> err.message = " + err.message); } + if (ERROR_LOG === true) { logger.write("[ERROR] getContainer -> err = " + err.stack); } } } @@ -218,7 +226,7 @@ } catch (err) { - if (ERROR_LOG === true) { logger.write("[ERROR] onFilesUpdated -> err.message = " + err.message); } + if (ERROR_LOG === true) { logger.write("[ERROR] onFilesUpdated -> err = " + err.stack); } } } @@ -256,7 +264,7 @@ } catch (err) { - if (ERROR_LOG === true) { logger.write("[ERROR] setTimePeriod -> err.message = " + err.message); } + if (ERROR_LOG === true) { logger.write("[ERROR] setTimePeriod -> err = " + err.stack); } } } @@ -284,7 +292,7 @@ } catch (err) { - if (ERROR_LOG === true) { logger.write("[ERROR] onDailyFileLoaded -> err.message = " + err.message); } + if (ERROR_LOG === true) { logger.write("[ERROR] onDailyFileLoaded -> err = " + err.stack); } } } @@ -300,7 +308,7 @@ } catch (err) { - if (ERROR_LOG === true) { logger.write("[ERROR] draw -> err.message = " + err.message); } + if (ERROR_LOG === true) { logger.write("[ERROR] draw -> err = " + err.stack); } } } @@ -324,7 +332,7 @@ } catch (err) { - if (ERROR_LOG === true) { logger.write("[ERROR] recalculate -> err.message = " + err.message); } + if (ERROR_LOG === true) { logger.write("[ERROR] recalculate -> err = " + err.stack); } } } @@ -453,7 +461,7 @@ } catch (err) { - if (ERROR_LOG === true) { logger.write("[ERROR] recalculateUsingDailyFiles -> err.message = " + err.message); } + if (ERROR_LOG === true) { logger.write("[ERROR] recalculateUsingDailyFiles -> err = " + err.stack); } } } @@ -550,7 +558,7 @@ } catch (err) { - if (ERROR_LOG === true) { logger.write("[ERROR] recalculateUsingMarketFiles -> err.message = " + err.message); } + if (ERROR_LOG === true) { logger.write("[ERROR] recalculateUsingMarketFiles -> err = " + err.stack); } } } @@ -603,7 +611,7 @@ } catch (err) { - if (ERROR_LOG === true) { logger.write("[ERROR] recalculateScale -> err.message = " + err.message); } + if (ERROR_LOG === true) { logger.write("[ERROR] recalculateScale -> err = " + err.stack); } } } @@ -611,7 +619,8 @@ try { - if (INTENSIVE_LOG === true) { logger.write("[INFO] plotChart -> Entering function."); } + let userPosition = getUserPosition() + let userPositionDate = userPosition.point.x let directionShort; let directionLong; @@ -782,19 +791,14 @@ browserCanvasContext.lineWidth = 1 browserCanvasContext.setLineDash([1, 4]) - if (datetime !== undefined) { - let dateValue = datetime.valueOf(); - if (dateValue >= record.begin && dateValue <= record.end) { - browserCanvasContext.lineWidth = 5 - browserCanvasContext.setLineDash([3, 4]) + if (userPositionDate >= record.begin && userPositionDate <= record.end) { + browserCanvasContext.lineWidth = 5 + browserCanvasContext.setLineDash([3, 4]) - /* highlight the current record */ - browserCanvasContext.strokeStyle = 'rgba(' + UI_COLOR.TITANIUM_YELLOW + ', 1)'; // Current record accroding to time - } + /* highlight the current record */ + browserCanvasContext.strokeStyle = 'rgba(' + UI_COLOR.TITANIUM_YELLOW + ', 1)'; // Current record accroding to time } - - browserCanvasContext.stroke() browserCanvasContext.setLineDash([0, 0]) @@ -817,13 +821,10 @@ browserCanvasContext.strokeStyle = 'rgba(' + UI_COLOR.RUSTED_RED + ', ' + opacity + ''; - if (datetime !== undefined) { - let dateValue = datetime.valueOf(); - if (dateValue >= record.begin && dateValue <= record.end) { + if (userPositionDate >= record.begin && userPositionDate <= record.end) { - /* highlight the current record */ - browserCanvasContext.strokeStyle = 'rgba(' + UI_COLOR.TITANIUM_YELLOW + ', 1)'; // Current record accroding to time - } + /* highlight the current record */ + browserCanvasContext.strokeStyle = 'rgba(' + UI_COLOR.TITANIUM_YELLOW + ', 1)'; // Current record accroding to time } browserCanvasContext.lineWidth = 1 @@ -849,13 +850,10 @@ browserCanvasContext.strokeStyle = 'rgba(' + UI_COLOR.GREEN + ', ' + opacity + ''; - if (datetime !== undefined) { - let dateValue = datetime.valueOf(); - if (dateValue >= record.begin && dateValue <= record.end) { + if (userPositionDate >= record.begin && userPositionDate <= record.end) { - /* highlight the current record */ - browserCanvasContext.strokeStyle = 'rgba(' + UI_COLOR.TITANIUM_YELLOW + ', 1)'; // Current record accroding to time - } + /* highlight the current record */ + browserCanvasContext.strokeStyle = 'rgba(' + UI_COLOR.TITANIUM_YELLOW + ', 1)'; // Current record accroding to time } browserCanvasContext.lineWidth = 1 @@ -959,13 +957,10 @@ browserCanvasContext.strokeStyle = 'rgba(' + UI_COLOR.DARK + ', 0.25)'; - if (datetime !== undefined) { - let dateValue = datetime.valueOf(); - if (dateValue >= record.begin && dateValue <= record.end) { + if (userPositionDate >= record.begin && userPositionDate <= record.end) { - /* highlight the current record */ - browserCanvasContext.strokeStyle = 'rgba(' + UI_COLOR.TITANIUM_YELLOW + ', 1)'; // Current record accroding to time - } + /* highlight the current record */ + browserCanvasContext.strokeStyle = 'rgba(' + UI_COLOR.TITANIUM_YELLOW + ', 1)'; // Current record accroding to time } browserCanvasContext.setLineDash([4, 3]) @@ -1140,7 +1135,7 @@ } catch (err) { - if (ERROR_LOG === true) { logger.write("[ERROR] plotChart -> err.message = " + err.message); } + if (ERROR_LOG === true) { logger.write("[ERROR] plotChart -> err = " + err.stack); } } } @@ -1155,7 +1150,7 @@ } catch (err) { - if (ERROR_LOG === true) { logger.write("[ERROR] onZoomChanged -> err.message = " + err.message); } + if (ERROR_LOG === true) { logger.write("[ERROR] onZoomChanged -> err = " + err.stack); } } } @@ -1172,7 +1167,7 @@ } catch (err) { - if (ERROR_LOG === true) { logger.write("[ERROR] onOffsetChanged -> err.message = " + err.message); } + if (ERROR_LOG === true) { logger.write("[ERROR] onOffsetChanged -> err = " + err.stack); } } } @@ -1186,7 +1181,7 @@ } catch (err) { - if (ERROR_LOG === true) { logger.write("[ERROR] onDragFinished -> err.message = " + err.message); } + if (ERROR_LOG === true) { logger.write("[ERROR] onDragFinished -> err = " + err.stack); } } } }