From ac18c984b27df072b152ba8522a865c514218e3d Mon Sep 17 00:00:00 2001 From: Luis Fernando Molina Date: Sat, 19 May 2018 19:57:50 +0200 Subject: [PATCH] BUG #4 fixed Dates are objects, be caurfull when copying them! --- ProductStorage.js | 7 +++-- TimelineChart.js | 70 +++++++++++++++++------------------------------ 2 files changed, 30 insertions(+), 47 deletions(-) diff --git a/ProductStorage.js b/ProductStorage.js index 4deaf42d6..826c68f4c 100644 --- a/ProductStorage.js +++ b/ProductStorage.js @@ -2,7 +2,7 @@ function newProductStorage(pName) { const MODULE_NAME = "Product Storage"; - const INFO_LOG = false; + const INFO_LOG = true; const ERROR_LOG = true; const logger = newDebugLog(); logger.fileName = MODULE_NAME; @@ -451,6 +451,9 @@ function newProductStorage(pName) { function setDatetime(pDatetime) { + console.log("recibi= " + pDatetime); + console.log("tenia = " + datetime); + if (INFO_LOG === true) { logger.write("[INFO] setDatetime -> Entering function."); } /* If there is a change in the day, then we take some actions, otherwise, we dont. */ @@ -458,7 +461,7 @@ function newProductStorage(pName) { let currentDate = Math.trunc(datetime.valueOf() / ONE_DAY_IN_MILISECONDS); let newDate = Math.trunc(pDatetime.valueOf() / ONE_DAY_IN_MILISECONDS); - datetime = pDatetime; + datetime = new Date(pDatetime); if (currentDate !== newDate) { diff --git a/TimelineChart.js b/TimelineChart.js index 8359a93a2..6cffff6d0 100644 --- a/TimelineChart.js +++ b/TimelineChart.js @@ -1,7 +1,7 @@ function newTimelineChart() { const MODULE_NAME = "Timeline Chart"; - const INFO_LOG = false; + const INFO_LOG = true; const INTENSIVE_LOG = false; const ERROR_LOG = true; const logger = newDebugLog(); @@ -75,7 +75,6 @@ viewPort.eventHandler.listenToEvent("Offset Changed", onOffsetChanged); viewPort.eventHandler.listenToEvent("Zoom Changed", onZoomChanged); - canvas.eventHandler.listenToEvent("Drag Finished", onDragFinished); initializeCompetitionPlotters(onCompetitionPlottersInitialized); @@ -718,21 +717,35 @@ } } - function onDragFinished() { + function setDatetime(pDatetime) { - if (INFO_LOG === true) { logger.write("[INFO] onDragFinished -> Entering function."); } + if (INFO_LOG === true) { logger.write("[INFO] setDatetime -> Entering function."); } - if (initializationReady === true) { + /* 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()) { + if (thisObject.container.frame.isInViewPort()) { - saveUserPosition(thisObject.container, timeLineCoordinateSystem); + for (let i = 0; i < productPlotters.length; i++) { + + let productPlotter = productPlotters[i]; + + productPlotter.productCard.setDatetime(pDatetime); + productPlotter.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 (productPlotter.plotter.positionAtDatetime !== undefined) { + productPlotter.plotter.positionAtDatetime(pDatetime); + } } - if (thisObject.container.frame.isInViewPort() && tooSmall() === false) { + for (let i = 0; i < competitionPlotters.length; i++) { + let competitionPlotter = competitionPlotters[i]; + competitionPlotter.plotter.setDatetime(datetime); } } @@ -747,7 +760,7 @@ if (thisObject.container.frame.isInViewPort()) { recalculateCurrentDatetime(); - + saveUserPosition(thisObject.container, timeLineCoordinateSystem); } } @@ -759,7 +772,7 @@ /* - 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 + 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 we must calculate. */ @@ -777,6 +790,8 @@ datetime = newDate; + console.log("nueva = " + datetime); + for (let i = 0; i < productPlotters.length; i++) { let productPlotter = productPlotters[i]; @@ -820,41 +835,6 @@ } - function setDatetime(pDatetime) { - - if (INFO_LOG === true) { logger.write("[INFO] setDatetime -> Entering function."); } - - /* 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()) { - - for (let i = 0; i < productPlotters.length; i++) { - - let productPlotter = productPlotters[i]; - - productPlotter.productCard.setDatetime(pDatetime); - productPlotter.storage.setDatetime(pDatetime); - productPlotter.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 (productPlotter.plotter.positionAtDatetime !== undefined) { - productPlotter.plotter.positionAtDatetime(pDatetime); - } - - } - - for (let i = 0; i < competitionPlotters.length; i++) { - - let competitionPlotter = competitionPlotters[i]; - - competitionPlotter.plotter.setDatetime(datetime); - - } - } - } - function recalculateScale() { if (INFO_LOG === true) { logger.write("[INFO] recalculateScale -> Entering function."); }