diff --git a/.vs/AAWebPlatform/v15/.suo b/.vs/AAWebPlatform/v15/.suo index 16a92535e..11f0b3e06 100644 Binary files a/.vs/AAWebPlatform/v15/.suo and b/.vs/AAWebPlatform/v15/.suo differ diff --git a/FileCloud.js b/FileCloud.js index 0a548ff8f..f06b3649d 100644 --- a/FileCloud.js +++ b/FileCloud.js @@ -1,6 +1,8 @@  function newFileCloud() { + const CONSOLE_LOG = true; + var fileCloud = { getFile: getFile, initialize: initialize @@ -50,7 +52,11 @@ function newFileCloud() { fileService.getFileToText('data', filePath, fileName, undefined, onFileReceived); - //console.log("File Requested > " + filePath); + if (CONSOLE_LOG === true) { + + console.log("FileCloud -> File Requested -> " + filePath + "/" + fileName); + + } function onFileReceived(err, text, response) { diff --git a/FileCursor.js b/FileCursor.js index d59188a28..44c557d16 100644 --- a/FileCursor.js +++ b/FileCursor.js @@ -36,11 +36,11 @@ function newFileCursor() { cursorDate = pCursorDate; timePeriod = pTimePeriod; - setTimePeriod(pCurrentTimePeriod, callBackFunction); + setTimePeriod(pCurrentTimePeriod, pCursorDate, callBackFunction); } - function setTimePeriod(pTimePeriod, callBackFunction) { + function setTimePeriod(pTimePeriod, pDatetime, callBackFunction) { /* @@ -53,6 +53,8 @@ function newFileCursor() { */ + cursorDate = pDatetime; // Adjust the cursor date to the one received. + let positionA; for (let i = 0; i < dailyFilePeriods.length; i++) { @@ -239,11 +241,11 @@ function newFileCursor() { - function setDatetime(datetime, callBackFunction) { + function setDatetime(pDatetime, callBackFunction) { - if (datetime === undefined) { return; } + if (pDatetime === undefined) { return; } - cursorDate = datetime; + cursorDate = pDatetime; getFiles(callBackFunction); diff --git a/FileCursorCache.js b/FileCursorCache.js index 9667d630e..3ffd833bb 100644 --- a/FileCursorCache.js +++ b/FileCursorCache.js @@ -1,7 +1,7 @@  function newFileCursorCache() { - const CONSOLE_LOG = true; + const CONSOLE_LOG = false; let fileCursorCache = { getFileCursor: getFileCursor, @@ -95,7 +95,7 @@ function newFileCursorCache() { } } - function setTimePeriod(pTimePeriod) { + function setTimePeriod(pTimePeriod, pDatetime) { filesLoaded = 0; expectedFiles = 0; @@ -104,7 +104,7 @@ function newFileCursorCache() { function setTimePeriodToEach(fileCursor, key, map) { - fileCursor.setTimePeriod(pTimePeriod, onFileReceived); + fileCursor.setTimePeriod(pTimePeriod, pDatetime, onFileReceived); expectedFiles = expectedFiles + fileCursor.getExpectedFiles(); } diff --git a/ProductCard.js b/ProductCard.js index f8ee628eb..85426f051 100644 --- a/ProductCard.js +++ b/ProductCard.js @@ -1,6 +1,6 @@ function newProductCard() { - const CONSOLE_LOG = true; + const CONSOLE_LOG = false; var thisObject = { container: undefined, @@ -10,11 +10,14 @@ bot: undefined, product: undefined, code: undefined, + + setDatetime: setDatetime, + setTimePeriod: setTimePeriod, + onMarketFileLoaded: onMarketFileLoaded, onDailyFileLoaded: onDailyFileLoaded, onSingleFileLoaded: onSingleFileLoaded, - onDayChanged: onDayChanged, - onTimePeriodChanged: onTimePeriodChanged, + getContainer: getContainer, // returns the inner most container that holds the point received by parameter. initialize: initialize }; @@ -48,6 +51,9 @@ strokeStyle: UNLOADED_STROKE_STYLE }; + let timePeriod = INITIAL_TIME_PERIOD; + let datetime = INITIAL_DATE; + return thisObject; function initialize() { @@ -118,7 +124,7 @@ } - function onDayChanged() { + function setDatetime(pDatetime) { /* @@ -127,17 +133,27 @@ */ - dailyFileProgressBar.animatedValue = 0; + let currentDate = Math.trunc(datetime.valueOf() / ONE_DAY_IN_MILISECONDS); + let newDate = Math.trunc(pDatetime.valueOf() / ONE_DAY_IN_MILISECONDS); - if (CONSOLE_LOG === true) { + datetime = pDatetime; - console.log("ProductCard -> onDayChanged -> dailyFileProgressBar.animatedValue = " + dailyFileProgressBar.animatedValue); + if (currentDate !== newDate) { + if (timePeriod <= _1_HOUR_IN_MILISECONDS) { + + dailyFileProgressBar.animatedValue = 0; + + if (CONSOLE_LOG === true) { + + console.log("ProductCard -> onDayChanged -> dailyFileProgressBar.animatedValue = " + dailyFileProgressBar.animatedValue); + + } + } } - } - function onTimePeriodChanged() { + function setTimePeriod(pTimePeriod) { /* @@ -146,75 +162,58 @@ */ - dailyFileProgressBar.animatedValue = 0; + if (timePeriod !== pTimePeriod) { - if (CONSOLE_LOG === true) { + timePeriod = pTimePeriod; - console.log("ProductCard -> onTimePeriodChanged -> dailyFileProgressBar.animatedValue = " + dailyFileProgressBar.animatedValue); + if (timePeriod <= _1_HOUR_IN_MILISECONDS) { + dailyFileProgressBar.animatedValue = 0; + + if (CONSOLE_LOG === true) { + + console.log("ProductCard -> onTimePeriodChanged -> dailyFileProgressBar.animatedValue = " + dailyFileProgressBar.animatedValue); + + } + } } - } function onMarketFileLoaded(event) { - if (event.currentValue === event.totalValue) { - - marketFileProgressBar.value= 100; - - } else { - - marketFileProgressBar.value = Math.trunc(event.currentValue * 100 / event.totalValue); - marketFileProgressBar.fillStyle = LOADING_FILL_STYLE; - marketFileProgressBar.strokeStyle = LOADING_STROKE_STYLE; - - } + marketFileProgressBar.value = Math.trunc(event.currentValue * 100 / event.totalValue); + marketFileProgressBar.fillStyle = LOADING_FILL_STYLE; + marketFileProgressBar.strokeStyle = LOADING_STROKE_STYLE; if (CONSOLE_LOG === true) { - console.log("ProductCard onMarketFileLoaded Value = " + marketFileProgressBar.value + "% for " + thisObject.code); + console.log("ProductCard onMarketFileLoaded Value = " + marketFileProgressBar.value + "% for " + thisObject.code + ". Event = " + JSON.stringify(event)); } } function onDailyFileLoaded(event) { - if (event.currentValue === event.totalValue) { - - dailyFileProgressBar.value = 100; - - } else { - - dailyFileProgressBar.value = Math.trunc(event.currentValue * 100 / event.totalValue); - dailyFileProgressBar.fillStyle = LOADING_FILL_STYLE; - dailyFileProgressBar.strokeStyle = LOADING_STROKE_STYLE; - - } + dailyFileProgressBar.value = Math.trunc(event.currentValue * 100 / event.totalValue); + dailyFileProgressBar.fillStyle = LOADING_FILL_STYLE; + dailyFileProgressBar.strokeStyle = LOADING_STROKE_STYLE; if (CONSOLE_LOG === true) { - console.log("ProductCard onDailyFileLoaded Value = " + dailyFileProgressBar.value + "% for " + thisObject.code); + console.log("ProductCard onDailyFileLoaded Value = " + dailyFileProgressBar.value + "% for " + thisObject.code + ". Event = " + JSON.stringify(event)); } } function onSingleFileLoaded(event) { - if (event.currentValue === event.totalValue) { - - singleFileProgressBar.value = 100; - - } else { - - singleFileProgressBar.value = Math.trunc(event.currentValue * 100 / event.totalValue); - singleFileProgressBar.fillStyle = LOADING_FILL_STYLE; - singleFileProgressBar.strokeStyle = LOADING_STROKE_STYLE; - - } + singleFileProgressBar.value = Math.trunc(event.currentValue * 100 / event.totalValue); + singleFileProgressBar.fillStyle = LOADING_FILL_STYLE; + singleFileProgressBar.strokeStyle = LOADING_STROKE_STYLE; if (CONSOLE_LOG === true) { - console.log("ProductCard onSingleFileLoaded Value = " + singleFileProgressBar.value + "% for " + thisObject.code); + console.log("ProductCard onSingleFileLoaded Value = " + singleFileProgressBar.value + "% for " + thisObject.code + ". Event = " + JSON.stringify(event)); } } diff --git a/Storage.js b/Storage.js index bbfa0244f..deabab773 100644 --- a/Storage.js +++ b/Storage.js @@ -18,6 +18,9 @@ function newStorage(pName) { fileCursorCache: undefined, file: undefined, + setDatetime: setDatetime, + setTimePeriod: setTimePeriod, + eventHandler: undefined, initialize: initialize @@ -29,10 +32,16 @@ function newStorage(pName) { thisObject.eventHandler.name = "Storage-" + pName; + let datetime; + let timePeriod; + return thisObject; function initialize(pDevTeam, pBot, pProduct, pExchange, pMarket, pDatetime, pTimePeriod, callBackFunction) { + datetime = pDatetime; + timePeriod = pTimePeriod; + if (CONSOLE_LOG === true) { console.log("Storage initialize for " + pDevTeam.codeName + "-" + pBot.codeName + "-" + pProduct.codeName); @@ -176,5 +185,42 @@ function newStorage(pName) { } } } + + function setDatetime(pDatetime) { + + /* If there is a change in the day, then we take some actions, otherwise, we dont. */ + + let currentDate = Math.trunc(datetime.valueOf() / ONE_DAY_IN_MILISECONDS); + let newDate = Math.trunc(pDatetime.valueOf() / ONE_DAY_IN_MILISECONDS); + + datetime = pDatetime; + + if (currentDate !== newDate) { + + if (timePeriod <= _1_HOUR_IN_MILISECONDS) { + + thisObject.fileCursorCache.setDatetime(pDatetime); + + } + } + } + + function setTimePeriod(pTimePeriod) { + + /* We are going to filter out the cases in which the timePeriod received is the same that the one we already know. */ + + if (timePeriod !== pTimePeriod) { + + timePeriod = pTimePeriod; + + if (timePeriod <= _1_HOUR_IN_MILISECONDS) { + + if (thisObject.fileCursorCache !== undefined) { + + thisObject.fileCursorCache.setTimePeriod(pTimePeriod, datetime); + } + } + } + } } diff --git a/TimelineChart.js b/TimelineChart.js index 67c313407..6c2192b8e 100644 --- a/TimelineChart.js +++ b/TimelineChart.js @@ -182,7 +182,8 @@ function newTimelineChart() { let activePlotter = { productCard: pProductCard, - plotter: plotter + plotter: plotter, + storage: storage }; /* Add the new Active Protter to the Array */ @@ -244,33 +245,24 @@ function newTimelineChart() { timePeriod = recalculatePeriod(event.newLevel); + /* If the period changes, we need to spread the word in cascade towards all the depending objects. */ + if (timePeriod !== currentTimePeriod) { - for (var i = 0; i < activePlotters.length; i++) { + for (let i = 0; i < activePlotters.length; i++) { let activePlotter = activePlotters[i]; + + activePlotter.productCard.setTimePeriod(timePeriod); + activePlotter.storage.setTimePeriod(timePeriod); activePlotter.plotter.setTimePeriod(timePeriod); - - if (timePeriod <= _1_HOUR_IN_MILISECONDS) { - - for (var i = 0; i < activePlotters.length; i++) { - - activePlotter.productCard.onTimePeriodChanged(); - - } - } + } } recalculateCurrentDatetime(); - if (thisObject.container.frame.isInViewPort() && tooSmall() === false) { - - - - } } - } function onDragFinished() { @@ -300,6 +292,13 @@ function newTimelineChart() { function recalculateCurrentDatetime() { + /* + + The view port was moved or the view port zoom level was changed and the center of the screen points to a different datetime that me + must calculate. + + */ + let center = { x: (viewPort.visibleArea.bottomRight.x - viewPort.visibleArea.bottomLeft.x) / 2, y: (viewPort.visibleArea.bottomRight.y - viewPort.visibleArea.topRight.y) / 2 @@ -311,15 +310,16 @@ function newTimelineChart() { let newDate = new Date(0); newDate.setUTCSeconds(center.x / 1000); - tellProductCardsWhenDayChanges(newDate); - datetime = newDate; for (var i = 0; i < activePlotters.length; i++) { let activePlotter = activePlotters[i]; - activePlotter.plotter.setDatetime(datetime); + activePlotter.productCard.setDatetime(datetime); + activePlotter.storage.setDatetime(datetime); + activePlotter.plotter.setDatetime(datetime); + } thisObject.container.eventHandler.raiseEvent("Datetime Changed", datetime); @@ -345,32 +345,9 @@ function newTimelineChart() { } - function tellProductCardsWhenDayChanges(pDatetime) { - - /* If there is a change in the day, then we tell it to the Product Card so that it can represent the activity of the daily cursors on the UI. */ - - let currentDate = Math.trunc(datetime.valueOf() / ONE_DAY_IN_MILISECONDS); - let newDate = Math.trunc(pDatetime.valueOf() / ONE_DAY_IN_MILISECONDS); - - if (currentDate !== newDate) { - - if (timePeriod <= _1_HOUR_IN_MILISECONDS) { - - for (var i = 0; i < activePlotters.length; i++) { - - let activePlotter = activePlotters[i]; - activePlotter.productCard.onDayChanged(); - - } - } - } - } - - function setDatetime(pDatetime) { - tellProductCardsWhenDayChanges(pDatetime); - + /* This function is used when the time is changed through the user interface, but without zooming or panning. */ /* No matter if the day changed or not, we need to inform all visible Plotters. */ if (thisObject.container.frame.isInViewPort()) { @@ -378,8 +355,13 @@ function newTimelineChart() { for (var i = 0; i < activePlotters.length; i++) { let activePlotter = activePlotters[i]; + + activePlotter.productCard.setDatetime(pDatetime); + activePlotter.storage.setDatetime(pDatetime); activePlotter.plotter.setDatetime(pDatetime); + /* The time has changed, but the viewPort is still on the same place, so we request any of the plotters to reposition it. */ + if (activePlotter.plotter.positionAtDatetime !== undefined) { activePlotter.plotter.positionAtDatetime(pDatetime); }