diff --git a/.vs/Plotters-Candles-Volumes/v15/.suo b/.vs/Plotters-Candles-Volumes/v15/.suo index 3e53531af..51998f4f1 100644 Binary files a/.vs/Plotters-Candles-Volumes/v15/.suo and b/.vs/Plotters-Candles-Volumes/v15/.suo differ diff --git a/Candles.js b/Candles.js index d0ebe2e4b..5e8cb0d86 100644 --- a/Candles.js +++ b/Candles.js @@ -40,76 +40,34 @@ return thisObject; - function initialize(pExchange, pMarket, pDatetime, pTimePeriod, callBackFunction) { + function initialize(pStorage, pExchange, pMarket, pDatetime, pTimePeriod, callBackFunction) { - let cursorCacheInProgress = false; - let finaleStepsInProgress = false; + /* Store the information received. */ + + fileCache = pStorage.fileCache; + fileCursorCache = pStorage.fileCursorCache; datetime = pDatetime; timePeriod = pTimePeriod; - fileCache = newFileCache(); - fileCache.initialize("AAMasters", "AAOlivia", "Candles", "Market Files", pExchange, pMarket, onFileReady); + /* We need a Market File in order to calculate the Y scale, since this scale depends on actual data. */ - function onFileReady() { + marketFile = fileCache.getFile(ONE_DAY_IN_MILISECONDS); // This file is the one processed faster. - let newMarketFile = fileCache.getFile(ONE_DAY_IN_MILISECONDS); + recalculateScale(); + recalculate(); - if (newMarketFile !== undefined) { + /* Now we set the right files according to current Period. */ - marketFile = newMarketFile; + marketFile = fileCache.getFile(pTimePeriod); + fileCursor = fileCursorCache.getFileCursor(pTimePeriod); - initializeFileCursorCache(); + /* Listen to the necesary events. */ - } - } + viewPort.eventHandler.listenToEvent("Zoom Changed", onZoomChanged); + canvas.eventHandler.listenToEvent("Drag Finished", onDragFinished); - function initializeFileCursorCache() { - - if (cursorCacheInProgress === false) { - - cursorCacheInProgress = true; - - fileCursorCache = newFileCursorCache(); - fileCursorCache.initialize("AAMasters", "AAOlivia", "Candles", "Daily Files", pExchange, pMarket, pDatetime, pTimePeriod, onFileCursorReady); - - } - } - - function onFileCursorReady() { - - recalculate(); - - let newFileCursor = fileCursorCache.getFileCursor(pTimePeriod); - - if (newFileCursor !== undefined) { // if the file ready is the one we need then it and we dont have it yet, then we will continue here. - - let stringDate = datetime.getUTCFullYear() + '-' + pad(datetime.getUTCMonth() + 1, 2) + '-' + pad(datetime.getUTCDate(), 2); - - let dailyFile = newFileCursor.files.get(stringDate); - - if (dailyFile !== undefined) { - - if (finaleStepsInProgress === false) { - - finaleStepsInProgress = true; - - fileCursor = newFileCursor; - - recalculateScale(); // With any of the market files we can calculate the scale. - - recalculate(); - - viewPort.eventHandler.listenToEvent("Zoom Changed", onZoomChanged); - canvas.eventHandler.listenToEvent("Drag Finished", onDragFinished); - - callBackFunction(); - - } - } - } - - } + callBackFunction(); } diff --git a/Volumes.js b/Volumes.js index db889e796..ad1520b2c 100644 --- a/Volumes.js +++ b/Volumes.js @@ -30,82 +30,43 @@ let fileCache; // This object will provide the different Market Files at different Time Periods. let fileCursorCache; // This object will provide the different File Cursors at different Time Periods. + let scaleFile; // This file is used to calculate the scale. + /* these are module specific variables: */ let volumes = []; // Here we keep the volumes to be ploted every time the Draw() function is called by the AAWebPlatform. return thisObject; - function initialize(pExchange, pMarket, pDatetime, pTimePeriod, callBackFunction) { + function initialize(pStorage, pExchange, pMarket, pDatetime, pTimePeriod, callBackFunction) { - let cursorCacheInProgress = false; - let finaleStepsInProgress = false; + /* Store the information received. */ + + fileCache = pStorage.fileCache; + fileCursorCache = pStorage.fileCursorCache; datetime = pDatetime; timePeriod = pTimePeriod; - fileCache = newFileCache(); - fileCache.initialize("AAMasters", "AAOlivia", "Volumes", "Market Files", pExchange, pMarket, onFileReady); + /* We need a Market File in order to calculate the Y scale, since this scale depends on actual data. */ - function onFileReady() { + scaleFile = fileCache.getFile(ONE_DAY_IN_MILISECONDS); // This file is the one processed faster. - let newMarketFile = fileCache.getFile(ONE_DAY_IN_MILISECONDS); + recalculateScaleX(); + recalculate(); + recalculateScaleY(); - if (newMarketFile !== undefined) { + /* Now we set the right files according to current Period. */ - marketFile = newMarketFile; + marketFile = fileCache.getFile(pTimePeriod); + fileCursor = fileCursorCache.getFileCursor(pTimePeriod); - initializeFileCursorCache(); + /* Listen to the necesary events. */ - } - } + viewPort.eventHandler.listenToEvent("Zoom Changed", onZoomChanged); + canvas.eventHandler.listenToEvent("Drag Finished", onDragFinished); - function initializeFileCursorCache() { - - if (cursorCacheInProgress === false) { - - cursorCacheInProgress = true; - - fileCursorCache = newFileCursorCache(); - fileCursorCache.initialize("AAMasters", "AAOlivia", "Volumes", "Daily Files", pExchange, pMarket, pDatetime, pTimePeriod, onFileCursorReady); - - } - } - - function onFileCursorReady() { - - recalculate(); - - let newFileCursor = fileCursorCache.getFileCursor(pTimePeriod); - - if (newFileCursor !== undefined) { // if the file ready is the one we need then it and we dont have it yet, then we will continue here. - - let stringDate = datetime.getUTCFullYear() + '-' + pad(datetime.getUTCMonth() + 1, 2) + '-' + pad(datetime.getUTCDate(), 2); - - let dailyFile = newFileCursor.files.get(stringDate); - - if (dailyFile !== undefined) { - - if (finaleStepsInProgress === false) { - - finaleStepsInProgress = true; - - fileCursor = newFileCursor; - - recalculateScaleX(); - recalculate(); - recalculateScaleY(); - - viewPort.eventHandler.listenToEvent("Zoom Changed", onZoomChanged); - canvas.eventHandler.listenToEvent("Drag Finished", onDragFinished); - - callBackFunction(); - - } - } - } - - } + callBackFunction(); } @@ -404,9 +365,9 @@ let maxValue = 0; - for (var i = 0; i < marketFile.length; i++) { + for (var i = 0; i < scaleFile.length; i++) { - let currentMax = (marketFile[i][0] + marketFile[i][1]) * 4; + let currentMax = (scaleFile[i][0] + scaleFile[i][1]) * 4; if (maxValue < currentMax) { maxValue = currentMax;