846 lines
29 KiB
JavaScript
846 lines
29 KiB
JavaScript
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. */
|
|
|
|
onDailyFileLoaded: onDailyFileLoaded,
|
|
|
|
// Main functions and properties.
|
|
|
|
initialize: initialize,
|
|
container: undefined,
|
|
getContainer: getContainer,
|
|
setTimePeriod: setTimePeriod,
|
|
setDatetime: setDatetime,
|
|
draw: draw
|
|
};
|
|
|
|
/* this is part of the module template */
|
|
|
|
let container = newContainer(); // Do not touch this 3 lines, they are just needed.
|
|
container.initialize();
|
|
thisObject.container = container;
|
|
|
|
let timeLineCoordinateSystem = newTimeLineCoordinateSystem(); // Needed to be able to plot on the timeline, otherwise not.
|
|
let plotAreaFrame = newTimeLineCoordinateSystem(); // This chart uses this extra object.
|
|
|
|
let timePeriod; // This will hold the current Time Period the user is at.
|
|
let datetime; // This will hold the current Datetime the user is at.
|
|
|
|
let marketFile; // This is the current Market File being plotted.
|
|
let fileCursor; // This is the current File Cursor being used to retrieve Daily Files.
|
|
|
|
let marketFiles; // This object will provide the different Market Files at different Time Periods.
|
|
let dailyFiles; // 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(pStorage, pExchange, pMarket, pDatetime, pTimePeriod, callBackFunction) {
|
|
|
|
try {
|
|
|
|
if (INFO_LOG === true) { logger.write("[INFO] initialize -> Entering function."); }
|
|
|
|
/* Store the information received. */
|
|
|
|
marketFiles = pStorage.marketFiles[0];
|
|
dailyFiles = pStorage.dailyFiles[0];
|
|
|
|
datetime = pDatetime;
|
|
timePeriod = pTimePeriod;
|
|
|
|
/* We need a Market File in order to calculate the Y scale, since this scale depends on actual data. */
|
|
|
|
scaleFile = marketFiles.getFile(ONE_DAY_IN_MILISECONDS); // This file is the one processed faster.
|
|
|
|
/* Now we set the right files according to current Period. */
|
|
|
|
marketFile = marketFiles.getFile(pTimePeriod);
|
|
fileCursor = dailyFiles.getFileCursor(pTimePeriod);
|
|
|
|
/* Listen to the necesary events. */
|
|
|
|
viewPort.eventHandler.listenToEvent("Zoom Changed", onZoomChanged);
|
|
viewPort.eventHandler.listenToEvent("Offset Changed", onOffsetChanged);
|
|
marketFiles.eventHandler.listenToEvent("Files Updated", onFilesUpdated);
|
|
canvas.eventHandler.listenToEvent("Drag Finished", onDragFinished);
|
|
|
|
/* 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) {
|
|
|
|
try {
|
|
|
|
if (INFO_LOG === true) { logger.write("[INFO] setTimePeriod -> Entering function."); }
|
|
|
|
if (timePeriod !== pTimePeriod) {
|
|
|
|
timePeriod = pTimePeriod;
|
|
|
|
if (timePeriod >= _1_HOUR_IN_MILISECONDS) {
|
|
|
|
let newMarketFile = marketFiles.getFile(pTimePeriod);
|
|
|
|
if (newMarketFile !== undefined) {
|
|
|
|
marketFile = newMarketFile;
|
|
recalculate();
|
|
}
|
|
|
|
} else {
|
|
|
|
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) {
|
|
|
|
try {
|
|
|
|
if (INFO_LOG === true) { logger.write("[INFO] onDailyFileLoaded -> Entering function."); }
|
|
|
|
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() {
|
|
|
|
try {
|
|
|
|
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() {
|
|
|
|
try {
|
|
|
|
if (INFO_LOG === true) { logger.write("[INFO] recalculate -> Entering function."); }
|
|
|
|
if (timePeriod >= _1_HOUR_IN_MILISECONDS) {
|
|
|
|
recalculateUsingMarketFiles();
|
|
|
|
} else {
|
|
|
|
recalculateUsingDailyFiles();
|
|
|
|
}
|
|
|
|
thisObject.container.eventHandler.raiseEvent("Volumes Changed", volumes);
|
|
|
|
} catch (err) {
|
|
|
|
if (ERROR_LOG === true) { logger.write("[ERROR] recalculate -> err.message = " + err.message); }
|
|
}
|
|
}
|
|
|
|
function recalculateUsingDailyFiles() {
|
|
|
|
try {
|
|
|
|
if (INFO_LOG === true) { logger.write("[INFO] recalculateUsingDailyFiles -> Entering function."); }
|
|
|
|
if (fileCursor === undefined) { return; } // We need to wait
|
|
|
|
if (fileCursor.files.size === 0) { return; } // We need to wait until there are files in the cursor
|
|
|
|
let leftDate = getDateFromPoint(viewPort.visibleArea.topLeft, thisObject.container, timeLineCoordinateSystem);
|
|
let rightDate = getDateFromPoint(viewPort.visibleArea.topRight, thisObject.container, timeLineCoordinateSystem);
|
|
|
|
let dateDiff = rightDate.valueOf() - leftDate.valueOf();
|
|
|
|
let farLeftDate = new Date(leftDate.valueOf() - dateDiff * 1.5);
|
|
let farRightDate = new Date(rightDate.valueOf() + dateDiff * 1.5);
|
|
|
|
let currentDate = new Date(farLeftDate.valueOf());
|
|
|
|
volumes = [];
|
|
|
|
while (currentDate.valueOf() <= farRightDate.valueOf() + ONE_DAY_IN_MILISECONDS) {
|
|
|
|
let stringDate = currentDate.getFullYear() + '-' + pad(currentDate.getMonth() + 1, 2) + '-' + pad(currentDate.getDate(), 2);
|
|
|
|
let dailyFile = fileCursor.files.get(stringDate);
|
|
|
|
if (dailyFile !== undefined) {
|
|
|
|
for (let i = 0; i < dailyFile.length; i++) {
|
|
|
|
let volume = {
|
|
amountBuy: 0,
|
|
amountSell: 0,
|
|
begin: undefined,
|
|
end: undefined
|
|
};
|
|
|
|
volume.amountBuy = dailyFile[i][0];
|
|
volume.amountSell = dailyFile[i][1];
|
|
|
|
volume.begin = dailyFile[i][2];
|
|
volume.end = dailyFile[i][3];
|
|
|
|
if (volume.begin >= farLeftDate.valueOf() && volume.end <= farRightDate.valueOf()) {
|
|
|
|
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);
|
|
}
|
|
|
|
/* Lests check if all the visible screen is going to be covered by volumes. */
|
|
|
|
let lowerEnd = leftDate.valueOf();
|
|
let upperEnd = rightDate.valueOf();
|
|
|
|
if (volumes.length > 0) {
|
|
|
|
if (volumes[0].begin > lowerEnd || volumes[volumes.length - 1].end < upperEnd) {
|
|
|
|
setTimeout(recalculate, 2000);
|
|
|
|
//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); }
|
|
}
|
|
}
|
|
|
|
function recalculateUsingMarketFiles() {
|
|
|
|
try {
|
|
|
|
if (INFO_LOG === true) { logger.write("[INFO] recalculateUsingMarketFiles -> Entering function."); }
|
|
|
|
if (marketFile === undefined) { return; } // Initialization not complete yet.
|
|
|
|
let leftDate = getDateFromPoint(viewPort.visibleArea.topLeft, thisObject.container, timeLineCoordinateSystem);
|
|
let rightDate = getDateFromPoint(viewPort.visibleArea.topRight, thisObject.container, timeLineCoordinateSystem);
|
|
|
|
let dateDiff = rightDate.valueOf() - leftDate.valueOf();
|
|
|
|
leftDate = new Date(leftDate.valueOf() - dateDiff * 1.5);
|
|
rightDate = new Date(rightDate.valueOf() + dateDiff * 1.5);
|
|
|
|
volumes = [];
|
|
|
|
for (let i = 0; i < marketFile.length; i++) {
|
|
|
|
let volume = {
|
|
amountBuy: 0,
|
|
amountSell: 0,
|
|
begin: undefined,
|
|
end: undefined
|
|
};
|
|
|
|
volume.amountBuy = marketFile[i][0];
|
|
volume.amountSell = marketFile[i][1];
|
|
|
|
volume.begin = marketFile[i][2];
|
|
volume.end = marketFile[i][3];
|
|
|
|
if (volume.begin >= leftDate.valueOf() && volume.end <= rightDate.valueOf()) {
|
|
|
|
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);
|
|
|
|
} catch (err) {
|
|
|
|
if (ERROR_LOG === true) { logger.write("[ERROR] recalculateUsingMarketFiles -> err.message = " + err.message); }
|
|
}
|
|
}
|
|
|
|
function recalculateScaleX() {
|
|
|
|
try {
|
|
|
|
if (INFO_LOG === true) { logger.write("[INFO] recalculateScaleX -> Entering function."); }
|
|
|
|
var minValue = {
|
|
x: EARLIEST_DATE.valueOf()
|
|
};
|
|
|
|
var maxValue = {
|
|
x: MAX_PLOTABLE_DATE.valueOf()
|
|
};
|
|
|
|
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() {
|
|
|
|
try {
|
|
|
|
if (INFO_LOG === true) { logger.write("[INFO] recalculateScaleY -> Entering function."); }
|
|
|
|
var minValue = {
|
|
y: 0
|
|
};
|
|
|
|
var maxValue = {
|
|
y: 0
|
|
};
|
|
|
|
let timePeriodRatio = ONE_DAY_IN_MILISECONDS / timePeriod;
|
|
|
|
maxValue.y = getMaxVolume() / (timePeriodRatio / 2.5);
|
|
|
|
timeLineCoordinateSystem.initializeY(
|
|
minValue,
|
|
maxValue,
|
|
viewPort.visibleArea.bottomRight.y - viewPort.visibleArea.topLeft.y
|
|
);
|
|
|
|
plotAreaFrame.initializeY(
|
|
minValue,
|
|
maxValue,
|
|
thisObject.container.frame.height
|
|
);
|
|
|
|
function getMaxVolume() {
|
|
|
|
if (INFO_LOG === true) { logger.write("[INFO] initialize -> Entering function."); }
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
} catch (err) {
|
|
|
|
if (ERROR_LOG === true) { logger.write("[ERROR] recalculateScaleY -> err.message = " + err.message); }
|
|
}
|
|
}
|
|
|
|
function plotChart() {
|
|
|
|
try {
|
|
|
|
if (INTENSIVE_LOG === true) { logger.write("[INFO] plotChart -> Entering function."); }
|
|
|
|
if (volumes.length > 0) {
|
|
|
|
/* 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 (volumes.length > 0) {
|
|
|
|
for (var i = 0; i < volumes.length; i++) {
|
|
|
|
volume = volumes[i];
|
|
|
|
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 (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(timeLineCoordinateSystem, visibleHeight) === false) { continue; } // We snap t to the view port.
|
|
|
|
/* 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) {
|
|
|
|
volumePointB1 = {
|
|
x: volume.begin + timePeriod / 7 * 2,
|
|
y: height
|
|
};
|
|
|
|
volumePointB2 = {
|
|
x: volume.begin + timePeriod / 7 * 2,
|
|
y: height - volume.amountSell
|
|
};
|
|
|
|
volumePointB3 = {
|
|
x: volume.begin + timePeriod / 7 * 5,
|
|
y: height - volume.amountSell
|
|
};
|
|
|
|
volumePointB4 = {
|
|
x: volume.begin + timePeriod / 7 * 5,
|
|
y: height
|
|
};
|
|
|
|
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(timeLineCoordinateSystem, visibleHeight); // We snap it to the view port.
|
|
|
|
/* 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;
|
|
|
|
volumePointB1.x = volumePointB1.x - baseIncrement;
|
|
volumePointB4.x = volumePointB4.x + baseIncrement;
|
|
|
|
/* We put a less wider top */
|
|
|
|
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;
|
|
|
|
|
|
/* Everything must fit within the visible area */
|
|
|
|
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);
|
|
|
|
/* 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) {
|
|
|
|
volumePointA2.y = volumePointB1.y;
|
|
volumePointA3.y = volumePointB1.y;
|
|
|
|
}
|
|
|
|
if (volumePointB2.y > volumePointA1.y) {
|
|
|
|
volumePointB2.y = volumePointA1.y;
|
|
volumePointB3.y = volumePointA1.y;
|
|
|
|
}
|
|
|
|
/* Now the drawing of the volume bars*/
|
|
|
|
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.closePath();
|
|
|
|
|
|
if (datetime !== undefined) {
|
|
|
|
let dateValue = datetime.valueOf();
|
|
|
|
if (dateValue >= volume.begin && dateValue <= volume.end) {
|
|
|
|
browserCanvasContext.fillStyle = 'rgba(' + UI_COLOR.TITANIUM_YELLOW + ', 0.40)'; // Current bar accroding to time
|
|
|
|
} else {
|
|
|
|
browserCanvasContext.fillStyle = 'rgba(' + UI_COLOR.GREEN + ', 0.40)';
|
|
}
|
|
|
|
} else {
|
|
|
|
browserCanvasContext.fillStyle = 'rgba(' + UI_COLOR.GREEN + ', 0.40)';
|
|
|
|
}
|
|
|
|
browserCanvasContext.fill();
|
|
browserCanvasContext.strokeStyle = 'rgba(' + UI_COLOR.PATINATED_TURQUOISE + ', 0.40)';
|
|
browserCanvasContext.lineWidth = 1;
|
|
browserCanvasContext.stroke();
|
|
|
|
|
|
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.closePath();
|
|
|
|
if (datetime !== undefined) {
|
|
|
|
let dateValue = datetime.valueOf();
|
|
|
|
if (dateValue >= volume.begin && dateValue <= volume.end) {
|
|
|
|
browserCanvasContext.fillStyle = 'rgba(' + UI_COLOR.TITANIUM_YELLOW + ', 0.40)'; // Current volume accroding to time
|
|
|
|
} else {
|
|
|
|
browserCanvasContext.fillStyle = 'rgba(' + UI_COLOR.RUSTED_RED + ', 0.40)';
|
|
}
|
|
|
|
} else {
|
|
|
|
browserCanvasContext.fillStyle = 'rgba(' + UI_COLOR.RUSTED_RED + ', 0.40)';
|
|
|
|
}
|
|
|
|
browserCanvasContext.strokeStyle = 'rgba(' + UI_COLOR.RED + ', 0.40)';
|
|
|
|
browserCanvasContext.fill();
|
|
browserCanvasContext.lineWidth = 1;
|
|
browserCanvasContext.stroke();
|
|
|
|
|
|
|
|
if (datetime !== undefined) {
|
|
|
|
let dateValue = datetime.valueOf();
|
|
|
|
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 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
|
|
};
|
|
|
|
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) {
|
|
|
|
try {
|
|
|
|
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() {
|
|
|
|
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); }
|
|
}
|
|
}
|
|
}
|
|
|