From 217a673ff91201cf84331142f40b68287879bf63 Mon Sep 17 00:00:00 2001 From: Luis Fernando Molina Date: Wed, 30 May 2018 13:29:10 +0200 Subject: [PATCH] Error Handling and Logging improved --- Candles.js | 835 +++++++++++++++++++++++++++-------------------- Volumes.js | 924 ++++++++++++++++++++++++++++++----------------------- 2 files changed, 1016 insertions(+), 743 deletions(-) diff --git a/Candles.js b/Candles.js index 020bd3faf..0b9393412 100644 --- a/Candles.js +++ b/Candles.js @@ -1,5 +1,12 @@ function newAAMastersPlottersCandlesVolumesCandles() { + const MODULE_NAME = "Candles Plotter"; + const INFO_LOG = false; + const ERROR_LOG = true; + const INTENSIVE_LOG = false; + const logger = newWebDebugLog(); + logger.fileName = MODULE_NAME; + let thisObject = { // Main functions and properties. @@ -46,595 +53,725 @@ function initialize(pStorage, pExchange, pMarket, pDatetime, pTimePeriod, callBackFunction) { - /* Store the information received. */ + try { - marketFiles = pStorage.marketFiles[0]; - dailyFiles = pStorage.dailyFiles[0]; + if (INFO_LOG === true) { logger.write("[INFO] initialize -> Entering function."); } - datetime = pDatetime; - timePeriod = pTimePeriod; + /* Store the information received. */ - /* We need a Market File in order to calculate the Y scale, since this scale depends on actual data. */ + marketFiles = pStorage.marketFiles[0]; + dailyFiles = pStorage.dailyFiles[0]; - marketFile = marketFiles.getFile(ONE_DAY_IN_MILISECONDS); // This file is the one processed faster. + datetime = pDatetime; + timePeriod = pTimePeriod; - recalculateScale(); + /* We need a Market File in order to calculate the Y scale, since this scale depends on actual data. */ - /* Now we set the right files according to current Period. */ + marketFile = marketFiles.getFile(ONE_DAY_IN_MILISECONDS); // This file is the one processed faster. - marketFile = marketFiles.getFile(pTimePeriod); - fileCursor = dailyFiles.getFileCursor(pTimePeriod); + recalculateScale(); - /* Listen to the necesary events. */ + /* Now we set the right files according to current Period. */ - viewPort.eventHandler.listenToEvent("Zoom Changed", onZoomChanged); - viewPort.eventHandler.listenToEvent("Offset Changed", onOffsetChanged); - marketFiles.eventHandler.listenToEvent("Files Updated", onFilesUpdated); - canvas.eventHandler.listenToEvent("Drag Finished", onDragFinished); + marketFile = marketFiles.getFile(pTimePeriod); + fileCursor = dailyFiles.getFileCursor(pTimePeriod); - /* Get ready for plotting. */ + /* Listen to the necesary events. */ - recalculate(); + viewPort.eventHandler.listenToEvent("Zoom Changed", onZoomChanged); + viewPort.eventHandler.listenToEvent("Offset Changed", onOffsetChanged); + marketFiles.eventHandler.listenToEvent("Files Updated", onFilesUpdated); + canvas.eventHandler.listenToEvent("Drag Finished", onDragFinished); - callBackFunction(); + /* Get ready for plotting. */ + recalculate(); + + callBackFunction(); + + } catch (err) { + + if (ERROR_LOG === true) { logger.write("[ERROR] initialize -> err.message = " + err.message); } + } } function getContainer(point) { - let container; + try { - /* First we check if this point is inside this space. */ + if (INFO_LOG === true) { logger.write("[INFO] getContainer -> Entering function."); } - if (this.container.frame.isThisPointHere(point) === true) { + let container; - return this.container; + /* First we check if this point is inside this space. */ - } else { + if (this.container.frame.isThisPointHere(point) === true) { - /* This point does not belong to this space. */ + return this.container; - return undefined; + } else { + + /* This point does not belong to this space. */ + + return undefined; + } + + } catch (err) { + + if (ERROR_LOG === true) { logger.write("[ERROR] getContainer -> err.message = " + err.message); } } - } function onFilesUpdated() { - let newMarketFile = marketFiles.getFile(timePeriod); + try { - if (newMarketFile !== undefined) { + if (INFO_LOG === true) { logger.write("[INFO] onFilesUpdated -> Entering function."); } - marketFile = newMarketFile; - recalculate(); + let newMarketFile = marketFiles.getFile(timePeriod); + + if (newMarketFile !== undefined) { + + marketFile = newMarketFile; + recalculate(); + } + + } catch (err) { + + if (ERROR_LOG === true) { logger.write("[ERROR] onFilesUpdated -> err.message = " + err.message); } } - } function setTimePeriod(pTimePeriod) { - if (timePeriod !== pTimePeriod) { + try { - timePeriod = pTimePeriod; + if (INFO_LOG === true) { logger.write("[INFO] setTimePeriod -> Entering function."); } - if (timePeriod >= _1_HOUR_IN_MILISECONDS) { + if (timePeriod !== pTimePeriod) { - let newMarketFile = marketFiles.getFile(pTimePeriod); + timePeriod = pTimePeriod; - if (newMarketFile !== undefined) { + if (timePeriod >= _1_HOUR_IN_MILISECONDS) { - marketFile = newMarketFile; - recalculate(); - } + let newMarketFile = marketFiles.getFile(pTimePeriod); - } else { + if (newMarketFile !== undefined) { - let newFileCursor = dailyFiles.getFileCursor(pTimePeriod); + marketFile = newMarketFile; + recalculate(); + } - if (newFileCursor !== undefined) { + } else { - fileCursor = newFileCursor; - recalculate(); + let newFileCursor = dailyFiles.getFileCursor(pTimePeriod); + + if (newFileCursor !== undefined) { + + fileCursor = newFileCursor; + recalculate(); + } } } + + } catch (err) { + + if (ERROR_LOG === true) { logger.write("[ERROR] setTimePeriod -> err.message = " + err.message); } } } function setDatetime(pDatetime) { + if (INFO_LOG === true) { logger.write("[INFO] setDatetime -> Entering function."); } + datetime = pDatetime; } function positionAtDatetime(newDatetime) { - value = newDatetime.valueOf(); + try { - /* Now we calculate which candle has this new time, because it will give us the y coordinate. */ + if (INFO_LOG === true) { logger.write("[INFO] positionAtDatetime -> Entering function."); } - for (let i = 0; i < candles.length; i++) { + value = newDatetime.valueOf(); - if (value >= candles[i].begin && value <= candles[i].end) { + /* Now we calculate which candle has this new time, because it will give us the y coordinate. */ - let targetPoint = { - x: value, - y: candles[i].open - }; + for (let i = 0; i < candles.length; i++) { - targetPoint = timeLineCoordinateSystem.transformThisPoint(targetPoint); - targetPoint = transformThisPoint(targetPoint, thisObject.container); + if (value >= candles[i].begin && value <= candles[i].end) { - let targetMax = { - x: value, - y: candles[i].max - }; - - targetMax = timeLineCoordinateSystem.transformThisPoint(targetMax); - targetMax = transformThisPoint(targetMax, thisObject.container); - - let targetMin = { - x: value, - y: candles[i].min - }; - - targetMin = timeLineCoordinateSystem.transformThisPoint(targetMin); - targetMin = transformThisPoint(targetMin, thisObject.container); - - let center = { - x: (viewPort.visibleArea.bottomRight.x - viewPort.visibleArea.bottomLeft.x) / 2, - y: (viewPort.visibleArea.bottomRight.y - viewPort.visibleArea.topRight.y) / 2 - }; - - if (targetMax.y < viewPort.visibleArea.topLeft.y || targetMin.y > viewPort.visibleArea.bottomRight.y) { - - let displaceVector = { - x: 0, - y: center.y - targetPoint.y + let targetPoint = { + x: value, + y: candles[i].open }; - viewPort.displaceTarget(displaceVector); + targetPoint = timeLineCoordinateSystem.transformThisPoint(targetPoint); + targetPoint = transformThisPoint(targetPoint, thisObject.container); + let targetMax = { + x: value, + y: candles[i].max + }; + + targetMax = timeLineCoordinateSystem.transformThisPoint(targetMax); + targetMax = transformThisPoint(targetMax, thisObject.container); + + let targetMin = { + x: value, + y: candles[i].min + }; + + targetMin = timeLineCoordinateSystem.transformThisPoint(targetMin); + targetMin = transformThisPoint(targetMin, thisObject.container); + + let center = { + x: (viewPort.visibleArea.bottomRight.x - viewPort.visibleArea.bottomLeft.x) / 2, + y: (viewPort.visibleArea.bottomRight.y - viewPort.visibleArea.topRight.y) / 2 + }; + + if (targetMax.y < viewPort.visibleArea.topLeft.y || targetMin.y > viewPort.visibleArea.bottomRight.y) { + + let displaceVector = { + x: 0, + y: center.y - targetPoint.y + }; + + viewPort.displaceTarget(displaceVector); + + } + + let displaceVector = { + x: center.x - targetPoint.x, + y: 0 + }; + + viewPort.displace(displaceVector); + + return; } - - let displaceVector = { - x: center.x - targetPoint.x, - y: 0 - }; - - viewPort.displace(displaceVector); - - return; } + + } catch (err) { + + if (ERROR_LOG === true) { logger.write("[ERROR] positionAtDatetime -> err.message = " + err.message); } } } function onDailyFileLoaded(event) { - if (event.currentValue === event.totalValue) { + try { - /* This happens only when all of the files in the cursor have been loaded. */ + if (INFO_LOG === true) { logger.write("[INFO] onDailyFileLoaded -> Entering function."); } - recalculate(); + if (event.currentValue === event.totalValue) { + /* This happens only when all of the files in the cursor have been loaded. */ + + recalculate(); + + } + + } catch (err) { + + if (ERROR_LOG === true) { logger.write("[ERROR] onDailyFileLoaded -> err.message = " + err.message); } } } function draw() { - this.container.frame.draw(); + try { - plotChart(); + if (INTENSIVE_LOG === true) { logger.write("[INFO] draw -> Entering function."); } + this.container.frame.draw(); + + plotChart(); + + } catch (err) { + + if (ERROR_LOG === true) { logger.write("[ERROR] draw -> err.message = " + err.message); } + } } function recalculate() { - if (timePeriod >= _1_HOUR_IN_MILISECONDS) { + try { - recalculateUsingMarketFiles(); + if (INFO_LOG === true) { logger.write("[INFO] recalculate -> Entering function."); } - } else { + if (timePeriod >= _1_HOUR_IN_MILISECONDS) { - recalculateUsingDailyFiles(); + recalculateUsingMarketFiles(); + } else { + + recalculateUsingDailyFiles(); + + } + + thisObject.container.eventHandler.raiseEvent("Candles Changed", candles); + + } catch (err) { + + if (ERROR_LOG === true) { logger.write("[ERROR] recalculate -> err.message = " + err.message); } } - - thisObject.container.eventHandler.raiseEvent("Candles Changed", candles); } function recalculateUsingDailyFiles() { - if (fileCursor === undefined) { return; } // We need to wait + try { - if (fileCursor.files.size === 0) { return;} // We need to wait until there are files in the cursor + if (INFO_LOG === true) { logger.write("[INFO] recalculateUsingDailyFiles -> Entering function."); } - let daysOnSides = getSideDays(timePeriod); + if (fileCursor === undefined) { return; } // We need to wait - let leftDate = getDateFromPoint(viewPort.visibleArea.topLeft, thisObject.container, timeLineCoordinateSystem); - let rightDate = getDateFromPoint(viewPort.visibleArea.topRight, thisObject.container, timeLineCoordinateSystem); + if (fileCursor.files.size === 0) { return; } // We need to wait until there are files in the cursor - let dateDiff = rightDate.valueOf() - leftDate.valueOf(); + let daysOnSides = getSideDays(timePeriod); - let farLeftDate = new Date(leftDate.valueOf() - dateDiff * 1.5); - let farRightDate = new Date(rightDate.valueOf() + dateDiff * 1.5); + let leftDate = getDateFromPoint(viewPort.visibleArea.topLeft, thisObject.container, timeLineCoordinateSystem); + let rightDate = getDateFromPoint(viewPort.visibleArea.topRight, thisObject.container, timeLineCoordinateSystem); - let currentDate = new Date(farLeftDate.valueOf()); + let dateDiff = rightDate.valueOf() - leftDate.valueOf(); - candles = []; + let farLeftDate = new Date(leftDate.valueOf() - dateDiff * 1.5); + let farRightDate = new Date(rightDate.valueOf() + dateDiff * 1.5); - while (currentDate.valueOf() <= farRightDate.valueOf() + ONE_DAY_IN_MILISECONDS) { + let currentDate = new Date(farLeftDate.valueOf()); - let stringDate = currentDate.getFullYear() + '-' + pad(currentDate.getMonth() + 1, 2) + '-' + pad(currentDate.getDate(), 2); + candles = []; - let dailyFile = fileCursor.files.get(stringDate); + while (currentDate.valueOf() <= farRightDate.valueOf() + ONE_DAY_IN_MILISECONDS) { - if (dailyFile !== undefined) { + let stringDate = currentDate.getFullYear() + '-' + pad(currentDate.getMonth() + 1, 2) + '-' + pad(currentDate.getDate(), 2); - for (let i = 0; i < dailyFile.length; i++) { + let dailyFile = fileCursor.files.get(stringDate); - let candle = { - open: undefined, - close: undefined, - min: 10000000000000, - max: 0, - begin: undefined, - end: undefined, - direction: undefined - }; + if (dailyFile !== undefined) { - candle.min = dailyFile[i][0]; - candle.max = dailyFile[i][1]; + for (let i = 0; i < dailyFile.length; i++) { - candle.open = dailyFile[i][2]; - candle.close = dailyFile[i][3]; + let candle = { + open: undefined, + close: undefined, + min: 10000000000000, + max: 0, + begin: undefined, + end: undefined, + direction: undefined + }; - candle.begin = dailyFile[i][4]; - candle.end = dailyFile[i][5]; + candle.min = dailyFile[i][0]; + candle.max = dailyFile[i][1]; - if (candle.open > candle.close) { candle.direction = 'down'; } - if (candle.open < candle.close) { candle.direction = 'up'; } - if (candle.open === candle.close) { candle.direction = 'side'; } + candle.open = dailyFile[i][2]; + candle.close = dailyFile[i][3]; - if (candle.begin >= farLeftDate.valueOf() && candle.end <= farRightDate.valueOf()) { + candle.begin = dailyFile[i][4]; + candle.end = dailyFile[i][5]; - candles.push(candle); + if (candle.open > candle.close) { candle.direction = 'down'; } + if (candle.open < candle.close) { candle.direction = 'up'; } + if (candle.open === candle.close) { candle.direction = 'side'; } - if (datetime.valueOf() >= candle.begin && datetime.valueOf() <= candle.end) { + if (candle.begin >= farLeftDate.valueOf() && candle.end <= farRightDate.valueOf()) { - thisObject.currentCandle = candle; - thisObject.container.eventHandler.raiseEvent("Current Candle Changed", thisObject.currentCandle); + candles.push(candle); + if (datetime.valueOf() >= candle.begin && datetime.valueOf() <= candle.end) { + + thisObject.currentCandle = candle; + thisObject.container.eventHandler.raiseEvent("Current Candle Changed", thisObject.currentCandle); + + } } } } - } - - currentDate = new Date(currentDate.valueOf() + ONE_DAY_IN_MILISECONDS); - } - - /* Lests check if all the visible screen is going to be covered by candles. */ - - let lowerEnd = leftDate.valueOf(); - let upperEnd = rightDate.valueOf(); - - if (candles.length > 0) { - - if (candles[0].begin > lowerEnd || candles[candles.length - 1].end < upperEnd) { - - setTimeout(recalculate, 2000); - - //console.log("File missing while calculating candles, scheduling a recalculation in 2 seconds."); + currentDate = new Date(currentDate.valueOf() + ONE_DAY_IN_MILISECONDS); } + + /* Lests check if all the visible screen is going to be covered by candles. */ + + let lowerEnd = leftDate.valueOf(); + let upperEnd = rightDate.valueOf(); + + if (candles.length > 0) { + + if (candles[0].begin > lowerEnd || candles[candles.length - 1].end < upperEnd) { + + setTimeout(recalculate, 2000); + + //console.log("File missing while calculating candles, scheduling a recalculation in 2 seconds."); + + } + } + + //console.log("Olivia > recalculateUsingDailyFiles > total candles generated : " + candles.length); + + } catch (err) { + + if (ERROR_LOG === true) { logger.write("[ERROR] recalculateUsingDailyFiles -> err.message = " + err.message); } } - - //console.log("Olivia > recalculateUsingDailyFiles > total candles generated : " + candles.length); - } function recalculateUsingMarketFiles() { - if (marketFile === undefined) { return; } // Initialization not complete yet. + try { - let daysOnSides = getSideDays(timePeriod); + if (INFO_LOG === true) { logger.write("[INFO] recalculateUsingMarketFiles -> Entering function."); } - let leftDate = getDateFromPoint(viewPort.visibleArea.topLeft, thisObject.container, timeLineCoordinateSystem); - let rightDate = getDateFromPoint(viewPort.visibleArea.topRight, thisObject.container, timeLineCoordinateSystem); + if (marketFile === undefined) { return; } // Initialization not complete yet. - let dateDiff = rightDate.valueOf() - leftDate.valueOf(); + let daysOnSides = getSideDays(timePeriod); - leftDate = new Date(leftDate.valueOf() - dateDiff * 1.5); - rightDate = new Date(rightDate.valueOf() + dateDiff * 1.5); + let leftDate = getDateFromPoint(viewPort.visibleArea.topLeft, thisObject.container, timeLineCoordinateSystem); + let rightDate = getDateFromPoint(viewPort.visibleArea.topRight, thisObject.container, timeLineCoordinateSystem); - candles = []; + let dateDiff = rightDate.valueOf() - leftDate.valueOf(); - for (let i = 0; i < marketFile.length; i++) { + leftDate = new Date(leftDate.valueOf() - dateDiff * 1.5); + rightDate = new Date(rightDate.valueOf() + dateDiff * 1.5); - let candle = { - open: undefined, - close: undefined, - min: 10000000000000, - max: 0, - begin: undefined, - end: undefined, - direction: undefined - }; + candles = []; - candle.min = marketFile[i][0]; - candle.max = marketFile[i][1]; + for (let i = 0; i < marketFile.length; i++) { - candle.open = marketFile[i][2]; - candle.close = marketFile[i][3]; + let candle = { + open: undefined, + close: undefined, + min: 10000000000000, + max: 0, + begin: undefined, + end: undefined, + direction: undefined + }; - candle.begin = marketFile[i][4]; - candle.end = marketFile[i][5]; + candle.min = marketFile[i][0]; + candle.max = marketFile[i][1]; - if (candle.open > candle.close) { candle.direction = 'down'; } - if (candle.open < candle.close) { candle.direction = 'up'; } - if (candle.open === candle.close) { candle.direction = 'side'; } + candle.open = marketFile[i][2]; + candle.close = marketFile[i][3]; - if (candle.begin >= leftDate.valueOf() && candle.end <= rightDate.valueOf()) { + candle.begin = marketFile[i][4]; + candle.end = marketFile[i][5]; - candles.push(candle); + if (candle.open > candle.close) { candle.direction = 'down'; } + if (candle.open < candle.close) { candle.direction = 'up'; } + if (candle.open === candle.close) { candle.direction = 'side'; } - if (datetime.valueOf() >= candle.begin && datetime.valueOf() <= candle.end) { + if (candle.begin >= leftDate.valueOf() && candle.end <= rightDate.valueOf()) { - thisObject.currentCandle = candle; - thisObject.container.eventHandler.raiseEvent("Current Candle Changed", thisObject.currentCandle); + candles.push(candle); + if (datetime.valueOf() >= candle.begin && datetime.valueOf() <= candle.end) { + + thisObject.currentCandle = candle; + thisObject.container.eventHandler.raiseEvent("Current Candle Changed", thisObject.currentCandle); + + } } - } - } + } - //console.log("Olivia > recalculateUsingMarketFiles > total candles generated : " + candles.length); + //console.log("Olivia > recalculateUsingMarketFiles > total candles generated : " + candles.length); + + } catch (err) { + + if (ERROR_LOG === true) { logger.write("[ERROR] recalculateUsingMarketFiles -> err.message = " + err.message); } + } } function recalculateScale() { - if (marketFile === undefined) { return; } // We need the market file to be loaded to make the calculation. + try { - if (timeLineCoordinateSystem.maxValue > 0) { return; } // Already calculated. + if (INFO_LOG === true) { logger.write("[INFO] recalculateScale -> Entering function."); } - let minValue = { - x: EARLIEST_DATE.valueOf(), - y: 0 - }; + if (marketFile === undefined) { return; } // We need the market file to be loaded to make the calculation. - let maxValue = { - x: MAX_PLOTABLE_DATE.valueOf(), - y: nextPorwerOf10(getMaxRate()) / 4 // TODO: This 4 is temporary - }; + if (timeLineCoordinateSystem.maxValue > 0) { return; } // Already calculated. + + let minValue = { + x: EARLIEST_DATE.valueOf(), + y: 0 + }; + + let maxValue = { + x: MAX_PLOTABLE_DATE.valueOf(), + y: nextPorwerOf10(getMaxRate()) / 4 // TODO: This 4 is temporary + }; - timeLineCoordinateSystem.initialize( - minValue, - maxValue, - thisObject.container.frame.width, - thisObject.container.frame.height - ); + timeLineCoordinateSystem.initialize( + minValue, + maxValue, + thisObject.container.frame.width, + thisObject.container.frame.height + ); - function getMaxRate() { + function getMaxRate() { - let maxValue = 0; + if (INFO_LOG === true) { logger.write("[INFO] recalculateScale -> getMaxRate -> Entering function."); } - for (let i = 0; i < marketFile.length; i++) { + let maxValue = 0; - let currentMax = marketFile[i][1]; // 1 = rates. + for (let i = 0; i < marketFile.length; i++) { - if (maxValue < currentMax) { - maxValue = currentMax; + let currentMax = marketFile[i][1]; // 1 = rates. + + if (maxValue < currentMax) { + maxValue = currentMax; + } } + + return maxValue; + } - return maxValue; + } catch (err) { + if (ERROR_LOG === true) { logger.write("[ERROR] recalculateScale -> err.message = " + err.message); } } - } function plotChart() { - if (candles.length > 0) { + try { - /* Now we calculate and plot the candles */ + if (INTENSIVE_LOG === true) { logger.write("[INFO] plotChart -> Entering function."); } - for (let i = 0; i < candles.length; i++) { + if (candles.length > 0) { - candle = candles[i]; + /* Now we calculate and plot the candles */ - let candlePoint1 = { - x: candle.begin + timePeriod / 7 * 1.5, - y: candle.open - }; + for (let i = 0; i < candles.length; i++) { - let candlePoint2 = { - x: candle.begin + timePeriod / 7 * 5.5, - y: candle.open - }; + candle = candles[i]; - let candlePoint3 = { - x: candle.begin + timePeriod / 7 * 5.5, - y: candle.close - }; + let candlePoint1 = { + x: candle.begin + timePeriod / 7 * 1.5, + y: candle.open + }; - let candlePoint4 = { - x: candle.begin + timePeriod / 7 * 1.5, - y: candle.close - }; + let candlePoint2 = { + x: candle.begin + timePeriod / 7 * 5.5, + y: candle.open + }; - candlePoint1 = timeLineCoordinateSystem.transformThisPoint(candlePoint1); - candlePoint2 = timeLineCoordinateSystem.transformThisPoint(candlePoint2); - candlePoint3 = timeLineCoordinateSystem.transformThisPoint(candlePoint3); - candlePoint4 = timeLineCoordinateSystem.transformThisPoint(candlePoint4); + let candlePoint3 = { + x: candle.begin + timePeriod / 7 * 5.5, + y: candle.close + }; - candlePoint1 = transformThisPoint(candlePoint1, thisObject.container); - candlePoint2 = transformThisPoint(candlePoint2, thisObject.container); - candlePoint3 = transformThisPoint(candlePoint3, thisObject.container); - candlePoint4 = transformThisPoint(candlePoint4, thisObject.container); + let candlePoint4 = { + x: candle.begin + timePeriod / 7 * 1.5, + y: candle.close + }; - if (candlePoint2.x < viewPort.visibleArea.bottomLeft.x || candlePoint1.x > viewPort.visibleArea.bottomRight.x) { - continue; - } + candlePoint1 = timeLineCoordinateSystem.transformThisPoint(candlePoint1); + candlePoint2 = timeLineCoordinateSystem.transformThisPoint(candlePoint2); + candlePoint3 = timeLineCoordinateSystem.transformThisPoint(candlePoint3); + candlePoint4 = timeLineCoordinateSystem.transformThisPoint(candlePoint4); - candlePoint1 = viewPort.fitIntoVisibleArea(candlePoint1); - candlePoint2 = viewPort.fitIntoVisibleArea(candlePoint2); - candlePoint3 = viewPort.fitIntoVisibleArea(candlePoint3); - candlePoint4 = viewPort.fitIntoVisibleArea(candlePoint4); + candlePoint1 = transformThisPoint(candlePoint1, thisObject.container); + candlePoint2 = transformThisPoint(candlePoint2, thisObject.container); + candlePoint3 = transformThisPoint(candlePoint3, thisObject.container); + candlePoint4 = transformThisPoint(candlePoint4, thisObject.container); - let stickPoint1 = { - x: candle.begin + timePeriod / 7 * 3.2, - y: candle.max - }; + if (candlePoint2.x < viewPort.visibleArea.bottomLeft.x || candlePoint1.x > viewPort.visibleArea.bottomRight.x) { + continue; + } - let stickPoint2 = { - x: candle.begin + timePeriod / 7 * 3.8, - y: candle.max - }; + candlePoint1 = viewPort.fitIntoVisibleArea(candlePoint1); + candlePoint2 = viewPort.fitIntoVisibleArea(candlePoint2); + candlePoint3 = viewPort.fitIntoVisibleArea(candlePoint3); + candlePoint4 = viewPort.fitIntoVisibleArea(candlePoint4); - let stickPoint3 = { - x: candle.begin + timePeriod / 7 * 3.8, - y: candle.min - }; + let stickPoint1 = { + x: candle.begin + timePeriod / 7 * 3.2, + y: candle.max + }; - let stickPoint4 = { - x: candle.begin + timePeriod / 7 * 3.2, - y: candle.min - }; + let stickPoint2 = { + x: candle.begin + timePeriod / 7 * 3.8, + y: candle.max + }; - stickPoint1 = timeLineCoordinateSystem.transformThisPoint(stickPoint1); - stickPoint2 = timeLineCoordinateSystem.transformThisPoint(stickPoint2); - stickPoint3 = timeLineCoordinateSystem.transformThisPoint(stickPoint3); - stickPoint4 = timeLineCoordinateSystem.transformThisPoint(stickPoint4); + let stickPoint3 = { + x: candle.begin + timePeriod / 7 * 3.8, + y: candle.min + }; - stickPoint1 = transformThisPoint(stickPoint1, thisObject.container); - stickPoint2 = transformThisPoint(stickPoint2, thisObject.container); - stickPoint3 = transformThisPoint(stickPoint3, thisObject.container); - stickPoint4 = transformThisPoint(stickPoint4, thisObject.container); + let stickPoint4 = { + x: candle.begin + timePeriod / 7 * 3.2, + y: candle.min + }; - stickPoint1 = viewPort.fitIntoVisibleArea(stickPoint1); - stickPoint2 = viewPort.fitIntoVisibleArea(stickPoint2); - stickPoint3 = viewPort.fitIntoVisibleArea(stickPoint3); - stickPoint4 = viewPort.fitIntoVisibleArea(stickPoint4); + stickPoint1 = timeLineCoordinateSystem.transformThisPoint(stickPoint1); + stickPoint2 = timeLineCoordinateSystem.transformThisPoint(stickPoint2); + stickPoint3 = timeLineCoordinateSystem.transformThisPoint(stickPoint3); + stickPoint4 = timeLineCoordinateSystem.transformThisPoint(stickPoint4); - browserCanvasContext.beginPath(); + stickPoint1 = transformThisPoint(stickPoint1, thisObject.container); + stickPoint2 = transformThisPoint(stickPoint2, thisObject.container); + stickPoint3 = transformThisPoint(stickPoint3, thisObject.container); + stickPoint4 = transformThisPoint(stickPoint4, thisObject.container); - browserCanvasContext.moveTo(stickPoint1.x, stickPoint1.y); - browserCanvasContext.lineTo(stickPoint2.x, stickPoint2.y); - browserCanvasContext.lineTo(stickPoint3.x, stickPoint3.y); - browserCanvasContext.lineTo(stickPoint4.x, stickPoint4.y); + stickPoint1 = viewPort.fitIntoVisibleArea(stickPoint1); + stickPoint2 = viewPort.fitIntoVisibleArea(stickPoint2); + stickPoint3 = viewPort.fitIntoVisibleArea(stickPoint3); + stickPoint4 = viewPort.fitIntoVisibleArea(stickPoint4); - browserCanvasContext.closePath(); - browserCanvasContext.fillStyle = 'rgba(54, 54, 54, 1)'; - browserCanvasContext.fill(); + browserCanvasContext.beginPath(); - if (datetime !== undefined) { + browserCanvasContext.moveTo(stickPoint1.x, stickPoint1.y); + browserCanvasContext.lineTo(stickPoint2.x, stickPoint2.y); + browserCanvasContext.lineTo(stickPoint3.x, stickPoint3.y); + browserCanvasContext.lineTo(stickPoint4.x, stickPoint4.y); - let dateValue = datetime.valueOf(); + browserCanvasContext.closePath(); + browserCanvasContext.fillStyle = 'rgba(54, 54, 54, 1)'; + browserCanvasContext.fill(); - if (dateValue >= candle.begin && dateValue <= candle.end) { + if (datetime !== undefined) { - browserCanvasContext.strokeStyle = 'rgba(255, 233, 31, 1)'; // Current candle accroding to time + let dateValue = datetime.valueOf(); + + if (dateValue >= candle.begin && dateValue <= candle.end) { + + browserCanvasContext.strokeStyle = 'rgba(255, 233, 31, 1)'; // Current candle accroding to time + + } else { + browserCanvasContext.strokeStyle = 'rgba(212, 206, 201, 1)'; + } } else { browserCanvasContext.strokeStyle = 'rgba(212, 206, 201, 1)'; } - } else { - browserCanvasContext.strokeStyle = 'rgba(212, 206, 201, 1)'; - } + browserCanvasContext.lineWidth = 1; + browserCanvasContext.stroke(); - browserCanvasContext.lineWidth = 1; - browserCanvasContext.stroke(); + browserCanvasContext.beginPath(); - browserCanvasContext.beginPath(); + browserCanvasContext.moveTo(candlePoint1.x, candlePoint1.y); + browserCanvasContext.lineTo(candlePoint2.x, candlePoint2.y); + browserCanvasContext.lineTo(candlePoint3.x, candlePoint3.y); + browserCanvasContext.lineTo(candlePoint4.x, candlePoint4.y); - browserCanvasContext.moveTo(candlePoint1.x, candlePoint1.y); - browserCanvasContext.lineTo(candlePoint2.x, candlePoint2.y); - browserCanvasContext.lineTo(candlePoint3.x, candlePoint3.y); - browserCanvasContext.lineTo(candlePoint4.x, candlePoint4.y); + browserCanvasContext.closePath(); - browserCanvasContext.closePath(); + if (candle.direction === 'up') { browserCanvasContext.strokeStyle = 'rgba(27, 105, 7, 1)'; } + if (candle.direction === 'down') { browserCanvasContext.strokeStyle = 'rgba(130, 9, 9, 1)'; } + if (candle.direction === 'side') { browserCanvasContext.strokeStyle = 'rgba(27, 7, 105, 1)'; } - if (candle.direction === 'up') { browserCanvasContext.strokeStyle = 'rgba(27, 105, 7, 1)'; } - if (candle.direction === 'down') { browserCanvasContext.strokeStyle = 'rgba(130, 9, 9, 1)'; } - if (candle.direction === 'side') { browserCanvasContext.strokeStyle = 'rgba(27, 7, 105, 1)'; } + if (datetime !== undefined) { - if (datetime !== undefined) { + let dateValue = datetime.valueOf(); - let dateValue = datetime.valueOf(); + if (dateValue >= candle.begin && dateValue <= candle.end) { - if (dateValue >= candle.begin && dateValue <= candle.end) { + /* highlight the current candle */ - /* highlight the current candle */ + browserCanvasContext.fillStyle = 'rgba(255, 233, 31, 1)'; // Current candle accroding to time - browserCanvasContext.fillStyle = 'rgba(255, 233, 31, 1)'; // Current candle accroding to time + let currentCandle = { + bodyWidth: candlePoint2.x - candlePoint1.x, + bodyHeight: candlePoint3.y - candlePoint2.y, + stickHeight: stickPoint4.y - stickPoint2.y, + stickWidth: stickPoint2.x - stickPoint1.x, + stickStart: candlePoint2.y - stickPoint2.y, + period: timePeriod, + innerCandle: candle + }; - let currentCandle = { - bodyWidth: candlePoint2.x - candlePoint1.x, - bodyHeight: candlePoint3.y - candlePoint2.y, - stickHeight: stickPoint4.y - stickPoint2.y, - stickWidth: stickPoint2.x - stickPoint1.x, - stickStart: candlePoint2.y - stickPoint2.y, - period: timePeriod, - innerCandle: candle - }; + thisObject.container.eventHandler.raiseEvent("Current Candle Changed", currentCandle); - thisObject.container.eventHandler.raiseEvent("Current Candle Changed", currentCandle); + } else { + + if (candle.direction === 'up') { browserCanvasContext.fillStyle = 'rgba(64, 217, 26, 1)'; } + if (candle.direction === 'down') { browserCanvasContext.fillStyle = 'rgba(219, 18, 18, 1)'; } + if (candle.direction === 'side') { browserCanvasContext.fillStyle = 'rgba(64, 26, 217, 1)'; } + } } else { if (candle.direction === 'up') { browserCanvasContext.fillStyle = 'rgba(64, 217, 26, 1)'; } if (candle.direction === 'down') { browserCanvasContext.fillStyle = 'rgba(219, 18, 18, 1)'; } if (candle.direction === 'side') { browserCanvasContext.fillStyle = 'rgba(64, 26, 217, 1)'; } + } - } else { - if (candle.direction === 'up') { browserCanvasContext.fillStyle = 'rgba(64, 217, 26, 1)'; } - if (candle.direction === 'down') { browserCanvasContext.fillStyle = 'rgba(219, 18, 18, 1)'; } - if (candle.direction === 'side') { browserCanvasContext.fillStyle = 'rgba(64, 26, 217, 1)'; } + + if ( + candlePoint1.x < viewPort.visibleArea.topLeft.x + 50 + || + candlePoint1.x > viewPort.visibleArea.bottomRight.x - 50 + ) { + // we leave this candles without fill. + } else { + browserCanvasContext.fill(); + } + + browserCanvasContext.lineWidth = 1; + browserCanvasContext.stroke(); + } - - - - if ( - candlePoint1.x < viewPort.visibleArea.topLeft.x + 50 - || - candlePoint1.x > viewPort.visibleArea.bottomRight.x - 50 - ) { - // we leave this candles without fill. - } else { - browserCanvasContext.fill(); - } - - browserCanvasContext.lineWidth = 1; - browserCanvasContext.stroke(); - - } + + } catch (err) { + + if (ERROR_LOG === true) { logger.write("[ERROR] plotChart -> err.message = " + err.message); } } } function onZoomChanged(event) { - recalculate(); + try { + if (INFO_LOG === true) { logger.write("[INFO] onZoomChanged -> Entering function."); } + + recalculate(); + + } catch (err) { + + if (ERROR_LOG === true) { logger.write("[ERROR] onZoomChanged -> err.message = " + err.message); } + } } function onOffsetChanged() { - if (Math.random() * 100 > 95) { + try { - recalculate() - }; + if (INFO_LOG === true) { logger.write("[INFO] onOffsetChanged -> Entering function."); } + if (Math.random() * 100 > 95) { + + recalculate() + }; + + } catch (err) { + + if (ERROR_LOG === true) { logger.write("[ERROR] onOffsetChanged -> err.message = " + err.message); } + } } function onDragFinished() { - recalculate(); + try { + if (INFO_LOG === true) { logger.write("[INFO] onDragFinished -> Entering function."); } + + recalculate(); + + } catch (err) { + + if (ERROR_LOG === true) { logger.write("[ERROR] onDragFinished -> err.message = " + err.message); } + } } } diff --git a/Volumes.js b/Volumes.js index 0fb840edd..83de73609 100644 --- a/Volumes.js +++ b/Volumes.js @@ -1,5 +1,12 @@ function newAAMastersPlottersCandlesVolumesVolumes() { + const MODULE_NAME = "Volumes Plotter"; + const INFO_LOG = false; + const ERROR_LOG = true; + const INTENSIVE_LOG = false; + const logger = newWebDebugLog(); + logger.fileName = MODULE_NAME; + let thisObject = { /* Events declared outside the plotter. */ @@ -44,666 +51,795 @@ function initialize(pStorage, pExchange, pMarket, pDatetime, pTimePeriod, callBackFunction) { - /* Store the information received. */ + try { - marketFiles = pStorage.marketFiles[0]; - dailyFiles = pStorage.dailyFiles[0]; + if (INFO_LOG === true) { logger.write("[INFO] initialize -> Entering function."); } - datetime = pDatetime; - timePeriod = pTimePeriod; + /* Store the information received. */ - /* We need a Market File in order to calculate the Y scale, since this scale depends on actual data. */ + marketFiles = pStorage.marketFiles[0]; + dailyFiles = pStorage.dailyFiles[0]; - scaleFile = marketFiles.getFile(ONE_DAY_IN_MILISECONDS); // This file is the one processed faster. + datetime = pDatetime; + timePeriod = pTimePeriod; - /* Now we set the right files according to current Period. */ + /* We need a Market File in order to calculate the Y scale, since this scale depends on actual data. */ - marketFile = marketFiles.getFile(pTimePeriod); - fileCursor = dailyFiles.getFileCursor(pTimePeriod); + scaleFile = marketFiles.getFile(ONE_DAY_IN_MILISECONDS); // This file is the one processed faster. - /* Listen to the necesary events. */ + /* Now we set the right files according to current Period. */ - viewPort.eventHandler.listenToEvent("Zoom Changed", onZoomChanged); - viewPort.eventHandler.listenToEvent("Offset Changed", onOffsetChanged); - marketFiles.eventHandler.listenToEvent("Files Updated", onFilesUpdated); - canvas.eventHandler.listenToEvent("Drag Finished", onDragFinished); + marketFile = marketFiles.getFile(pTimePeriod); + fileCursor = dailyFiles.getFileCursor(pTimePeriod); - /* Get ready for plotting. */ + /* Listen to the necesary events. */ - recalculateScaleX(); - recalculate(); - recalculateScaleY(); + viewPort.eventHandler.listenToEvent("Zoom Changed", onZoomChanged); + viewPort.eventHandler.listenToEvent("Offset Changed", onOffsetChanged); + marketFiles.eventHandler.listenToEvent("Files Updated", onFilesUpdated); + canvas.eventHandler.listenToEvent("Drag Finished", onDragFinished); - callBackFunction(); - - } - - function getContainer(point) { - - let container; - - /* First we check if this point is inside this space. */ - - if (this.container.frame.isThisPointHere(point) === true) { - - return this.container; - - } else { - - /* This point does not belong to this space. */ - - return undefined; - } - - } - - function onFilesUpdated() { - - let newMarketFile = marketFiles.getFile(timePeriod); - - if (newMarketFile !== undefined) { - - marketFile = newMarketFile; + /* Get ready for plotting. */ recalculateScaleX(); recalculate(); recalculateScaleY(); - } + callBackFunction(); + } catch (err) { + + if (ERROR_LOG === true) { logger.write("[ERROR] initialize -> err.message = " + err.message); } + } + } + + function getContainer(point) { + + try { + + if (INFO_LOG === true) { logger.write("[INFO] getContainer -> Entering function."); } + + let container; + + /* First we check if this point is inside this space. */ + + if (this.container.frame.isThisPointHere(point) === true) { + + return this.container; + + } else { + + /* This point does not belong to this space. */ + + return undefined; + } + + } catch (err) { + + if (ERROR_LOG === true) { logger.write("[ERROR] getContainer -> err.message = " + err.message); } + } + } + + function onFilesUpdated() { + + try { + + if (INFO_LOG === true) { logger.write("[INFO] onFilesUpdated -> Entering function."); } + + let newMarketFile = marketFiles.getFile(timePeriod); + + if (newMarketFile !== undefined) { + + marketFile = newMarketFile; + + recalculateScaleX(); + recalculate(); + recalculateScaleY(); + + } + + } catch (err) { + + if (ERROR_LOG === true) { logger.write("[ERROR] onFilesUpdated -> err.message = " + err.message); } + } } function setTimePeriod(pTimePeriod) { - if (timePeriod !== pTimePeriod) { + try { - timePeriod = pTimePeriod; + if (INFO_LOG === true) { logger.write("[INFO] setTimePeriod -> Entering function."); } - if (timePeriod >= _1_HOUR_IN_MILISECONDS) { + if (timePeriod !== pTimePeriod) { - let newMarketFile = marketFiles.getFile(pTimePeriod); + timePeriod = pTimePeriod; - if (newMarketFile !== undefined) { + if (timePeriod >= _1_HOUR_IN_MILISECONDS) { - marketFile = newMarketFile; - recalculate(); - } + let newMarketFile = marketFiles.getFile(pTimePeriod); - } else { + if (newMarketFile !== undefined) { - let newFileCursor = dailyFiles.getFileCursor(pTimePeriod); + marketFile = newMarketFile; + recalculate(); + } - if (newFileCursor !== undefined) { + } else { - fileCursor = newFileCursor; - recalculate(); + let newFileCursor = dailyFiles.getFileCursor(pTimePeriod); + + if (newFileCursor !== undefined) { + + fileCursor = newFileCursor; + recalculate(); + } } } + + } catch (err) { + + if (ERROR_LOG === true) { logger.write("[ERROR] setTimePeriod -> err.message = " + err.message); } } } function setDatetime(pDatetime) { + if (INFO_LOG === true) { logger.write("[INFO] setDatetime -> Entering function."); } + datetime = pDatetime; } function onDailyFileLoaded(event) { - if (event.currentValue === event.totalValue) { + try { - /* This happens only when all of the files in the cursor have been loaded. */ + if (INFO_LOG === true) { logger.write("[INFO] onDailyFileLoaded -> Entering function."); } - recalculateScaleX(); - recalculate(); - recalculateScaleY(); + if (event.currentValue === event.totalValue) { + /* This happens only when all of the files in the cursor have been loaded. */ + + recalculateScaleX(); + recalculate(); + recalculateScaleY(); + + } + + } catch (err) { + + if (ERROR_LOG === true) { logger.write("[ERROR] onDailyFileLoaded -> err.message = " + err.message); } } } function draw() { - this.container.frame.draw(); + try { - plotChart(); + if (INTENSIVE_LOG === true) { logger.write("[INFO] draw -> Entering function."); } + this.container.frame.draw(); + + plotChart(); + + } catch (err) { + + if (ERROR_LOG === true) { logger.write("[ERROR] draw -> err.message = " + err.message); } + } } function recalculate() { - if (timePeriod >= _1_HOUR_IN_MILISECONDS) { + try { - recalculateUsingMarketFiles(); + if (INFO_LOG === true) { logger.write("[INFO] recalculate -> Entering function."); } - } else { + if (timePeriod >= _1_HOUR_IN_MILISECONDS) { - recalculateUsingDailyFiles(); + recalculateUsingMarketFiles(); + } else { + + recalculateUsingDailyFiles(); + + } + + thisObject.container.eventHandler.raiseEvent("Volumes Changed", volumes); + + } catch (err) { + + if (ERROR_LOG === true) { logger.write("[ERROR] recalculate -> err.message = " + err.message); } } - - thisObject.container.eventHandler.raiseEvent("Volumes Changed", volumes); } function recalculateUsingDailyFiles() { - if (fileCursor === undefined) { return; } // We need to wait + try { - if (fileCursor.files.size === 0) { return; } // We need to wait until there are files in the cursor + if (INFO_LOG === true) { logger.write("[INFO] recalculateUsingDailyFiles -> Entering function."); } - let leftDate = getDateFromPoint(viewPort.visibleArea.topLeft, thisObject.container, timeLineCoordinateSystem); - let rightDate = getDateFromPoint(viewPort.visibleArea.topRight, thisObject.container, timeLineCoordinateSystem); + if (fileCursor === undefined) { return; } // We need to wait - let dateDiff = rightDate.valueOf() - leftDate.valueOf(); + if (fileCursor.files.size === 0) { return; } // We need to wait until there are files in the cursor - let farLeftDate = new Date(leftDate.valueOf() - dateDiff * 1.5); - let farRightDate = new Date(rightDate.valueOf() + dateDiff * 1.5); + let leftDate = getDateFromPoint(viewPort.visibleArea.topLeft, thisObject.container, timeLineCoordinateSystem); + let rightDate = getDateFromPoint(viewPort.visibleArea.topRight, thisObject.container, timeLineCoordinateSystem); - let currentDate = new Date(farLeftDate.valueOf()); + let dateDiff = rightDate.valueOf() - leftDate.valueOf(); - volumes = []; + let farLeftDate = new Date(leftDate.valueOf() - dateDiff * 1.5); + let farRightDate = new Date(rightDate.valueOf() + dateDiff * 1.5); - while (currentDate.valueOf() <= farRightDate.valueOf() + ONE_DAY_IN_MILISECONDS) { + let currentDate = new Date(farLeftDate.valueOf()); - let stringDate = currentDate.getFullYear() + '-' + pad(currentDate.getMonth() + 1, 2) + '-' + pad(currentDate.getDate(), 2); + volumes = []; - let dailyFile = fileCursor.files.get(stringDate); + while (currentDate.valueOf() <= farRightDate.valueOf() + ONE_DAY_IN_MILISECONDS) { - if (dailyFile !== undefined) { + let stringDate = currentDate.getFullYear() + '-' + pad(currentDate.getMonth() + 1, 2) + '-' + pad(currentDate.getDate(), 2); - for (let i = 0; i < dailyFile.length; i++) { + let dailyFile = fileCursor.files.get(stringDate); - let volume = { - amountBuy: 0, - amountSell: 0, - begin: undefined, - end: undefined - }; + if (dailyFile !== undefined) { - volume.amountBuy = dailyFile[i][0]; - volume.amountSell = dailyFile[i][1]; + for (let i = 0; i < dailyFile.length; i++) { - volume.begin = dailyFile[i][2]; - volume.end = dailyFile[i][3]; + let volume = { + amountBuy: 0, + amountSell: 0, + begin: undefined, + end: undefined + }; - if (volume.begin >= farLeftDate.valueOf() && volume.end <= farRightDate.valueOf()) { + volume.amountBuy = dailyFile[i][0]; + volume.amountSell = dailyFile[i][1]; - volumes.push(volume); + volume.begin = dailyFile[i][2]; + volume.end = dailyFile[i][3]; - if (datetime.valueOf() >= volume.begin && datetime.valueOf() <= volume.end) { + if (volume.begin >= farLeftDate.valueOf() && volume.end <= farRightDate.valueOf()) { - thisObject.container.eventHandler.raiseEvent("Current Volume Changed", thisObject.currentCandle); + volumes.push(volume); + if (datetime.valueOf() >= volume.begin && datetime.valueOf() <= volume.end) { + + thisObject.container.eventHandler.raiseEvent("Current Volume Changed", thisObject.currentCandle); + + } } } } + + currentDate = new Date(currentDate.valueOf() + ONE_DAY_IN_MILISECONDS); } - currentDate = new Date(currentDate.valueOf() + ONE_DAY_IN_MILISECONDS); - } + /* Lests check if all the visible screen is going to be covered by volumes. */ - /* Lests check if all the visible screen is going to be covered by volumes. */ + let lowerEnd = leftDate.valueOf(); + let upperEnd = rightDate.valueOf(); - let lowerEnd = leftDate.valueOf(); - let upperEnd = rightDate.valueOf(); + if (volumes.length > 0) { - if (volumes.length > 0) { + if (volumes[0].begin > lowerEnd || volumes[volumes.length - 1].end < upperEnd) { - if (volumes[0].begin > lowerEnd || volumes[volumes.length - 1].end < upperEnd) { + setTimeout(recalculate, 2000); - setTimeout(recalculate, 2000); - - //console.log("File missing while calculating volumes, scheduling a recalculation in 2 seconds."); + //console.log("File missing while calculating volumes, scheduling a recalculation in 2 seconds."); + } } + + //console.log("Olivia > recalculateUsingDailyFiles > total volumes generated : " + volumes.length); + + } catch (err) { + + if (ERROR_LOG === true) { logger.write("[ERROR] recalculateUsingDailyFiles -> err.message = " + err.message); } } - - //console.log("Olivia > recalculateUsingDailyFiles > total volumes generated : " + volumes.length); - } function recalculateUsingMarketFiles() { - if (marketFile === undefined) { return; } // Initialization not complete yet. + try { - let leftDate = getDateFromPoint(viewPort.visibleArea.topLeft, thisObject.container, timeLineCoordinateSystem); - let rightDate = getDateFromPoint(viewPort.visibleArea.topRight, thisObject.container, timeLineCoordinateSystem); + if (INFO_LOG === true) { logger.write("[INFO] recalculateUsingMarketFiles -> Entering function."); } - let dateDiff = rightDate.valueOf() - leftDate.valueOf(); + if (marketFile === undefined) { return; } // Initialization not complete yet. - leftDate = new Date(leftDate.valueOf() - dateDiff * 1.5); - rightDate = new Date(rightDate.valueOf() + dateDiff * 1.5); + let leftDate = getDateFromPoint(viewPort.visibleArea.topLeft, thisObject.container, timeLineCoordinateSystem); + let rightDate = getDateFromPoint(viewPort.visibleArea.topRight, thisObject.container, timeLineCoordinateSystem); - volumes = []; + let dateDiff = rightDate.valueOf() - leftDate.valueOf(); - for (let i = 0; i < marketFile.length; i++) { + leftDate = new Date(leftDate.valueOf() - dateDiff * 1.5); + rightDate = new Date(rightDate.valueOf() + dateDiff * 1.5); - let volume = { - amountBuy: 0, - amountSell: 0, - begin: undefined, - end: undefined - }; + volumes = []; - volume.amountBuy = marketFile[i][0]; - volume.amountSell = marketFile[i][1]; + for (let i = 0; i < marketFile.length; i++) { - volume.begin = marketFile[i][2]; - volume.end = marketFile[i][3]; + let volume = { + amountBuy: 0, + amountSell: 0, + begin: undefined, + end: undefined + }; - if (volume.begin >= leftDate.valueOf() && volume.end <= rightDate.valueOf()) { + volume.amountBuy = marketFile[i][0]; + volume.amountSell = marketFile[i][1]; - volumes.push(volume); + volume.begin = marketFile[i][2]; + volume.end = marketFile[i][3]; - if (datetime.valueOf() >= volume.begin && datetime.valueOf() <= volume.end) { + if (volume.begin >= leftDate.valueOf() && volume.end <= rightDate.valueOf()) { - thisObject.container.eventHandler.raiseEvent("Current Volume Changed", thisObject.currentCandle); + volumes.push(volume); + if (datetime.valueOf() >= volume.begin && datetime.valueOf() <= volume.end) { + + thisObject.container.eventHandler.raiseEvent("Current Volume Changed", thisObject.currentCandle); + + } } } - } - //console.log("Olivia > recalculateUsingMarketFiles > total volumes generated : " + volumes.length); + //console.log("Olivia > recalculateUsingMarketFiles > total volumes generated : " + volumes.length); + + } catch (err) { + + if (ERROR_LOG === true) { logger.write("[ERROR] recalculateUsingMarketFiles -> err.message = " + err.message); } + } } function recalculateScaleX() { + try { - var minValue = { - x: EARLIEST_DATE.valueOf() - }; + if (INFO_LOG === true) { logger.write("[INFO] recalculateScaleX -> Entering function."); } - var maxValue = { - x: MAX_PLOTABLE_DATE.valueOf() - }; + var minValue = { + x: EARLIEST_DATE.valueOf() + }; - timeLineCoordinateSystem.initializeX( - minValue, - maxValue, - thisObject.container.frame.width - ); + var maxValue = { + x: MAX_PLOTABLE_DATE.valueOf() + }; - plotAreaFrame.initializeX( - minValue, - maxValue, - thisObject.container.frame.width - ); + timeLineCoordinateSystem.initializeX( + minValue, + maxValue, + thisObject.container.frame.width + ); + plotAreaFrame.initializeX( + minValue, + maxValue, + thisObject.container.frame.width + ); + + } catch (err) { + + if (ERROR_LOG === true) { logger.write("[ERROR] recalculateScaleX -> err.message = " + err.message); } + } } function recalculateScaleY() { - var minValue = { - y: 0 - }; + try { - var maxValue = { - y: 0 - }; + if (INFO_LOG === true) { logger.write("[INFO] recalculateScaleY -> Entering function."); } - let timePeriodRatio = ONE_DAY_IN_MILISECONDS / timePeriod; + var minValue = { + y: 0 + }; - maxValue.y = getMaxVolume() / (timePeriodRatio / 2.5); + var maxValue = { + y: 0 + }; - timeLineCoordinateSystem.initializeY( - minValue, - maxValue, - viewPort.visibleArea.bottomRight.y - viewPort.visibleArea.topLeft.y - ); + let timePeriodRatio = ONE_DAY_IN_MILISECONDS / timePeriod; - plotAreaFrame.initializeY( - minValue, - maxValue, - thisObject.container.frame.height - ); + maxValue.y = getMaxVolume() / (timePeriodRatio / 2.5); - function getMaxVolume() { + timeLineCoordinateSystem.initializeY( + minValue, + maxValue, + viewPort.visibleArea.bottomRight.y - viewPort.visibleArea.topLeft.y + ); - let maxValue = 0; + plotAreaFrame.initializeY( + minValue, + maxValue, + thisObject.container.frame.height + ); - for (var i = 0; i < scaleFile.length; i++) { + function getMaxVolume() { - let currentMax = (scaleFile[i][0] + scaleFile[i][1]) * 4; + if (INFO_LOG === true) { logger.write("[INFO] initialize -> Entering function."); } - if (maxValue < currentMax) { - maxValue = currentMax; + let maxValue = 0; + + for (var i = 0; i < scaleFile.length; i++) { + + let currentMax = (scaleFile[i][0] + scaleFile[i][1]) * 4; + + if (maxValue < currentMax) { + maxValue = currentMax; + } } + + return maxValue; + } - return maxValue; + } catch (err) { + if (ERROR_LOG === true) { logger.write("[ERROR] recalculateScaleY -> err.message = " + err.message); } } - } function plotChart() { - if (volumes.length > 0) { + try { - /* Now we calculate and plot the volumes */ - - let visibleHeight = viewPort.visibleArea.bottomRight.y - viewPort.visibleArea.topLeft.y; - - let frameCorner1 = { - x: 0, - y: 0 - }; - - let frameCorner2 = { - x: thisObject.container.frame.width, - y: thisObject.container.frame.height - }; - - - /* Now the transformations. */ - - frameCorner1 = transformThisPoint(frameCorner1, thisObject.container.frame.container); - frameCorner2 = transformThisPoint(frameCorner2, thisObject.container.frame.container); - - let frameHeightInViewPort = frameCorner2.y - frameCorner1.y; + if (INTENSIVE_LOG === true) { logger.write("[INFO] plotChart -> Entering function."); } if (volumes.length > 0) { - for (var i = 0; i < volumes.length; i++) { + /* Now we calculate and plot the volumes */ - volume = volumes[i]; + let visibleHeight = viewPort.visibleArea.bottomRight.y - viewPort.visibleArea.topLeft.y; - let volumePointA1; - let volumePointA2; - let volumePointA3; - let volumePointA4; + let frameCorner1 = { + x: 0, + y: 0 + }; - function calculateBuys(plot, height) { + let frameCorner2 = { + x: thisObject.container.frame.width, + y: thisObject.container.frame.height + }; - volumePointA1 = { - x: volume.begin + timePeriod / 7 * 2, - y: 0 - }; - volumePointA2 = { - x: volume.begin + timePeriod / 7 * 2, - y: volume.amountBuy - }; + /* Now the transformations. */ - volumePointA3 = { - x: volume.begin + timePeriod / 7 * 5, - y: volume.amountBuy - }; + frameCorner1 = transformThisPoint(frameCorner1, thisObject.container.frame.container); + frameCorner2 = transformThisPoint(frameCorner2, thisObject.container.frame.container); - volumePointA4 = { - x: volume.begin + timePeriod / 7 * 5, - y: 0 - }; + let frameHeightInViewPort = frameCorner2.y - frameCorner1.y; - volumePointA1 = plot.transformThisPoint(volumePointA1); - volumePointA2 = plot.transformThisPoint(volumePointA2); - volumePointA3 = plot.transformThisPoint(volumePointA3); - volumePointA4 = plot.transformThisPoint(volumePointA4); + if (volumes.length > 0) { - volumePointA1 = transformThisPoint(volumePointA1, thisObject.container); - volumePointA2 = transformThisPoint(volumePointA2, thisObject.container); - volumePointA3 = transformThisPoint(volumePointA3, thisObject.container); - volumePointA4 = transformThisPoint(volumePointA4, thisObject.container); + for (var i = 0; i < volumes.length; i++) { - let baseIncrement = (volumePointA3.x - volumePointA1.x) * WIDHTER_VOLUME_BAR_BASE_FACTOR; + volume = volumes[i]; - volumePointA1.x = volumePointA1.x - baseIncrement; - volumePointA4.x = volumePointA4.x + baseIncrement; + let volumePointA1; + let volumePointA2; + let volumePointA3; + let volumePointA4; + + function calculateBuys(plot, height) { + + volumePointA1 = { + x: volume.begin + timePeriod / 7 * 2, + y: 0 + }; + + volumePointA2 = { + x: volume.begin + timePeriod / 7 * 2, + y: volume.amountBuy + }; + + volumePointA3 = { + x: volume.begin + timePeriod / 7 * 5, + y: volume.amountBuy + }; + + volumePointA4 = { + x: volume.begin + timePeriod / 7 * 5, + y: 0 + }; + + volumePointA1 = plot.transformThisPoint(volumePointA1); + volumePointA2 = plot.transformThisPoint(volumePointA2); + volumePointA3 = plot.transformThisPoint(volumePointA3); + volumePointA4 = plot.transformThisPoint(volumePointA4); + + volumePointA1 = transformThisPoint(volumePointA1, thisObject.container); + volumePointA2 = transformThisPoint(volumePointA2, thisObject.container); + volumePointA3 = transformThisPoint(volumePointA3, thisObject.container); + volumePointA4 = transformThisPoint(volumePointA4, thisObject.container); + + let baseIncrement = (volumePointA3.x - volumePointA1.x) * WIDHTER_VOLUME_BAR_BASE_FACTOR; + + volumePointA1.x = volumePointA1.x - baseIncrement; + volumePointA4.x = volumePointA4.x + baseIncrement; + + if (volumePointA4.x < viewPort.visibleArea.bottomLeft.x || volumePointA1.x > viewPort.visibleArea.bottomRight.x) { + return false; + } + + return true; - if (volumePointA4.x < viewPort.visibleArea.bottomLeft.x || volumePointA1.x > viewPort.visibleArea.bottomRight.x) { - return false; } - return true; + if (calculateBuys(plotAreaFrame, thisObject.container.frame.height) === false) { continue; } // We try to see if it fits in the visible area. - } + if (volumePointA1.y > viewPort.visibleArea.bottomLeft.y && frameHeightInViewPort > visibleHeight * 2 / 3) { - if (calculateBuys(plotAreaFrame, thisObject.container.frame.height) === false) { continue; } // We try to see if it fits in the visible area. + if (calculateBuys(timeLineCoordinateSystem, visibleHeight) === false) { continue; } // We snap t to the view port. - if (volumePointA1.y > viewPort.visibleArea.bottomLeft.y && frameHeightInViewPort > visibleHeight * 2 / 3) { + /* Now we set the real value of y. */ - if (calculateBuys(timeLineCoordinateSystem, visibleHeight) === false) { continue; } // We snap t to the view port. + volumePointA1.y = viewPort.visibleArea.bottomRight.y; + volumePointA2.y = viewPort.visibleArea.bottomRight.y - volume.amountBuy * timeLineCoordinateSystem.scale.y; + volumePointA3.y = viewPort.visibleArea.bottomRight.y - volume.amountBuy * timeLineCoordinateSystem.scale.y; + volumePointA4.y = viewPort.visibleArea.bottomRight.y; - /* Now we set the real value of y. */ + } - volumePointA1.y = viewPort.visibleArea.bottomRight.y; - volumePointA2.y = viewPort.visibleArea.bottomRight.y - volume.amountBuy * timeLineCoordinateSystem.scale.y; - volumePointA3.y = viewPort.visibleArea.bottomRight.y - volume.amountBuy * timeLineCoordinateSystem.scale.y; - volumePointA4.y = viewPort.visibleArea.bottomRight.y; + let volumePointB1; + let volumePointB2; + let volumePointB3; + let volumePointB4; - } + function calculateSells(plot, height) { - let volumePointB1; - let volumePointB2; - let volumePointB3; - let volumePointB4; + volumePointB1 = { + x: volume.begin + timePeriod / 7 * 2, + y: height + }; - function calculateSells(plot, height) { + volumePointB2 = { + x: volume.begin + timePeriod / 7 * 2, + y: height - volume.amountSell + }; - volumePointB1 = { - x: volume.begin + timePeriod / 7 * 2, - y: height - }; + volumePointB3 = { + x: volume.begin + timePeriod / 7 * 5, + y: height - volume.amountSell + }; - volumePointB2 = { - x: volume.begin + timePeriod / 7 * 2, - y: height - volume.amountSell - }; + volumePointB4 = { + x: volume.begin + timePeriod / 7 * 5, + y: height + }; - volumePointB3 = { - x: volume.begin + timePeriod / 7 * 5, - y: height - volume.amountSell - }; + volumePointB1 = plot.transformThisPoint2(volumePointB1); + volumePointB2 = plot.transformThisPoint2(volumePointB2); + volumePointB3 = plot.transformThisPoint2(volumePointB3); + volumePointB4 = plot.transformThisPoint2(volumePointB4); - volumePointB4 = { - x: volume.begin + timePeriod / 7 * 5, - y: height - }; + volumePointB1 = transformThisPoint(volumePointB1, thisObject.container); + volumePointB2 = transformThisPoint(volumePointB2, thisObject.container); + volumePointB3 = transformThisPoint(volumePointB3, thisObject.container); + volumePointB4 = transformThisPoint(volumePointB4, thisObject.container); - volumePointB1 = plot.transformThisPoint2(volumePointB1); - volumePointB2 = plot.transformThisPoint2(volumePointB2); - volumePointB3 = plot.transformThisPoint2(volumePointB3); - volumePointB4 = plot.transformThisPoint2(volumePointB4); + } - volumePointB1 = transformThisPoint(volumePointB1, thisObject.container); - volumePointB2 = transformThisPoint(volumePointB2, thisObject.container); - volumePointB3 = transformThisPoint(volumePointB3, thisObject.container); - volumePointB4 = transformThisPoint(volumePointB4, thisObject.container); + calculateSells(plotAreaFrame, thisObject.container.frame.height); // We try to see if it fits in the visible area. - } + if (volumePointB1.y < viewPort.visibleArea.topLeft.y && frameHeightInViewPort > visibleHeight * 2 / 3) { - calculateSells(plotAreaFrame, thisObject.container.frame.height); // We try to see if it fits in the visible area. + calculateSells(timeLineCoordinateSystem, visibleHeight); // We snap it to the view port. - if (volumePointB1.y < viewPort.visibleArea.topLeft.y && frameHeightInViewPort > visibleHeight * 2 / 3) { + /* Now we set the real value of y. */ - calculateSells(timeLineCoordinateSystem, visibleHeight); // We snap it to the view port. + volumePointB1.y = viewPort.visibleArea.topLeft.y; + volumePointB2.y = viewPort.visibleArea.topLeft.y + volume.amountSell * timeLineCoordinateSystem.scale.y; + volumePointB3.y = viewPort.visibleArea.topLeft.y + volume.amountSell * timeLineCoordinateSystem.scale.y; + volumePointB4.y = viewPort.visibleArea.topLeft.y; - /* Now we set the real value of y. */ + } - volumePointB1.y = viewPort.visibleArea.topLeft.y; - volumePointB2.y = viewPort.visibleArea.topLeft.y + volume.amountSell * timeLineCoordinateSystem.scale.y; - volumePointB3.y = viewPort.visibleArea.topLeft.y + volume.amountSell * timeLineCoordinateSystem.scale.y; - volumePointB4.y = viewPort.visibleArea.topLeft.y; + /* We put a wider base */ - } + let baseIncrement = (volumePointB3.x - volumePointB1.x) * WIDHTER_VOLUME_BAR_BASE_FACTOR; - /* We put a wider base */ + volumePointB1.x = volumePointB1.x - baseIncrement; + volumePointB4.x = volumePointB4.x + baseIncrement; - let baseIncrement = (volumePointB3.x - volumePointB1.x) * WIDHTER_VOLUME_BAR_BASE_FACTOR; + /* We put a less wider top */ - volumePointB1.x = volumePointB1.x - baseIncrement; - volumePointB4.x = volumePointB4.x + baseIncrement; + let baseDencrement = (volumePointA3.x - volumePointA2.x) * LESS_WIDHTER_VOLUME_BAR_TOP_FACTOR; - /* We put a less wider top */ + volumePointA2.x = volumePointA2.x + baseDencrement; + volumePointA3.x = volumePointA3.x - baseDencrement; - let baseDencrement = (volumePointA3.x - volumePointA2.x) * LESS_WIDHTER_VOLUME_BAR_TOP_FACTOR; - - volumePointA2.x = volumePointA2.x + baseDencrement; - volumePointA3.x = volumePointA3.x - baseDencrement; - - volumePointB2.x = volumePointB2.x + baseDencrement; - volumePointB3.x = volumePointB3.x - baseDencrement; + volumePointB2.x = volumePointB2.x + baseDencrement; + volumePointB3.x = volumePointB3.x - baseDencrement; - /* Everything must fit within the visible area */ + /* Everything must fit within the visible area */ - volumePointA1 = viewPort.fitIntoVisibleArea(volumePointA1); - volumePointA2 = viewPort.fitIntoVisibleArea(volumePointA2); - volumePointA3 = viewPort.fitIntoVisibleArea(volumePointA3); - volumePointA4 = viewPort.fitIntoVisibleArea(volumePointA4); + volumePointA1 = viewPort.fitIntoVisibleArea(volumePointA1); + volumePointA2 = viewPort.fitIntoVisibleArea(volumePointA2); + volumePointA3 = viewPort.fitIntoVisibleArea(volumePointA3); + volumePointA4 = viewPort.fitIntoVisibleArea(volumePointA4); - volumePointB1 = viewPort.fitIntoVisibleArea(volumePointB1); - volumePointB2 = viewPort.fitIntoVisibleArea(volumePointB2); - volumePointB3 = viewPort.fitIntoVisibleArea(volumePointB3); - volumePointB4 = viewPort.fitIntoVisibleArea(volumePointB4); + volumePointB1 = viewPort.fitIntoVisibleArea(volumePointB1); + volumePointB2 = viewPort.fitIntoVisibleArea(volumePointB2); + volumePointB3 = viewPort.fitIntoVisibleArea(volumePointB3); + volumePointB4 = viewPort.fitIntoVisibleArea(volumePointB4); - /* Everything must fit within the Frame. We know that that is equivalent to say that each bar con not be higher than the base of the opposite . */ + /* Everything must fit within the Frame. We know that that is equivalent to say that each bar con not be higher than the base of the opposite . */ - if (volumePointA2.y < volumePointB1.y) { + if (volumePointA2.y < volumePointB1.y) { - volumePointA2.y = volumePointB1.y; - volumePointA3.y = volumePointB1.y; + volumePointA2.y = volumePointB1.y; + volumePointA3.y = volumePointB1.y; - } + } - if (volumePointB2.y > volumePointA1.y) { + if (volumePointB2.y > volumePointA1.y) { - volumePointB2.y = volumePointA1.y; - volumePointB3.y = volumePointA1.y; + volumePointB2.y = volumePointA1.y; + volumePointB3.y = volumePointA1.y; - } + } - /* Now the drawing of the volume bars*/ + /* Now the drawing of the volume bars*/ - browserCanvasContext.beginPath(); + browserCanvasContext.beginPath(); - browserCanvasContext.moveTo(volumePointA1.x, volumePointA1.y); - browserCanvasContext.lineTo(volumePointA2.x, volumePointA2.y); - browserCanvasContext.lineTo(volumePointA3.x, volumePointA3.y); - browserCanvasContext.lineTo(volumePointA4.x, volumePointA4.y); + browserCanvasContext.moveTo(volumePointA1.x, volumePointA1.y); + browserCanvasContext.lineTo(volumePointA2.x, volumePointA2.y); + browserCanvasContext.lineTo(volumePointA3.x, volumePointA3.y); + browserCanvasContext.lineTo(volumePointA4.x, volumePointA4.y); - browserCanvasContext.closePath(); + browserCanvasContext.closePath(); - if (datetime !== undefined) { + if (datetime !== undefined) { - let dateValue = datetime.valueOf(); + let dateValue = datetime.valueOf(); - if (dateValue >= volume.begin && dateValue <= volume.end) { + if (dateValue >= volume.begin && dateValue <= volume.end) { - browserCanvasContext.fillStyle = 'rgba(255, 233, 31, 0.40)'; // Current bar accroding to time + browserCanvasContext.fillStyle = 'rgba(255, 233, 31, 0.40)'; // Current bar accroding to time + + } else { + + browserCanvasContext.fillStyle = 'rgba(64, 217, 26, 0.40)'; + } } else { browserCanvasContext.fillStyle = 'rgba(64, 217, 26, 0.40)'; + } - } else { - - browserCanvasContext.fillStyle = 'rgba(64, 217, 26, 0.40)'; - - } - - browserCanvasContext.fill(); - browserCanvasContext.strokeStyle = 'rgba(27, 105, 7, 0.40)'; - browserCanvasContext.lineWidth = 1; - browserCanvasContext.stroke(); + browserCanvasContext.fill(); + browserCanvasContext.strokeStyle = 'rgba(27, 105, 7, 0.40)'; + browserCanvasContext.lineWidth = 1; + browserCanvasContext.stroke(); - browserCanvasContext.beginPath(); + browserCanvasContext.beginPath(); - browserCanvasContext.moveTo(volumePointB1.x, volumePointB1.y); - browserCanvasContext.lineTo(volumePointB2.x, volumePointB2.y); - browserCanvasContext.lineTo(volumePointB3.x, volumePointB3.y); - browserCanvasContext.lineTo(volumePointB4.x, volumePointB4.y); + browserCanvasContext.moveTo(volumePointB1.x, volumePointB1.y); + browserCanvasContext.lineTo(volumePointB2.x, volumePointB2.y); + browserCanvasContext.lineTo(volumePointB3.x, volumePointB3.y); + browserCanvasContext.lineTo(volumePointB4.x, volumePointB4.y); - browserCanvasContext.closePath(); + browserCanvasContext.closePath(); - if (datetime !== undefined) { + if (datetime !== undefined) { - let dateValue = datetime.valueOf(); + let dateValue = datetime.valueOf(); - if (dateValue >= volume.begin && dateValue <= volume.end) { + if (dateValue >= volume.begin && dateValue <= volume.end) { - browserCanvasContext.fillStyle = 'rgba(255, 233, 31, 0.40)'; // Current volume accroding to time + browserCanvasContext.fillStyle = 'rgba(255, 233, 31, 0.40)'; // Current volume accroding to time + + } else { + + browserCanvasContext.fillStyle = 'rgba(219, 18, 18, 0.40)'; + } } else { browserCanvasContext.fillStyle = 'rgba(219, 18, 18, 0.40)'; + } - } else { + browserCanvasContext.strokeStyle = 'rgba(130, 9, 9, 0.40)'; - browserCanvasContext.fillStyle = 'rgba(219, 18, 18, 0.40)'; - - } - - browserCanvasContext.strokeStyle = 'rgba(130, 9, 9, 0.40)'; - - browserCanvasContext.fill(); - browserCanvasContext.lineWidth = 1; - browserCanvasContext.stroke(); + browserCanvasContext.fill(); + browserCanvasContext.lineWidth = 1; + browserCanvasContext.stroke(); - if (datetime !== undefined) { + if (datetime !== undefined) { - let dateValue = datetime.valueOf(); + let dateValue = datetime.valueOf(); - if (dateValue >= volume.begin && dateValue <= volume.end) { + if (dateValue >= volume.begin && dateValue <= volume.end) { - let buyInfo = { - baseWidth: volumePointA4.x - volumePointA1.x, - topWidth: volumePointA3.x - volumePointA2.x, - height: volumePointA2.y - volumePointA1.y - }; + let buyInfo = { + baseWidth: volumePointA4.x - volumePointA1.x, + topWidth: volumePointA3.x - volumePointA2.x, + height: volumePointA2.y - volumePointA1.y + }; - let sellInfo = { - baseWidth: volumePointB4.x - volumePointB1.x, - topWidth: volumePointB3.x - volumePointB2.x, - height: volumePointB2.y - volumePointB1.y - }; + let sellInfo = { + baseWidth: volumePointB4.x - volumePointB1.x, + topWidth: volumePointB3.x - volumePointB2.x, + height: volumePointB2.y - volumePointB1.y + }; - let currentVolume = { - buyInfo: buyInfo, - sellInfo: sellInfo, - period: timePeriod, - innerVolumeBar: volume - }; + let currentVolume = { + buyInfo: buyInfo, + sellInfo: sellInfo, + period: timePeriod, + innerVolumeBar: volume + }; - thisObject.container.eventHandler.raiseEvent("Current Volume Changed", currentVolume); + thisObject.container.eventHandler.raiseEvent("Current Volume Changed", currentVolume); + } } } } } + + } catch (err) { + + if (ERROR_LOG === true) { logger.write("[ERROR] plotChart -> err.message = " + err.message); } } } function onZoomChanged(event) { - recalculateScaleX(); - recalculate(); - recalculateScaleY(); + try { - } - - function onOffsetChanged() { - - if (Math.random() * 100 > 95) { + if (INFO_LOG === true) { logger.write("[INFO] onZoomChanged -> Entering function."); } recalculateScaleX(); recalculate(); recalculateScaleY(); - }; + } catch (err) { + + if (ERROR_LOG === true) { logger.write("[ERROR] onZoomChanged -> err.message = " + err.message); } + } + } + + function onOffsetChanged() { + + try { + + if (INFO_LOG === true) { logger.write("[INFO] onOffsetChanged -> Entering function."); } + + if (Math.random() * 100 > 95) { + + recalculateScaleX(); + recalculate(); + recalculateScaleY(); + + }; + + } catch (err) { + + if (ERROR_LOG === true) { logger.write("[ERROR] onOffsetChanged -> err.message = " + err.message); } + } } function onDragFinished() { - recalculateScaleX(); - recalculate(); - recalculateScaleY(); + try { + if (INFO_LOG === true) { logger.write("[INFO] onDragFinished -> Entering function."); } + + recalculateScaleX(); + recalculate(); + recalculateScaleY(); + + } catch (err) { + + if (ERROR_LOG === true) { logger.write("[ERROR] onDragFinished -> err.message = " + err.message); } + } } }