Merge pull request #25 from AAMasters/master
Updating Master after a long time
This commit is contained in:
65 files changed
+8299
-12356
No files matched your search
+95
-121
@@ -1,11 +1,10 @@
|
||||
|
||||
function newAnimation() {
|
||||
|
||||
const MODULE_NAME = "Animation";
|
||||
const INFO_LOG = false;
|
||||
const ERROR_LOG = true;
|
||||
const logger = newWebDebugLog();
|
||||
logger.fileName = MODULE_NAME;
|
||||
function newAnimation () {
|
||||
const MODULE_NAME = 'Animation'
|
||||
const INFO_LOG = false
|
||||
const ERROR_LOG = true
|
||||
const logger = newWebDebugLog()
|
||||
logger.fileName = MODULE_NAME
|
||||
|
||||
/*
|
||||
|
||||
@@ -15,157 +14,132 @@ function newAnimation() {
|
||||
|
||||
*/
|
||||
|
||||
let animationLoopHandle; // This is the handle to the animation loop. With this handle we can cancel the loop, for instance.
|
||||
let callBackFunctions = new Map();
|
||||
let animationLoopHandle // This is the handle to the animation loop. With this handle we can cancel the loop, for instance.
|
||||
let callBackFunctions = new Map()
|
||||
|
||||
let thisObject = {
|
||||
start: start,
|
||||
stop: stop,
|
||||
addCallBackFunction: addCallBackFunction,
|
||||
removeCallBackFunction: removeCallBackFunction,
|
||||
initialize: initialize
|
||||
};
|
||||
let thisObject = {
|
||||
start: start,
|
||||
stop: stop,
|
||||
addCallBackFunction: addCallBackFunction,
|
||||
removeCallBackFunction: removeCallBackFunction,
|
||||
initialize: initialize,
|
||||
finalize: finalize
|
||||
}
|
||||
|
||||
return thisObject;
|
||||
return thisObject
|
||||
|
||||
function initialize(callBackFunction) {
|
||||
function finalize () {
|
||||
try {
|
||||
if (INFO_LOG === true) { logger.write('[INFO] finalize -> Entering function.') }
|
||||
|
||||
try {
|
||||
thisObject.stop()
|
||||
} catch (err) {
|
||||
if (ERROR_LOG === true) { logger.write('[ERROR] finalize -> err = ' + err) }
|
||||
}s
|
||||
}
|
||||
|
||||
if (INFO_LOG === true) { logger.write("[INFO] initialize -> Entering function."); }
|
||||
function initialize (callBackFunction) {
|
||||
try {
|
||||
if (INFO_LOG === true) { logger.write('[INFO] initialize -> Entering function.') }
|
||||
|
||||
/* Nothing to do here yet. */
|
||||
callBackFunction(GLOBAL.CUSTOM_OK_RESPONSE);
|
||||
|
||||
} catch (err) {
|
||||
|
||||
if (ERROR_LOG === true) { logger.write("[ERROR] initialize -> err = " + err); }
|
||||
callBackFunction(GLOBAL.DEFAULT_FAIL_RESPONSE);
|
||||
}
|
||||
callBackFunction(GLOBAL.CUSTOM_OK_RESPONSE)
|
||||
} catch (err) {
|
||||
if (ERROR_LOG === true) { logger.write('[ERROR] initialize -> err = ' + err) }
|
||||
callBackFunction(GLOBAL.DEFAULT_FAIL_RESPONSE)
|
||||
}
|
||||
}
|
||||
|
||||
function start (callBackFunction) {
|
||||
try {
|
||||
if (INFO_LOG === true) { logger.write('[INFO] start -> Entering function.') }
|
||||
|
||||
function start(callBackFunction) {
|
||||
|
||||
try {
|
||||
|
||||
if (INFO_LOG === true) { logger.write("[INFO] start -> Entering function."); }
|
||||
|
||||
animationLoop(); // Inside this function the animation process is started, and at the same time it creates a loop.
|
||||
|
||||
} catch (err) {
|
||||
|
||||
if (ERROR_LOG === true) { logger.write("[ERROR] start -> err = " + err); }
|
||||
callBackFunction(GLOBAL.DEFAULT_FAIL_RESPONSE);
|
||||
}
|
||||
animationLoop() // Inside this function the animation process is started, and at the same time it creates a loop.
|
||||
} catch (err) {
|
||||
if (ERROR_LOG === true) { logger.write('[ERROR] start -> err = ' + err) }
|
||||
callBackFunction(GLOBAL.DEFAULT_FAIL_RESPONSE)
|
||||
}
|
||||
}
|
||||
|
||||
function stop(callBackFunction) {
|
||||
function stop (callBackFunction) {
|
||||
try {
|
||||
if (INFO_LOG === true) { logger.write('[INFO] stop -> Entering function.') }
|
||||
|
||||
try {
|
||||
|
||||
if (INFO_LOG === true) { logger.write("[INFO] stop -> Entering function."); }
|
||||
|
||||
window.cancelAnimationFrame(animationLoopHandle);
|
||||
|
||||
} catch (err) {
|
||||
|
||||
if (ERROR_LOG === true) { logger.write("[ERROR] stop -> err = " + err); }
|
||||
callBackFunction(GLOBAL.DEFAULT_FAIL_RESPONSE);
|
||||
}
|
||||
window.cancelAnimationFrame(animationLoopHandle)
|
||||
} catch (err) {
|
||||
if (ERROR_LOG === true) { logger.write('[ERROR] stop -> err = ' + err) }
|
||||
callBackFunction(GLOBAL.DEFAULT_FAIL_RESPONSE)
|
||||
}
|
||||
}
|
||||
|
||||
function addCallBackFunction(key, callBack, callBackFunction) {
|
||||
function addCallBackFunction (key, callBack, callBackFunction) {
|
||||
try {
|
||||
if (INFO_LOG === true) { logger.write('[INFO] addCallBackFunction -> Entering function.') }
|
||||
|
||||
try {
|
||||
|
||||
if (INFO_LOG === true) { logger.write("[INFO] addCallBackFunction -> Entering function."); }
|
||||
|
||||
callBackFunctions.set(key, callBack);
|
||||
|
||||
} catch (err) {
|
||||
|
||||
if (ERROR_LOG === true) { logger.write("[ERROR] addCallBackFunction -> err = " + err); }
|
||||
callBackFunction(GLOBAL.DEFAULT_FAIL_RESPONSE);
|
||||
}
|
||||
callBackFunctions.set(key, callBack)
|
||||
} catch (err) {
|
||||
if (ERROR_LOG === true) { logger.write('[ERROR] addCallBackFunction -> err = ' + err) }
|
||||
callBackFunction(GLOBAL.DEFAULT_FAIL_RESPONSE)
|
||||
}
|
||||
}
|
||||
|
||||
function removeCallBackFunction(key, callBackFunction) {
|
||||
function removeCallBackFunction (key, callBackFunction) {
|
||||
try {
|
||||
if (INFO_LOG === true) { logger.write('[INFO] removeCallBackFunction -> Entering function.') }
|
||||
|
||||
try {
|
||||
|
||||
if (INFO_LOG === true) { logger.write("[INFO] removeCallBackFunction -> Entering function."); }
|
||||
|
||||
callBackFunctions.delete(key);
|
||||
|
||||
} catch (err) {
|
||||
|
||||
if (ERROR_LOG === true) { logger.write("[ERROR] removeCallBackFunction -> err = " + err); }
|
||||
callBackFunction(GLOBAL.DEFAULT_FAIL_RESPONSE);
|
||||
}
|
||||
callBackFunctions.delete(key)
|
||||
} catch (err) {
|
||||
if (ERROR_LOG === true) { logger.write('[ERROR] removeCallBackFunction -> err = ' + err) }
|
||||
callBackFunction(GLOBAL.DEFAULT_FAIL_RESPONSE)
|
||||
}
|
||||
}
|
||||
|
||||
function animationLoop() {
|
||||
|
||||
try {
|
||||
|
||||
if (INFO_LOG === true) { logger.write("[INFO] animationLoop -> Entering function."); }
|
||||
|
||||
if (window.canvasApp.visible === true) {
|
||||
function animationLoop () {
|
||||
try {
|
||||
if (INFO_LOG === true) { logger.write('[INFO] animationLoop -> Entering function.') }
|
||||
|
||||
if (window.canvasApp.visible === true) {
|
||||
/* We set the canvas to its normal width and height */
|
||||
|
||||
browserCanvas.width = window.innerWidth;
|
||||
browserCanvas.height = window.innerHeight - window.canvasApp.topMargin;
|
||||
browserCanvas.width = window.innerWidth
|
||||
browserCanvas.height = window.innerHeight - window.canvasApp.topMargin
|
||||
|
||||
/* First thing is to clear the actual canvas */
|
||||
|
||||
clearBrowserCanvas();
|
||||
clearBrowserCanvas()
|
||||
|
||||
/* Let reset the current chart that is on focus */
|
||||
|
||||
window.CHART_ON_FOCUS = ''
|
||||
|
||||
/* We loop through the callback functions collections and execute them all. */
|
||||
|
||||
callBackFunctions.forEach(function (callBackFunction) {
|
||||
|
||||
callBackFunction();
|
||||
|
||||
});
|
||||
|
||||
} else {
|
||||
|
||||
browserCanvas.width = 1;
|
||||
browserCanvas.height = 1;
|
||||
|
||||
}
|
||||
callBackFunctions.forEach(function (callBackFunction) {
|
||||
callBackFunction()
|
||||
})
|
||||
} else {
|
||||
browserCanvas.width = 1
|
||||
browserCanvas.height = 1
|
||||
}
|
||||
|
||||
/* We request the next frame to be drawn, and stablishing a loop */
|
||||
|
||||
animationLoopHandle = window.requestAnimationFrame(animationLoop);
|
||||
|
||||
} catch (err) {
|
||||
|
||||
if (ERROR_LOG === true) { logger.write("[ERROR] animationLoop -> err = " + err); }
|
||||
|
||||
}
|
||||
animationLoopHandle = window.requestAnimationFrame(animationLoop)
|
||||
} catch (err) {
|
||||
if (ERROR_LOG === true) { logger.write('[ERROR] animationLoop -> err = ' + err) }
|
||||
}
|
||||
}
|
||||
|
||||
function clearBrowserCanvas() {
|
||||
function clearBrowserCanvas () {
|
||||
if (INFO_LOG === true) { logger.write('[INFO] clearBrowserCanvas -> Entering function.') }
|
||||
|
||||
if (INFO_LOG === true) { logger.write("[INFO] clearBrowserCanvas -> Entering function."); }
|
||||
browserCanvasContext.beginPath()
|
||||
|
||||
browserCanvasContext.beginPath();
|
||||
browserCanvasContext.rect(0, 0, browserCanvas.width, browserCanvas.height)
|
||||
browserCanvasContext.fillStyle = 'rgba(' + UI_COLOR.WHITE + ', 1)'
|
||||
|
||||
browserCanvasContext.rect(0, 0, browserCanvas.width, browserCanvas.height);
|
||||
browserCanvasContext.fillStyle = 'rgba(' + UI_COLOR.WHITE + ', 1)';
|
||||
|
||||
browserCanvasContext.closePath();
|
||||
browserCanvasContext.fill();
|
||||
|
||||
}
|
||||
browserCanvasContext.closePath()
|
||||
browserCanvasContext.fill()
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -1,130 +1,113 @@
|
||||
function newChartAspectRatio() {
|
||||
function newChartAspectRatio () {
|
||||
let thisObject = {
|
||||
aspectRatio: undefined,
|
||||
draw: draw,
|
||||
getContainer: getContainer,
|
||||
initialize: initialize
|
||||
}
|
||||
|
||||
let thisObject = {
|
||||
aspectRatio: undefined,
|
||||
draw: draw,
|
||||
getContainer: getContainer,
|
||||
initialize: initialize
|
||||
};
|
||||
let container = newContainer()
|
||||
container.initialize()
|
||||
thisObject.container = container
|
||||
|
||||
let container = newContainer();
|
||||
container.initialize();
|
||||
thisObject.container = container;
|
||||
thisObject.container.frame.width = 50
|
||||
thisObject.container.frame.height = BOTTOM_SPACE_HEIGHT
|
||||
|
||||
thisObject.container.frame.width = 50;
|
||||
thisObject.container.frame.height = BOTTOM_SPACE_HEIGHT;
|
||||
resize()
|
||||
|
||||
resize();
|
||||
container.isDraggeable = false
|
||||
container.isClickeable = false
|
||||
container.isWheeleable = true
|
||||
|
||||
container.isDraggeable = false;
|
||||
container.isClickeable = false;
|
||||
container.isWheeleable = true;
|
||||
thisObject.aspectRatio = {}
|
||||
|
||||
thisObject.aspectRatio = {};
|
||||
const INITIAL_Y_ASPECT_RATIO = 5 / 10
|
||||
const MIN_Y_ASPECT_RATIO = 1 / 10
|
||||
const MAX_Y_ASPECT_RATIO = 10 / 10
|
||||
|
||||
const INITIAL_Y_ASPECT_RATIO = 5 / 10;
|
||||
const MIN_Y_ASPECT_RATIO = 1 / 10;
|
||||
const MAX_Y_ASPECT_RATIO = 10 / 10;
|
||||
thisObject.aspectRatio.x = 1
|
||||
thisObject.aspectRatio.y = INITIAL_Y_ASPECT_RATIO
|
||||
|
||||
thisObject.aspectRatio.x = 1;
|
||||
thisObject.aspectRatio.y = INITIAL_Y_ASPECT_RATIO;
|
||||
canDrawIcon = false
|
||||
|
||||
canDrawIcon = false;
|
||||
return thisObject
|
||||
|
||||
return thisObject;
|
||||
function initialize () {
|
||||
icon = new Image()
|
||||
|
||||
function initialize() {
|
||||
icon.onload = onImageLoad
|
||||
|
||||
icon = new Image();
|
||||
function onImageLoad () {
|
||||
canDrawIcon = true
|
||||
}
|
||||
|
||||
icon.onload = onImageLoad;
|
||||
icon.src = window.canvasApp.urlPrefix + 'Images/Icons/chart-scale.png'
|
||||
|
||||
function onImageLoad() {
|
||||
canDrawIcon = true;
|
||||
}
|
||||
thisObject.container.eventHandler.listenToEvent('Mouse Wheel', onMouseWheel)
|
||||
|
||||
icon.src = window.canvasApp.urlPrefix + "Images/Icons/chart-scale.png";
|
||||
window.canvasApp.eventHandler.listenToEvent('Browser Resized', resize)
|
||||
}
|
||||
|
||||
thisObject.container.eventHandler.listenToEvent('Mouse Wheel', onMouseWheel);
|
||||
function resize () {
|
||||
container.frame.position.x = viewPort.visibleArea.topRight.x - thisObject.container.frame.width
|
||||
container.frame.position.y = viewPort.visibleArea.bottomLeft.y
|
||||
}
|
||||
|
||||
window.canvasApp.eventHandler.listenToEvent("Browser Resized", resize);
|
||||
function onMouseWheel (pDelta) {
|
||||
if (viewPort.isMinZoom() === false) { return } // We only make this button to work at the min zoom level.
|
||||
|
||||
}
|
||||
if (pDelta < 0) {
|
||||
pDelta = -0.1
|
||||
} else {
|
||||
pDelta = 0.1
|
||||
}
|
||||
|
||||
function resize() {
|
||||
thisObject.aspectRatio.y = thisObject.aspectRatio.y + pDelta
|
||||
thisObject.aspectRatio.y = Math.round(thisObject.aspectRatio.y * 100) / 100
|
||||
|
||||
container.frame.position.x = viewPort.visibleArea.topRight.x - thisObject.container.frame.width;
|
||||
container.frame.position.y = viewPort.visibleArea.bottomLeft.y;
|
||||
if (thisObject.aspectRatio.y < MIN_Y_ASPECT_RATIO) {
|
||||
thisObject.aspectRatio.y = MIN_Y_ASPECT_RATIO
|
||||
}
|
||||
|
||||
}
|
||||
if (thisObject.aspectRatio.y > MAX_Y_ASPECT_RATIO) {
|
||||
thisObject.aspectRatio.y = MAX_Y_ASPECT_RATIO
|
||||
}
|
||||
|
||||
function onMouseWheel(pDelta) {
|
||||
thisObject.container.eventHandler.raiseEvent('Chart Aspect Ratio Changed', thisObject.aspectRatio)
|
||||
}
|
||||
|
||||
if (viewPort.isMinZoom() === false) { return; } // We only make this button to work at the min zoom level.
|
||||
|
||||
if (pDelta < 0) {
|
||||
pDelta = -0.1;
|
||||
} else {
|
||||
pDelta = 0.1;
|
||||
}
|
||||
|
||||
thisObject.aspectRatio.y = thisObject.aspectRatio.y + pDelta;
|
||||
thisObject.aspectRatio.y = Math.round(thisObject.aspectRatio.y * 100) / 100;
|
||||
|
||||
if (thisObject.aspectRatio.y < MIN_Y_ASPECT_RATIO) {
|
||||
|
||||
thisObject.aspectRatio.y = MIN_Y_ASPECT_RATIO;
|
||||
|
||||
}
|
||||
|
||||
if (thisObject.aspectRatio.y > MAX_Y_ASPECT_RATIO) {
|
||||
|
||||
thisObject.aspectRatio.y = MAX_Y_ASPECT_RATIO;
|
||||
|
||||
}
|
||||
|
||||
thisObject.container.eventHandler.raiseEvent("Chart Aspect Ratio Changed", thisObject.aspectRatio);
|
||||
|
||||
}
|
||||
|
||||
function getContainer(point) {
|
||||
|
||||
let container;
|
||||
function getContainer (point) {
|
||||
let container
|
||||
|
||||
/* First we check if this point is inside this object UI. */
|
||||
|
||||
if (thisObject.container.frame.isThisPointHere(point, true) === true) {
|
||||
|
||||
return this.container;
|
||||
|
||||
} else {
|
||||
|
||||
if (thisObject.container.frame.isThisPointHere(point, true) === true) {
|
||||
return this.container
|
||||
} else {
|
||||
/* This point does not belong to this space. */
|
||||
|
||||
return undefined;
|
||||
}
|
||||
}
|
||||
return undefined
|
||||
}
|
||||
}
|
||||
|
||||
function draw() {
|
||||
function draw () {
|
||||
thisObject.container.frame.draw(false, false)
|
||||
|
||||
thisObject.container.frame.draw(false, false);
|
||||
if (canDrawIcon === false) { return }
|
||||
if (viewPort.isMinZoom() === false) { return } // We only show this button at the min zoom level.
|
||||
|
||||
if (canDrawIcon === false) { return; }
|
||||
if (viewPort.isMinZoom() === false) { return; } // We only show this button at the min zoom level.
|
||||
let breakpointsHeight = 15
|
||||
|
||||
let breakpointsHeight = 15;
|
||||
let imageHeight = 15
|
||||
let imageWidth = 15
|
||||
|
||||
let imageHeight = 15;
|
||||
let imageWidth = 15;
|
||||
let imagePoint = {
|
||||
x: 10,
|
||||
y: thisObject.container.frame.height / 2 - imageHeight / 2 + breakpointsHeight
|
||||
}
|
||||
|
||||
let imagePoint = {
|
||||
x: 10,
|
||||
y: thisObject.container.frame.height / 2 - imageHeight / 2 + breakpointsHeight
|
||||
};
|
||||
imagePoint = thisObject.container.frame.frameThisPoint(imagePoint)
|
||||
|
||||
imagePoint = thisObject.container.frame.frameThisPoint(imagePoint);
|
||||
|
||||
browserCanvasContext.drawImage(icon, imagePoint.x, imagePoint.y, imageWidth, imageHeight);
|
||||
}
|
||||
|
||||
}
|
||||
browserCanvasContext.drawImage(icon, imagePoint.x, imagePoint.y, imageWidth, imageHeight)
|
||||
}
|
||||
}
|
||||
+177
-230
@@ -1,86 +1,75 @@
|
||||
|
||||
function newDeleteTradingHistory() {
|
||||
|
||||
function newDeleteTradingHistory () {
|
||||
const MODULE_NAME = 'Delete Trading History'
|
||||
const INFO_LOG = false
|
||||
const ERROR_LOG = true
|
||||
const logger = newWebDebugLog()
|
||||
logger.fileName = MODULE_NAME
|
||||
|
||||
const MODULE_NAME = "Delete Trading History";
|
||||
const INFO_LOG = false;
|
||||
const ERROR_LOG = true;
|
||||
const logger = newWebDebugLog();
|
||||
logger.fileName = MODULE_NAME;
|
||||
var thisObject = {
|
||||
container: undefined,
|
||||
draw: draw,
|
||||
getContainer: getContainer, // returns the inner most container that holds the point received by parameter.
|
||||
initialize: initialize
|
||||
}
|
||||
|
||||
var thisObject = {
|
||||
container: undefined,
|
||||
draw: draw,
|
||||
getContainer: getContainer, // returns the inner most container that holds the point received by parameter.
|
||||
initialize: initialize
|
||||
};
|
||||
var container = newContainer()
|
||||
container.initialize()
|
||||
thisObject.container = container
|
||||
|
||||
var container = newContainer();
|
||||
container.initialize();
|
||||
thisObject.container = container;
|
||||
thisObject.container.frame.width = 50
|
||||
thisObject.container.frame.height = BOTTOM_SPACE_HEIGHT
|
||||
|
||||
thisObject.container.frame.width = 50;
|
||||
thisObject.container.frame.height = BOTTOM_SPACE_HEIGHT;
|
||||
resize()
|
||||
|
||||
resize();
|
||||
container.isDraggeable = false
|
||||
container.isClickeable = true
|
||||
|
||||
container.isDraggeable = false;
|
||||
container.isClickeable = true;
|
||||
let icon
|
||||
let canDrawIcon = false
|
||||
|
||||
let icon;
|
||||
let canDrawIcon = false;
|
||||
return thisObject
|
||||
|
||||
return thisObject;
|
||||
function initialize (callBackFunction) {
|
||||
try {
|
||||
if (INFO_LOG === true) { logger.write('[INFO] initialize -> Entering function.') }
|
||||
|
||||
function initialize(callBackFunction) {
|
||||
icon = new Image()
|
||||
|
||||
try {
|
||||
icon.onload = onImageLoad
|
||||
|
||||
if (INFO_LOG === true) { logger.write("[INFO] initialize -> Entering function."); }
|
||||
function onImageLoad () {
|
||||
canDrawIcon = true
|
||||
}
|
||||
|
||||
icon = new Image();
|
||||
icon.src = window.canvasApp.urlPrefix + 'Images/Icons/trash.png'
|
||||
|
||||
icon.onload = onImageLoad;
|
||||
thisObject.container.eventHandler.listenToEvent('onMouseClick', onClick)
|
||||
|
||||
function onImageLoad() {
|
||||
canDrawIcon = true;
|
||||
}
|
||||
|
||||
icon.src = window.canvasApp.urlPrefix + "Images/Icons/trash.png";
|
||||
|
||||
thisObject.container.eventHandler.listenToEvent("onMouseClick", onClick);
|
||||
|
||||
window.canvasApp.eventHandler.listenToEvent("Browser Resized", resize);
|
||||
|
||||
if (callBackFunction !== undefined) { callBackFunction(GLOBAL.DEFAULT_OK_RESPONSE); }
|
||||
|
||||
} catch (err) {
|
||||
|
||||
if (ERROR_LOG === true) { logger.write("[ERROR] initialize -> err.message = " + err.message); }
|
||||
if (callBackFunction !== undefined) { callBackFunction(GLOBAL.DEFAULT_FAIL_RESPONSE); }
|
||||
}
|
||||
window.canvasApp.eventHandler.listenToEvent('Browser Resized', resize)
|
||||
|
||||
if (callBackFunction !== undefined) { callBackFunction(GLOBAL.DEFAULT_OK_RESPONSE) }
|
||||
} catch (err) {
|
||||
if (ERROR_LOG === true) { logger.write('[ERROR] initialize -> err.message = ' + err.message) }
|
||||
if (callBackFunction !== undefined) { callBackFunction(GLOBAL.DEFAULT_FAIL_RESPONSE) }
|
||||
}
|
||||
}
|
||||
|
||||
function resize() {
|
||||
function resize () {
|
||||
container.frame.position.x = viewPort.visibleArea.topRight.x
|
||||
container.frame.position.y = viewPort.visibleArea.bottomLeft.y
|
||||
}
|
||||
|
||||
container.frame.position.x = viewPort.visibleArea.topRight.x;
|
||||
container.frame.position.y = viewPort.visibleArea.bottomLeft.y;
|
||||
function onClick () {
|
||||
try {
|
||||
if (INFO_LOG === true) { logger.write('[INFO] onClick -> Entering function.') }
|
||||
|
||||
}
|
||||
let sessionToken = window.localStorage.getItem('sessionToken')
|
||||
|
||||
|
||||
function onClick() {
|
||||
|
||||
try {
|
||||
|
||||
if (INFO_LOG === true) { logger.write("[INFO] onClick -> Entering function."); }
|
||||
|
||||
let sessionToken = window.localStorage.getItem('sessionToken');
|
||||
|
||||
if (sessionToken === null || sessionToken === "") {
|
||||
if (sessionToken === null || sessionToken === '') {
|
||||
/* not logged in */
|
||||
return;
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
/*
|
||||
|
||||
@@ -94,243 +83,201 @@ function newDeleteTradingHistory() {
|
||||
6. Delete every execution context file found.
|
||||
7. Delete the execution history file after finishing the interation.
|
||||
8. Delete the Sequence file belonging to the received Start Mode.
|
||||
9. Save the Status Report without the records of this Start Mode.
|
||||
|
||||
9. Save the Status Report without the records of this Start Mode.
|
||||
|
||||
*/
|
||||
|
||||
let storage = AzureStorage.Blob;
|
||||
let storage = AzureStorage.Blob
|
||||
|
||||
let readOnlyBlobService;
|
||||
let writeOnlyBlobService;
|
||||
let deleteOnlyBlobService;
|
||||
let readOnlyBlobService
|
||||
let writeOnlyBlobService
|
||||
let deleteOnlyBlobService
|
||||
|
||||
let readConnectionString = window.USER_PROFILE.storagePermissions.get(window.DEV_TEAM + "." + "READ");
|
||||
let readConnectionString = window.USER_PROFILE.storagePermissions.get(window.DEV_TEAM + '.' + 'READ')
|
||||
|
||||
if (readConnectionString !== undefined) {
|
||||
readOnlyBlobService = storage.createBlobService(readConnectionString);
|
||||
}
|
||||
if (readConnectionString !== undefined) {
|
||||
readOnlyBlobService = storage.createBlobService(readConnectionString)
|
||||
}
|
||||
|
||||
let writeConnectionString = window.USER_PROFILE.storagePermissions.get(window.DEV_TEAM + "." + "WRITE");
|
||||
let writeConnectionString = window.USER_PROFILE.storagePermissions.get(window.DEV_TEAM + '.' + 'WRITE')
|
||||
|
||||
if (writeConnectionString !== undefined) {
|
||||
writeOnlyBlobService = storage.createBlobService(writeConnectionString);
|
||||
}
|
||||
if (writeConnectionString !== undefined) {
|
||||
writeOnlyBlobService = storage.createBlobService(writeConnectionString)
|
||||
}
|
||||
|
||||
let deleteConnectionString = window.USER_PROFILE.storagePermissions.get(window.DEV_TEAM + "." + "DELETE");
|
||||
let deleteConnectionString = window.USER_PROFILE.storagePermissions.get(window.DEV_TEAM + '.' + 'DELETE')
|
||||
|
||||
if (deleteConnectionString !== undefined) {
|
||||
deleteOnlyBlobService = storage.createBlobService(deleteConnectionString);
|
||||
}
|
||||
if (deleteConnectionString !== undefined) {
|
||||
deleteOnlyBlobService = storage.createBlobService(deleteConnectionString)
|
||||
}
|
||||
|
||||
let containerName = window.DEV_TEAM.toLowerCase();
|
||||
let containerName = window.DEV_TEAM.toLowerCase()
|
||||
|
||||
let statusReportFilePath = window.DEV_TEAM + "/" + window.CURRENT_BOT_CODE_NAME + ".1.0" + "/" + "AACloud.1.1" + "/" + "Poloniex" + "/" + "dataSet.V1" + "/" + "Reports" + "/" + "Trading-Process";
|
||||
let statusReportFileName = window.CURRENT_START_MODE + "." + "Status.Report.USDT_BTC.json";
|
||||
let statusReportFilePath = window.DEV_TEAM + '/' + window.CURRENT_BOT_CODE_NAME + '.1.0' + '/' + 'AACloud.1.1' + '/' + 'Poloniex' + '/' + 'dataSet.V1' + '/' + 'Reports' + '/' + 'Trading-Process'
|
||||
let statusReportFileName = window.CURRENT_START_MODE + '.' + 'Status.Report.USDT_BTC.json'
|
||||
|
||||
readOnlyBlobService.getBlobToText(containerName, statusReportFilePath + "/" + statusReportFileName, onStatusReport);
|
||||
readOnlyBlobService.getBlobToText(containerName, statusReportFilePath + '/' + statusReportFileName, onStatusReport)
|
||||
|
||||
function onStatusReport(err, text, response) {
|
||||
function onStatusReport (err, text, response) {
|
||||
try {
|
||||
if (INFO_LOG === true) { logger.write('[INFO] onClick -> onStatusReport -> Entering function.') }
|
||||
|
||||
try {
|
||||
if (err && err.code === 'BlobNotFound') {
|
||||
console.log(statusReportFilePath + '/' + statusReportFileName + ' not found. No history detected for this start mode.')
|
||||
return
|
||||
}
|
||||
|
||||
if (INFO_LOG === true) { logger.write("[INFO] onClick -> onStatusReport -> Entering function."); }
|
||||
let statusReport = JSON.parse(text)
|
||||
|
||||
if (err && err.code === 'BlobNotFound') {
|
||||
|
||||
console.log(statusReportFilePath + "/" + statusReportFileName + " not found. No history detected for this start mode.");
|
||||
return;
|
||||
}
|
||||
|
||||
let statusReport = JSON.parse(text);
|
||||
|
||||
let toBeDeleted = 0;
|
||||
let deleted = 0;
|
||||
|
||||
for (let i = 0; i < statusReport.runs.length; i++) {
|
||||
let toBeDeleted = 0
|
||||
let deleted = 0
|
||||
|
||||
for (let i = 0; i < statusReport.runs.length; i++) {
|
||||
/* For each record, we will get the execution history file. */
|
||||
|
||||
let filePath = window.DEV_TEAM + "/" + window.CURRENT_BOT_CODE_NAME + ".1.0" + "/" + "AACloud.1.1" + "/" + "Poloniex" + "/" + "dataSet.V1" + "/" + "Output" + "/" + "Trading-Process";
|
||||
let fileName = "Execution.History." + window.CURRENT_START_MODE + "." + i + ".json";
|
||||
let filePath = window.DEV_TEAM + '/' + window.CURRENT_BOT_CODE_NAME + '.1.0' + '/' + 'AACloud.1.1' + '/' + 'Poloniex' + '/' + 'dataSet.V1' + '/' + 'Output' + '/' + 'Trading-Process'
|
||||
let fileName = 'Execution.History.' + window.CURRENT_START_MODE + '.' + i + '.json'
|
||||
|
||||
readOnlyBlobService.getBlobToText(containerName, filePath + "/" + fileName, onExecutionHistory);
|
||||
readOnlyBlobService.getBlobToText(containerName, filePath + '/' + fileName, onExecutionHistory)
|
||||
|
||||
function onExecutionHistory(err, text, response) {
|
||||
function onExecutionHistory (err, text, response) {
|
||||
let executionHistory = JSON.parse(text)
|
||||
|
||||
let executionHistory = JSON.parse(text);
|
||||
for (let j = 0; j < executionHistory.length; j++) {
|
||||
let dateTime = new Date(executionHistory[j][0])
|
||||
|
||||
for (let j = 0; j < executionHistory.length; j++) {
|
||||
let datePath = dateTime.getUTCFullYear() + '/' + pad(dateTime.getUTCMonth() + 1, 2) + '/' + pad(dateTime.getUTCDate(), 2) + '/' + pad(dateTime.getUTCHours(), 2) + '/' + pad(dateTime.getUTCMinutes(), 2)
|
||||
|
||||
let dateTime = new Date(executionHistory[j][0]);
|
||||
let filePath = window.DEV_TEAM + '/' + window.CURRENT_BOT_CODE_NAME + '.1.0' + '/' + 'AACloud.1.1' + '/' + 'Poloniex' + '/' + 'dataSet.V1' + '/' + 'Output' + '/' + 'Trading-Process' + '/' + datePath
|
||||
let fileName = 'Execution.Context.' + window.CURRENT_START_MODE + '.' + i + '.json'
|
||||
|
||||
let datePath = dateTime.getUTCFullYear() + "/" + pad(dateTime.getUTCMonth() + 1, 2) + "/" + pad(dateTime.getUTCDate(), 2) + "/" + pad(dateTime.getUTCHours(), 2) + "/" + pad(dateTime.getUTCMinutes(), 2);
|
||||
deleteOnlyBlobService.deleteBlob(containerName, filePath + '/' + fileName, onDeleted)
|
||||
|
||||
let filePath = window.DEV_TEAM + "/" + window.CURRENT_BOT_CODE_NAME + ".1.0" + "/" + "AACloud.1.1" + "/" + "Poloniex" + "/" + "dataSet.V1" + "/" + "Output" + "/" + "Trading-Process" + "/" + datePath;
|
||||
let fileName = "Execution.Context." + window.CURRENT_START_MODE + "." + i + ".json";
|
||||
toBeDeleted++
|
||||
|
||||
deleteOnlyBlobService.deleteBlob(containerName, filePath + "/" + fileName, onDeleted);
|
||||
function onDeleted (err, text, response) {
|
||||
if (err) {
|
||||
|
||||
toBeDeleted++;
|
||||
console.log(filePath + '/' + fileName + ' NOT deleted.')
|
||||
console.log('err.message = ' + err.message)
|
||||
} else {
|
||||
|
||||
function onDeleted(err, text, response) {
|
||||
console.log(filePath + '/' + fileName + ' deleted.')
|
||||
}
|
||||
|
||||
if (err) {
|
||||
deleted++
|
||||
|
||||
console.log(filePath + "/" + fileName + " NOT deleted.");
|
||||
console.log("err.message = " + err.message);
|
||||
} else {
|
||||
if (toBeDeleted === deleted) {
|
||||
|
||||
console.log(filePath + "/" + fileName + " deleted.");
|
||||
|
||||
}
|
||||
|
||||
deleted++;
|
||||
|
||||
if (toBeDeleted === deleted) {
|
||||
|
||||
updateStatusReport();
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
updateStatusReport()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/* Now we delete the execution history file. */
|
||||
|
||||
deleteOnlyBlobService.deleteBlob(containerName, filePath + "/" + fileName, onExecutionHistoryDeleted);
|
||||
deleteOnlyBlobService.deleteBlob(containerName, filePath + '/' + fileName, onExecutionHistoryDeleted)
|
||||
|
||||
function onExecutionHistoryDeleted(err, text, response) {
|
||||
function onExecutionHistoryDeleted (err, text, response) {
|
||||
console.log(filePath + '/' + fileName + ' deleted.')
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
console.log(filePath + "/" + fileName + " deleted.");
|
||||
function updateStatusReport () {
|
||||
try {
|
||||
if (INFO_LOG === true) { logger.write('[INFO] onClick -> onStatusReport -> updateStatusReport -> Entering function.') }
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function updateStatusReport() {
|
||||
|
||||
try {
|
||||
|
||||
if (INFO_LOG === true) { logger.write("[INFO] onClick -> onStatusReport -> updateStatusReport -> Entering function."); }
|
||||
|
||||
statusReport.runs = [];
|
||||
statusReport.runs = []
|
||||
|
||||
/* Here is where we update the current Status Report file with the new version without records for the current Start Mode. */
|
||||
|
||||
let fileContent = JSON.stringify(statusReport);
|
||||
let fileContent = JSON.stringify(statusReport)
|
||||
|
||||
writeOnlyBlobService.createBlockBlobFromText(containerName, statusReportFilePath + "/" + statusReportFileName, fileContent, onStatusReportUpdated);
|
||||
writeOnlyBlobService.createBlockBlobFromText(containerName, statusReportFilePath + '/' + statusReportFileName, fileContent, onStatusReportUpdated)
|
||||
|
||||
function onStatusReportUpdated(err, text, response) {
|
||||
|
||||
console.log(statusReportFilePath + "/" + statusReportFileName + " updated.");
|
||||
|
||||
}
|
||||
function onStatusReportUpdated (err, text, response) {
|
||||
console.log(statusReportFilePath + '/' + statusReportFileName + ' updated.')
|
||||
}
|
||||
|
||||
/* Finally we delete the sequence file. */
|
||||
|
||||
let filePath = window.DEV_TEAM + "/" + window.CURRENT_BOT_CODE_NAME + ".1.0" + "/" + "AACloud.1.1" + "/" + "Poloniex" + "/" + "dataSet.V1" + "/" + "Output" + "/" + "Trading-Process";
|
||||
let fileName = "Execution.History." + window.CURRENT_START_MODE + "." + "Sequence" + ".json";
|
||||
let filePath = window.DEV_TEAM + '/' + window.CURRENT_BOT_CODE_NAME + '.1.0' + '/' + 'AACloud.1.1' + '/' + 'Poloniex' + '/' + 'dataSet.V1' + '/' + 'Output' + '/' + 'Trading-Process'
|
||||
let fileName = 'Execution.History.' + window.CURRENT_START_MODE + '.' + 'Sequence' + '.json'
|
||||
|
||||
deleteOnlyBlobService.deleteBlob(containerName, filePath + "/" + fileName, onDeleted);
|
||||
deleteOnlyBlobService.deleteBlob(containerName, filePath + '/' + fileName, onDeleted)
|
||||
|
||||
function onDeleted(err, text, response) {
|
||||
|
||||
console.log(filePath + "/" + fileName + " deleted.");
|
||||
|
||||
}
|
||||
|
||||
} catch (err) {
|
||||
|
||||
if (ERROR_LOG === true) { logger.write("[ERROR] onClick -> onStatusReport -> updateStatusReport -> err.message = " + err.message); }
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
} catch (err) {
|
||||
|
||||
if (ERROR_LOG === true) { logger.write("[ERROR] onClick -> onStatusReport -> err.message = " + err.message); }
|
||||
|
||||
}
|
||||
function onDeleted (err, text, response) {
|
||||
console.log(filePath + '/' + fileName + ' deleted.')
|
||||
}
|
||||
} catch (err) {
|
||||
if (ERROR_LOG === true) { logger.write('[ERROR] onClick -> onStatusReport -> updateStatusReport -> err.message = ' + err.message) }
|
||||
}
|
||||
|
||||
function pad(str, max) {
|
||||
str = str.toString();
|
||||
return str.length < max ? pad("0" + str, max) : str;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
} catch (err) {
|
||||
|
||||
if (ERROR_LOG === true) { logger.write("[ERROR] onClick -> err.message = " + err.message); }
|
||||
|
||||
if (ERROR_LOG === true) { logger.write('[ERROR] onClick -> onStatusReport -> err.message = ' + err.message) }
|
||||
}
|
||||
}
|
||||
|
||||
function pad (str, max) {
|
||||
str = str.toString()
|
||||
return str.length < max ? pad('0' + str, max) : str
|
||||
}
|
||||
} catch (err) {
|
||||
if (ERROR_LOG === true) { logger.write('[ERROR] onClick -> err.message = ' + err.message) }
|
||||
}
|
||||
}
|
||||
|
||||
function getContainer(point) {
|
||||
function getContainer (point) {
|
||||
try {
|
||||
if (INFO_LOG === true) { logger.write('[INFO] getContainer -> Entering function.') }
|
||||
|
||||
try {
|
||||
|
||||
if (INFO_LOG === true) { logger.write("[INFO] getContainer -> Entering function."); }
|
||||
|
||||
let container;
|
||||
let container
|
||||
|
||||
/* First we check if this point is inside this object UI. */
|
||||
|
||||
if (thisObject.container.frame.isThisPointHere(point, true) === true) {
|
||||
|
||||
return this.container;
|
||||
|
||||
} else {
|
||||
|
||||
if (thisObject.container.frame.isThisPointHere(point, true) === 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); }
|
||||
|
||||
}
|
||||
return undefined
|
||||
}
|
||||
} catch (err) {
|
||||
if (ERROR_LOG === true) { logger.write('[ERROR] getContainer -> err.message = ' + err.message) }
|
||||
}
|
||||
}
|
||||
|
||||
function draw() {
|
||||
function draw () {
|
||||
try {
|
||||
if (INFO_LOG === true) { logger.write('[INFO] draw -> Entering function.') }
|
||||
|
||||
try {
|
||||
let sessionToken = window.localStorage.getItem('sessionToken')
|
||||
|
||||
if (INFO_LOG === true) { logger.write("[INFO] draw -> Entering function."); }
|
||||
|
||||
let sessionToken = window.localStorage.getItem('sessionToken');
|
||||
|
||||
if (sessionToken === null || sessionToken === "") {
|
||||
if (sessionToken === null || sessionToken === '') {
|
||||
/* not logged in */
|
||||
return;
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
thisObject.container.frame.draw(false, false);
|
||||
thisObject.container.frame.draw(false, false)
|
||||
|
||||
if (canDrawIcon === false) { return; }
|
||||
if (canDrawIcon === false) { return }
|
||||
|
||||
let breakpointsHeight = 14;
|
||||
let breakpointsHeight = 0
|
||||
|
||||
let imageHeight = 15;
|
||||
let imageWidth = 15;
|
||||
let imageHeight = 15
|
||||
let imageWidth = 15
|
||||
|
||||
let imagePoint = {
|
||||
x: 10,
|
||||
y: thisObject.container.frame.height / 2 - imageHeight / 2 + breakpointsHeight
|
||||
};
|
||||
let imagePoint = {
|
||||
x: 10,
|
||||
y: thisObject.container.frame.height / 2 - imageHeight / 2 + breakpointsHeight
|
||||
}
|
||||
|
||||
imagePoint = thisObject.container.frame.frameThisPoint(imagePoint);
|
||||
imagePoint = thisObject.container.frame.frameThisPoint(imagePoint)
|
||||
|
||||
browserCanvasContext.drawImage(icon, imagePoint.x, imagePoint.y, imageWidth, imageHeight);
|
||||
|
||||
|
||||
} catch (err) {
|
||||
|
||||
if (ERROR_LOG === true) { logger.write("[ERROR] draw -> err.message = " + err.message); }
|
||||
|
||||
}
|
||||
browserCanvasContext.drawImage(icon, imagePoint.x, imagePoint.y, imageWidth, imageHeight)
|
||||
} catch (err) {
|
||||
if (ERROR_LOG === true) { logger.write('[ERROR] draw -> err.message = ' + err.message) }
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,164 +0,0 @@
|
||||
|
||||
function newPlayStopButton() {
|
||||
|
||||
var thisObject = {
|
||||
container: undefined,
|
||||
setDatetime: setDatetime,
|
||||
draw: draw,
|
||||
getContainer: getContainer, // returns the inner most container that holds the point received by parameter.
|
||||
initialize: initialize
|
||||
};
|
||||
|
||||
var container = newContainer();
|
||||
container.initialize();
|
||||
thisObject.container = container;
|
||||
|
||||
thisObject.container.frame.width = 50;
|
||||
thisObject.container.frame.height = BOTTOM_SPACE_HEIGHT;
|
||||
|
||||
resize();
|
||||
|
||||
container.isDraggeable = false;
|
||||
container.isClickeable = true;
|
||||
|
||||
let play;
|
||||
let stop;
|
||||
let canDraw = false;
|
||||
let showing = "Play";
|
||||
let image;
|
||||
|
||||
let datetime;
|
||||
let timePeriod;
|
||||
|
||||
return thisObject;
|
||||
|
||||
function initialize() {
|
||||
|
||||
play = new Image();
|
||||
|
||||
play.onload = onImageLoad;
|
||||
|
||||
function onImageLoad() {
|
||||
image = play;
|
||||
canDraw = true;
|
||||
}
|
||||
|
||||
play.src = window.canvasApp.urlPrefix + "Images/Icons/play.png";
|
||||
|
||||
stop = new Image();
|
||||
|
||||
stop.src = window.canvasApp.urlPrefix + "Images/Icons/pause.png";
|
||||
|
||||
thisObject.container.eventHandler.listenToEvent("onMouseClick", onClick);
|
||||
|
||||
viewPort.eventHandler.listenToEvent("Zoom Changed", onZoomChanged);
|
||||
timePeriod = INITIAL_TIME_PERIOD;
|
||||
|
||||
window.canvasApp.eventHandler.listenToEvent("Browser Resized", resize);
|
||||
|
||||
}
|
||||
|
||||
function resize() {
|
||||
|
||||
container.frame.position.x = viewPort.visibleArea.topLeft.x + 150 * 4;
|
||||
container.frame.position.y = viewPort.visibleArea.bottomLeft.y;
|
||||
|
||||
}
|
||||
|
||||
|
||||
function onClick() {
|
||||
|
||||
let sessionToken = window.localStorage.getItem('sessionToken');
|
||||
|
||||
if (sessionToken === null || sessionToken === "") {
|
||||
/* not logged in */
|
||||
return;
|
||||
}
|
||||
|
||||
switch (showing) {
|
||||
|
||||
case "Play": {
|
||||
image = stop;
|
||||
showing = "Stop";
|
||||
|
||||
let UI_COMMANDS = {
|
||||
beginDatetime: datetime,
|
||||
endDatetime: undefined,
|
||||
timePeriod: timePeriod,
|
||||
startMode: window.CURRENT_START_MODE,
|
||||
eventHandler: thisObject.container.eventHandler
|
||||
};
|
||||
|
||||
cloudVM.onBotPlayPressed(UI_COMMANDS);
|
||||
|
||||
break;
|
||||
}
|
||||
case "Stop": {
|
||||
image = play;
|
||||
showing = "Play";
|
||||
|
||||
cloudVM.onBotStopPressed();
|
||||
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function onZoomChanged(event) {
|
||||
|
||||
timePeriod = recalculatePeriod(event.newLevel);
|
||||
|
||||
}
|
||||
|
||||
function setDatetime(pDatetime) {
|
||||
|
||||
datetime = new Date(pDatetime);
|
||||
}
|
||||
|
||||
function getContainer(point) {
|
||||
|
||||
let container;
|
||||
|
||||
/* First we check if this point is inside this object UI. */
|
||||
|
||||
if (thisObject.container.frame.isThisPointHere(point, true) === true) {
|
||||
|
||||
return this.container;
|
||||
|
||||
} else {
|
||||
|
||||
/* This point does not belong to this space. */
|
||||
|
||||
return undefined;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
function draw() {
|
||||
|
||||
let sessionToken = window.localStorage.getItem('sessionToken');
|
||||
|
||||
if (sessionToken === null || sessionToken === "") {
|
||||
/* not logged in */
|
||||
return;
|
||||
}
|
||||
|
||||
thisObject.container.frame.draw(false, false);
|
||||
|
||||
let breakpointsHeight = 14;
|
||||
|
||||
if (canDraw === false) { return; }
|
||||
|
||||
let imageHeight = 20;
|
||||
let imageWidth = 20;
|
||||
|
||||
let imagePoint = {
|
||||
x: thisObject.container.frame.width / 2 - imageWidth / 2,
|
||||
y: thisObject.container.frame.height / 2 - imageHeight / 2 + breakpointsHeight
|
||||
};
|
||||
|
||||
imagePoint = thisObject.container.frame.frameThisPoint(imagePoint);
|
||||
|
||||
browserCanvasContext.drawImage(image, imagePoint.x, imagePoint.y, imageWidth, imageHeight);
|
||||
}
|
||||
}
|
||||
+131
-155
@@ -1,219 +1,195 @@
|
||||
|
||||
function newBreakpointsBar() {
|
||||
|
||||
var thisObject = {
|
||||
setDatetime: setDatetime,
|
||||
container: undefined,
|
||||
draw: draw,
|
||||
getContainer: getContainer, // returns the inner most container that holds the point received by parameter.
|
||||
initialize: initialize
|
||||
};
|
||||
function newBreakpointsBar () {
|
||||
var thisObject = {
|
||||
setDatetime: setDatetime,
|
||||
container: undefined,
|
||||
draw: draw,
|
||||
getContainer: getContainer, // returns the inner most container that holds the point received by parameter.
|
||||
initialize: initialize
|
||||
}
|
||||
|
||||
var container = newContainer();
|
||||
container.initialize();
|
||||
thisObject.container = container;
|
||||
var container = newContainer()
|
||||
container.initialize()
|
||||
thisObject.container = container
|
||||
|
||||
thisObject.container.frame.width = browserCanvasContext.width;
|
||||
thisObject.container.frame.height = 15;
|
||||
thisObject.container.frame.width = browserCanvasContext.width
|
||||
thisObject.container.frame.height = 15
|
||||
|
||||
container.frame.position.x = 0;
|
||||
container.frame.position.y = viewPort.visibleArea.bottomRight.y;
|
||||
container.frame.position.x = 0
|
||||
container.frame.position.y = viewPort.visibleArea.bottomRight.y
|
||||
|
||||
container.isDraggeable = false;
|
||||
container.isClickeable = true;
|
||||
container.isDraggeable = false
|
||||
container.isClickeable = true
|
||||
|
||||
let logo;
|
||||
let canDrawLogo = false;
|
||||
let logo
|
||||
let canDrawLogo = false
|
||||
|
||||
let datetime;
|
||||
let timePeriod;
|
||||
let timeLineCoordinateSystem;
|
||||
let chartContainer;
|
||||
let datetime
|
||||
let timePeriod
|
||||
let timeLineCoordinateSystem
|
||||
let chartContainer
|
||||
|
||||
let breakpointsByTimePeriod = new Map();
|
||||
let breakpointsByTimePeriod = new Map()
|
||||
|
||||
return thisObject;
|
||||
return thisObject
|
||||
|
||||
function initialize(pChartContainer, pTimeLineCoordinateSystem) {
|
||||
function initialize (pChartContainer, pTimeLineCoordinateSystem) {
|
||||
timeLineCoordinateSystem = pTimeLineCoordinateSystem
|
||||
chartContainer = pChartContainer
|
||||
|
||||
timeLineCoordinateSystem = pTimeLineCoordinateSystem;
|
||||
chartContainer = pChartContainer;
|
||||
viewPort.eventHandler.listenToEvent('Zoom Changed', onZoomChanged)
|
||||
timePeriod = INITIAL_TIME_PERIOD
|
||||
|
||||
viewPort.eventHandler.listenToEvent("Zoom Changed", onZoomChanged);
|
||||
timePeriod = INITIAL_TIME_PERIOD;
|
||||
thisObject.container.eventHandler.listenToEvent('onMouseClick', onClick)
|
||||
|
||||
thisObject.container.eventHandler.listenToEvent("onMouseClick", onClick);
|
||||
|
||||
for (let i = 0; i < marketFilesPeriods.length; i++) {
|
||||
|
||||
let breakpointsMap = new Map();
|
||||
breakpointsByTimePeriod.set(marketFilesPeriods[i][0], breakpointsMap);
|
||||
|
||||
}
|
||||
|
||||
for (let i = 0; i < dailyFilePeriods.length; i++) {
|
||||
|
||||
let breakpointsMap = new Map();
|
||||
breakpointsByTimePeriod.set(dailyFilePeriods[i][0], breakpointsMap);
|
||||
|
||||
}
|
||||
for (let i = 0; i < marketFilesPeriods.length; i++) {
|
||||
let breakpointsMap = new Map()
|
||||
breakpointsByTimePeriod.set(marketFilesPeriods[i][0], breakpointsMap)
|
||||
}
|
||||
|
||||
function onClick(pPoint) {
|
||||
for (let i = 0; i < dailyFilePeriods.length; i++) {
|
||||
let breakpointsMap = new Map()
|
||||
breakpointsByTimePeriod.set(dailyFilePeriods[i][0], breakpointsMap)
|
||||
}
|
||||
}
|
||||
|
||||
let point = {
|
||||
x: pPoint.x,
|
||||
y: pPoint.y
|
||||
};
|
||||
function onClick (pPoint) {
|
||||
let point = {
|
||||
x: pPoint.x,
|
||||
y: pPoint.y
|
||||
}
|
||||
|
||||
let miliSeconds = getMilisecondsFromPoint(point, chartContainer, timeLineCoordinateSystem);
|
||||
let miliSeconds = getMilisecondsFromPoint(point, chartContainer, timeLineCoordinateSystem)
|
||||
|
||||
miliSeconds = normalizeX(miliSeconds); // We are now exactly at the middle of the "candle" correspondind to the point clicked.
|
||||
miliSeconds = normalizeX(miliSeconds) // We are now exactly at the middle of the "candle" correspondind to the point clicked.
|
||||
|
||||
let breakpointsMap = breakpointsByTimePeriod.get(timePeriod);
|
||||
let breakpoint = breakpointsMap.get(miliSeconds);
|
||||
|
||||
if (breakpoint === undefined) {
|
||||
let breakpointsMap = breakpointsByTimePeriod.get(timePeriod)
|
||||
let breakpoint = breakpointsMap.get(miliSeconds)
|
||||
|
||||
if (breakpoint === undefined) {
|
||||
/* The breakpoint didnt exist, then we create one. */
|
||||
breakpointsMap.set(miliSeconds, 1);
|
||||
|
||||
} else {
|
||||
|
||||
breakpointsMap.set(miliSeconds, 1)
|
||||
} else {
|
||||
/* The breakpoint existed, so we remove it. */
|
||||
breakpointsMap.set(miliSeconds, undefined);
|
||||
|
||||
}
|
||||
breakpointsMap.set(miliSeconds, undefined)
|
||||
}
|
||||
}
|
||||
|
||||
function normalizeX(pX) {
|
||||
function normalizeX (pX) {
|
||||
return Math.trunc(pX / timePeriod) * timePeriod + timePeriod / 2
|
||||
}
|
||||
|
||||
return Math.trunc(pX / timePeriod) * timePeriod + timePeriod / 2;
|
||||
function onZoomChanged (event) {
|
||||
timePeriod = recalculatePeriod(event.newLevel)
|
||||
}
|
||||
|
||||
}
|
||||
function setDatetime (pDatetime) {
|
||||
datetime = new Date(pDatetime)
|
||||
}
|
||||
|
||||
function onZoomChanged(event) {
|
||||
|
||||
timePeriod = recalculatePeriod(event.newLevel);
|
||||
|
||||
}
|
||||
|
||||
function setDatetime(pDatetime) {
|
||||
|
||||
datetime = new Date(pDatetime);
|
||||
}
|
||||
|
||||
function getContainer(point) {
|
||||
|
||||
let container;
|
||||
function getContainer (point) {
|
||||
let container
|
||||
|
||||
/* First we check if this point is inside this object UI. */
|
||||
|
||||
if (thisObject.container.frame.isThisPointHere(point, true) === true) {
|
||||
|
||||
return this.container;
|
||||
|
||||
} else {
|
||||
|
||||
if (thisObject.container.frame.isThisPointHere(point, true) === true) {
|
||||
return this.container
|
||||
} else {
|
||||
/* This point does not belong to this space. */
|
||||
|
||||
return undefined;
|
||||
}
|
||||
|
||||
return undefined
|
||||
}
|
||||
}
|
||||
|
||||
function draw() {
|
||||
|
||||
function draw () {
|
||||
/*
|
||||
To draw the breakpoints, we will calculate the miliseconds for the first x pixel of the breakpoint bar, and for the last x pixel. Once we have that
|
||||
we can create an array with all the possible points for breack points. Finally we can see if brealpoints exists at those points. We plot only the ones
|
||||
that exists.
|
||||
*/
|
||||
|
||||
let breakpointsMap = breakpointsByTimePeriod.get(timePeriod);
|
||||
let breakpointsMap = breakpointsByTimePeriod.get(timePeriod)
|
||||
|
||||
let beginX = {
|
||||
x: viewPort.visibleArea.bottomLeft.x,
|
||||
y: 0
|
||||
};
|
||||
let beginX = {
|
||||
x: viewPort.visibleArea.bottomLeft.x,
|
||||
y: 0
|
||||
}
|
||||
|
||||
let endX = {
|
||||
x: viewPort.visibleArea.bottomRight.x,
|
||||
y: 0
|
||||
};
|
||||
let endX = {
|
||||
x: viewPort.visibleArea.bottomRight.x,
|
||||
y: 0
|
||||
}
|
||||
|
||||
let beginMiliseconds = getMilisecondsFromPoint(beginX, chartContainer, timeLineCoordinateSystem);
|
||||
let endMiliseconds = getMilisecondsFromPoint(endX, chartContainer, timeLineCoordinateSystem);
|
||||
let beginMiliseconds = getMilisecondsFromPoint(beginX, chartContainer, timeLineCoordinateSystem)
|
||||
let endMiliseconds = getMilisecondsFromPoint(endX, chartContainer, timeLineCoordinateSystem)
|
||||
|
||||
beginMiliseconds = normalizeX(beginMiliseconds);
|
||||
endMiliseconds = normalizeX(endMiliseconds);
|
||||
beginMiliseconds = normalizeX(beginMiliseconds)
|
||||
endMiliseconds = normalizeX(endMiliseconds)
|
||||
|
||||
window.AT_BREAKPOINT = false;
|
||||
window.AT_BREAKPOINT = false
|
||||
|
||||
for (let miliSeconds = beginMiliseconds; miliSeconds < endMiliseconds; miliSeconds = miliSeconds + timePeriod) {
|
||||
for (let miliSeconds = beginMiliseconds; miliSeconds < endMiliseconds; miliSeconds = miliSeconds + timePeriod) {
|
||||
let breakpoint = breakpointsMap.get(miliSeconds)
|
||||
|
||||
let breakpoint = breakpointsMap.get(miliSeconds);
|
||||
if (breakpoint !== undefined) {
|
||||
let point1 = {
|
||||
x: miliSeconds,
|
||||
y: 0
|
||||
}
|
||||
|
||||
if (breakpoint !== undefined) {
|
||||
point1 = timeLineCoordinateSystem.transformThisPoint(point1)
|
||||
point1 = transformThisPoint(point1, chartContainer)
|
||||
|
||||
let point1 = {
|
||||
x: miliSeconds,
|
||||
y: 0
|
||||
}
|
||||
let point2 = {
|
||||
x: miliSeconds,
|
||||
y: thisObject.container.frame.height / 2 + 1
|
||||
}
|
||||
|
||||
point1 = timeLineCoordinateSystem.transformThisPoint(point1);
|
||||
point1 = transformThisPoint(point1, chartContainer);
|
||||
point2 = thisObject.container.frame.frameThisPoint(point2)
|
||||
|
||||
let point2 = {
|
||||
x: miliSeconds,
|
||||
y: thisObject.container.frame.height / 2 + 1
|
||||
}
|
||||
let point = {
|
||||
x: point1.x,
|
||||
y: point2.y
|
||||
}
|
||||
|
||||
point2 = thisObject.container.frame.frameThisPoint(point2);
|
||||
let isCurrentRecord = false
|
||||
|
||||
let point = {
|
||||
x: point1.x,
|
||||
y: point2.y
|
||||
}
|
||||
if (datetime !== undefined) {
|
||||
let dateValue = datetime.valueOf()
|
||||
if (dateValue >= miliSeconds - timePeriod / 2 && dateValue <= miliSeconds + timePeriod / 2 - 1) {
|
||||
isCurrentRecord = true
|
||||
}
|
||||
}
|
||||
|
||||
let isCurrentRecord = false;
|
||||
let radius = 5
|
||||
|
||||
if (datetime !== undefined) {
|
||||
let dateValue = datetime.valueOf();
|
||||
if (dateValue >= miliSeconds - timePeriod / 2 && dateValue <= miliSeconds + timePeriod / 2 - 1) {
|
||||
isCurrentRecord = true;
|
||||
}
|
||||
}
|
||||
let opacity = '0.5'
|
||||
|
||||
let radius = 5;
|
||||
|
||||
let opacity = '0.5';
|
||||
|
||||
browserCanvasContext.lineWidth = 1;
|
||||
browserCanvasContext.lineWidth = 1
|
||||
|
||||
/* Outer Circle */
|
||||
|
||||
browserCanvasContext.beginPath();
|
||||
browserCanvasContext.beginPath()
|
||||
|
||||
browserCanvasContext.strokeStyle = 'rgba(123, 50, 40, ' + opacity + ')';
|
||||
browserCanvasContext.strokeStyle = 'rgba(123, 50, 40, ' + opacity + ')'
|
||||
|
||||
if (isCurrentRecord === false) {
|
||||
browserCanvasContext.fillStyle = 'rgba(223, 70, 60, ' + opacity + ')';
|
||||
} else {
|
||||
browserCanvasContext.fillStyle = 'rgba(255, 233, 31, ' + opacity + ')'; /* highlight the current record */
|
||||
if (isCurrentRecord === false) {
|
||||
browserCanvasContext.fillStyle = 'rgba(223, 70, 60, ' + opacity + ')'
|
||||
} else {
|
||||
browserCanvasContext.fillStyle = 'rgba(255, 233, 31, ' + opacity + ')' /* highlight the current record */
|
||||
|
||||
window.AT_BREAKPOINT = true; // We are hitting a breakpoint!
|
||||
}
|
||||
|
||||
browserCanvasContext.arc(point.x, point.y, radius, 0, Math.PI * 2, true);
|
||||
browserCanvasContext.closePath();
|
||||
|
||||
if (point.x < viewPort.visibleArea.topLeft.x + 50 || point.x > viewPort.visibleArea.bottomRight.x - 50) {/*we leave this history without fill. */ } else {
|
||||
browserCanvasContext.fill();
|
||||
}
|
||||
|
||||
browserCanvasContext.stroke();
|
||||
}
|
||||
window.AT_BREAKPOINT = true // We are hitting a breakpoint!
|
||||
}
|
||||
|
||||
browserCanvasContext.arc(point.x, point.y, radius, 0, Math.PI * 2, true)
|
||||
browserCanvasContext.closePath()
|
||||
|
||||
if (point.x < viewPort.visibleArea.topLeft.x + 50 || point.x > viewPort.visibleArea.bottomRight.x - 50) { /* we leave this history without fill. */ } else {
|
||||
browserCanvasContext.fill()
|
||||
}
|
||||
|
||||
browserCanvasContext.stroke()
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,17 +1,15 @@
|
||||
function newCandle() {
|
||||
function newCandle () {
|
||||
var candle = {
|
||||
open: undefined,
|
||||
close: undefined,
|
||||
min: 10000000000000,
|
||||
max: 0,
|
||||
begin: undefined,
|
||||
end: undefined,
|
||||
direction: undefined,
|
||||
beginId: undefined,
|
||||
endId: undefined
|
||||
}
|
||||
|
||||
var candle = {
|
||||
open: undefined,
|
||||
close: undefined,
|
||||
min: 10000000000000,
|
||||
max: 0,
|
||||
begin: undefined,
|
||||
end: undefined,
|
||||
direction: undefined,
|
||||
beginId: undefined,
|
||||
endId: undefined
|
||||
};
|
||||
|
||||
return candle;
|
||||
|
||||
}
|
||||
return candle
|
||||
}
|
||||
+105
-113
@@ -1,150 +1,142 @@
|
||||
|
||||
|
||||
function getSideDays(timePeriod) {
|
||||
function getSideDays (timePeriod) {
|
||||
let daysOnSides
|
||||
|
||||
let daysOnSides;
|
||||
if (timePeriod < _1_HOUR_IN_MILISECONDS) {
|
||||
daysOnSides = 1
|
||||
}
|
||||
|
||||
if (timePeriod < _1_HOUR_IN_MILISECONDS) {
|
||||
daysOnSides = 1;
|
||||
}
|
||||
if (timePeriod === _1_HOUR_IN_MILISECONDS) {
|
||||
daysOnSides = 9
|
||||
}
|
||||
|
||||
if (timePeriod === _1_HOUR_IN_MILISECONDS) {
|
||||
daysOnSides = 9;
|
||||
}
|
||||
if (timePeriod === _2_HOURS_IN_MILISECONDS) {
|
||||
daysOnSides = 10
|
||||
}
|
||||
|
||||
if (timePeriod === _2_HOURS_IN_MILISECONDS) {
|
||||
daysOnSides = 10;
|
||||
}
|
||||
if (timePeriod === _3_HOURS_IN_MILISECONDS) {
|
||||
daysOnSides = 12
|
||||
}
|
||||
|
||||
if (timePeriod === _3_HOURS_IN_MILISECONDS) {
|
||||
daysOnSides = 12;
|
||||
}
|
||||
if (timePeriod === _4_HOURS_IN_MILISECONDS) {
|
||||
daysOnSides = 20
|
||||
}
|
||||
|
||||
if (timePeriod === _4_HOURS_IN_MILISECONDS) {
|
||||
daysOnSides = 20;
|
||||
}
|
||||
if (timePeriod === _6_HOURS_IN_MILISECONDS) {
|
||||
daysOnSides = 35
|
||||
}
|
||||
|
||||
if (timePeriod === _6_HOURS_IN_MILISECONDS) {
|
||||
daysOnSides = 35;
|
||||
}
|
||||
if (timePeriod === _8_HOURS_IN_MILISECONDS) {
|
||||
daysOnSides = 44
|
||||
}
|
||||
|
||||
if (timePeriod === _8_HOURS_IN_MILISECONDS) {
|
||||
daysOnSides = 44;
|
||||
}
|
||||
if (timePeriod === _12_HOURS_IN_MILISECONDS) {
|
||||
daysOnSides = 56
|
||||
}
|
||||
|
||||
if (timePeriod === _12_HOURS_IN_MILISECONDS) {
|
||||
daysOnSides = 56;
|
||||
}
|
||||
if (timePeriod === ONE_DAY_IN_MILISECONDS) {
|
||||
daysOnSides = 154
|
||||
}
|
||||
|
||||
if (timePeriod === ONE_DAY_IN_MILISECONDS) {
|
||||
daysOnSides = 154;
|
||||
}
|
||||
|
||||
return daysOnSides;
|
||||
return daysOnSides
|
||||
}
|
||||
|
||||
|
||||
function getCondenseFactor(timePeriod) {
|
||||
|
||||
switch (timePeriod) {
|
||||
case _1_MINUTE_IN_MILISECONDS: return 1;
|
||||
case _5_MINUTES_IN_MILISECONDS: return 5;
|
||||
case _10_MINUTES_IN_MILISECONDS: return 10;
|
||||
case _30_MINUTES_IN_MILISECONDS: return 50;
|
||||
case _1_HOUR_IN_MILISECONDS: return 100;
|
||||
}
|
||||
function getCondenseFactor (timePeriod) {
|
||||
switch (timePeriod) {
|
||||
case _1_MINUTE_IN_MILISECONDS: return 1
|
||||
case _5_MINUTES_IN_MILISECONDS: return 5
|
||||
case _10_MINUTES_IN_MILISECONDS: return 10
|
||||
case _30_MINUTES_IN_MILISECONDS: return 50
|
||||
case _1_HOUR_IN_MILISECONDS: return 100
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
function getTransparenceFactor(timePeriod) {
|
||||
|
||||
switch (timePeriod) {
|
||||
case _1_MINUTE_IN_MILISECONDS: return "0.12";
|
||||
case _5_MINUTES_IN_MILISECONDS: return "0.10";
|
||||
case _10_MINUTES_IN_MILISECONDS: return "0.08";
|
||||
case _30_MINUTES_IN_MILISECONDS: return "0.06";
|
||||
case _1_HOUR_IN_MILISECONDS: return "0.04";
|
||||
}
|
||||
function getTransparenceFactor (timePeriod) {
|
||||
switch (timePeriod) {
|
||||
case _1_MINUTE_IN_MILISECONDS: return '0.12'
|
||||
case _5_MINUTES_IN_MILISECONDS: return '0.10'
|
||||
case _10_MINUTES_IN_MILISECONDS: return '0.08'
|
||||
case _30_MINUTES_IN_MILISECONDS: return '0.06'
|
||||
case _1_HOUR_IN_MILISECONDS: return '0.04'
|
||||
}
|
||||
}
|
||||
|
||||
function recalculatePeriod (zoomLevel) {
|
||||
// console.log(" recalculatePeriod > " + zoomLevel);
|
||||
|
||||
function recalculatePeriod(zoomLevel) {
|
||||
if (zoomLevel > 200) {
|
||||
return _1_MINUTE_IN_MILISECONDS
|
||||
}
|
||||
|
||||
//console.log(" recalculatePeriod > " + zoomLevel);
|
||||
if (zoomLevel > 120) {
|
||||
return _2_MINUTES_IN_MILISECONDS
|
||||
}
|
||||
|
||||
if (zoomLevel > 200) {
|
||||
return _1_MINUTE_IN_MILISECONDS;
|
||||
}
|
||||
if (zoomLevel > 80) {
|
||||
return _3_MINUTES_IN_MILISECONDS
|
||||
}
|
||||
|
||||
if (zoomLevel > 120) {
|
||||
return _2_MINUTES_IN_MILISECONDS;
|
||||
}
|
||||
if (zoomLevel > 60) {
|
||||
return _4_MINUTES_IN_MILISECONDS
|
||||
}
|
||||
|
||||
if (zoomLevel > 80) {
|
||||
return _3_MINUTES_IN_MILISECONDS;
|
||||
}
|
||||
if (zoomLevel > 15) {
|
||||
return _5_MINUTES_IN_MILISECONDS
|
||||
}
|
||||
|
||||
if (zoomLevel > 60) {
|
||||
return _4_MINUTES_IN_MILISECONDS;
|
||||
}
|
||||
if (zoomLevel > -7) {
|
||||
return _10_MINUTES_IN_MILISECONDS
|
||||
}
|
||||
|
||||
if (zoomLevel > 15) {
|
||||
return _5_MINUTES_IN_MILISECONDS;
|
||||
}
|
||||
if (zoomLevel > -10) {
|
||||
return _15_MINUTES_IN_MILISECONDS
|
||||
}
|
||||
|
||||
if (zoomLevel > - 7) {
|
||||
return _10_MINUTES_IN_MILISECONDS;
|
||||
}
|
||||
if (zoomLevel > -13) {
|
||||
return _20_MINUTES_IN_MILISECONDS
|
||||
}
|
||||
|
||||
if (zoomLevel > - 10) {
|
||||
return _15_MINUTES_IN_MILISECONDS;
|
||||
}
|
||||
if (zoomLevel > -15) {
|
||||
return _30_MINUTES_IN_MILISECONDS
|
||||
}
|
||||
|
||||
if (zoomLevel > - 13) {
|
||||
return _20_MINUTES_IN_MILISECONDS;
|
||||
}
|
||||
if (zoomLevel > -16) {
|
||||
return _40_MINUTES_IN_MILISECONDS
|
||||
}
|
||||
|
||||
if (zoomLevel > - 15) {
|
||||
return _30_MINUTES_IN_MILISECONDS;
|
||||
}
|
||||
if (zoomLevel > -17) {
|
||||
return _45_MINUTES_IN_MILISECONDS
|
||||
}
|
||||
|
||||
if (zoomLevel > - 16) {
|
||||
return _40_MINUTES_IN_MILISECONDS;
|
||||
}
|
||||
if (zoomLevel > -18) {
|
||||
return _1_HOUR_IN_MILISECONDS
|
||||
}
|
||||
|
||||
if (zoomLevel > - 17) {
|
||||
return _45_MINUTES_IN_MILISECONDS;
|
||||
}
|
||||
if (zoomLevel > -24) {
|
||||
return _2_HOURS_IN_MILISECONDS
|
||||
}
|
||||
|
||||
if (zoomLevel > - 18) {
|
||||
return _1_HOUR_IN_MILISECONDS;
|
||||
}
|
||||
if (zoomLevel > -25) {
|
||||
return _3_HOURS_IN_MILISECONDS
|
||||
}
|
||||
|
||||
if (zoomLevel > - 24) {
|
||||
return _2_HOURS_IN_MILISECONDS;
|
||||
}
|
||||
if (zoomLevel > -27) {
|
||||
return _4_HOURS_IN_MILISECONDS
|
||||
}
|
||||
|
||||
if (zoomLevel > - 25) {
|
||||
return _3_HOURS_IN_MILISECONDS;
|
||||
}
|
||||
if (zoomLevel > -27.5) {
|
||||
return _6_HOURS_IN_MILISECONDS
|
||||
}
|
||||
|
||||
if (zoomLevel > - 27) {
|
||||
return _4_HOURS_IN_MILISECONDS;
|
||||
}
|
||||
if (zoomLevel > -27.75) {
|
||||
return _8_HOURS_IN_MILISECONDS
|
||||
}
|
||||
|
||||
if (zoomLevel > - 27.5) {
|
||||
return _6_HOURS_IN_MILISECONDS;
|
||||
}
|
||||
if (zoomLevel > -28) {
|
||||
return _12_HOURS_IN_MILISECONDS
|
||||
}
|
||||
|
||||
if (zoomLevel > - 27.75) {
|
||||
return _8_HOURS_IN_MILISECONDS;
|
||||
}
|
||||
|
||||
if (zoomLevel > - 28) {
|
||||
return _12_HOURS_IN_MILISECONDS;
|
||||
}
|
||||
|
||||
if (zoomLevel <= - 28) {
|
||||
return ONE_DAY_IN_MILISECONDS;
|
||||
}
|
||||
if (zoomLevel <= -28) {
|
||||
return ONE_DAY_IN_MILISECONDS
|
||||
}
|
||||
}
|
||||
@@ -1,61 +0,0 @@
|
||||
function newCloudRequire(bot, logger) {
|
||||
|
||||
const INFO_LOG = true;
|
||||
const LOG_FILE_CONTENT = false;
|
||||
|
||||
const MODULE_NAME = "Cloud Require";
|
||||
|
||||
let thisObject = {
|
||||
downloadBot: downloadBot,
|
||||
downloadCommons: downloadCommons
|
||||
};
|
||||
|
||||
return thisObject;
|
||||
|
||||
function downloadBot(pCloudStorage, pFilePath, callBackFunction) {
|
||||
|
||||
try {
|
||||
|
||||
if (INFO_LOG === true) { logger.write(MODULE_NAME, "[INFO] downloadBot -> Entering function."); }
|
||||
|
||||
let filePath = window.canvasApp.urlPrefix + "Bots" + "/" + pFilePath + "/" + "User.Bot.js";
|
||||
|
||||
downloadModule(filePath, onDownloaded)
|
||||
|
||||
function onDownloaded(pModule) {
|
||||
|
||||
callBackFunction(window.DEFAULT_OK_RESPONSE, pModule);
|
||||
return;
|
||||
|
||||
}
|
||||
|
||||
} catch (err) {
|
||||
logger.write(MODULE_NAME, "[ERROR] downloadBot -> err = " + err.message);
|
||||
callBackFunction(window.DEFAULT_FAIL_RESPONSE);
|
||||
}
|
||||
}
|
||||
|
||||
function downloadCommons(pCloudStorage, pFilePath, callBackFunction) {
|
||||
|
||||
try {
|
||||
|
||||
if (INFO_LOG === true) { logger.write(MODULE_NAME, "[INFO] downloadCommons -> Entering function."); }
|
||||
|
||||
let filePath = window.canvasApp.urlPrefix + "Bots" + "/" + pFilePath + "/" + "Commons.js";
|
||||
|
||||
downloadModule(filePath, onDownloaded)
|
||||
|
||||
function onDownloaded(pModule) {
|
||||
|
||||
callBackFunction(window.DEFAULT_OK_RESPONSE, pModule);
|
||||
return;
|
||||
|
||||
}
|
||||
|
||||
} catch (err) {
|
||||
logger.write(MODULE_NAME, "[ERROR] downloadCommons -> err = " + err.message);
|
||||
callBackFunction(window.DEFAULT_FAIL_RESPONSE);
|
||||
}
|
||||
}
|
||||
|
||||
};
|
||||
@@ -1,143 +0,0 @@
|
||||
|
||||
/*
|
||||
|
||||
This module is for enabling the AACloud to run at the browser.
|
||||
|
||||
When running at the clode on NodeJS some things work diffently that at the browser. That gap will be fixed by the functions at this module.
|
||||
|
||||
*/
|
||||
|
||||
function webRequire(pModulePath) {
|
||||
|
||||
switch (pModulePath) {
|
||||
|
||||
case './AzureStorage': {
|
||||
|
||||
let MODULE = {};
|
||||
MODULE.newAzureStorage = newAzureStorage;
|
||||
return MODULE;
|
||||
|
||||
function newAzureStorage() {
|
||||
|
||||
return AzureStorage.Blob;
|
||||
|
||||
}
|
||||
}
|
||||
case './EventHandler': {
|
||||
|
||||
let MODULE = {};
|
||||
MODULE.newEventHandler = newEventHandler;
|
||||
return MODULE;
|
||||
}
|
||||
case './BlobStorage': {
|
||||
|
||||
let MODULE = {};
|
||||
MODULE.newBlobStorage = newBlobStorage;
|
||||
return MODULE;
|
||||
}
|
||||
case './DebugLog': {
|
||||
|
||||
let MODULE = {};
|
||||
MODULE.newDebugLog = newDebugLog;
|
||||
return MODULE;
|
||||
}
|
||||
case './TradingBotProcessMainLoop': {
|
||||
|
||||
let MODULE = {};
|
||||
MODULE.newTradingBotProcessMainLoop = newTradingBotProcessMainLoop;
|
||||
return MODULE;
|
||||
}
|
||||
case './ExtractionBotProcessMainLoop': {
|
||||
|
||||
let MODULE = {};
|
||||
MODULE.newExtractionBotProcessMainLoop = newExtractionBotProcessMainLoop;
|
||||
return MODULE;
|
||||
}
|
||||
case './IndicatorBotProcessMainLoop': {
|
||||
|
||||
let MODULE = {};
|
||||
MODULE.newIndicatorBotProcessMainLoop = newIndicatorBotProcessMainLoop;
|
||||
return MODULE;
|
||||
}
|
||||
case './CloudUtilities': {
|
||||
|
||||
let MODULE = {};
|
||||
MODULE.newCloudUtilities = newCloudUtilities;
|
||||
return MODULE;
|
||||
}
|
||||
case './PoloniexAPIClient': {
|
||||
|
||||
let MODULE = {};
|
||||
MODULE.newPoloniexAPIClient = newPoloniexAPIClient;
|
||||
return MODULE;
|
||||
}
|
||||
case './Exchange/ExchangeAPI': {
|
||||
|
||||
let MODULE = {};
|
||||
MODULE.newExchangeAPI = newExchangeAPI;
|
||||
return MODULE;
|
||||
}
|
||||
case './Context': {
|
||||
|
||||
let MODULE = {};
|
||||
MODULE.newContext = newContext;
|
||||
return MODULE;
|
||||
}
|
||||
case './Assistant': {
|
||||
|
||||
let MODULE = {};
|
||||
MODULE.newAssistant = newAssistant;
|
||||
return MODULE;
|
||||
}
|
||||
case './StatusReport': {
|
||||
|
||||
let MODULE = {};
|
||||
MODULE.newStatusReport = newStatusReport;
|
||||
return MODULE;
|
||||
}
|
||||
case './DataSet': {
|
||||
|
||||
let MODULE = {};
|
||||
MODULE.newDataSet = newDataSet;
|
||||
return MODULE;
|
||||
}
|
||||
case './StatusDependencies': {
|
||||
|
||||
let MODULE = {};
|
||||
MODULE.newStatusDependencies = newStatusDependencies;
|
||||
return MODULE;
|
||||
}
|
||||
case './DataDependencies': {
|
||||
|
||||
let MODULE = {};
|
||||
MODULE.newDataDependencies = newDataDependencies;
|
||||
return MODULE;
|
||||
}
|
||||
case './CloudRequire': {
|
||||
|
||||
let MODULE = {};
|
||||
MODULE.newCloudRequire = newCloudRequire;
|
||||
return MODULE;
|
||||
}
|
||||
default: {
|
||||
console.log(pModulePath + " not found. ");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function downloadModule(pPath, callBackFunction) {
|
||||
|
||||
/* We will need this to load individual bots modules. */
|
||||
|
||||
REQUIREJS([pPath], onRequired);
|
||||
|
||||
function onRequired(pModule) {
|
||||
|
||||
console.log("CloudVM " + pPath + " downloaded.");
|
||||
|
||||
let MODULE = {};
|
||||
MODULE.newUserBot = newUserBot;
|
||||
callBackFunction(MODULE);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,152 +0,0 @@
|
||||
|
||||
function newCloudVM() {
|
||||
|
||||
const MODULE_NAME = "CloudVM";
|
||||
const INFO_LOG = false;
|
||||
const ERROR_LOG = true;
|
||||
const logger = newWebDebugLog();
|
||||
logger.fileName = MODULE_NAME;
|
||||
|
||||
var thisObject = {
|
||||
onBotPlayPressed: onBotPlayPressed,
|
||||
onBotStopPressed: onBotStopPressed
|
||||
};
|
||||
|
||||
let root = newRoot();
|
||||
let intervalHandler;
|
||||
let previousBotCode = "";
|
||||
let errorsCheckingForBotCodeChanges = 0;
|
||||
|
||||
return thisObject;
|
||||
|
||||
function onBotPlayPressed(pUI_COMMANDS) {
|
||||
|
||||
try {
|
||||
|
||||
if (INFO_LOG === true) { logger.write("[INFO] onBotPlayPressed -> Entering function."); }
|
||||
|
||||
window.SHALL_BOT_STOP = false;
|
||||
errorsCheckingForBotCodeChanges = 0;
|
||||
|
||||
window.CURRENT_ENVIRONMENT = "Develop";
|
||||
window.CURRENT_EXECUTION_AT = "Browser";
|
||||
window.STORAGE_PERMISSIONS = ecosystem.getStoragePermissions();
|
||||
|
||||
window.EXCHANGE_NAME = "Poloniex";
|
||||
window.MARKET = {
|
||||
assetA: "USDT",
|
||||
assetB: "BTC"
|
||||
};
|
||||
|
||||
/*
|
||||
When running at the browser, the AACloud VM will look for this data, in this case it does not contain any key or secret, since the browser only know the
|
||||
session token the user received when he logged in.
|
||||
*/
|
||||
|
||||
window.EXCHANGE_KEYS = {
|
||||
Poloniex: {
|
||||
Key: "",
|
||||
Secret: ""
|
||||
}
|
||||
}
|
||||
|
||||
root.initialize(pUI_COMMANDS, onInitialized);
|
||||
|
||||
function onInitialized() {
|
||||
|
||||
try {
|
||||
|
||||
if (INFO_LOG === true) { logger.write("[INFO] onBotPlayPressed -> Entering function."); }
|
||||
|
||||
root.start();
|
||||
|
||||
intervalHandler = setInterval(checkForChangesInBotCode, 10000);
|
||||
|
||||
} catch (err) {
|
||||
|
||||
if (ERROR_LOG === true) { logger.write("[ERROR] onBotPlayPressed -> onInitialized -> err.message = " + err.message); }
|
||||
}
|
||||
}
|
||||
|
||||
} catch (err) {
|
||||
|
||||
if (ERROR_LOG === true) { logger.write("[ERROR] onBotPlayPressed -> err.message = " + err.message); }
|
||||
}
|
||||
}
|
||||
|
||||
function onBotStopPressed() {
|
||||
|
||||
if (INFO_LOG === true) { logger.write("[INFO] onBotStopPressed -> Entering function."); }
|
||||
|
||||
window.SHALL_BOT_STOP = true;
|
||||
errorsCheckingForBotCodeChanges = 0;
|
||||
|
||||
}
|
||||
|
||||
function checkForChangesInBotCode() {
|
||||
|
||||
try {
|
||||
|
||||
if (INFO_LOG === true) { logger.write("[INFO] checkForChangesInBotCode -> Entering function."); }
|
||||
|
||||
let botFunction = newUserBot;
|
||||
|
||||
if (botFunction !== undefined) {
|
||||
|
||||
let currentBotCode = botFunction.toString();
|
||||
|
||||
if (previousBotCode !== "") {
|
||||
|
||||
if (currentBotCode !== previousBotCode) {
|
||||
|
||||
console.log("CloudVM -> Bot code changes detected.");
|
||||
|
||||
let path = window.canvasApp.urlPrefix
|
||||
+ "AABrowserAPI" + "/"
|
||||
+ "saveBotCode" + "/"
|
||||
+ window.DEV_TEAM + "/"
|
||||
+ "members" + "/"
|
||||
+ window.USER_LOGGED_IN + "/"
|
||||
+ window.CURRENT_BOT_REPO + "/"
|
||||
+ window.CURRENT_PROCESS + "/"
|
||||
+ "User.Bot.js"
|
||||
;
|
||||
|
||||
callServer(currentBotCode, path, onServerResponse);
|
||||
|
||||
function onServerResponse(err) {
|
||||
|
||||
err = JSON.parse(err);
|
||||
|
||||
if (INFO_LOG === true) { logger.write("[INFO] checkForChangesInBotCode -> onServerResponse -> Entering function."); }
|
||||
|
||||
if (err.result !== GLOBAL.DEFAULT_OK_RESPONSE.result) {
|
||||
|
||||
if (ERROR_LOG === true) { logger.write("[ERROR] checkForChangesInBotCode -> onServerResponse -> err.message = " + err.message); }
|
||||
console.log("CloudVM -> Changes in code NOT saved. Plase check the error log and try again.");
|
||||
return;
|
||||
}
|
||||
|
||||
console.log("CloudVM -> Changes in code saved.");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
previousBotCode = currentBotCode;
|
||||
}
|
||||
|
||||
} catch (err) {
|
||||
|
||||
if (ERROR_LOG === true) { logger.write("[ERROR] checkForChangesInBotCode -> err.message = " + err.message); }
|
||||
errorsCheckingForBotCodeChanges++;
|
||||
|
||||
if (errorsCheckingForBotCodeChanges > 2) {
|
||||
|
||||
if (ERROR_LOG === true) { logger.write("[ERROR] checkForChangesInBotCode -> Giving up."); }
|
||||
|
||||
clearInterval(intervalHandler);
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,71 +0,0 @@
|
||||
function newWebFS() {
|
||||
|
||||
const MODULE_NAME = "Web FS";
|
||||
const INFO_LOG = false;
|
||||
const ERROR_LOG = true;
|
||||
const logger = newWebDebugLog();
|
||||
logger.fileName = MODULE_NAME;
|
||||
|
||||
/*
|
||||
|
||||
This is the module emulates the NodeJS 'fs'.
|
||||
|
||||
*/
|
||||
|
||||
var thisObject = {
|
||||
readFileSync: readFileSync,
|
||||
appendFileSync: appendFileSync,
|
||||
mkdirSync: mkdirSync,
|
||||
statSync: statSync,
|
||||
readdir: readdir,
|
||||
readdirSync: readdirSync,
|
||||
readFile: readFile
|
||||
};
|
||||
|
||||
|
||||
return thisObject;
|
||||
|
||||
function readFileSync(pPath, pEncoding) {
|
||||
|
||||
switch (pPath) {
|
||||
|
||||
case '': {
|
||||
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function appendFileSync(pPath, pText) {
|
||||
|
||||
/* We will ignore this since we can not and dont want to really write something on disk while we are at the browser. */
|
||||
}
|
||||
|
||||
function readdir(pPath, callBackFunction) {
|
||||
|
||||
/* We will return an empty array of files. */
|
||||
callBackFunction([]);
|
||||
}
|
||||
|
||||
function readdirSync(pPath, callBackFunction) {
|
||||
|
||||
|
||||
}
|
||||
|
||||
function mkdirSync(pPath) {
|
||||
|
||||
/* Again we do nothing. */
|
||||
}
|
||||
|
||||
function readFile(pPath) {
|
||||
|
||||
/* Again we do nothing. */
|
||||
}
|
||||
|
||||
function statSync(pPath) {
|
||||
|
||||
let stats
|
||||
stats.size = 0;
|
||||
return stats
|
||||
}
|
||||
}
|
||||
+138
-144
@@ -1,160 +1,154 @@
|
||||
|
||||
function newCompetitionStorage(pName) {
|
||||
|
||||
const MODULE_NAME = "Competition Storage";
|
||||
const INFO_LOG = false;
|
||||
const ERROR_LOG = true;
|
||||
const logger = newWebDebugLog();
|
||||
logger.fileName = MODULE_NAME;
|
||||
function newCompetitionStorage (pName) {
|
||||
const MODULE_NAME = 'Competition Storage'
|
||||
const INFO_LOG = false
|
||||
const ERROR_LOG = true
|
||||
const logger = newWebDebugLog()
|
||||
logger.fileName = MODULE_NAME
|
||||
|
||||
let thisObject = {
|
||||
let thisObject = {
|
||||
|
||||
competitorsSequences: [],
|
||||
eventHandler: undefined,
|
||||
initialize: initialize
|
||||
competitorsSequences: [],
|
||||
eventHandler: undefined,
|
||||
initialize: initialize,
|
||||
finalize: finalize
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
thisObject.eventHandler = newEventHandler();
|
||||
thisObject.eventHandler = newEventHandler()
|
||||
|
||||
/* We name the event Handler to easy debugging. */
|
||||
|
||||
thisObject.eventHandler.name = "Storage-" + pName;
|
||||
thisObject.eventHandler.name = 'Storage-' + pName
|
||||
|
||||
let fileSequences = [];
|
||||
let fileSequences = []
|
||||
|
||||
return thisObject;
|
||||
return thisObject
|
||||
|
||||
function initialize(pHost, pCompetition, pExchange, pMarket, callBackFunction) {
|
||||
function finalize () {
|
||||
try {
|
||||
if (INFO_LOG === true) { logger.write('[INFO] finalize -> Entering function.') }
|
||||
|
||||
try {
|
||||
|
||||
if (INFO_LOG === true) { logger.write("[INFO] initialize -> Entering function."); }
|
||||
if (INFO_LOG === true) { logger.write("[INFO] initialize -> key = " + pHost.codeName + "-" + pCompetition.codeName); }
|
||||
|
||||
let dataSetsToLoad = 0;
|
||||
let dataSetsLoaded = 0;
|
||||
|
||||
fileSequences = [];
|
||||
|
||||
for (let j = 0; j < pCompetition.participants.length; j++) {
|
||||
|
||||
let devTeam = ecosystem.getTeam(pCompetition.participants[j].devTeam);
|
||||
let bot = ecosystem.getBot(devTeam, pCompetition.participants[j].bot)
|
||||
let product = ecosystem.getProduct(bot, "Competition Trading History");
|
||||
|
||||
if (INFO_LOG === true) { logger.write("[INFO] initialize -> key = " + devTeam.codeName + "-" + bot.codeName + "-" + product.codeName); }
|
||||
|
||||
for (let i = 0; i < product.dataSets.length; i++) {
|
||||
|
||||
let thisSet = product.dataSets[i];
|
||||
|
||||
switch (thisSet.type) {
|
||||
case 'File Sequence': {
|
||||
|
||||
if (INFO_LOG === true) { logger.write("[INFO] initialize -> File Sequence -> key = " + pHost.codeName + "-" + pCompetition.codeName + "-" + devTeam.codeName + "-" + bot.codeName + "-" + product.codeName); }
|
||||
|
||||
let fileSequence = newFileSequence();
|
||||
fileSequence.initialize(devTeam, bot, product, thisSet, pExchange, pMarket, onFileSequenceReady);
|
||||
fileSequences.push(fileSequence);
|
||||
dataSetsToLoad++;
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
function onFileSequenceReady(err, pCaller) {
|
||||
|
||||
try {
|
||||
|
||||
if (INFO_LOG === true) { logger.write("[INFO] initialize -> onFileSequenceReady -> Entering function."); }
|
||||
if (INFO_LOG === true) { logger.write("[INFO] initialize -> onFileSequenceReady -> key = " + pHost.codeName + "-" + pCompetition.codeName + "-" + devTeam.codeName + "-" + bot.codeName + "-" + product.codeName); }
|
||||
|
||||
switch (err.result) {
|
||||
case GLOBAL.DEFAULT_OK_RESPONSE.result: {
|
||||
|
||||
if (INFO_LOG === true) { logger.write("[INFO] initialize -> onFileSequenceReady -> Received OK Response."); }
|
||||
break;
|
||||
}
|
||||
|
||||
case GLOBAL.DEFAULT_FAIL_RESPONSE.result: {
|
||||
|
||||
if (INFO_LOG === true) { logger.write("[INFO] initialize -> onFileSequenceReady -> Received FAIL Response."); }
|
||||
callBackFunction(GLOBAL.DEFAULT_FAIL_RESPONSE);
|
||||
return;
|
||||
}
|
||||
|
||||
case GLOBAL.CUSTOM_FAIL_RESPONSE.result: {
|
||||
|
||||
if (INFO_LOG === true) { logger.write("[INFO] initialize -> onFileSequenceReady -> Received CUSTOM FAIL Response."); }
|
||||
if (INFO_LOG === true) { logger.write("[INFO] initialize -> onFileSequenceReady -> err.message = " + err.message); }
|
||||
if (INFO_LOG === true) { logger.write("[INFO] initialize -> onFileSequenceReady -> This bot has not starting competing yet."); }
|
||||
|
||||
break;
|
||||
}
|
||||
|
||||
default: {
|
||||
|
||||
if (INFO_LOG === true) { logger.write("[INFO] initialize -> onFileSequenceReady -> Received Unexpected Response."); }
|
||||
callBackFunction(err);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
let event = {
|
||||
totalValue: pCaller.getExpectedFiles(),
|
||||
currentValue: pCaller.getFilesLoaded()
|
||||
}
|
||||
|
||||
thisObject.eventHandler.raiseEvent('File Sequence Loaded', event);
|
||||
|
||||
if (event.currentValue === event.totalValue) {
|
||||
|
||||
dataSetsLoaded++;
|
||||
|
||||
checkInitializeComplete();
|
||||
}
|
||||
|
||||
} catch (err) {
|
||||
|
||||
if (ERROR_LOG === true) { logger.write("[ERROR] initialize -> onFileSequenceReady -> err = " + err); }
|
||||
callBackFunction(GLOBAL.DEFAULT_FAIL_RESPONSE);
|
||||
}
|
||||
}
|
||||
|
||||
function checkInitializeComplete() {
|
||||
|
||||
try {
|
||||
|
||||
if (INFO_LOG === true) { logger.write("[INFO] checkInitializeComplete -> Entering function."); }
|
||||
if (INFO_LOG === true) { logger.write("[INFO] checkInitializeComplete -> key = " + pHost.codeName + "-" + pCompetition.codeName + "-" + devTeam.codeName + "-" + bot.codeName + "-" + product.codeName); }
|
||||
|
||||
if (dataSetsLoaded === dataSetsToLoad) {
|
||||
|
||||
callBackFunction(GLOBAL.DEFAULT_OK_RESPONSE);
|
||||
|
||||
}
|
||||
|
||||
} catch (err) {
|
||||
|
||||
if (ERROR_LOG === true) { logger.write("[ERROR] initialize -> checkInitializeComplete -> err = " + err); }
|
||||
callBackFunction(GLOBAL.DEFAULT_FAIL_RESPONSE);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
thisObject.competitorsSequences.push(fileSequences);
|
||||
|
||||
if (pCompetition.participants.length === 0) { //If there are no competitions, respond OK
|
||||
callBackFunction(GLOBAL.DEFAULT_OK_RESPONSE);
|
||||
}
|
||||
|
||||
} catch (err) {
|
||||
|
||||
if (ERROR_LOG === true) { logger.write("[ERROR] initialize -> err = " + err); }
|
||||
callBackFunction(GLOBAL.DEFAULT_FAIL_RESPONSE);
|
||||
if (thisObject.fileSequences !== undefined) {
|
||||
for (let i = 0; i < thisObject.fileSequences.length; i++) {
|
||||
let fileSequence = thisObject.fileSequences[i]
|
||||
fileSequence.finalize()
|
||||
}
|
||||
}
|
||||
|
||||
thisObject.fileSequences = undefined
|
||||
} catch (err) {
|
||||
if (ERROR_LOG === true) { logger.write('[ERROR] finalize -> err = ' + err) }
|
||||
}
|
||||
}
|
||||
|
||||
function initialize (pHost, pCompetition, pExchange, pMarket, callBackFunction) {
|
||||
try {
|
||||
if (INFO_LOG === true) { logger.write('[INFO] initialize -> Entering function.') }
|
||||
if (INFO_LOG === true) { logger.write('[INFO] initialize -> key = ' + pHost.codeName + '-' + pCompetition.codeName) }
|
||||
|
||||
let dataSetsToLoad = 0
|
||||
let dataSetsLoaded = 0
|
||||
|
||||
fileSequences = []
|
||||
|
||||
for (let j = 0; j < pCompetition.participants.length; j++) {
|
||||
let devTeam = ecosystem.getTeam(pCompetition.participants[j].devTeam)
|
||||
let bot = ecosystem.getBot(devTeam, pCompetition.participants[j].bot)
|
||||
bot.cloneId = pCompetition.participants[j].clonesId
|
||||
let product = ecosystem.getProduct(bot, 'Competition Trading History')
|
||||
|
||||
if (INFO_LOG === true) { logger.write('[INFO] initialize -> key = ' + devTeam.codeName + '-' + bot.codeName + '-' + product.codeName) }
|
||||
|
||||
for (let i = 0; i < product.dataSets.length; i++) {
|
||||
let thisSet = product.dataSets[i]
|
||||
|
||||
switch (thisSet.type) {
|
||||
case 'File Sequence': {
|
||||
if (INFO_LOG === true) { logger.write('[INFO] initialize -> File Sequence -> key = ' + pHost.codeName + '-' + pCompetition.codeName + '-' + devTeam.codeName + '-' + bot.codeName + '-' + product.codeName) }
|
||||
|
||||
let fileSequence = newFileSequence()
|
||||
fileSequence.initialize(devTeam, bot, product, thisSet, pExchange, pMarket, onFileSequenceReady)
|
||||
fileSequences.push(fileSequence)
|
||||
dataSetsToLoad++
|
||||
}
|
||||
break
|
||||
}
|
||||
|
||||
function onFileSequenceReady (err, pCaller) {
|
||||
try {
|
||||
if (INFO_LOG === true) { logger.write('[INFO] initialize -> onFileSequenceReady -> Entering function.') }
|
||||
if (INFO_LOG === true) { logger.write('[INFO] initialize -> onFileSequenceReady -> key = ' + pHost.codeName + '-' + pCompetition.codeName + '-' + devTeam.codeName + '-' + bot.codeName + '-' + product.codeName) }
|
||||
|
||||
switch (err.result) {
|
||||
case GLOBAL.DEFAULT_OK_RESPONSE.result: {
|
||||
if (INFO_LOG === true) { logger.write('[INFO] initialize -> onFileSequenceReady -> Received OK Response.') }
|
||||
break
|
||||
}
|
||||
|
||||
case GLOBAL.DEFAULT_FAIL_RESPONSE.result: {
|
||||
if (INFO_LOG === true) { logger.write('[INFO] initialize -> onFileSequenceReady -> Received FAIL Response.') }
|
||||
callBackFunction(GLOBAL.DEFAULT_FAIL_RESPONSE)
|
||||
return
|
||||
}
|
||||
|
||||
case GLOBAL.CUSTOM_FAIL_RESPONSE.result: {
|
||||
if (INFO_LOG === true) { logger.write('[INFO] initialize -> onFileSequenceReady -> Received CUSTOM FAIL Response.') }
|
||||
if (INFO_LOG === true) { logger.write('[INFO] initialize -> onFileSequenceReady -> err.message = ' + err.message) }
|
||||
if (INFO_LOG === true) { logger.write('[INFO] initialize -> onFileSequenceReady -> This bot has not starting competing yet.') }
|
||||
|
||||
break
|
||||
}
|
||||
|
||||
default: {
|
||||
if (INFO_LOG === true) { logger.write('[INFO] initialize -> onFileSequenceReady -> Received Unexpected Response.') }
|
||||
callBackFunction(err)
|
||||
return
|
||||
}
|
||||
}
|
||||
|
||||
let event = {
|
||||
totalValue: pCaller.getExpectedFiles(),
|
||||
currentValue: pCaller.getFilesLoaded()
|
||||
}
|
||||
|
||||
thisObject.eventHandler.raiseEvent('File Sequence Loaded', event)
|
||||
|
||||
if (event.currentValue === event.totalValue) {
|
||||
dataSetsLoaded++
|
||||
|
||||
checkInitializeComplete()
|
||||
}
|
||||
} catch (err) {
|
||||
if (ERROR_LOG === true) { logger.write('[ERROR] initialize -> onFileSequenceReady -> err = ' + err) }
|
||||
callBackFunction(GLOBAL.DEFAULT_FAIL_RESPONSE)
|
||||
}
|
||||
}
|
||||
|
||||
function checkInitializeComplete () {
|
||||
try {
|
||||
if (INFO_LOG === true) { logger.write('[INFO] checkInitializeComplete -> Entering function.') }
|
||||
if (INFO_LOG === true) { logger.write('[INFO] checkInitializeComplete -> key = ' + pHost.codeName + '-' + pCompetition.codeName + '-' + devTeam.codeName + '-' + bot.codeName + '-' + product.codeName) }
|
||||
|
||||
if (dataSetsLoaded === dataSetsToLoad) {
|
||||
callBackFunction(GLOBAL.DEFAULT_OK_RESPONSE)
|
||||
}
|
||||
} catch (err) {
|
||||
if (ERROR_LOG === true) { logger.write('[ERROR] initialize -> checkInitializeComplete -> err = ' + err) }
|
||||
callBackFunction(GLOBAL.DEFAULT_FAIL_RESPONSE)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
thisObject.competitorsSequences.push(fileSequences)
|
||||
|
||||
if (pCompetition.participants.length === 0) { // If there are no competitions, respond OK
|
||||
callBackFunction(GLOBAL.DEFAULT_OK_RESPONSE)
|
||||
}
|
||||
} catch (err) {
|
||||
if (ERROR_LOG === true) { logger.write('[ERROR] initialize -> err = ' + err) }
|
||||
callBackFunction(GLOBAL.DEFAULT_FAIL_RESPONSE)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
+27
-31
@@ -1,36 +1,32 @@
|
||||
|
||||
|
||||
function newContainer() {
|
||||
function newContainer () {
|
||||
var container = {
|
||||
frame: undefined,
|
||||
displacement: undefined,
|
||||
eventHandler: undefined,
|
||||
parentContainer: undefined,
|
||||
isDraggeable: true,
|
||||
isClickeable: false,
|
||||
isWheelable: false,
|
||||
name: undefined,
|
||||
initialize: initialize
|
||||
}
|
||||
|
||||
var container = {
|
||||
frame: undefined,
|
||||
displacement: undefined,
|
||||
eventHandler: undefined,
|
||||
parentContainer: undefined,
|
||||
isDraggeable: true,
|
||||
isClickeable: false,
|
||||
isWheelable: false,
|
||||
name: undefined,
|
||||
initialize: initialize
|
||||
};
|
||||
return container
|
||||
|
||||
return container;
|
||||
function initialize () {
|
||||
var frame = newFrame()
|
||||
frame.initialize()
|
||||
this.frame = frame
|
||||
frame.container = container
|
||||
|
||||
function initialize() {
|
||||
var eventHandler = newEventHandler()
|
||||
eventHandler.initialize()
|
||||
eventHandler.name = container.name
|
||||
this.eventHandler = eventHandler
|
||||
|
||||
var frame = newFrame();
|
||||
frame.initialize();
|
||||
this.frame = frame;
|
||||
frame.container = container;
|
||||
|
||||
var eventHandler = newEventHandler();
|
||||
eventHandler.initialize();
|
||||
eventHandler.name = container.name;
|
||||
this.eventHandler = eventHandler;
|
||||
|
||||
var displacement = newDisplacement();
|
||||
this.displacement = displacement;
|
||||
displacement.container = container;
|
||||
|
||||
}
|
||||
}
|
||||
var displacement = newDisplacement()
|
||||
this.displacement = displacement
|
||||
displacement.container = container
|
||||
}
|
||||
}
|
||||
+128
-165
@@ -1,133 +1,108 @@
|
||||
|
||||
let canvas;
|
||||
let markets;
|
||||
let ecosystem = newEcosystem();
|
||||
let cloudVM = newCloudVM();
|
||||
let INITIAL_ZOOM_LEVEL = -26; // This is the zoom level at the view port in which the APP starts.
|
||||
let INITIAL_TIME_PERIOD = recalculatePeriod(INITIAL_ZOOM_LEVEL); // This value will be overwritten at the viewPort.initialize if the user had a prevous session with this same browser.
|
||||
let viewPort = newViewPort();
|
||||
|
||||
let canvas
|
||||
let markets
|
||||
let ecosystem = newEcosystem()
|
||||
let INITIAL_ZOOM_LEVEL = -26 // This is the zoom level at the view port in which the APP starts.
|
||||
let INITIAL_TIME_PERIOD = recalculatePeriod(INITIAL_ZOOM_LEVEL) // This value will be overwritten at the viewPort.initialize if the user had a prevous session with this same browser.
|
||||
let viewPort = newViewPort()
|
||||
|
||||
function newDashboard() {
|
||||
function newDashboard () {
|
||||
const MODULE_NAME = 'Dashboard'
|
||||
const INFO_LOG = false
|
||||
const ERROR_LOG = true
|
||||
const INTENSIVE_LOG = false
|
||||
const logger = newWebDebugLog()
|
||||
logger.fileName = MODULE_NAME
|
||||
|
||||
const MODULE_NAME = "Dashboard";
|
||||
const INFO_LOG = false;
|
||||
const ERROR_LOG = true;
|
||||
const INTENSIVE_LOG = false;
|
||||
const logger = newWebDebugLog();
|
||||
logger.fileName = MODULE_NAME;
|
||||
let thisObject = {
|
||||
start: start
|
||||
}
|
||||
|
||||
let thisObject = {
|
||||
start: start
|
||||
};
|
||||
const DEBUG_START_UP_DELAY = 0 // 3000; // This is a waiting time in case there is a need to debug the very first steps of initialization, to be able to hit F12 on time.
|
||||
|
||||
const DEBUG_START_UP_DELAY = 0; //3000; // This is a waiting time in case there is a need to debug the very first steps of initialization, to be able to hit F12 on time.
|
||||
return thisObject
|
||||
|
||||
return thisObject;
|
||||
function start () {
|
||||
try {
|
||||
if (INFO_LOG === true) { logger.write('[INFO] start -> Entering function.') }
|
||||
|
||||
function start() {
|
||||
/* If this method is executed for a second time, it should finalize the current execution structure */
|
||||
|
||||
try {
|
||||
if (canvas !== undefined) { canvas.finalize() }
|
||||
|
||||
if (INFO_LOG === true) { logger.write("[INFO] start -> Entering function."); }
|
||||
/* Here we will setup the global eventHandler that will enable the Canvas App to react to events happening outside its execution scope. */
|
||||
|
||||
/* Here we will setup the global eventHandler that will enable the Canvas App to react to events happening outside its execution scope. */
|
||||
window.canvasApp.eventHandler = newEventHandler()
|
||||
window.canvasApp.eventHandler.listenToEvent('User Profile Changed', userProfileChanged)
|
||||
window.canvasApp.eventHandler.listenToEvent('Browser Resized', browserResized)
|
||||
|
||||
window.canvasApp.eventHandler = newEventHandler();
|
||||
window.canvasApp.eventHandler.listenToEvent("User Profile Changed", userProfileChanged);
|
||||
window.canvasApp.eventHandler.listenToEvent("Browser Resized", browserResized);
|
||||
loadImages(onImagesLoaded)
|
||||
|
||||
loadImages(onImagesLoaded);
|
||||
function onImagesLoaded () {
|
||||
if (INFO_LOG === true) { logger.write('[INFO] start -> onImagesLoaded -> Entering function.') }
|
||||
|
||||
function onImagesLoaded() {
|
||||
/* Next we start the App */
|
||||
|
||||
if (INFO_LOG === true) { logger.write("[INFO] start -> onImagesLoaded -> Entering function."); }
|
||||
|
||||
/* Next we start the App*/
|
||||
|
||||
setTimeout(delayedStart, DEBUG_START_UP_DELAY);
|
||||
|
||||
}
|
||||
|
||||
} catch (err) {
|
||||
|
||||
if (ERROR_LOG === true) { logger.write("[ERROR] start -> err = " + err); }
|
||||
|
||||
}
|
||||
setTimeout(delayedStart, DEBUG_START_UP_DELAY)
|
||||
}
|
||||
} catch (err) {
|
||||
if (ERROR_LOG === true) { logger.write('[ERROR] start -> err = ' + err) }
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
function delayedStart() {
|
||||
|
||||
try {
|
||||
|
||||
if (INFO_LOG === true) { logger.write("[INFO] delayedStart -> Entering function."); }
|
||||
function delayedStart () {
|
||||
try {
|
||||
if (INFO_LOG === true) { logger.write('[INFO] delayedStart -> Entering function.') }
|
||||
|
||||
/* For now, we are supporting only one market. */
|
||||
|
||||
let market = {
|
||||
id: 2,
|
||||
assetA: "USDT",
|
||||
assetB: "BTC"
|
||||
};
|
||||
let market = {
|
||||
id: 2,
|
||||
assetA: 'USDT',
|
||||
assetB: 'BTC'
|
||||
}
|
||||
|
||||
markets = new Map();
|
||||
markets = new Map()
|
||||
|
||||
markets.set(market.id, market);
|
||||
markets.set(market.id, market)
|
||||
|
||||
canvas = newCanvas();
|
||||
canvas.initialize();
|
||||
|
||||
} catch (err) {
|
||||
|
||||
if (ERROR_LOG === true) { logger.write("[ERROR] delayedStart -> err = " + err); }
|
||||
|
||||
}
|
||||
canvas = newCanvas()
|
||||
canvas.initialize()
|
||||
} catch (err) {
|
||||
if (ERROR_LOG === true) { logger.write('[ERROR] delayedStart -> err = ' + err) }
|
||||
}
|
||||
}
|
||||
|
||||
function userProfileChanged() {
|
||||
|
||||
try {
|
||||
|
||||
if (INFO_LOG === true) { logger.write("[INFO] userProfileChanged -> Entering function."); }
|
||||
|
||||
canvas.topSpace.initialize();
|
||||
|
||||
} catch (err) {
|
||||
|
||||
if (ERROR_LOG === true) { logger.write("[ERROR] userProfileChanged -> err = " + err); }
|
||||
|
||||
}
|
||||
function userProfileChanged () {
|
||||
try {
|
||||
if (INFO_LOG === true) { logger.write('[INFO] userProfileChanged -> Entering function.') }
|
||||
|
||||
canvas.topSpace.initialize()
|
||||
} catch (err) {
|
||||
if (ERROR_LOG === true) { logger.write('[ERROR] userProfileChanged -> err = ' + err) }
|
||||
}
|
||||
}
|
||||
|
||||
function browserResized() {
|
||||
function browserResized () {
|
||||
try {
|
||||
if (INFO_LOG === true) { logger.write('[INFO] browserResized -> Entering function.') }
|
||||
|
||||
try {
|
||||
browserCanvas = document.getElementById('canvas')
|
||||
|
||||
if (INFO_LOG === true) { logger.write("[INFO] browserResized -> Entering function."); }
|
||||
|
||||
browserCanvas = document.getElementById('canvas');
|
||||
|
||||
browserCanvas.width = window.innerWidth;
|
||||
browserCanvas.height = window.innerHeight - window.canvasApp.topMargin;
|
||||
|
||||
viewPort.initialize();
|
||||
|
||||
} catch (err) {
|
||||
|
||||
if (ERROR_LOG === true) { logger.write("[ERROR] browserResized -> err = " + err); }
|
||||
|
||||
}
|
||||
browserCanvas.width = window.innerWidth
|
||||
browserCanvas.height = window.innerHeight - window.canvasApp.topMargin
|
||||
|
||||
viewPort.initialize()
|
||||
} catch (err) {
|
||||
if (ERROR_LOG === true) { logger.write('[ERROR] browserResized -> err = ' + err) }
|
||||
}
|
||||
}
|
||||
|
||||
function loadImages(callBack) {
|
||||
function loadImages (callBack) {
|
||||
try {
|
||||
if (INFO_LOG === true) { logger.write('[INFO] loadImages -> Entering function.') }
|
||||
|
||||
try {
|
||||
|
||||
if (INFO_LOG === true) { logger.write("[INFO] loadImages -> Entering function."); }
|
||||
|
||||
const accessToken = "";
|
||||
const accessToken = ''
|
||||
|
||||
/*
|
||||
Soon, we will need to get images from the Financial Beings Module. I live this core here as a sample for that:
|
||||
@@ -187,25 +162,25 @@ function newDashboard() {
|
||||
|
||||
*/
|
||||
|
||||
const networkInterfaceTeams = Apollo.lib.createNetworkInterface({
|
||||
uri: window.canvasApp.graphQL.masterAppApiUrl
|
||||
});
|
||||
const networkInterfaceTeams = Apollo.lib.createNetworkInterface({
|
||||
uri: window.canvasApp.graphQL.masterAppApiUrl
|
||||
})
|
||||
|
||||
networkInterfaceTeams.use([{
|
||||
applyMiddleware(req, next) {
|
||||
req.options.headers = {
|
||||
authorization: `Bearer ${accessToken}`
|
||||
};
|
||||
next();
|
||||
}
|
||||
}]);
|
||||
|
||||
const apolloClientTeams = new Apollo.lib.ApolloClient({
|
||||
networkInterface: networkInterfaceTeams,
|
||||
connectToDevTools: true,
|
||||
});
|
||||
networkInterfaceTeams.use([{
|
||||
applyMiddleware (req, next) {
|
||||
req.options.headers = {
|
||||
authorization: `Bearer ${accessToken}`
|
||||
}
|
||||
next()
|
||||
}
|
||||
}])
|
||||
|
||||
const ALL_TEAMS_QUERY = Apollo.gql`
|
||||
const apolloClientTeams = new Apollo.lib.ApolloClient({
|
||||
networkInterface: networkInterfaceTeams,
|
||||
connectToDevTools: true
|
||||
})
|
||||
|
||||
const ALL_TEAMS_QUERY = Apollo.gql`
|
||||
{
|
||||
teams_Teams{
|
||||
edges{
|
||||
@@ -238,70 +213,58 @@ function newDashboard() {
|
||||
}
|
||||
`
|
||||
|
||||
let teams;
|
||||
let teams
|
||||
|
||||
const getTeams = () => {
|
||||
return new Promise((resolve, reject) => {
|
||||
apolloClientTeams.query({
|
||||
query: ALL_TEAMS_QUERY
|
||||
})
|
||||
const getTeams = () => {
|
||||
return new Promise((resolve, reject) => {
|
||||
apolloClientTeams.query({
|
||||
query: ALL_TEAMS_QUERY
|
||||
})
|
||||
.then(response => {
|
||||
teams = response.data.teams_Teams;
|
||||
window.localStorage.setItem('Teams', JSON.stringify(response.data.teams_Teams));
|
||||
resolve({ teams: response.data.teams_Teams })
|
||||
})
|
||||
teams = response.data.teams_Teams
|
||||
window.localStorage.setItem('Teams', JSON.stringify(response.data.teams_Teams))
|
||||
resolve({ teams: response.data.teams_Teams })
|
||||
})
|
||||
.catch(err => {
|
||||
if (ERROR_LOG === true) { logger.write("[ERROR] loadImages -> getTeams -> Error fetching data from Teams Module."); }
|
||||
if (ERROR_LOG === true) { logger.write("[ERROR] loadImages -> getTeams -> err = " + err); }
|
||||
reject(err)
|
||||
});
|
||||
})
|
||||
}
|
||||
if (ERROR_LOG === true) { logger.write('[ERROR] loadImages -> getTeams -> Error fetching data from Teams Module.') }
|
||||
if (ERROR_LOG === true) { logger.write('[ERROR] loadImages -> getTeams -> err = ' + err) }
|
||||
reject(err)
|
||||
})
|
||||
})
|
||||
}
|
||||
|
||||
// To avoid race conditions, add asynchronous fetches to array
|
||||
let fetchDataPromises = [];
|
||||
let fetchDataPromises = []
|
||||
|
||||
fetchDataPromises.push(/*getUser(),*/ getTeams()); // <-- Here we must add the function calll to the Financial Beings module.
|
||||
fetchDataPromises.push(/* getUser(), */ getTeams()) // <-- Here we must add the function calll to the Financial Beings module.
|
||||
|
||||
// When all asynchronous fetches resolve, authenticate user or throw error.
|
||||
Promise.all(fetchDataPromises).then(result => {
|
||||
|
||||
Promise.all(fetchDataPromises).then(result => {
|
||||
/* All good, we will go through the results creating a map with all the Images URLs */
|
||||
|
||||
let teamProfileImages = new Map();
|
||||
let fbProfileImages = new Map();
|
||||
let teamProfileImages = new Map()
|
||||
let fbProfileImages = new Map()
|
||||
|
||||
for (let i = 0; i < teams.edges.length; i++) {
|
||||
for (let i = 0; i < teams.edges.length; i++) {
|
||||
let team = teams.edges[i].node
|
||||
|
||||
let team = teams.edges[i].node;
|
||||
|
||||
teamProfileImages.set(team.slug, team.profile.avatar);
|
||||
|
||||
if (team.fb.length > 0) {
|
||||
|
||||
fbProfileImages.set(team.slug + "-" + team.fb[0].slug, team.fb[0].avatar);
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
window.canvasApp.context.teamProfileImages = teamProfileImages;
|
||||
window.canvasApp.context.fbProfileImages = fbProfileImages;
|
||||
|
||||
callBack();
|
||||
|
||||
}, err => {
|
||||
if (ERROR_LOG === true) { logger.write("[ERROR] loadImages -> Error fetching data from Teams Module."); }
|
||||
if (ERROR_LOG === true) { logger.write("[ERROR] loadImages -> err = " + err); }
|
||||
});
|
||||
|
||||
} catch (err) {
|
||||
|
||||
if (ERROR_LOG === true) { logger.write("[ERROR] loadImages -> err = " + err); }
|
||||
teamProfileImages.set(team.slug, team.profile.avatar)
|
||||
|
||||
if (team.fb.length > 0) {
|
||||
fbProfileImages.set(team.slug + '-' + team.fb[0].slug, team.fb[0].avatar)
|
||||
}
|
||||
}
|
||||
|
||||
window.canvasApp.context.teamProfileImages = teamProfileImages
|
||||
window.canvasApp.context.fbProfileImages = fbProfileImages
|
||||
|
||||
callBack()
|
||||
}, err => {
|
||||
if (ERROR_LOG === true) { logger.write('[ERROR] loadImages -> Error fetching data from Teams Module.') }
|
||||
if (ERROR_LOG === true) { logger.write('[ERROR] loadImages -> err = ' + err) }
|
||||
})
|
||||
} catch (err) {
|
||||
if (ERROR_LOG === true) { logger.write('[ERROR] loadImages -> err = ' + err) }
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
+42
-59
@@ -1,81 +1,64 @@
|
||||
|
||||
/*
|
||||
|
||||
/*
|
||||
|
||||
We call displacement to the offset we can produce to the object which the displcement object is is a child from.
|
||||
The displacement is a vector that displaces everything static drawn on on the context of the parent object.
|
||||
|
||||
We call displacement to the offset we can produce to the object which the displcement object is is a child from.
|
||||
The displacement is a vector that displaces everything static drawn on on the context of the parent object.
|
||||
|
||||
*/
|
||||
|
||||
function newDisplacement() {
|
||||
function newDisplacement () {
|
||||
var displacement = {
|
||||
containerName: '', // This is for debugging purposes only.
|
||||
parentDisplacement: undefined, // Here we store the displacement object of the parent cointainer, if exists.
|
||||
container: undefined,
|
||||
x: 0, // This is the actual x displacement.
|
||||
y: 0, // This is the actual y displacement.
|
||||
displace: displace,
|
||||
undisplaceThisPoint: undisplaceThisPoint,
|
||||
displaceThisPoint: displaceThisPoint
|
||||
}
|
||||
|
||||
var displacement = {
|
||||
containerName: "", // This is for debugging purposes only.
|
||||
parentDisplacement: undefined, // Here we store the displacement object of the parent cointainer, if exists.
|
||||
container: undefined,
|
||||
x: 0, // This is the actual x displacement.
|
||||
y: 0, // This is the actual y displacement.
|
||||
displace: displace,
|
||||
undisplaceThisPoint: undisplaceThisPoint,
|
||||
displaceThisPoint: displaceThisPoint
|
||||
};
|
||||
|
||||
return displacement;
|
||||
|
||||
|
||||
function displace(amountX, amountY) {
|
||||
return displacement
|
||||
|
||||
function displace (amountX, amountY) {
|
||||
/* First we check if by allowing this displacement we would produce the current frame to be beyond its limit. */
|
||||
|
||||
tempDisplacement = newDisplacement();
|
||||
tempDisplacement.x = amountX;
|
||||
tempDisplacement.y = amountY;
|
||||
|
||||
if (this.container.frame.canYouMoveHere(tempDisplacement)) {
|
||||
tempDisplacement = newDisplacement()
|
||||
tempDisplacement.x = amountX
|
||||
tempDisplacement.y = amountY
|
||||
|
||||
if (this.container.frame.canYouMoveHere(tempDisplacement)) {
|
||||
/* Now we displace */
|
||||
|
||||
displacement.x = displacement.x + amountX;
|
||||
displacement.y = displacement.y + amountY;
|
||||
displacement.x = displacement.x + amountX
|
||||
displacement.y = displacement.y + amountY
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
return true
|
||||
}
|
||||
|
||||
function displaceThisPoint(point) {
|
||||
return false
|
||||
}
|
||||
|
||||
if (this.parentDisplacement !== undefined) {
|
||||
|
||||
point = this.parentDisplacement.displaceThisPoint(point);
|
||||
|
||||
}
|
||||
|
||||
point.x = point.x + displacement.x;
|
||||
point.y = point.y + displacement.y;
|
||||
|
||||
return point;
|
||||
function displaceThisPoint (point) {
|
||||
if (this.parentDisplacement !== undefined) {
|
||||
point = this.parentDisplacement.displaceThisPoint(point)
|
||||
}
|
||||
|
||||
function undisplaceThisPoint(point) {
|
||||
point.x = point.x + displacement.x
|
||||
point.y = point.y + displacement.y
|
||||
|
||||
if (this.parentDisplacement !== undefined) {
|
||||
return point
|
||||
}
|
||||
|
||||
point = this.parentDisplacement.undisplaceThisPoint(point);
|
||||
|
||||
}
|
||||
|
||||
point.x = point.x - displacement.x;
|
||||
point.y = point.y - displacement.y;
|
||||
|
||||
return point;
|
||||
function undisplaceThisPoint (point) {
|
||||
if (this.parentDisplacement !== undefined) {
|
||||
point = this.parentDisplacement.undisplaceThisPoint(point)
|
||||
}
|
||||
|
||||
point.x = point.x - displacement.x
|
||||
point.y = point.y - displacement.y
|
||||
|
||||
return point
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
+51
-72
@@ -1,93 +1,72 @@
|
||||
|
||||
function newEventHandler() {
|
||||
|
||||
function newEventHandler () {
|
||||
const CONSOLE_LOG = false
|
||||
|
||||
const CONSOLE_LOG = false;
|
||||
let thisObject = {
|
||||
name: undefined, // This is for debugging purposes only.
|
||||
parentEventHandler: undefined, // Here we store the parent cointainer zoom object.
|
||||
listenToEvent: listenToEvent,
|
||||
stopListening: stopListening,
|
||||
raiseEvent: raiseEvent,
|
||||
initialize: initialize
|
||||
}
|
||||
|
||||
let thisObject = {
|
||||
name: undefined, // This is for debugging purposes only.
|
||||
parentEventHandler: undefined, // Here we store the parent cointainer zoom object.
|
||||
listenToEvent: listenToEvent,
|
||||
stopListening: stopListening,
|
||||
raiseEvent: raiseEvent,
|
||||
initialize: initialize
|
||||
};
|
||||
var eventHandlers = [] // Here we store all the functions we will call when an event is comming.
|
||||
|
||||
var eventHandlers = []; // Here we store all the functions we will call when an event is comming.
|
||||
return thisObject
|
||||
|
||||
return thisObject;
|
||||
function initialize () {
|
||||
|
||||
function initialize() {
|
||||
}
|
||||
|
||||
|
||||
function listenToEvent (eventType, handler, extraData) {
|
||||
eventHandlers.push([eventType, handler, extraData])
|
||||
|
||||
if (thisObject.name !== undefined && CONSOLE_LOG === true) {
|
||||
console.log('Event Handler named ' + thisObject.name + ' received a request to listenToEvent ' + eventType + ' and call ' + (handler.toString()).substring(0, 50))
|
||||
}
|
||||
}
|
||||
|
||||
function stopListening (pEventType, pHandler) {
|
||||
if (thisObject.name !== undefined && CONSOLE_LOG === true) {
|
||||
console.log('Event Handler named ' + thisObject.name + ' received a request to stop listening to an the event ' + pEventType + ' with this handler: ' + pHandler)
|
||||
}
|
||||
|
||||
function listenToEvent(eventType, handler, extraData) {
|
||||
for (let i = 0; i < eventHandlers.length; i++) {
|
||||
let record = eventHandlers[i]
|
||||
let eventType = record[0]
|
||||
let handler = record[1]
|
||||
|
||||
eventHandlers.push([eventType, handler, extraData]);
|
||||
if (pEventType === eventType && pHandler.toString() === handler.toString()) {
|
||||
eventHandlers.splice(i, 1)
|
||||
|
||||
if (thisObject.name !== undefined && CONSOLE_LOG === true) {
|
||||
|
||||
console.log("Event Handler named " + thisObject.name + " received a request to listenToEvent " + eventType + " and call " + (handler.toString()).substring(0, 50));
|
||||
|
||||
console.log('Evethandler found and deleted.')
|
||||
}
|
||||
|
||||
return
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function raiseEvent (eventType, event) {
|
||||
if (thisObject.name !== undefined && CONSOLE_LOG === true) {
|
||||
console.log('Event Handler named ' + thisObject.name + ' received a request to raiseEvent ' + eventType + ' with this data ' + (event.toString()).substring(0, 50))
|
||||
}
|
||||
|
||||
function stopListening(pEventType, pHandler) {
|
||||
|
||||
if (thisObject.name !== undefined && CONSOLE_LOG === true) {
|
||||
|
||||
console.log("Event Handler named " + thisObject.name + " received a request to stop listening to an the event " + pEventType + " with this handler: " + pHandler);
|
||||
|
||||
}
|
||||
|
||||
for (let i = 0; i < eventHandlers.length; i++) {
|
||||
|
||||
let record = eventHandlers[i];
|
||||
let eventType = record[0];
|
||||
let handler = record[1];
|
||||
|
||||
if (pEventType === eventType && pHandler.toString() === handler.toString()) {
|
||||
|
||||
eventHandlers.splice(i, 1);
|
||||
|
||||
if (thisObject.name !== undefined && CONSOLE_LOG === true) {
|
||||
|
||||
console.log("Evethandler found and deleted.");
|
||||
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function raiseEvent(eventType, event) {
|
||||
|
||||
if (thisObject.name !== undefined && CONSOLE_LOG === true) {
|
||||
|
||||
console.log("Event Handler named " + thisObject.name + " received a request to raiseEvent " + eventType + " with this data " + (event.toString()).substring(0, 50));
|
||||
|
||||
}
|
||||
|
||||
for (var i = 0; i < eventHandlers.length; i++) {
|
||||
|
||||
for (var i = 0; i < eventHandlers.length; i++) {
|
||||
/* We will execute all the functions listening to this event type. */
|
||||
|
||||
if (eventHandlers[i][0] === eventType) {
|
||||
if (eventHandlers[i][0] === eventType) {
|
||||
var handler = eventHandlers[i][1]
|
||||
var extraData = eventHandlers[i][2]
|
||||
|
||||
var handler = eventHandlers[i][1];
|
||||
var extraData = eventHandlers[i][2];
|
||||
|
||||
if (thisObject.name !== undefined && CONSOLE_LOG === true) {
|
||||
|
||||
console.log("Event Handler named " + thisObject.name + " received a request to raiseEvent " + eventType + " and will call this handler: " + (handler.toString()).substring(0,50));
|
||||
|
||||
}
|
||||
|
||||
handler(event, extraData);
|
||||
|
||||
}
|
||||
if (thisObject.name !== undefined && CONSOLE_LOG === true) {
|
||||
console.log('Event Handler named ' + thisObject.name + ' received a request to raiseEvent ' + eventType + ' and will call this handler: ' + (handler.toString()).substring(0, 50))
|
||||
}
|
||||
|
||||
handler(event, extraData)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
+59
-94
@@ -1,65 +1,57 @@
|
||||
function newExchangeAPI() {
|
||||
function newExchangeAPI () {
|
||||
const INFO_LOG = true
|
||||
const LOG_FILE_CONTENT = true
|
||||
|
||||
const INFO_LOG = true;
|
||||
const LOG_FILE_CONTENT = true;
|
||||
const MODULE_NAME = 'CloudVM -> Exchange API'
|
||||
|
||||
const MODULE_NAME = "CloudVM -> Exchange API";
|
||||
const SERVER_URL = window.canvasApp.urlPrefix + 'ExchangeAPI/'
|
||||
|
||||
const SERVER_URL = window.canvasApp.urlPrefix + "ExchangeAPI/";
|
||||
|
||||
let thisObject = {
|
||||
initialize: initialize,
|
||||
getTicker: getTicker,
|
||||
getOpenPositions: getOpenPositions,
|
||||
getExecutedTrades: getExecutedTrades,
|
||||
putPosition: putPosition,
|
||||
movePosition: movePosition,
|
||||
getPublicTradeHistory: getPublicTradeHistory
|
||||
};
|
||||
let thisObject = {
|
||||
initialize: initialize,
|
||||
getTicker: getTicker,
|
||||
getOpenPositions: getOpenPositions,
|
||||
getExecutedTrades: getExecutedTrades,
|
||||
putPosition: putPosition,
|
||||
movePosition: movePosition,
|
||||
getPublicTradeHistory: getPublicTradeHistory
|
||||
}
|
||||
|
||||
return thisObject;
|
||||
|
||||
function initialize(callBackFunction) {
|
||||
return thisObject
|
||||
|
||||
function initialize (callBackFunction) {
|
||||
/* When this initialized is called from the Browser, there is no need to send it to the server since the server will
|
||||
anyways initialize this library at each method call. */
|
||||
|
||||
callBackFunction(window.DEFAULT_OK_RESPONSE);
|
||||
|
||||
}
|
||||
callBackFunction(window.DEFAULT_OK_RESPONSE)
|
||||
}
|
||||
|
||||
function getTicker(pMarket, callBackFunction) {
|
||||
|
||||
let authToken = window.localStorage.getItem('access_token');
|
||||
function getTicker (pMarket, callBackFunction) {
|
||||
let authToken = window.localStorage.getItem('access_token')
|
||||
|
||||
let path = SERVER_URL
|
||||
+ CURRENT_BOT_CODE_NAME + "/"
|
||||
+ "getTicker" + "/"
|
||||
+ authToken
|
||||
;
|
||||
|
||||
callServer(undefined, path + "/NO-LOG", onServerResponse);
|
||||
callServer(undefined, path + '/NO-LOG', onServerResponse)
|
||||
|
||||
function onServerResponse(pServerResponse) {
|
||||
let response = JSON.parse(pServerResponse);
|
||||
if (response.result === window.DEFAULT_FAIL_RESPONSE.result)
|
||||
callBackFunction(window.DEFAULT_FAIL_RESPONSE);
|
||||
else
|
||||
callBackFunction(window.DEFAULT_OK_RESPONSE, response);
|
||||
}
|
||||
}
|
||||
|
||||
function getOpenPositions(pMarket, callBackFunction) {
|
||||
function onServerResponse (pServerResponse) {
|
||||
let response = JSON.parse(pServerResponse)
|
||||
if (response.result === window.DEFAULT_FAIL_RESPONSE.result) {
|
||||
callBackFunction(window.DEFAULT_FAIL_RESPONSE)
|
||||
} else {
|
||||
callBackFunction(window.DEFAULT_OK_RESPONSE, response)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function getOpenPositions (pMarket, callBackFunction) {
|
||||
let authToken = window.localStorage.getItem('access_token');
|
||||
|
||||
let path = SERVER_URL
|
||||
+ CURRENT_BOT_CODE_NAME + "/"
|
||||
+ "getOpenPositions" + "/"
|
||||
+ authToken
|
||||
;
|
||||
|
||||
callServer(undefined, path + "/NO-LOG", onServerResponse);
|
||||
|
||||
callServer(undefined, path + '/NO-LOG', onServerResponse)
|
||||
|
||||
function onServerResponse(pServerResponse) {
|
||||
let response = JSON.parse(pServerResponse);
|
||||
@@ -75,7 +67,6 @@
|
||||
let authToken = window.localStorage.getItem('access_token');
|
||||
|
||||
let path = SERVER_URL
|
||||
+ CURRENT_BOT_CODE_NAME + "/"
|
||||
+ "getExecutedTrades" + "/"
|
||||
+ authToken + "/"
|
||||
+ pPositionId
|
||||
@@ -97,7 +88,6 @@
|
||||
let authToken = window.localStorage.getItem('access_token');
|
||||
|
||||
let path = SERVER_URL
|
||||
+ CURRENT_BOT_CODE_NAME + "/"
|
||||
+ "putPosition" + "/"
|
||||
+ authToken + "/"
|
||||
+ pType + "/"
|
||||
@@ -106,61 +96,36 @@
|
||||
+ pAmountB
|
||||
;
|
||||
|
||||
callServer(undefined, path + "/NO-LOG", onServerResponse);
|
||||
callServer(undefined, path + '/NO-LOG', onServerResponse)
|
||||
|
||||
function onServerResponse(pServerResponse) {
|
||||
let response = JSON.parse(pServerResponse);
|
||||
if (response.result === window.DEFAULT_FAIL_RESPONSE.result)
|
||||
callBackFunction(window.DEFAULT_FAIL_RESPONSE);
|
||||
else
|
||||
callBackFunction(window.DEFAULT_OK_RESPONSE, response);
|
||||
}
|
||||
}
|
||||
function onServerResponse (pServerResponse) {
|
||||
let response = JSON.parse(pServerResponse)
|
||||
if (response.result === window.DEFAULT_FAIL_RESPONSE.result) {
|
||||
callBackFunction(window.DEFAULT_FAIL_RESPONSE)
|
||||
} else {
|
||||
callBackFunction(window.DEFAULT_OK_RESPONSE, response)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function getPublicTradeHistory (pMarket, startTime, endTime, callBackFunction) {
|
||||
let authToken = window.localStorage.getItem('access_token')
|
||||
|
||||
function movePosition(pPositionId, pNewRate, pPositionAmountB, callBackFunction) {
|
||||
|
||||
let authToken = window.localStorage.getItem('access_token');
|
||||
|
||||
let path = SERVER_URL
|
||||
+ CURRENT_BOT_CODE_NAME + "/"
|
||||
+ "movePosition" + "/"
|
||||
+ authToken + "/"
|
||||
+ pPositionId + "/"
|
||||
+ pNewRate + "/"
|
||||
+ pPositionAmountB
|
||||
;
|
||||
|
||||
callServer(undefined, path + "/NO-LOG", onServerResponse);
|
||||
|
||||
function onServerResponse(pServerResponse) {
|
||||
let response = JSON.parse(pServerResponse);
|
||||
if (response.result === window.DEFAULT_FAIL_RESPONSE.result)
|
||||
callBackFunction(window.DEFAULT_FAIL_RESPONSE);
|
||||
else
|
||||
callBackFunction(window.DEFAULT_OK_RESPONSE, response);
|
||||
}
|
||||
}
|
||||
|
||||
function getPublicTradeHistory(pMarket, startTime, endTime, callBackFunction) {
|
||||
|
||||
let authToken = window.localStorage.getItem('access_token');
|
||||
|
||||
let path = SERVER_URL
|
||||
+ CURRENT_BOT_CODE_NAME + "/"
|
||||
+ "getPublicTradeHistory" + "/"
|
||||
+ authToken + "/"
|
||||
+ startTime + "/"
|
||||
let path = SERVER_URL
|
||||
+ CURRENT_BOT_CODE_NAME + '/'
|
||||
+ 'getPublicTradeHistory' + '/'
|
||||
+ authToken + '/'
|
||||
+ startTime + '/'
|
||||
+ endTime
|
||||
;
|
||||
|
||||
callServer(undefined, path + "/NO-LOG", onServerResponse);
|
||||
callServer(undefined, path + '/NO-LOG', onServerResponse)
|
||||
|
||||
function onServerResponse(pServerResponse) {
|
||||
let response = JSON.parse(pServerResponse);
|
||||
if (response.result === window.DEFAULT_FAIL_RESPONSE.result)
|
||||
callBackFunction(window.DEFAULT_FAIL_RESPONSE);
|
||||
else
|
||||
callBackFunction(window.DEFAULT_OK_RESPONSE, response);
|
||||
}
|
||||
function onServerResponse(pServerResponse) {
|
||||
let response = JSON.parse(pServerResponse);
|
||||
if (response.result === window.DEFAULT_FAIL_RESPONSE.result)
|
||||
callBackFunction(window.DEFAULT_FAIL_RESPONSE);
|
||||
else
|
||||
callBackFunction(window.DEFAULT_OK_RESPONSE, response);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,392 +0,0 @@
|
||||
|
||||
function newDailyFiles() {
|
||||
|
||||
const MODULE_NAME = "Daily Files";
|
||||
const INFO_LOG = false;
|
||||
const ERROR_LOG = true;
|
||||
const logger = newWebDebugLog();
|
||||
logger.fileName = MODULE_NAME;
|
||||
|
||||
let thisObject = {
|
||||
getFileCursor: getFileCursor,
|
||||
setDatetime: setDatetime,
|
||||
setTimePeriod: setTimePeriod,
|
||||
getExpectedFiles: getExpectedFiles,
|
||||
getFilesLoaded: getFilesLoaded,
|
||||
initialize: initialize,
|
||||
finalize: finalize
|
||||
}
|
||||
|
||||
let filesLoaded = 0;
|
||||
let expectedFiles = 0;
|
||||
|
||||
let fileCloud;
|
||||
|
||||
let fileCursors = new Map;
|
||||
|
||||
let callBackWhenFileReceived;
|
||||
|
||||
return thisObject;
|
||||
|
||||
function finalize() {
|
||||
|
||||
try {
|
||||
|
||||
if (INFO_LOG === true) { logger.write("[INFO] finalize -> Entering function."); }
|
||||
|
||||
filesLoaded = undefined;
|
||||
expectedFiles = undefined;
|
||||
fileCloud = undefined;
|
||||
|
||||
fileCursors.forEach(finalizeEach);
|
||||
|
||||
function finalizeEach(item, key, mapObj) {
|
||||
|
||||
if (INFO_LOG === true) { logger.write("[INFO] finalize -> finalizeEach -> Entering function."); }
|
||||
|
||||
item.finalize();
|
||||
}
|
||||
|
||||
} catch (err) {
|
||||
|
||||
if (ERROR_LOG === true) { logger.write("[ERROR] finalize -> err = " + err); }
|
||||
}
|
||||
}
|
||||
|
||||
function initialize(pDevTeam, pBot, pProduct, pSet, pExchange, pMarket, pDatetime, pTimePeriod, callBackFunction) {
|
||||
|
||||
try {
|
||||
|
||||
if (INFO_LOG === true) { logger.write("[INFO] initialize -> Entering function."); }
|
||||
if (INFO_LOG === true) { logger.write("[INFO] initialize -> key = " + pDevTeam.codeName + "-" + pBot.codeName + "-" + pProduct.codeName); }
|
||||
|
||||
callBackWhenFileReceived = callBackFunction;
|
||||
|
||||
let exchange = ecosystem.getExchange(pProduct, pExchange);
|
||||
|
||||
if (exchange === undefined) {
|
||||
|
||||
throw "Exchange not supoorted by this product of the ecosystem! - pDevTeam.codeName = " + pDevTeam.codeName + ", pBot.codeName = " + pBot.codeName + ", pProduct.codeName = " + pProduct.codeName + ", pExchange = " + pExchange;
|
||||
|
||||
}
|
||||
|
||||
fileCloud = newFileCloud();
|
||||
fileCloud.initialize(pBot);
|
||||
|
||||
/* First we will get the Data Range */
|
||||
|
||||
fileCloud.getFile(pDevTeam, pBot, pSet, exchange, pMarket, undefined, undefined, undefined, true, onDataRangeReceived);
|
||||
|
||||
function onDataRangeReceived(err, pFile) {
|
||||
|
||||
try {
|
||||
|
||||
if (INFO_LOG === true) { logger.write("[INFO] initialize -> onFileReceived -> Entering function."); }
|
||||
|
||||
let beginDateRange;
|
||||
let endDateRange;
|
||||
|
||||
switch (err.result) {
|
||||
case GLOBAL.DEFAULT_OK_RESPONSE.result: {
|
||||
|
||||
if (INFO_LOG === true) { logger.write("[INFO] initialize -> onFileReceived -> Received OK Response."); }
|
||||
|
||||
beginDateRange = new Date(pFile.begin);
|
||||
endDateRange = new Date(pFile.end);
|
||||
|
||||
break;
|
||||
}
|
||||
|
||||
case GLOBAL.DEFAULT_FAIL_RESPONSE.result: {
|
||||
|
||||
if (INFO_LOG === true) { logger.write("[INFO] initialize -> onFileReceived -> Received FAIL Response."); }
|
||||
callBackFunction(GLOBAL.DEFAULT_FAIL_RESPONSE);
|
||||
return;
|
||||
}
|
||||
|
||||
case GLOBAL.CUSTOM_FAIL_RESPONSE.result: {
|
||||
|
||||
if (INFO_LOG === true) { logger.write("[INFO] initialize -> onFileReceived -> Received CUSTOM FAIL Response."); }
|
||||
if (INFO_LOG === true) { logger.write("[INFO] initialize -> onFileReceived -> err.message = " + err.message); }
|
||||
|
||||
if (err.message === "File does not exist.") {
|
||||
|
||||
if (INFO_LOG === true) { logger.write("[WARN] initialize -> onFileReceived -> No Date Range file found. maxDate will be set to current datetime. "); }
|
||||
|
||||
endDateRange = new Date();
|
||||
break;
|
||||
}
|
||||
|
||||
if (err.message === "Missing Configuration.") {
|
||||
|
||||
if (ERROR_LOG === true) { logger.write("[WARN] initialize -> onFileReceived -> The needed configuration for the dateRange at the dataSet of the product was not found."); }
|
||||
if (ERROR_LOG === true) { logger.write("[WARN] initialize -> onFileReceived -> maxDate will be set to current datetime."); }
|
||||
|
||||
endDateRange = new Date();
|
||||
break;
|
||||
}
|
||||
|
||||
/* If none of the previous conditions are met, the we return the err to the caller. */
|
||||
|
||||
callBackFunction(err);
|
||||
return;
|
||||
}
|
||||
|
||||
default: {
|
||||
|
||||
if (INFO_LOG === true) { logger.write("[INFO] initialize -> onFileReceived -> Received Unexpected Response."); }
|
||||
callBackFunction(err);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
/* Now we will get the daily files */
|
||||
|
||||
for (i = 0; i < dailyFilePeriods.length; i++) {
|
||||
|
||||
let periodTime = dailyFilePeriods[i][0];
|
||||
let periodName = dailyFilePeriods[i][1];
|
||||
|
||||
if (INFO_LOG === true) { logger.write("[INFO] initialize -> onFileReceived -> periodTime = " + periodTime); }
|
||||
if (INFO_LOG === true) { logger.write("[INFO] initialize -> onFileReceived -> periodName = " + periodName); }
|
||||
|
||||
if (pSet.validPeriods.includes(periodName) === true) {
|
||||
|
||||
let fileCursor = newFileCursor();
|
||||
fileCursor.initialize(fileCloud, pDevTeam, pBot, pSet, exchange, pMarket, periodName, periodTime, pDatetime, pTimePeriod, beginDateRange, endDateRange, onInitialized);
|
||||
|
||||
function onInitialized(err) {
|
||||
|
||||
try {
|
||||
|
||||
if (INFO_LOG === true) { logger.write("[INFO] initialize -> onFileReceived -> onInitialized -> Entering function."); }
|
||||
|
||||
switch (err.result) {
|
||||
case GLOBAL.DEFAULT_OK_RESPONSE.result: {
|
||||
|
||||
if (INFO_LOG === true) { logger.write("[INFO] initialize -> onFileReceived -> onInitialized -> Received OK Response."); }
|
||||
break;
|
||||
}
|
||||
|
||||
case GLOBAL.DEFAULT_FAIL_RESPONSE.result: {
|
||||
|
||||
if (INFO_LOG === true) { logger.write("[INFO] initialize -> onFileReceived -> onInitialized -> Received FAIL Response."); }
|
||||
callBackWhenFileReceived(GLOBAL.DEFAULT_FAIL_RESPONSE);
|
||||
return;
|
||||
}
|
||||
default: {
|
||||
|
||||
if (INFO_LOG === true) { logger.write("[INFO] initialize -> onFileReceived -> onInitialized -> Received Unexpected Response."); }
|
||||
callBackWhenFileReceived(err);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
fileCursors.set(periodTime, fileCursor);
|
||||
|
||||
if (INFO_LOG === true) { logger.write("[INFO] initialize -> onFileReceived -> onInitialized -> expectedFiles = " + expectedFiles); }
|
||||
|
||||
expectedFiles = expectedFiles + fileCursor.getExpectedFiles();
|
||||
|
||||
if (INFO_LOG === true) { logger.write("[INFO] initialize -> onFileReceived -> onInitialized -> expectedFiles = " + expectedFiles); }
|
||||
|
||||
} catch (err) {
|
||||
|
||||
if (ERROR_LOG === true) { logger.write("[ERROR] initialize -> onFileReceived -> onInitialized -> err = " + err); }
|
||||
callBackFunction(GLOBAL.DEFAULT_FAIL_RESPONSE);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
loadThemAll();
|
||||
|
||||
function loadThemAll() {
|
||||
|
||||
try {
|
||||
|
||||
if (INFO_LOG === true) { logger.write("[INFO] initialize -> onFileReceived -> loadThemAll -> Entering function."); }
|
||||
|
||||
for (i = 0; i < dailyFilePeriods.length; i++) {
|
||||
|
||||
let periodTime = dailyFilePeriods[i][0];
|
||||
let periodName = dailyFilePeriods[i][1];
|
||||
|
||||
if (INFO_LOG === true) { logger.write("[INFO] initialize -> onFileReceived -> loadThemAll -> periodTime = " + periodTime); }
|
||||
if (INFO_LOG === true) { logger.write("[INFO] initialize -> onFileReceived -> loadThemAll -> periodName = " + periodName); }
|
||||
|
||||
if (pSet.validPeriods.includes(periodName) === true) {
|
||||
|
||||
let fileCursor = fileCursors.get(periodTime);
|
||||
fileCursor.reload(onFileReceived);
|
||||
|
||||
}
|
||||
}
|
||||
} catch (err) {
|
||||
|
||||
if (ERROR_LOG === true) { logger.write("[ERROR] initialize -> onFileReceived -> loadThemAll -> err = " + err); }
|
||||
callBackFunction(GLOBAL.DEFAULT_FAIL_RESPONSE);
|
||||
}
|
||||
}
|
||||
|
||||
} catch (err) {
|
||||
|
||||
if (ERROR_LOG === true) { logger.write("[ERROR] initialize -> onFileReceived -> err = " + err); }
|
||||
callBackFunction(GLOBAL.DEFAULT_FAIL_RESPONSE);
|
||||
}
|
||||
}
|
||||
|
||||
} catch (err) {
|
||||
|
||||
if (ERROR_LOG === true) { logger.write("[ERROR] initialize -> err = " + err); }
|
||||
callBackFunction(GLOBAL.DEFAULT_FAIL_RESPONSE);
|
||||
}
|
||||
}
|
||||
|
||||
function onFileReceived(err) {
|
||||
|
||||
try {
|
||||
|
||||
if (INFO_LOG === true) { logger.write("[INFO] onFileReceived -> Entering function."); }
|
||||
|
||||
switch (err.result) {
|
||||
case GLOBAL.DEFAULT_OK_RESPONSE.result: {
|
||||
|
||||
if (INFO_LOG === true) { logger.write("[INFO] onFileReceived -> Received OK Response."); }
|
||||
break;
|
||||
}
|
||||
|
||||
case GLOBAL.DEFAULT_FAIL_RESPONSE.result: {
|
||||
|
||||
if (INFO_LOG === true) { logger.write("[INFO] onFileReceived -> Received FAIL Response."); }
|
||||
callBackWhenFileReceived(GLOBAL.DEFAULT_FAIL_RESPONSE);
|
||||
return;
|
||||
}
|
||||
|
||||
case GLOBAL.CUSTOM_FAIL_RESPONSE.result: {
|
||||
|
||||
if (INFO_LOG === true) { logger.write("[INFO] onFileReceived -> Received CUSTOM FAIL Response."); }
|
||||
if (INFO_LOG === true) { logger.write("[INFO] onFileReceived -> err.message = " + err.message); }
|
||||
|
||||
callBackWhenFileReceived(err);
|
||||
return;
|
||||
}
|
||||
|
||||
default: {
|
||||
|
||||
if (INFO_LOG === true) { logger.write("[INFO] onFileReceived -> Received Unexpected Response."); }
|
||||
callBackWhenFileReceived(err);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
filesLoaded++;
|
||||
|
||||
if (INFO_LOG === true) { logger.write("[INFO] onFileReceived -> filesLoaded = " + filesLoaded); }
|
||||
|
||||
callBackWhenFileReceived(GLOBAL.DEFAULT_OK_RESPONSE, thisObject); // Note that the call back is called for every file loaded at each cursor.
|
||||
|
||||
} catch (err) {
|
||||
|
||||
if (ERROR_LOG === true) { logger.write("[ERROR] onFileReceived -> err = " + err); }
|
||||
callBackWhenFileReceived(GLOBAL.DEFAULT_FAIL_RESPONSE);
|
||||
}
|
||||
}
|
||||
|
||||
function getFileCursor(pPeriod) {
|
||||
|
||||
try {
|
||||
|
||||
if (INFO_LOG === true) { logger.write("[INFO] getFileCursor -> Entering function."); }
|
||||
|
||||
return fileCursors.get(pPeriod);
|
||||
|
||||
} catch (err) {
|
||||
|
||||
if (ERROR_LOG === true) { logger.write("[ERROR] getFileCursor -> err = " + err); }
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
function setDatetime(pDatetime) {
|
||||
|
||||
try {
|
||||
|
||||
if (INFO_LOG === true) { logger.write("[INFO] setDatetime -> Entering function."); }
|
||||
|
||||
filesLoaded = 0;
|
||||
expectedFiles = 0;
|
||||
|
||||
fileCursors.forEach(setDatetimeToEach)
|
||||
|
||||
function setDatetimeToEach(fileCursor, key, map) {
|
||||
|
||||
fileCursor.setDatetime(pDatetime);
|
||||
|
||||
if (INFO_LOG === true) { logger.write("[INFO] setDatetime -> expectedFiles = " + expectedFiles); }
|
||||
|
||||
expectedFiles = expectedFiles + fileCursor.getExpectedFiles();
|
||||
|
||||
if (INFO_LOG === true) { logger.write("[INFO] setDatetime -> expectedFiles = " + expectedFiles); }
|
||||
|
||||
fileCursor.reload(onFileReceived);
|
||||
|
||||
}
|
||||
|
||||
} catch (err) {
|
||||
|
||||
if (ERROR_LOG === true) { logger.write("[ERROR] setDatetime -> err = " + err); }
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
function setTimePeriod(pTimePeriod, pDatetime) {
|
||||
|
||||
try {
|
||||
|
||||
if (INFO_LOG === true) { logger.write("[INFO] setTimePeriod -> Entering function."); }
|
||||
|
||||
filesLoaded = 0;
|
||||
expectedFiles = 0;
|
||||
|
||||
fileCursors.forEach(setTimePeriodToEach)
|
||||
|
||||
function setTimePeriodToEach(fileCursor, key, map) {
|
||||
|
||||
fileCursor.setTimePeriod(pTimePeriod, pDatetime);
|
||||
|
||||
if (INFO_LOG === true) { logger.write("[INFO] setTimePeriod -> expectedFiles = " + expectedFiles); }
|
||||
|
||||
expectedFiles = expectedFiles + fileCursor.getExpectedFiles();
|
||||
|
||||
if (INFO_LOG === true) { logger.write("[INFO] setTimePeriod -> expectedFiles = " + expectedFiles); }
|
||||
|
||||
fileCursor.reload(onFileReceived);
|
||||
|
||||
}
|
||||
|
||||
} catch (err) {
|
||||
|
||||
if (ERROR_LOG === true) { logger.write("[ERROR] setTimePeriod -> err = " + err); }
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
function getExpectedFiles() {
|
||||
|
||||
if (INFO_LOG === true) { logger.write("[INFO] getExpectedFiles -> Entering function."); }
|
||||
if (INFO_LOG === true) { logger.write("[INFO] getExpectedFiles -> expectedFiles = " + expectedFiles); }
|
||||
|
||||
return expectedFiles;
|
||||
|
||||
}
|
||||
|
||||
function getFilesLoaded() {
|
||||
|
||||
if (INFO_LOG === true) { logger.write("[INFO] getFilesLoaded -> Entering function."); }
|
||||
if (INFO_LOG === true) { logger.write("[INFO] getFilesLoaded -> filesLoaded = " + filesLoaded); }
|
||||
|
||||
return filesLoaded;
|
||||
|
||||
}
|
||||
}
|
||||
@@ -1,252 +0,0 @@
|
||||
|
||||
function newFileCloud() {
|
||||
|
||||
const MODULE_NAME = "File Cloud";
|
||||
const INFO_LOG = false;
|
||||
const ERROR_LOG = true;
|
||||
const logger = newWebDebugLog();
|
||||
logger.fileName = MODULE_NAME;
|
||||
|
||||
/*
|
||||
|
||||
This is the module in the system that actually connects to the cloud storage and grabs from there the needed files.
|
||||
|
||||
*/
|
||||
|
||||
var thisObject = {
|
||||
getFile: getFile,
|
||||
initialize: initialize
|
||||
};
|
||||
|
||||
let blobService;
|
||||
|
||||
return thisObject;
|
||||
|
||||
function initialize(pBot) {
|
||||
|
||||
try {
|
||||
|
||||
if (INFO_LOG === true) { logger.write("[INFO] initialize -> Entering function."); }
|
||||
if (INFO_LOG === true) { logger.write("[INFO] initialize -> pBot = " + pBot.codeName); }
|
||||
|
||||
blobService = AzureStorage.Blob.createBlobServiceWithSas(pBot.storage.fileUri, pBot.storage.sas);
|
||||
|
||||
} catch (err) {
|
||||
|
||||
if (ERROR_LOG === true) { logger.write("[ERROR] initialize -> err = " + err); }
|
||||
//callBackFunction(GLOBAL.DEFAULT_FAIL_RESPONSE); TODO> Handle this callback.
|
||||
}
|
||||
}
|
||||
|
||||
function getFile(pDevTeam, pBot, pSet, pExchange, pMarket, pPeriodName, pDatetime, pSequence, pDataRange, callBackFunction) {
|
||||
|
||||
try {
|
||||
|
||||
if (INFO_LOG === true) { logger.write("[INFO] getFile -> Entering function."); }
|
||||
|
||||
const MAX_RETRIES = 3;
|
||||
|
||||
getFileRecursively(0, pDevTeam, pBot, pSet, pExchange, pMarket, pPeriodName, pDatetime, pSequence, pDataRange, callBackFunction)
|
||||
|
||||
function getFileRecursively(pRetryCounter, pDevTeam, pBot, pSet, pExchange, pMarket, pPeriodName, pDatetime, pSequence, pDataRange, callBackFunction) {
|
||||
|
||||
try {
|
||||
|
||||
if (INFO_LOG === true) { logger.write("[INFO] getFile -> getFileRecursively -> Entering function."); }
|
||||
if (INFO_LOG === true) { logger.write("[INFO] getFile -> getFileRecursively -> key = " + pDevTeam.codeName + "-" + pBot.codeName + "-" + pSet.filePath + "-" + pSet.fileName); }
|
||||
|
||||
let fileName;
|
||||
let filePath;
|
||||
|
||||
if (pDataRange === undefined) {
|
||||
|
||||
fileName = pSet.fileName;
|
||||
filePath = pSet.filePath;
|
||||
|
||||
} else {
|
||||
|
||||
if (pSet.dataRange !== undefined) {
|
||||
|
||||
fileName = pSet.dataRange.fileName;
|
||||
filePath = pSet.dataRange.filePath;
|
||||
|
||||
} else {
|
||||
|
||||
let customErr = {
|
||||
result: GLOBAL.CUSTOM_FAIL_RESPONSE.result,
|
||||
message: "Missing Configuration."
|
||||
};
|
||||
|
||||
if (ERROR_LOG === true) { logger.write("[WARN] getFile -> getFileRecursively -> onFileReceived -> customErr.message = " + customErr.message); }
|
||||
if (ERROR_LOG === true) { logger.write("[WARN] getFile -> getFileRecursively -> onFileReceived -> Data Range configuration could not be found. "); }
|
||||
|
||||
callBackFunction(customErr);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
if (fileName === undefined) {
|
||||
|
||||
logger.write("[ERROR] getFile -> getFileRecursively -> Inconsistant data. Check the following: ");
|
||||
logger.write("[ERROR] getFile -> getFileRecursively -> pDevTeam = " + JSON.stringify(pDevTeam));
|
||||
logger.write("[ERROR] getFile -> getFileRecursively -> pBot = " + JSON.stringify(pBot));
|
||||
logger.write("[ERROR] getFile -> getFileRecursively -> pSet = " + JSON.stringify(pSet));
|
||||
logger.write("[ERROR] getFile -> getFileRecursively -> pExchange = " + JSON.stringify(pExchange));
|
||||
logger.write("[ERROR] getFile -> getFileRecursively -> pMarket = " + JSON.stringify(pMarket));
|
||||
logger.write("[ERROR] getFile -> getFileRecursively -> pPeriodName = " + JSON.stringify(pPeriodName));
|
||||
|
||||
throw ("Inconsistant data received.");
|
||||
}
|
||||
|
||||
if (pMarket !== undefined) {
|
||||
|
||||
fileName = fileName.replace("@AssetA", pMarket.assetA);
|
||||
fileName = fileName.replace("@AssetB", pMarket.assetB);
|
||||
}
|
||||
|
||||
if (pDevTeam !== undefined) {
|
||||
|
||||
filePath = filePath.replace("@DevTeam", pDevTeam.codeName);
|
||||
}
|
||||
|
||||
if (pBot !== undefined) {
|
||||
|
||||
filePath = filePath.replace("@Bot", pBot.codeName);
|
||||
}
|
||||
|
||||
if (pExchange !== undefined) {
|
||||
|
||||
filePath = filePath.replace("@Exchange", pExchange.name);
|
||||
}
|
||||
|
||||
filePath = filePath.replace("@Period", pPeriodName);
|
||||
|
||||
if (pDatetime !== undefined) {
|
||||
|
||||
filePath = filePath.replace("@Year", pDatetime.getUTCFullYear());
|
||||
filePath = filePath.replace("@Month", pad(pDatetime.getUTCMonth() + 1, 2));
|
||||
filePath = filePath.replace("@Day", pad(pDatetime.getUTCDate(), 2));
|
||||
filePath = filePath.replace("@Hour", pad(pDatetime.getUTCHours(), 2));
|
||||
filePath = filePath.replace("@Minute", pad(pDatetime.getUTCMinutes(), 2));
|
||||
|
||||
}
|
||||
|
||||
if (pSequence !== undefined) {
|
||||
|
||||
fileName = fileName.replace("@Sequence", pSequence);
|
||||
}
|
||||
|
||||
if (INFO_LOG === true) { logger.write("[INFO] getFile -> getFileRecursively -> filePath = " + filePath); }
|
||||
if (INFO_LOG === true) { logger.write("[INFO] getFile -> getFileRecursively -> fileName = " + fileName); }
|
||||
|
||||
let containerName;
|
||||
|
||||
containerName = pDevTeam.codeName.toLowerCase();
|
||||
|
||||
blobService.getBlobToText(containerName, filePath + "/" + fileName, onFileReceived);
|
||||
|
||||
function onFileReceived(err, text, response) {
|
||||
|
||||
try {
|
||||
|
||||
if (INFO_LOG === true) { logger.write("[INFO] getFile -> getFileRecursively -> onFileReceived -> Entering function."); }
|
||||
if (INFO_LOG === true) { logger.write("[INFO] getFile -> getFileRecursively -> onFileReceived -> filePath = " + filePath); }
|
||||
if (INFO_LOG === true) { logger.write("[INFO] getFile -> getFileRecursively -> onFileReceived -> fileName = " + fileName); }
|
||||
|
||||
let data;
|
||||
|
||||
if (err) {
|
||||
|
||||
if (err.code === "BlobNotFound" | err.code === "FileNotFound" | err.code === "ParentNotFound") {
|
||||
|
||||
let customErr = {
|
||||
result: GLOBAL.CUSTOM_FAIL_RESPONSE.result,
|
||||
message: "File does not exist."
|
||||
};
|
||||
|
||||
if (INFO_LOG === true) { logger.write("[WARN] getFile -> getFileRecursively -> onFileReceived -> customErr.message = " + customErr.message); }
|
||||
|
||||
callBackFunction(customErr);
|
||||
return;
|
||||
}
|
||||
|
||||
if (ERROR_LOG === true) { logger.write("[ERROR] getFile -> getFileRecursively -> onFileReceived -> containerName = " + containerName); }
|
||||
if (ERROR_LOG === true) { logger.write("[ERROR] getFile -> getFileRecursively -> onFileReceived -> filePath = " + filePath); }
|
||||
if (ERROR_LOG === true) { logger.write("[ERROR] getFile -> getFileRecursively -> onFileReceived -> fileName = " + fileName); }
|
||||
if (ERROR_LOG === true) { logger.write("[ERROR] getFile -> getFileRecursively -> onFileReceived -> Unexpected Error Ocurred."); }
|
||||
if (ERROR_LOG === true) { logger.write("[ERROR] getFile -> getFileRecursively -> onFileReceived -> err = " + err); }
|
||||
if (ERROR_LOG === true) { logger.write("[ERROR] getFile -> getFileRecursively -> onFileReceived -> text = " + text); }
|
||||
if (ERROR_LOG === true) { logger.write("[ERROR] getFile -> getFileRecursively -> onFileReceived -> response = " + response); }
|
||||
|
||||
if (err.message === "XHR error") {
|
||||
|
||||
if (pRetryCounter < MAX_RETRIES) {
|
||||
|
||||
if (ERROR_LOG === true) { logger.write("[ERROR] getFile -> getFileRecursively -> onFileReceived -> Retrying to get this file. "); }
|
||||
if (ERROR_LOG === true) { logger.write("[ERROR] getFile -> getFileRecursively -> onFileReceived -> MAX_RETRIES = " + MAX_RETRIES); }
|
||||
if (ERROR_LOG === true) { logger.write("[ERROR] getFile -> getFileRecursively -> onFileReceived -> pRetryCounter = " + pRetryCounter); }
|
||||
|
||||
getFileRecursively(pRetryCounter + 1, pDevTeam, pBot, pSet, pExchange, pMarket, pPeriodName, pDatetime, pSequence, pDataRange, callBackFunction)
|
||||
return;
|
||||
|
||||
} else {
|
||||
|
||||
if (ERROR_LOG === true) { logger.write("[ERROR] getFile -> getFileRecursively -> onFileReceived -> Could not get this file from storage. "); }
|
||||
if (ERROR_LOG === true) { logger.write("[ERROR] getFile -> getFileRecursively -> onFileReceived -> MAX_RETRIES = " + MAX_RETRIES); }
|
||||
if (ERROR_LOG === true) { logger.write("[ERROR] getFile -> getFileRecursively -> onFileReceived -> pRetryCounter = " + pRetryCounter); }
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
callBackFunction(GLOBAL.DEFAULT_FAIL_RESPONSE);
|
||||
return;
|
||||
|
||||
} else {
|
||||
|
||||
try {
|
||||
|
||||
data = JSON.parse(text);
|
||||
|
||||
if (INFO_LOG === true) { logger.write("[INFO] getFile -> getFileRecursively -> onFileReceived -> Data received is valid JSON."); }
|
||||
|
||||
callBackFunction(GLOBAL.DEFAULT_OK_RESPONSE, data);
|
||||
return;
|
||||
|
||||
} catch (err) {
|
||||
|
||||
if (INFO_LOG === true) { logger.write("[WARN] getFile -> getFileRecursively -> onFileReceived -> err = " + err); }
|
||||
|
||||
let customErr = {
|
||||
result: GLOBAL.CUSTOM_OK_RESPONSE.result,
|
||||
message: "Data not in JSON Format."
|
||||
};
|
||||
|
||||
if (INFO_LOG === true) { logger.write("[WARN] getFile -> getFileRecursively -> onFileReceived -> customErr.message = " + customErr.message); }
|
||||
|
||||
callBackFunction(customErr, text);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
} catch (err) {
|
||||
|
||||
if (ERROR_LOG === true) { logger.write("[ERROR] getFile -> getFileRecursively -> onFileReceived -> err = " + err); }
|
||||
callBackFunction(GLOBAL.DEFAULT_FAIL_RESPONSE);
|
||||
}
|
||||
}
|
||||
|
||||
} catch (err) {
|
||||
|
||||
if (ERROR_LOG === true) { logger.write("[ERROR] getFile -> getFileRecursively -> err = " + err); }
|
||||
callBackFunction(GLOBAL.DEFAULT_FAIL_RESPONSE);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
} catch (err) {
|
||||
|
||||
if (ERROR_LOG === true) { logger.write("[ERROR] getFile -> err = " + err); }
|
||||
callBackFunction(GLOBAL.DEFAULT_FAIL_RESPONSE);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,688 +0,0 @@
|
||||
|
||||
function newFileCursor() {
|
||||
|
||||
const MODULE_NAME = "File Cursor";
|
||||
const INFO_LOG = false;
|
||||
const ERROR_LOG = true;
|
||||
const logger = newWebDebugLog();
|
||||
logger.fileName = MODULE_NAME;
|
||||
|
||||
let cursorDate;
|
||||
|
||||
let thisObject = {
|
||||
reload: reload,
|
||||
setDatetime: setDatetime,
|
||||
setTimePeriod: setTimePeriod,
|
||||
files: new Map,
|
||||
getExpectedFiles: getExpectedFiles,
|
||||
initialize: initialize,
|
||||
finalize: finalize
|
||||
};
|
||||
|
||||
let minCursorSize = 10;
|
||||
let maxCursorSize = 30;
|
||||
|
||||
let market;
|
||||
let exchange;
|
||||
let fileCloud;
|
||||
let devTeam;
|
||||
let bot;
|
||||
let thisSet;
|
||||
let periodName;
|
||||
let timePeriod;
|
||||
let beginDateRange;
|
||||
let endDateRange;
|
||||
|
||||
let intervalHandle;
|
||||
|
||||
return thisObject;
|
||||
|
||||
function finalize() {
|
||||
|
||||
try {
|
||||
|
||||
if (INFO_LOG === true) { logger.write("[INFO] finalize -> Entering function."); }
|
||||
|
||||
clearInterval(intervalHandle);
|
||||
|
||||
thisObject.files = undefined;
|
||||
cursorDate = undefined;
|
||||
fileCloud = undefined;
|
||||
periodName = undefined;
|
||||
timePeriod = undefined;
|
||||
|
||||
} catch (err) {
|
||||
|
||||
if (ERROR_LOG === true) { logger.write("[ERROR] finalize -> err = " + err); }
|
||||
}
|
||||
}
|
||||
|
||||
function initialize(pFileCloud, pDevTeam, pBot, pSet, pExchange, pMarket, pPeriodName, pTimePeriod, pCursorDate, pCurrentTimePeriod, pBeginDateRange, pEndDateRange, callBackFunction) {
|
||||
|
||||
try {
|
||||
|
||||
if (INFO_LOG === true) { logger.write("[INFO] initialize -> Entering function."); }
|
||||
if (INFO_LOG === true) { logger.write("[INFO] initialize -> key = " + pDevTeam.codeName + "-" + pBot.codeName + "-" + pSet.codeName + "-" + pPeriodName); }
|
||||
|
||||
market = pMarket;
|
||||
exchange = pExchange;
|
||||
fileCloud = pFileCloud;
|
||||
devTeam = pDevTeam;
|
||||
bot = pBot;
|
||||
thisSet = pSet;
|
||||
periodName = pPeriodName;
|
||||
cursorDate = pCursorDate;
|
||||
timePeriod = pTimePeriod;
|
||||
beginDateRange = pBeginDateRange;
|
||||
endDateRange = pEndDateRange;
|
||||
|
||||
if (INFO_LOG === true) { logger.write("[INFO] initialize -> market = " + market); }
|
||||
if (INFO_LOG === true) { logger.write("[INFO] initialize -> periodName = " + periodName); }
|
||||
if (INFO_LOG === true) { logger.write("[INFO] initialize -> cursorDate = " + cursorDate); }
|
||||
if (INFO_LOG === true) { logger.write("[INFO] initialize -> beginDateRange = " + beginDateRange); }
|
||||
if (INFO_LOG === true) { logger.write("[INFO] initialize -> endDateRange = " + endDateRange); }
|
||||
|
||||
setTimePeriod(pCurrentTimePeriod, pCursorDate);
|
||||
|
||||
intervalHandle = setInterval(updateFiles , timePeriod);
|
||||
|
||||
callBackFunction(GLOBAL.DEFAULT_OK_RESPONSE);
|
||||
|
||||
} catch (err) {
|
||||
|
||||
if (ERROR_LOG === true) { logger.write("[ERROR] initialize -> err = " + err); }
|
||||
callBackFunction(GLOBAL.DEFAULT_FAIL_RESPONSE);
|
||||
}
|
||||
}
|
||||
|
||||
function updateFiles() {
|
||||
|
||||
try {
|
||||
|
||||
if (INFO_LOG === true) { logger.write("[INFO] updateFiles -> Entering function."); }
|
||||
|
||||
/*
|
||||
|
||||
In order to know if we need to update any file we follow this logic:
|
||||
|
||||
1. If the current date is already a file in the cursor, we need to update it.
|
||||
2. If the current date is one day ahead of a file in the cursor, we need to add this one to the cursor.
|
||||
|
||||
*/
|
||||
|
||||
let targetDate;
|
||||
let dateString;
|
||||
let file;
|
||||
|
||||
/* Situation 1 */
|
||||
|
||||
targetDate = new Date();
|
||||
dateString = targetDate.getUTCFullYear() + '-' + pad(targetDate.getUTCMonth() + 1, 2) + '-' + pad(targetDate.getUTCDate(), 2);
|
||||
|
||||
file = thisObject.files.get(dateString);
|
||||
|
||||
if (file !== undefined) {
|
||||
|
||||
if (INFO_LOG === true) { logger.write("[INFO] updateFiles -> File found at the cursor, proceeding to update."); }
|
||||
|
||||
fileCloud.getFile(devTeam, bot, thisSet, exchange, market, periodName, targetDate, undefined, undefined, onFileReceived);
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
/* Situation 2 */
|
||||
|
||||
targetDate = new Date( (new Date()).valueOf() - ONE_DAY_IN_MILISECONDS);
|
||||
dateString = targetDate.getUTCFullYear() + '-' + pad(targetDate.getUTCMonth() + 1, 2) + '-' + pad(targetDate.getUTCDate(), 2);
|
||||
|
||||
file = thisObject.files.get(dateString); // This is from yesterday
|
||||
|
||||
targetDate = new Date();
|
||||
dateString = targetDate.getUTCFullYear() + '-' + pad(targetDate.getUTCMonth() + 1, 2) + '-' + pad(targetDate.getUTCDate(), 2);
|
||||
|
||||
if (file !== undefined) {
|
||||
|
||||
if (INFO_LOG === true) { logger.write("[INFO] updateFiles -> Previous day file found at the cursor, proceeding to add current date."); }
|
||||
|
||||
fileCloud.getFile(devTeam, bot, thisSet, exchange, market, periodName, targetDate, undefined, undefined, onFileReceived);
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
function onFileReceived(err, file) {
|
||||
|
||||
try {
|
||||
|
||||
if (INFO_LOG === true) { logger.write("[INFO] updateFiles -> onFileReceived -> Entering function."); }
|
||||
|
||||
switch (err.result) {
|
||||
case GLOBAL.DEFAULT_OK_RESPONSE.result: {
|
||||
|
||||
if (INFO_LOG === true) { logger.write("[INFO] updateFiles -> onFileReceived -> Received OK Response."); }
|
||||
break;
|
||||
}
|
||||
|
||||
case GLOBAL.DEFAULT_FAIL_RESPONSE.result: {
|
||||
|
||||
if (INFO_LOG === true) { logger.write("[INFO] updateFiles -> onFileReceived -> Received FAIL Response."); }
|
||||
return;
|
||||
}
|
||||
|
||||
default: {
|
||||
|
||||
if (INFO_LOG === true) { logger.write("[INFO] updateFiles -> onFileReceived -> Received Unexpected Response."); }
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
thisObject.files.set(dateString, file);
|
||||
|
||||
if (INFO_LOG === true) { logger.write("[INFO] updateFiles -> onFileReceived -> File updated."); }
|
||||
if (INFO_LOG === true) { logger.write("[INFO] updateFiles -> onFileReceived -> devTeam = " + devTeam.codeName); }
|
||||
if (INFO_LOG === true) { logger.write("[INFO] updateFiles -> onFileReceived -> bot = " + bot.codeName); }
|
||||
if (INFO_LOG === true) { logger.write("[INFO] updateFiles -> onFileReceived -> thisSet = " + thisSet.codeName); }
|
||||
if (INFO_LOG === true) { logger.write("[INFO] updateFiles -> onFileReceived -> dateString = " + dateString); }
|
||||
|
||||
|
||||
} catch (err) {
|
||||
|
||||
if (ERROR_LOG === true) { logger.write("[ERROR] updateFiles -> onFileReceived -> err = " + err); }
|
||||
callBackFunction(GLOBAL.DEFAULT_FAIL_RESPONSE);
|
||||
}
|
||||
}
|
||||
} catch (err) {
|
||||
|
||||
if (ERROR_LOG === true) { logger.write("[ERROR] updateFiles -> err = " + err); }
|
||||
}
|
||||
}
|
||||
|
||||
function setTimePeriod(pTimePeriod, pDatetime) {
|
||||
|
||||
try {
|
||||
|
||||
if (INFO_LOG === true) { logger.write("[INFO] setTimePeriod -> Entering function."); }
|
||||
|
||||
/*
|
||||
|
||||
We are implementing here an algorithm designed to save bandwidth, memory and processing power at the browser.
|
||||
We say there is a saving mode where the cursor is running at a minimum size. When the end user aproaches the time period the cursor
|
||||
is set, then it should exit the saving mode and go to its actual size.
|
||||
|
||||
To do this we are going to measure the distance from the Time Period received to the one the cursors was initialized with.
|
||||
If these periods are consecutive, it means that the cursor should exit saving mode and load its full size.
|
||||
|
||||
*/
|
||||
|
||||
cursorDate = pDatetime; // Adjust the cursor date to the one received.
|
||||
|
||||
let positionA;
|
||||
|
||||
for (let i = 0; i < dailyFilePeriods.length; i++) {
|
||||
|
||||
let period = dailyFilePeriods[i];
|
||||
|
||||
if (period[0] === pTimePeriod) {
|
||||
|
||||
positionA = i;
|
||||
|
||||
}
|
||||
|
||||
if (period[0] === timePeriod) {
|
||||
|
||||
positionB = i;
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
if (Math.abs(positionB - positionA) <= 1) {
|
||||
|
||||
if (INFO_LOG === true) { logger.write("[INFO] setTimePeriod -> Will EXIT Saving Mode."); }
|
||||
if (INFO_LOG === true) { logger.write("[INFO] setTimePeriod -> pTimePeriod = " + convertTimePeriodToName(pTimePeriod)); }
|
||||
if (INFO_LOG === true) { logger.write("[INFO] setTimePeriod -> timePeriod = " + convertTimePeriodToName(timePeriod)); }
|
||||
|
||||
exitSavingMode();
|
||||
|
||||
} else {
|
||||
|
||||
if (INFO_LOG === true) { logger.write("[INFO] setTimePeriod -> Will ENTER Saving Mode."); }
|
||||
if (INFO_LOG === true) { logger.write("[INFO] setTimePeriod -> pTimePeriod = " + convertTimePeriodToName(pTimePeriod)); }
|
||||
if (INFO_LOG === true) { logger.write("[INFO] setTimePeriod -> timePeriod = " + convertTimePeriodToName(timePeriod)); }
|
||||
|
||||
enterSavingMode();
|
||||
|
||||
}
|
||||
|
||||
function enterSavingMode() {
|
||||
|
||||
try {
|
||||
|
||||
if (INFO_LOG === true) { logger.write("[INFO] setTimePeriod -> enterSavingMode -> Entering function."); }
|
||||
|
||||
switch (timePeriod) {
|
||||
|
||||
case _45_MINUTES_IN_MILISECONDS:
|
||||
{
|
||||
minCursorSize = 3;
|
||||
maxCursorSize = 30;
|
||||
}
|
||||
break;
|
||||
case _40_MINUTES_IN_MILISECONDS:
|
||||
{
|
||||
minCursorSize = 3;
|
||||
maxCursorSize = 20;
|
||||
}
|
||||
break;
|
||||
case _30_MINUTES_IN_MILISECONDS:
|
||||
{
|
||||
minCursorSize = 3;
|
||||
maxCursorSize = 15;
|
||||
}
|
||||
break;
|
||||
case _20_MINUTES_IN_MILISECONDS:
|
||||
{
|
||||
minCursorSize = 3;
|
||||
maxCursorSize = 15;
|
||||
}
|
||||
break;
|
||||
case _15_MINUTES_IN_MILISECONDS:
|
||||
{
|
||||
minCursorSize = 3;
|
||||
maxCursorSize = 15;
|
||||
}
|
||||
break;
|
||||
case _10_MINUTES_IN_MILISECONDS:
|
||||
{
|
||||
minCursorSize = 3;
|
||||
maxCursorSize = 15;
|
||||
}
|
||||
break;
|
||||
case _5_MINUTES_IN_MILISECONDS:
|
||||
{
|
||||
minCursorSize = 3;
|
||||
maxCursorSize = 15;
|
||||
}
|
||||
break;
|
||||
case _4_MINUTES_IN_MILISECONDS:
|
||||
{
|
||||
minCursorSize = 3;
|
||||
maxCursorSize = 15;
|
||||
}
|
||||
break;
|
||||
case _3_MINUTES_IN_MILISECONDS:
|
||||
{
|
||||
minCursorSize = 3;
|
||||
maxCursorSize = 15;
|
||||
}
|
||||
break;
|
||||
case _2_MINUTES_IN_MILISECONDS:
|
||||
{
|
||||
minCursorSize = 3;
|
||||
maxCursorSize = 15;
|
||||
}
|
||||
break;
|
||||
case _1_MINUTE_IN_MILISECONDS:
|
||||
{
|
||||
minCursorSize = 3;
|
||||
maxCursorSize = 15;
|
||||
}
|
||||
break;
|
||||
default:
|
||||
}
|
||||
|
||||
} catch (err) {
|
||||
|
||||
if (ERROR_LOG === true) { logger.write("[ERROR] setTimePeriod -> enterSavingMode -> err = " + err); }
|
||||
}
|
||||
}
|
||||
|
||||
function exitSavingMode() {
|
||||
|
||||
try {
|
||||
|
||||
if (INFO_LOG === true) { logger.write("[INFO] setTimePeriod -> exitSavingMode -> Entering function."); }
|
||||
|
||||
switch (timePeriod) {
|
||||
|
||||
case _45_MINUTES_IN_MILISECONDS:
|
||||
{
|
||||
minCursorSize = 15;
|
||||
maxCursorSize = 30;
|
||||
}
|
||||
break;
|
||||
case _40_MINUTES_IN_MILISECONDS:
|
||||
{
|
||||
minCursorSize = 13;
|
||||
maxCursorSize = 20;
|
||||
}
|
||||
break;
|
||||
case _30_MINUTES_IN_MILISECONDS:
|
||||
{
|
||||
minCursorSize = 11;
|
||||
maxCursorSize = 15;
|
||||
}
|
||||
break;
|
||||
case _20_MINUTES_IN_MILISECONDS:
|
||||
{
|
||||
minCursorSize = 9;
|
||||
maxCursorSize = 15;
|
||||
}
|
||||
break;
|
||||
case _15_MINUTES_IN_MILISECONDS:
|
||||
{
|
||||
minCursorSize = 7;
|
||||
maxCursorSize = 15;
|
||||
}
|
||||
break;
|
||||
case _10_MINUTES_IN_MILISECONDS:
|
||||
{
|
||||
minCursorSize = 7;
|
||||
maxCursorSize = 15;
|
||||
}
|
||||
break;
|
||||
case _5_MINUTES_IN_MILISECONDS:
|
||||
{
|
||||
minCursorSize = 5;
|
||||
maxCursorSize = 15;
|
||||
}
|
||||
break;
|
||||
case _4_MINUTES_IN_MILISECONDS:
|
||||
{
|
||||
minCursorSize = 5;
|
||||
maxCursorSize = 15;
|
||||
}
|
||||
break;
|
||||
case _3_MINUTES_IN_MILISECONDS:
|
||||
{
|
||||
minCursorSize = 5;
|
||||
maxCursorSize = 15;
|
||||
}
|
||||
break;
|
||||
case _2_MINUTES_IN_MILISECONDS:
|
||||
{
|
||||
minCursorSize = 5;
|
||||
maxCursorSize = 15;
|
||||
}
|
||||
break;
|
||||
case _1_MINUTE_IN_MILISECONDS:
|
||||
{
|
||||
minCursorSize = 5;
|
||||
maxCursorSize = 15;
|
||||
}
|
||||
break;
|
||||
default:
|
||||
}
|
||||
|
||||
} catch (err) {
|
||||
|
||||
if (ERROR_LOG === true) { logger.write("[ERROR] setTimePeriod -> exitSavingMode -> err = " + err); }
|
||||
}
|
||||
}
|
||||
|
||||
} catch (err) {
|
||||
|
||||
if (ERROR_LOG === true) { logger.write("[ERROR] setTimePeriod -> err = " + err); }
|
||||
}
|
||||
}
|
||||
|
||||
function setDatetime(pDatetime) {
|
||||
|
||||
try {
|
||||
|
||||
if (INFO_LOG === true) { logger.write("[INFO] setDatetime -> Entering function."); }
|
||||
|
||||
if (pDatetime === undefined) {
|
||||
|
||||
if (ERROR_LOG === true) { logger.write("[ERROR] setDatetime -> Received undefined datetime."); }
|
||||
return;
|
||||
}
|
||||
|
||||
cursorDate = pDatetime;
|
||||
|
||||
} catch (err) {
|
||||
|
||||
if (ERROR_LOG === true) { logger.write("[ERROR] setDatetime -> err = " + err); }
|
||||
}
|
||||
}
|
||||
|
||||
function reload(callBackFunction) {
|
||||
|
||||
try {
|
||||
|
||||
if (INFO_LOG === true) { logger.write("[INFO] reload -> Entering function."); }
|
||||
|
||||
getFiles(callBackFunction);
|
||||
|
||||
collectGarbage(callBackFunction);
|
||||
|
||||
} catch (err) {
|
||||
|
||||
if (ERROR_LOG === true) { logger.write("[ERROR] reload -> err = " + err); }
|
||||
callBackFunction(GLOBAL.DEFAULT_FAIL_RESPONSE);
|
||||
}
|
||||
}
|
||||
|
||||
function getFiles(callBackFunction) {
|
||||
|
||||
try {
|
||||
|
||||
if (INFO_LOG === true) { logger.write("[INFO] getFiles -> Entering function."); }
|
||||
|
||||
let i = 0;
|
||||
let j = 0;
|
||||
|
||||
let dateString;
|
||||
|
||||
getNextFile();
|
||||
|
||||
function getNextFile() {
|
||||
|
||||
try {
|
||||
|
||||
if (INFO_LOG === true) { logger.write("[INFO] getFiles -> getNextFile -> Entering function."); }
|
||||
|
||||
let targetDate = new Date(cursorDate);
|
||||
targetDate.setUTCDate(targetDate.getUTCDate() + j);
|
||||
|
||||
/* Small algorith to allow load first the current date, then alternate between the most forwad and the most backwards ones. */
|
||||
if (j === 0) { j++; }
|
||||
else {
|
||||
if (j < 0) {
|
||||
j = -j;
|
||||
j++;
|
||||
}
|
||||
else {
|
||||
j = -j;
|
||||
}
|
||||
}
|
||||
|
||||
let compareTargetDate = new Date(targetDate.toDateString());
|
||||
|
||||
if (beginDateRange !== undefined) {
|
||||
|
||||
let compareBeginDate = new Date(beginDateRange.toDateString());
|
||||
|
||||
if (compareTargetDate.valueOf() < compareBeginDate.valueOf()) {
|
||||
|
||||
if (INFO_LOG === true) { logger.write("[INFO] getFiles -> getNextFile -> compareTargetDate < compareBeginDate -> Not loading the file for this date."); }
|
||||
if (INFO_LOG === true) { logger.write("[INFO] getFiles -> getNextFile -> compareTargetDate < compareBeginDate -> compareTargetDate = " + compareTargetDate); }
|
||||
if (INFO_LOG === true) { logger.write("[INFO] getFiles -> getNextFile -> compareTargetDate < compareBeginDate -> compareBeginDate = " + compareBeginDate); }
|
||||
|
||||
controlLoop();
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
if (endDateRange !== undefined) {
|
||||
|
||||
let compareEndDate = new Date(endDateRange.toDateString());
|
||||
|
||||
if (compareTargetDate.valueOf() > compareEndDate.valueOf()) {
|
||||
|
||||
if (INFO_LOG === true) { logger.write("[INFO] getFiles -> getNextFile -> compareTargetDate > compareEndDate -> Not loading the file for this date."); }
|
||||
if (INFO_LOG === true) { logger.write("[INFO] getFiles -> getNextFile -> compareTargetDate > compareEndDate -> compareTargetDate = " + compareTargetDate); }
|
||||
if (INFO_LOG === true) { logger.write("[INFO] getFiles -> getNextFile -> compareTargetDate > compareEndDate -> compareEndDate = " + compareEndDate); }
|
||||
|
||||
controlLoop();
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
dateString = targetDate.getUTCFullYear() + '-' + pad(targetDate.getUTCMonth() + 1, 2) + '-' + pad(targetDate.getUTCDate(), 2);
|
||||
|
||||
let currentDay = Math.trunc((new Date()).valueOf() / (24 * 60 * 60 * 1000));
|
||||
let targetDay = Math.trunc(targetDate.valueOf() / (24 * 60 * 60 * 1000));
|
||||
|
||||
if (targetDay > currentDay) {
|
||||
|
||||
controlLoop();
|
||||
|
||||
} else {
|
||||
|
||||
if (thisObject.files.get(dateString) === undefined) { // We dont reload files we already have.
|
||||
|
||||
fileCloud.getFile(devTeam, bot, thisSet, exchange, market, periodName, targetDate, undefined, undefined, onFileReceived);
|
||||
|
||||
} else {
|
||||
|
||||
controlLoop();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
} catch (err) {
|
||||
|
||||
if (ERROR_LOG === true) { logger.write("[ERROR] getFiles -> getNextFile -> err = " + err); }
|
||||
callBackFunction(GLOBAL.DEFAULT_FAIL_RESPONSE);
|
||||
}
|
||||
}
|
||||
|
||||
function onFileReceived(err, file) {
|
||||
|
||||
try {
|
||||
|
||||
if (INFO_LOG === true) { logger.write("[INFO] getFiles -> onFileReceived -> Entering function."); }
|
||||
|
||||
switch (err.result) {
|
||||
case GLOBAL.DEFAULT_OK_RESPONSE.result: {
|
||||
|
||||
if (INFO_LOG === true) { logger.write("[INFO] getFiles -> onFileReceived -> Received OK Response."); }
|
||||
break;
|
||||
}
|
||||
|
||||
case GLOBAL.DEFAULT_FAIL_RESPONSE.result: {
|
||||
|
||||
if (INFO_LOG === true) { logger.write("[INFO] getFiles -> onFileReceived -> Received FAIL Response."); }
|
||||
callBackFunction(GLOBAL.DEFAULT_FAIL_RESPONSE);
|
||||
return;
|
||||
}
|
||||
|
||||
case GLOBAL.CUSTOM_FAIL_RESPONSE.result: {
|
||||
|
||||
if (INFO_LOG === true) { logger.write("[INFO] getFiles -> onFileReceived -> Received CUSTOM FAIL Response."); }
|
||||
if (INFO_LOG === true) { logger.write("[INFO] getFiles -> onFileReceived -> err.message = " + err.message); }
|
||||
|
||||
if (err.message === "File does not exist.") {
|
||||
|
||||
controlLoop();
|
||||
return;
|
||||
|
||||
} else {
|
||||
|
||||
callBackFunction(err);
|
||||
return;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
default: {
|
||||
|
||||
if (INFO_LOG === true) { logger.write("[INFO] getFiles -> onFileReceived -> Received Unexpected Response."); }
|
||||
callBackFunction(err);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
thisObject.files.set(dateString, file);
|
||||
|
||||
controlLoop();
|
||||
|
||||
} catch (err) {
|
||||
|
||||
if (ERROR_LOG === true) { logger.write("[ERROR] getFiles -> onFileReceived -> err = " + err); }
|
||||
callBackFunction(GLOBAL.DEFAULT_FAIL_RESPONSE);
|
||||
}
|
||||
}
|
||||
|
||||
function controlLoop() {
|
||||
|
||||
try {
|
||||
|
||||
if (INFO_LOG === true) { logger.write("[INFO] getFiles -> controlLoop -> Entering function."); }
|
||||
|
||||
if (callBackFunction !== undefined) {
|
||||
|
||||
callBackFunction(GLOBAL.DEFAULT_OK_RESPONSE);
|
||||
|
||||
}
|
||||
|
||||
i++;
|
||||
|
||||
if (i < minCursorSize) {
|
||||
|
||||
getNextFile();
|
||||
|
||||
}
|
||||
|
||||
} catch (err) {
|
||||
|
||||
if (ERROR_LOG === true) { logger.write("[ERROR] getFiles -> controlLoop -> err = " + err); }
|
||||
callBackFunction(GLOBAL.DEFAULT_FAIL_RESPONSE);
|
||||
}
|
||||
}
|
||||
|
||||
} catch (err) {
|
||||
|
||||
if (ERROR_LOG === true) { logger.write("[ERROR] getFiles -> err = " + err); }
|
||||
callBackFunction(GLOBAL.DEFAULT_FAIL_RESPONSE);
|
||||
}
|
||||
}
|
||||
|
||||
function collectGarbage(callBackFunction) {
|
||||
|
||||
try {
|
||||
|
||||
if (INFO_LOG === true) { logger.write("[INFO] collectGarbage -> Entering function."); }
|
||||
|
||||
date = removeTime(cursorDate);
|
||||
|
||||
let minDate = date.valueOf() - maxCursorSize * ONE_DAY_IN_MILISECONDS / 2;
|
||||
let maxDate = date.valueOf() + maxCursorSize * ONE_DAY_IN_MILISECONDS / 2;
|
||||
|
||||
for (let key of thisObject.files.keys()) {
|
||||
|
||||
let keyDate = new Date(key);
|
||||
|
||||
if (keyDate.valueOf() < minDate || keyDate.valueOf() > maxDate) {
|
||||
|
||||
thisObject.files.delete(key);
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
} catch (err) {
|
||||
|
||||
if (ERROR_LOG === true) { logger.write("[ERROR] collectGarbage -> err = " + err); }
|
||||
callBackFunction(GLOBAL.DEFAULT_FAIL_RESPONSE);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
function getExpectedFiles() {
|
||||
|
||||
if (INFO_LOG === true) { logger.write("[INFO] getExpectedFiles -> Entering function."); }
|
||||
|
||||
return minCursorSize;
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,385 +0,0 @@
|
||||
|
||||
function newFileSequence() {
|
||||
|
||||
const MODULE_NAME = "File Sequence";
|
||||
const INFO_LOG = false;
|
||||
const ERROR_LOG = true;
|
||||
const logger = newWebDebugLog();
|
||||
logger.fileName = MODULE_NAME;
|
||||
|
||||
let thisObject = {
|
||||
eventHandler: undefined,
|
||||
getFile: getFile,
|
||||
getExpectedFiles: getExpectedFiles,
|
||||
getFilesLoaded: getFilesLoaded,
|
||||
initialize: initialize,
|
||||
finalize: finalize
|
||||
}
|
||||
|
||||
let filesLoaded = 0;
|
||||
let fileCloud;
|
||||
let files = new Map;
|
||||
let maxSequence = -1; // This is replaced by the content of the sequence file, which contains an index that starts on zero. In the case that the sequence file is not found the default value is -1 so when you add 1 it gives you the amount of files in the sequence, zero.
|
||||
let market;
|
||||
let devTeam;
|
||||
let bot;
|
||||
let thisSet;
|
||||
let product;
|
||||
|
||||
thisObject.eventHandler = newEventHandler();
|
||||
|
||||
let intervalHandle;
|
||||
|
||||
return thisObject;
|
||||
|
||||
function finalize() {
|
||||
|
||||
try {
|
||||
|
||||
if (INFO_LOG === true) { logger.write("[INFO] finalize -> Entering function."); }
|
||||
if (INFO_LOG === true) { logger.write("[INFO] finalize -> devTeam = " + devTeam.codeName); }
|
||||
if (INFO_LOG === true) { logger.write("[INFO] finalize -> bot = " + bot.codeName); }
|
||||
if (INFO_LOG === true) { logger.write("[INFO] finalize -> thisSet = " + thisSet.codeName); }
|
||||
if (INFO_LOG === true) { logger.write("[INFO] finalize -> intervalHandle = " + intervalHandle); }
|
||||
|
||||
clearInterval(intervalHandle);
|
||||
|
||||
filesLoaded = undefined;
|
||||
fileCloud = undefined;
|
||||
files = undefined;
|
||||
maxSequence = undefined;
|
||||
|
||||
} catch (err) {
|
||||
|
||||
if (ERROR_LOG === true) { logger.write("[ERROR] finalize -> err = " + err); }
|
||||
}
|
||||
}
|
||||
|
||||
function initialize(pDevTeam, pBot, pProduct, pSet, pExchange, pMarket, callBackFunction) {
|
||||
|
||||
try {
|
||||
|
||||
if (INFO_LOG === true) { logger.write("[INFO] initialize -> Entering function."); }
|
||||
if (INFO_LOG === true) { logger.write("[INFO] initialize -> key = " + pDevTeam.codeName + "-" + pBot.codeName + "-" + pProduct.codeName); }
|
||||
|
||||
exchange = ecosystem.getExchange(pProduct, pExchange);
|
||||
|
||||
if (exchange === undefined) {
|
||||
|
||||
throw "Exchange not supoorted by this pProduct of the ecosystem! - pDevTeam.codeName = " + pDevTeam.codeName + ", pBot.codeName = " + pBot.codeName + ", pProduct.codeName = " + pProduct.codeName + ", pExchange = " + pExchange;
|
||||
|
||||
}
|
||||
|
||||
intervalHandle = setInterval(updateFiles, _1_MINUTE_IN_MILISECONDS);
|
||||
|
||||
if (INFO_LOG === true) { logger.write("[INFO] initialize -> intervalHandle = " + intervalHandle); }
|
||||
|
||||
market = pMarket;
|
||||
devTeam = pDevTeam;
|
||||
bot = pBot;
|
||||
thisSet = pSet;
|
||||
product = pProduct;
|
||||
|
||||
fileCloud = newFileCloud();
|
||||
fileCloud.initialize(bot);
|
||||
|
||||
/* First we will get the sequence max number */
|
||||
|
||||
fileCloud.getFile(devTeam, bot, thisSet, exchange, market, undefined, undefined, "Sequence", undefined, onSequenceFileReceived);
|
||||
|
||||
function onSequenceFileReceived(err, file) {
|
||||
|
||||
try {
|
||||
|
||||
if (INFO_LOG === true) { logger.write("[INFO] initialize -> onSequenceFileReceived -> Entering function."); }
|
||||
if (INFO_LOG === true) { logger.write("[INFO] initialize -> onSequenceFileReceived -> key = " + devTeam.codeName + "-" + bot.codeName + "-" + product.codeName); }
|
||||
|
||||
switch (err.result) {
|
||||
case GLOBAL.DEFAULT_OK_RESPONSE.result: {
|
||||
|
||||
if (INFO_LOG === true) { logger.write("[INFO] initialize -> onSequenceFileReceived -> Received OK Response."); }
|
||||
break;
|
||||
}
|
||||
|
||||
case GLOBAL.DEFAULT_FAIL_RESPONSE.result: {
|
||||
|
||||
if (INFO_LOG === true) { logger.write("[INFO] initialize -> onSequenceFileReceived -> Received FAIL Response."); }
|
||||
callBackFunction(GLOBAL.DEFAULT_FAIL_RESPONSE);
|
||||
return;
|
||||
}
|
||||
|
||||
case GLOBAL.CUSTOM_OK_RESPONSE.result: {
|
||||
|
||||
if (INFO_LOG === true) { logger.write("[INFO] initialize -> onSequenceFileReceived -> Received CUSTOM OK Response."); }
|
||||
if (INFO_LOG === true) { logger.write("[INFO] initialize -> onSequenceFileReceived -> err.message = " + err.message); }
|
||||
|
||||
callBackFunction(err);
|
||||
return;
|
||||
}
|
||||
|
||||
case GLOBAL.CUSTOM_FAIL_RESPONSE.result: {
|
||||
|
||||
if (INFO_LOG === true) { logger.write("[INFO] initialize -> onSequenceFileReceived -> Received CUSTOM FAIL Response."); }
|
||||
if (INFO_LOG === true) { logger.write("[INFO] initialize -> onSequenceFileReceived -> err.message = " + err.message); }
|
||||
|
||||
callBackFunction(err, thisObject);
|
||||
return;
|
||||
}
|
||||
|
||||
default: {
|
||||
|
||||
if (INFO_LOG === true) { logger.write("[INFO] initialize -> onSequenceFileReceived -> Received Unexpected Response."); }
|
||||
callBackFunction(err);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
maxSequence = Number(file);
|
||||
|
||||
if (INFO_LOG === true) { logger.write("[INFO] initialize -> onSequenceFileReceived -> maxSequence = " + maxSequence); }
|
||||
|
||||
/* Now we will get the sequence of files */
|
||||
|
||||
for (let i = 0; i <= maxSequence; i++) {
|
||||
|
||||
fileCloud.getFile(devTeam, bot, thisSet, exchange, market, undefined, undefined, i, undefined, onFileReceived);
|
||||
|
||||
function onFileReceived(err, file) {
|
||||
|
||||
try {
|
||||
|
||||
switch (err.result) {
|
||||
case GLOBAL.DEFAULT_OK_RESPONSE.result: {
|
||||
|
||||
if (INFO_LOG === true) { logger.write("[INFO] initialize -> onSequenceFileReceived -> onFileReceived -> Received OK Response."); }
|
||||
break;
|
||||
}
|
||||
|
||||
case GLOBAL.DEFAULT_FAIL_RESPONSE.result: {
|
||||
|
||||
if (INFO_LOG === true) { logger.write("[INFO] initialize -> onSequenceFileReceived -> onFileReceived -> Received FAIL Response."); }
|
||||
callBackFunction(GLOBAL.DEFAULT_FAIL_RESPONSE);
|
||||
return;
|
||||
}
|
||||
|
||||
case GLOBAL.CUSTOM_FAIL_RESPONSE.result: {
|
||||
|
||||
if (INFO_LOG === true) { logger.write("[INFO] initialize -> onSequenceFileReceived -> onFileReceived -> Received CUSTOM FAIL Response."); }
|
||||
if (INFO_LOG === true) { logger.write("[INFO] initialize -> onSequenceFileReceived -> onFileReceived -> err.message = " + err.message); }
|
||||
|
||||
callBackFunction(err);
|
||||
return;
|
||||
}
|
||||
|
||||
default: {
|
||||
|
||||
if (INFO_LOG === true) { logger.write("[INFO] initialize -> onSequenceFileReceived -> onFileReceived -> Received Unexpected Response."); }
|
||||
callBackFunction(err);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
files.set(i, file);
|
||||
|
||||
filesLoaded++;
|
||||
|
||||
callBackFunction(GLOBAL.DEFAULT_OK_RESPONSE, thisObject); // Note that the callback is called for every file loaded.
|
||||
|
||||
} catch (err) {
|
||||
|
||||
if (ERROR_LOG === true) { logger.write("[ERROR] initialize -> onSequenceFileReceived -> onFileReceived -> err = " + err); }
|
||||
callBackFunction(GLOBAL.DEFAULT_FAIL_RESPONSE);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
} catch (err) {
|
||||
|
||||
if (ERROR_LOG === true) { logger.write("[ERROR] initialize -> onSequenceFileReceived -> err = " + err); }
|
||||
callBackFunction(GLOBAL.DEFAULT_FAIL_RESPONSE);
|
||||
}
|
||||
}
|
||||
|
||||
} catch (err) {
|
||||
|
||||
if (ERROR_LOG === true) { logger.write("[ERROR] initialize -> err = " + err); }
|
||||
callBackFunction(GLOBAL.DEFAULT_FAIL_RESPONSE);
|
||||
}
|
||||
}
|
||||
|
||||
function updateFiles() {
|
||||
|
||||
try {
|
||||
|
||||
let updateFiles = 0;
|
||||
|
||||
if (INFO_LOG === true) { logger.write("[INFO] updateFiles -> Entering function."); }
|
||||
|
||||
/*
|
||||
|
||||
To keep this data structure up-to-date we need to:
|
||||
|
||||
1. Re-read the sequence file.
|
||||
2. Re-load the current last file.
|
||||
3. Re-load all new files after our last one.
|
||||
|
||||
*/
|
||||
|
||||
let currentMaxSequence = maxSequence;
|
||||
|
||||
if (INFO_LOG === true) { logger.write("[INFO] updateFiles -> currentMaxSequence = " + currentMaxSequence); }
|
||||
if (INFO_LOG === true) { logger.write("[INFO] updateFiles -> intervalHandle = " + intervalHandle); }
|
||||
|
||||
if (INFO_LOG === true) { logger.write("[INFO] updateFiles -> devTeam = " + devTeam.codeName); }
|
||||
if (INFO_LOG === true) { logger.write("[INFO] updateFiles -> bot = " + bot.codeName); }
|
||||
if (INFO_LOG === true) { logger.write("[INFO] updateFiles -> thisSet = " + thisSet.codeName); }
|
||||
|
||||
fileCloud.getFile(devTeam, bot, thisSet, exchange, market, undefined, undefined, "Sequence", undefined, onSequenceFileReceived);
|
||||
|
||||
function onSequenceFileReceived(err, file) {
|
||||
|
||||
try {
|
||||
|
||||
if (INFO_LOG === true) { logger.write("[INFO] updateFiles -> onSequenceFileReceived -> Entering function."); }
|
||||
if (INFO_LOG === true) { logger.write("[INFO] updateFiles -> onSequenceFileReceived -> key = " + devTeam.codeName + "-" + bot.codeName + "-" + product.codeName); }
|
||||
|
||||
switch (err.result) {
|
||||
case GLOBAL.DEFAULT_OK_RESPONSE.result: {
|
||||
|
||||
if (INFO_LOG === true) { logger.write("[INFO] updateFiles -> onSequenceFileReceived -> Received OK Response."); }
|
||||
break;
|
||||
}
|
||||
|
||||
case GLOBAL.DEFAULT_FAIL_RESPONSE.result: {
|
||||
|
||||
if (INFO_LOG === true) { logger.write("[INFO] updateFiles -> onSequenceFileReceived -> Received FAIL Response."); }
|
||||
return;
|
||||
}
|
||||
|
||||
case GLOBAL.CUSTOM_OK_RESPONSE.result: {
|
||||
|
||||
if (INFO_LOG === true) { logger.write("[INFO] updateFiles -> onSequenceFileReceived -> Received CUSTOM OK Response."); }
|
||||
if (INFO_LOG === true) { logger.write("[INFO] updateFiles -> onSequenceFileReceived -> err.message = " + err.message); }
|
||||
return;
|
||||
}
|
||||
|
||||
case GLOBAL.CUSTOM_FAIL_RESPONSE.result: {
|
||||
|
||||
if (INFO_LOG === true) { logger.write("[INFO] updateFiles -> onSequenceFileReceived -> Received CUSTOM FAIL Response."); }
|
||||
if (INFO_LOG === true) { logger.write("[INFO] updateFiles -> onSequenceFileReceived -> err.message = " + err.message); }
|
||||
return;
|
||||
}
|
||||
|
||||
default: {
|
||||
|
||||
if (INFO_LOG === true) { logger.write("[INFO] updateFiles -> onSequenceFileReceived -> Received Unexpected Response."); }
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
maxSequence = Number(file);
|
||||
|
||||
if (INFO_LOG === true) { logger.write("[INFO] updateFiles -> onSequenceFileReceived -> maxSequence = " + maxSequence); }
|
||||
|
||||
/* Now we will get the sequence of files, but in this case only from the currentMaxSequence and above. */
|
||||
|
||||
for (let i = currentMaxSequence; i <= maxSequence; i++) {
|
||||
|
||||
if (INFO_LOG === true) { logger.write("[INFO] updateFiles -> onSequenceFileReceived -> i = " + i); }
|
||||
|
||||
fileCloud.getFile(devTeam, bot, thisSet, exchange, market, undefined, undefined, i, undefined, onFileReceived);
|
||||
|
||||
function onFileReceived(err, file) {
|
||||
|
||||
try {
|
||||
|
||||
switch (err.result) {
|
||||
case GLOBAL.DEFAULT_OK_RESPONSE.result: {
|
||||
|
||||
if (INFO_LOG === true) { logger.write("[INFO] updateFiles -> onSequenceFileReceived -> onFileReceived -> Received OK Response."); }
|
||||
break;
|
||||
}
|
||||
|
||||
case GLOBAL.DEFAULT_FAIL_RESPONSE.result: {
|
||||
|
||||
if (INFO_LOG === true) { logger.write("[INFO] updateFiles -> onSequenceFileReceived -> onFileReceived -> Received FAIL Response."); }
|
||||
return;
|
||||
}
|
||||
|
||||
case GLOBAL.CUSTOM_FAIL_RESPONSE.result: {
|
||||
|
||||
if (INFO_LOG === true) { logger.write("[INFO] updateFiles -> onSequenceFileReceived -> onFileReceived -> Received CUSTOM FAIL Response."); }
|
||||
if (INFO_LOG === true) { logger.write("[INFO] updateFiles -> onSequenceFileReceived -> onFileReceived -> err.message = " + err.message); }
|
||||
return;
|
||||
}
|
||||
|
||||
default: {
|
||||
|
||||
if (INFO_LOG === true) { logger.write("[INFO] updateFiles -> onSequenceFileReceived -> onFileReceived -> Received Unexpected Response."); }
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
files.set(i, file);
|
||||
|
||||
if (INFO_LOG === true) { logger.write("[INFO] updateFiles -> onSequenceFileReceived -> onFileReceived -> File Updated."); }
|
||||
if (INFO_LOG === true) { logger.write("[INFO] updateFiles -> onSequenceFileReceived -> onFileReceived -> i = " + i); }
|
||||
if (INFO_LOG === true) { logger.write("[INFO] updateFiles -> onSequenceFileReceived -> onFileReceived -> file.length = " + file.length); }
|
||||
if (INFO_LOG === true) { logger.write("[INFO] updateFiles -> onSequenceFileReceived -> onFileReceived -> filesLoaded = " + filesLoaded); }
|
||||
|
||||
if (i !== currentMaxSequence) {
|
||||
|
||||
filesLoaded++;
|
||||
if (INFO_LOG === true) { logger.write("[INFO] updateFiles -> onSequenceFileReceived -> onFileReceived -> filesLoaded = " + filesLoaded); }
|
||||
|
||||
}
|
||||
|
||||
if (filesLoaded === maxSequence + 1) {
|
||||
|
||||
thisObject.eventHandler.raiseEvent("Files Updated", undefined);
|
||||
if (INFO_LOG === true) { logger.write("[INFO] updateFiles -> onSequenceFileReceived -> onFileReceived -> Files Updated event Raised."); }
|
||||
|
||||
}
|
||||
|
||||
} catch (err) {
|
||||
if (ERROR_LOG === true) { logger.write("[ERROR] updateFiles -> onSequenceFileReceived -> onFileReceived -> err = " + err); }
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
} catch (err) {
|
||||
if (ERROR_LOG === true) { logger.write("[ERROR] updateFiles -> onSequenceFileReceived -> err = " + err); }
|
||||
}
|
||||
}
|
||||
|
||||
} catch (err) {
|
||||
if (ERROR_LOG === true) { logger.write("[ERROR] updateFiles -> err = " + err); }
|
||||
}
|
||||
}
|
||||
|
||||
function getFile(pSequence) {
|
||||
|
||||
if (INFO_LOG === true) { logger.write("[INFO] getFile -> Entering function."); }
|
||||
if (INFO_LOG === true) { logger.write("[INFO] getFile -> pSequence = " + pSequence); }
|
||||
|
||||
return files.get(pSequence);
|
||||
|
||||
}
|
||||
|
||||
function getExpectedFiles() {
|
||||
|
||||
if (INFO_LOG === true) { logger.write("[INFO] getExpectedFiles -> Entering function."); }
|
||||
|
||||
return maxSequence + 1;
|
||||
|
||||
}
|
||||
|
||||
function getFilesLoaded() {
|
||||
|
||||
if (INFO_LOG === true) { logger.write("[INFO] getFilesLoaded -> Entering function."); }
|
||||
|
||||
return filesLoaded;
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,253 +0,0 @@
|
||||
|
||||
function newMarketFiles() {
|
||||
|
||||
const MODULE_NAME = "Market Files";
|
||||
const INFO_LOG = false;
|
||||
const ERROR_LOG = true;
|
||||
const logger = newWebDebugLog();
|
||||
logger.fileName = MODULE_NAME;
|
||||
|
||||
let thisObject = {
|
||||
eventHandler: undefined,
|
||||
getFile: getFile,
|
||||
getExpectedFiles: getExpectedFiles,
|
||||
getFilesLoaded: getFilesLoaded,
|
||||
initialize: initialize,
|
||||
finalize: finalize
|
||||
}
|
||||
|
||||
let filesLoaded = 0;
|
||||
|
||||
let fileCloud;
|
||||
|
||||
let files = new Map;
|
||||
|
||||
let market;
|
||||
let exchange;
|
||||
let devTeam;
|
||||
let bot;
|
||||
let thisSet;
|
||||
let periodName;
|
||||
|
||||
thisObject.eventHandler = newEventHandler();
|
||||
|
||||
let intervalHandle;
|
||||
|
||||
return thisObject;
|
||||
|
||||
function finalize() {
|
||||
|
||||
try {
|
||||
|
||||
if (INFO_LOG === true) { logger.write("[INFO] finalize -> Entering function."); }
|
||||
|
||||
clearInterval(intervalHandle);
|
||||
|
||||
filesLoaded = undefined;
|
||||
files = undefined;
|
||||
|
||||
} catch (err) {
|
||||
|
||||
if (ERROR_LOG === true) { logger.write("[ERROR] finalize -> err = " + err); }
|
||||
}
|
||||
}
|
||||
|
||||
function initialize(pDevTeam, pBot, pProduct, pSet, pExchange, pMarket, callBackFunction) {
|
||||
|
||||
try {
|
||||
|
||||
if (INFO_LOG === true) { logger.write("[INFO] initialize -> Entering function."); }
|
||||
if (INFO_LOG === true) { logger.write("[INFO] initialize -> key = " + pDevTeam.codeName + "-" + pBot.codeName + "-" + pProduct.codeName); }
|
||||
|
||||
exchange = ecosystem.getExchange(pProduct, pExchange);
|
||||
|
||||
if (exchange === undefined) {
|
||||
|
||||
throw "Exchange not supoorted by this pProduct of the ecosystem! - pDevTeam.codeName = " + pDevTeam.codeName + ", pBot.codeName = " + pBot.codeName + ", pProduct.codeName = " + pProduct.codeName + ", pExchange = " + pExchange;
|
||||
|
||||
}
|
||||
|
||||
intervalHandle = setInterval(updateFiles, _10_MINUTES_IN_MILISECONDS);
|
||||
|
||||
market = pMarket;
|
||||
devTeam = pDevTeam;
|
||||
bot = pBot;
|
||||
thisSet = pSet;
|
||||
|
||||
fileCloud = newFileCloud();
|
||||
fileCloud.initialize(pBot);
|
||||
|
||||
/* Now we will get the market files */
|
||||
|
||||
for (let i = 0; i < marketFilesPeriods.length; i++) {
|
||||
|
||||
let periodTime = marketFilesPeriods[i][0];
|
||||
let periodName = marketFilesPeriods[i][1];
|
||||
|
||||
if (thisSet.validPeriods.includes(periodName) === true) {
|
||||
|
||||
fileCloud.getFile(devTeam, bot, thisSet, exchange, market, periodName, undefined, undefined, undefined, onFileReceived);
|
||||
|
||||
function onFileReceived(err, file) {
|
||||
|
||||
try {
|
||||
|
||||
if (INFO_LOG === true) { logger.write("[INFO] initialize -> onFileReceived -> Entering function."); }
|
||||
|
||||
switch (err.result) {
|
||||
case GLOBAL.DEFAULT_OK_RESPONSE.result: {
|
||||
|
||||
if (INFO_LOG === true) { logger.write("[INFO] initialize -> onFileReceived -> Received OK Response."); }
|
||||
break;
|
||||
}
|
||||
|
||||
case GLOBAL.DEFAULT_FAIL_RESPONSE.result: {
|
||||
|
||||
if (INFO_LOG === true) { logger.write("[INFO] initialize -> onFileReceived -> Received FAIL Response."); }
|
||||
callBackFunction(GLOBAL.DEFAULT_FAIL_RESPONSE);
|
||||
return;
|
||||
}
|
||||
|
||||
case GLOBAL.CUSTOM_FAIL_RESPONSE.result: {
|
||||
|
||||
if (INFO_LOG === true) { logger.write("[INFO] initialize -> onFileReceived -> Received CUSTOM FAIL Response."); }
|
||||
if (INFO_LOG === true) { logger.write("[INFO] initialize -> onFileReceived -> err.message = " + err.message); }
|
||||
|
||||
callBackFunction(err);
|
||||
return;
|
||||
}
|
||||
|
||||
default: {
|
||||
|
||||
if (INFO_LOG === true) { logger.write("[INFO] initialize -> onFileReceived -> Received Unexpected Response."); }
|
||||
callBackFunction(err);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
files.set(periodTime, file);
|
||||
|
||||
filesLoaded++;
|
||||
|
||||
callBackFunction(GLOBAL.DEFAULT_OK_RESPONSE, thisObject); // Note that the callback is called for every file loaded.
|
||||
|
||||
} catch (err) {
|
||||
|
||||
if (ERROR_LOG === true) { logger.write("[ERROR] initialize -> onFileReceived -> err = " + err); }
|
||||
callBackFunction(GLOBAL.DEFAULT_FAIL_RESPONSE);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
} catch (err) {
|
||||
|
||||
if (ERROR_LOG === true) { logger.write("[ERROR] initialize -> err = " + err); }
|
||||
callBackFunction(GLOBAL.DEFAULT_FAIL_RESPONSE);
|
||||
}
|
||||
}
|
||||
|
||||
function updateFiles() {
|
||||
|
||||
try {
|
||||
|
||||
let updateFiles = 0;
|
||||
|
||||
if (INFO_LOG === true) { logger.write("[INFO] updateFiles -> Entering function."); }
|
||||
|
||||
/* Now we will get the market files */
|
||||
|
||||
for (let i = 0; i < marketFilesPeriods.length; i++) {
|
||||
|
||||
let periodTime = marketFilesPeriods[i][0];
|
||||
let periodName = marketFilesPeriods[i][1];
|
||||
|
||||
if (thisSet.validPeriods.includes(periodName) === true) {
|
||||
|
||||
fileCloud.getFile(devTeam, bot, thisSet, exchange, market, periodName, undefined, undefined, undefined, onFileReceived);
|
||||
|
||||
function onFileReceived(err, file) {
|
||||
|
||||
try {
|
||||
|
||||
if (INFO_LOG === true) { logger.write("[INFO] updateFiles -> onFileReceived -> Entering function."); }
|
||||
|
||||
switch (err.result) {
|
||||
case GLOBAL.DEFAULT_OK_RESPONSE.result: {
|
||||
|
||||
if (INFO_LOG === true) { logger.write("[INFO] updateFiles -> onFileReceived -> Received OK Response."); }
|
||||
break;
|
||||
}
|
||||
|
||||
case GLOBAL.DEFAULT_FAIL_RESPONSE.result: {
|
||||
|
||||
if (INFO_LOG === true) { logger.write("[INFO] updateFiles -> onFileReceived -> Received FAIL Response."); }
|
||||
return;
|
||||
}
|
||||
|
||||
case GLOBAL.CUSTOM_FAIL_RESPONSE.result: {
|
||||
|
||||
if (INFO_LOG === true) { logger.write("[INFO] updateFiles -> onFileReceived -> Received CUSTOM FAIL Response."); }
|
||||
if (INFO_LOG === true) { logger.write("[INFO] updateFiles -> onFileReceived -> err.message = " + err.message); }
|
||||
return;
|
||||
}
|
||||
|
||||
default: {
|
||||
|
||||
if (INFO_LOG === true) { logger.write("[INFO] updateFiles -> onFileReceived -> Received Unexpected Response."); }
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
files.set(periodTime, file);
|
||||
updateFiles++;
|
||||
|
||||
if (updateFiles === marketFilesPeriods.length) {
|
||||
|
||||
if (INFO_LOG === true) { logger.write("[INFO] updateFiles -> onFileReceived -> All files received. "); }
|
||||
if (INFO_LOG === true) { logger.write("[INFO] updateFiles -> onFileReceived -> devTeam = " + devTeam.codeName); }
|
||||
if (INFO_LOG === true) { logger.write("[INFO] updateFiles -> onFileReceived -> bot = " + bot.codeName); }
|
||||
if (INFO_LOG === true) { logger.write("[INFO] updateFiles -> onFileReceived -> thisSet = " + thisSet.codeName); }
|
||||
|
||||
thisObject.eventHandler.raiseEvent("Files Updated", undefined);
|
||||
}
|
||||
|
||||
} catch (err) {
|
||||
|
||||
if (ERROR_LOG === true) { logger.write("[ERROR] updateFiles -> onFileReceived -> err = " + err); }
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
} catch (err) {
|
||||
|
||||
if (ERROR_LOG === true) { logger.write("[ERROR] updateFiles -> err = " + err); }
|
||||
}
|
||||
}
|
||||
|
||||
function getFile(pPeriod) {
|
||||
|
||||
if (INFO_LOG === true) { logger.write("[INFO] getFile -> Entering function."); }
|
||||
|
||||
return files.get(pPeriod);
|
||||
|
||||
}
|
||||
|
||||
function getExpectedFiles() {
|
||||
|
||||
if (INFO_LOG === true) { logger.write("[INFO] getExpectedFiles -> Entering function."); }
|
||||
|
||||
return marketFilesPeriods.length;
|
||||
|
||||
}
|
||||
|
||||
function getFilesLoaded() {
|
||||
|
||||
if (INFO_LOG === true) { logger.write("[INFO] getFilesLoaded -> Entering function."); }
|
||||
|
||||
return filesLoaded;
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,105 +0,0 @@
|
||||
|
||||
function newSingleFile() {
|
||||
|
||||
const MODULE_NAME = "Single File";
|
||||
const INFO_LOG = false;
|
||||
const ERROR_LOG = true;
|
||||
const logger = newWebDebugLog();
|
||||
logger.fileName = MODULE_NAME;
|
||||
|
||||
let thisObject = {
|
||||
getFile: getFile,
|
||||
initialize: initialize
|
||||
}
|
||||
|
||||
let fileCloud;
|
||||
let file;
|
||||
|
||||
return thisObject;
|
||||
|
||||
function initialize(pDevTeam, pBot, pProduct, pSet, pExchange, pMarket, callBackFunction) {
|
||||
|
||||
try {
|
||||
|
||||
if (INFO_LOG === true) { logger.write("[INFO] initialize -> Entering function."); }
|
||||
if (INFO_LOG === true) { logger.write("[INFO] initialize -> key = " + pDevTeam.codeName + "-" + pBot.codeName + "-" + pProduct.codeName); }
|
||||
|
||||
let exchange = ecosystem.getExchange(pProduct, pExchange);
|
||||
|
||||
if (pExchange !== undefined && exchange === undefined) { // We support no exchange as a parameter, but if provided, then it must be at the list of exchanges of that product.
|
||||
|
||||
throw "Exchange not supoorted by this pProduct of the ecosystem! - pDevTeam.codeName = " + pDevTeam.codeName + ", pBot.codeName = " + pBot.codeName + ", pProduct.codeName = " + pProduct.codeName + ", pExchange = " + pExchange;
|
||||
|
||||
}
|
||||
|
||||
fileCloud = newFileCloud();
|
||||
fileCloud.initialize(pBot);
|
||||
|
||||
/* Now we will get the file */
|
||||
|
||||
fileCloud.getFile(pDevTeam, pBot, pSet, exchange, pMarket, undefined, undefined, undefined, undefined, onFileReceived);
|
||||
|
||||
function onFileReceived(err, pFile) {
|
||||
|
||||
try {
|
||||
|
||||
if (INFO_LOG === true) { logger.write("[INFO] initialize -> onFileReceived -> Entering function."); }
|
||||
|
||||
switch (err.result) {
|
||||
case GLOBAL.DEFAULT_OK_RESPONSE.result: {
|
||||
|
||||
if (INFO_LOG === true) { logger.write("[INFO] initialize -> onFileReceived -> Received OK Response."); }
|
||||
break;
|
||||
}
|
||||
|
||||
case GLOBAL.DEFAULT_FAIL_RESPONSE.result: {
|
||||
|
||||
if (INFO_LOG === true) { logger.write("[INFO] initialize -> onFileReceived -> Received FAIL Response."); }
|
||||
callBackFunction(GLOBAL.DEFAULT_FAIL_RESPONSE);
|
||||
return;
|
||||
}
|
||||
|
||||
case GLOBAL.CUSTOM_FAIL_RESPONSE.result: {
|
||||
|
||||
if (INFO_LOG === true) { logger.write("[INFO] initialize -> onFileReceived -> Received CUSTOM FAIL Response."); }
|
||||
if (INFO_LOG === true) { logger.write("[INFO] initialize -> onFileReceived -> err.message = " + err.message); }
|
||||
|
||||
callBackFunction(err);
|
||||
return;
|
||||
}
|
||||
|
||||
default: {
|
||||
|
||||
if (INFO_LOG === true) { logger.write("[INFO] initialize -> onFileReceived -> Received Unexpected Response."); }
|
||||
callBackFunction(err);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
file = pFile;
|
||||
|
||||
callBackFunction(GLOBAL.DEFAULT_OK_RESPONSE);
|
||||
|
||||
} catch (err) {
|
||||
|
||||
if (ERROR_LOG === true) { logger.write("[ERROR] initialize -> onFileReceived -> err = " + err); }
|
||||
callBackFunction(GLOBAL.DEFAULT_FAIL_RESPONSE);
|
||||
}
|
||||
}
|
||||
|
||||
} catch (err) {
|
||||
|
||||
if (ERROR_LOG === true) { logger.write("[ERROR] initialize -> err = " + err); }
|
||||
callBackFunction(GLOBAL.DEFAULT_FAIL_RESPONSE);
|
||||
}
|
||||
}
|
||||
|
||||
function getFile() {
|
||||
|
||||
if (INFO_LOG === true) { logger.write("[INFO] getFile -> Entering function."); }
|
||||
|
||||
return file;
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
+660
-787
File diff suppressed because it is too large.
Load diff
+185
-219
@@ -1,274 +1,240 @@
|
||||
|
||||
function newFloatingObject() {
|
||||
|
||||
function newFloatingObject () {
|
||||
const MODULE_NAME = 'Floating Object'
|
||||
const INFO_LOG = false
|
||||
const INTENSIVE_LOG = false
|
||||
const ERROR_LOG = true
|
||||
|
||||
const MODULE_NAME = "Floating Object";
|
||||
const INFO_LOG = false;
|
||||
const INTENSIVE_LOG = false;
|
||||
const ERROR_LOG = true;
|
||||
const logger = newWebDebugLog()
|
||||
logger.fileName = MODULE_NAME
|
||||
|
||||
const logger = newWebDebugLog();
|
||||
logger.fileName = MODULE_NAME;
|
||||
var thisObject = {
|
||||
|
||||
var thisObject = {
|
||||
physicsLoop: physicsLoop,
|
||||
eventHandler: undefined,
|
||||
|
||||
physicsLoop: physicsLoop,
|
||||
eventHandler: undefined,
|
||||
payload: undefined, // This is a reference to an object controlled by a Plotter. The plotter can change its internal value and we will see them from here.
|
||||
type: undefined, // Currently there are two types of Floating Objects: Profile Balls, and Notes.
|
||||
|
||||
payload: undefined, // This is a reference to an object controlled by a Plotter. The plotter can change its internal value and we will see them from here.
|
||||
type: undefined, // Currently there are two types of Floating Objects: Profile Balls, and Notes.
|
||||
physicsEnabled: false,
|
||||
|
||||
physicsEnabled: false,
|
||||
initializeMass: initializeMass,
|
||||
initializeRadius: initializeRadius,
|
||||
initializeImageSize: initializeImageSize,
|
||||
initializeFontSize: initializeFontSize,
|
||||
|
||||
initializeMass: initializeMass,
|
||||
initializeRadius: initializeRadius,
|
||||
initializeImageSize: initializeImageSize,
|
||||
initializeFontSize: initializeFontSize,
|
||||
imageId: undefined,
|
||||
|
||||
imageId: undefined,
|
||||
currentPosition: 0, // Current x,y position of the floating object at the floating object's layer, where there is no displacement or zoom. This position is always changing towards the target position.
|
||||
currentSpeed: 0, // This is the current speed of the floating object.
|
||||
currentRadius: 0, // This is the current radius of the floating object, including its zoom applied.
|
||||
currentMass: 0, // This is the current mass of the floating object, including its zoom applied.
|
||||
|
||||
currentPosition: 0, // Current x,y position of the floating object at the floating object's layer, where there is no displacement or zoom. This position is always changing towards the target position.
|
||||
currentSpeed: 0, // This is the current speed of the floating object.
|
||||
currentRadius: 0, // This is the current radius of the floating object, including its zoom applied.
|
||||
currentMass: 0, // This is the current mass of the floating object, including its zoom applied.
|
||||
friction: 0, // This is a factor that will ultimatelly desacelerate the floating object.
|
||||
|
||||
friction: 0, // This is a factor that will ultimatelly desacelerate the floating object.
|
||||
rawMass: 0, // This is the mass value without zoom.
|
||||
rawRadius: 0, // This is the radius of this floating object without zoom.
|
||||
|
||||
rawMass: 0, // This is the mass value without zoom.
|
||||
rawRadius: 0, // This is the radius of this floating object without zoom.
|
||||
targetRadius: 0, // This is the target radius of the floating object with zoom applied. It should be animated until reaching this value.
|
||||
|
||||
targetRadius: 0, // This is the target radius of the floating object with zoom applied. It should be animated until reaching this value.
|
||||
fillStyle: '',
|
||||
|
||||
fillStyle: '',
|
||||
labelStrokeStyle: '',
|
||||
|
||||
labelStrokeStyle: '',
|
||||
radomizeCurrentPosition: radomizeCurrentPosition,
|
||||
radomizeCurrentSpeed: radomizeCurrentSpeed,
|
||||
|
||||
radomizeCurrentPosition: radomizeCurrentPosition,
|
||||
radomizeCurrentSpeed: radomizeCurrentSpeed,
|
||||
drawBackground: drawBackground,
|
||||
drawForeground: drawForeground,
|
||||
|
||||
drawBackground: drawBackground,
|
||||
drawForeground: drawForeground,
|
||||
updateMass: updateMass, // Function to update the mass when the zoom level changed.
|
||||
updateRadius: updateRadius, // Function to update the radius when the zoom level changed.
|
||||
|
||||
updateMass: updateMass, // Function to update the mass when the zoom level changed.
|
||||
updateRadius: updateRadius, // Function to update the radius when the zoom level changed.
|
||||
linkedObject: undefined, // This is a reference to the object that this floating object is representing.
|
||||
linkedObjectType: '', // Since there might be floating objects for different types of objects, here we store the type of object we are linking to.
|
||||
|
||||
linkedObject: undefined, // This is a reference to the object that this floating object is representing.
|
||||
linkedObjectType: "", // Since there might be floating objects for different types of objects, here we store the type of object we are linking to.
|
||||
container: undefined, // This is a pointer to the object where the floating object belongs to.
|
||||
initialize: initialize
|
||||
|
||||
container: undefined, // This is a pointer to the object where the floating object belongs to.
|
||||
initialize: initialize
|
||||
}
|
||||
|
||||
};
|
||||
let underlayingObject
|
||||
|
||||
let underlayingObject;
|
||||
thisObject.eventHandler = newEventHandler()
|
||||
|
||||
thisObject.eventHandler = newEventHandler();
|
||||
return thisObject
|
||||
|
||||
return thisObject;
|
||||
function initialize (pType, callBackFunction) {
|
||||
try {
|
||||
if (INFO_LOG === true) { logger.write('[INFO] initialize -> Entering function.') }
|
||||
|
||||
function initialize(pType, callBackFunction) {
|
||||
switch (pType) {
|
||||
|
||||
try {
|
||||
case 'Profile Ball': {
|
||||
underlayingObject = newProfileBall()
|
||||
underlayingObject.initialize(onInitialized)
|
||||
|
||||
if (INFO_LOG === true) { logger.write("[INFO] initialize -> Entering function."); }
|
||||
function onInitialized (err) {
|
||||
|
||||
switch (pType) {
|
||||
}
|
||||
|
||||
case "Profile Ball": {
|
||||
|
||||
underlayingObject = newProfileBall();
|
||||
underlayingObject.initialize(onInitialized);
|
||||
|
||||
function onInitialized(err) {
|
||||
|
||||
|
||||
}
|
||||
|
||||
break;
|
||||
}
|
||||
case "Note": {
|
||||
|
||||
underlayingObject = newNote();
|
||||
underlayingObject.initialize(onInitialized);
|
||||
|
||||
function onInitialized(err) {
|
||||
|
||||
|
||||
}
|
||||
break;
|
||||
}
|
||||
default: {
|
||||
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
thisObject.type = pType;
|
||||
|
||||
thisObject.eventHandler.listenToEvent("onMouseOver", onMouseOver);
|
||||
canvas.eventHandler.listenToEvent("onMouseNotOver", onMouseNotOver);
|
||||
thisObject.eventHandler.listenToEvent("onMouseClick", onMouseClick);
|
||||
|
||||
if (callBackFunction !== undefined) { callBackFunction(GLOBAL.DEFAULT_OK_RESPONSE); }
|
||||
|
||||
} catch (err) {
|
||||
|
||||
if (ERROR_LOG === true) { logger.write("[ERROR] initialize -> err.message = " + err.message); }
|
||||
if (callBackFunction !== undefined) { callBackFunction(GLOBAL.DEFAULT_FAIL_RESPONSE); }
|
||||
break
|
||||
}
|
||||
}
|
||||
case 'Note': {
|
||||
underlayingObject = newNote()
|
||||
underlayingObject.initialize(onInitialized)
|
||||
|
||||
function physicsLoop(callBackFunction) {
|
||||
function onInitialized (err) {
|
||||
|
||||
try {
|
||||
|
||||
if (INFO_LOG === true) { logger.write("[INFO] initialize -> Entering function."); }
|
||||
|
||||
underlayingObject.physicsLoop();
|
||||
|
||||
if (callBackFunction !== undefined) { callBackFunction(GLOBAL.DEFAULT_OK_RESPONSE); }
|
||||
|
||||
} catch (err) {
|
||||
|
||||
if (ERROR_LOG === true) { logger.write("[ERROR] physicsLoop -> err.message = " + err.message); }
|
||||
if (callBackFunction !== undefined) { callBackFunction(GLOBAL.DEFAULT_FAIL_RESPONSE); }
|
||||
}
|
||||
}
|
||||
|
||||
function onMouseOver() {
|
||||
|
||||
thisObject.targetRadius = thisObject.rawRadius * 1.5;
|
||||
thisObject.targetImageSize = thisObject.rawImageSize * 1.5;
|
||||
thisObject.targetFontSize = thisObject.rawFontSize * 1.5;
|
||||
|
||||
underlayingObject.onMouseOver();
|
||||
}
|
||||
|
||||
function onMouseNotOver() {
|
||||
|
||||
thisObject.targetRadius = thisObject.rawRadius * 1;
|
||||
thisObject.targetImageSize = thisObject.rawImageSize * 1;
|
||||
thisObject.targetFontSize = thisObject.rawFontSize * 1;
|
||||
|
||||
underlayingObject.onMouseNotOver();
|
||||
}
|
||||
|
||||
function onMouseClick(pPoint) {
|
||||
|
||||
underlayingObject.onMouseClick(pPoint, thisObject);
|
||||
|
||||
}
|
||||
|
||||
function drawBackground() {
|
||||
|
||||
underlayingObject.drawBackground(thisObject);
|
||||
|
||||
}
|
||||
|
||||
function drawForeground() {
|
||||
|
||||
underlayingObject.drawForeground(thisObject);
|
||||
|
||||
}
|
||||
|
||||
function initializeMass(suggestedValue) {
|
||||
|
||||
var mass = suggestedValue;
|
||||
if (mass < 0.1) {
|
||||
mass = 0.1;
|
||||
}
|
||||
break
|
||||
}
|
||||
|
||||
thisObject.rawMass = mass;
|
||||
thisObject.currentMass = mass;
|
||||
|
||||
}
|
||||
|
||||
function initializeRadius(suggestedValue) {
|
||||
|
||||
var radius = suggestedValue;
|
||||
if (radius < 2) {
|
||||
radius = 2;
|
||||
default: {
|
||||
break
|
||||
}
|
||||
}
|
||||
|
||||
thisObject.rawRadius = radius;
|
||||
thisObject.targetRadius = radius;
|
||||
thisObject.currentRadius = radius / 3;
|
||||
thisObject.type = pType
|
||||
|
||||
thisObject.eventHandler.listenToEvent('onMouseOver', onMouseOver)
|
||||
canvas.eventHandler.listenToEvent('onMouseNotOver', onMouseNotOver)
|
||||
thisObject.eventHandler.listenToEvent('onMouseClick', onMouseClick)
|
||||
|
||||
if (callBackFunction !== undefined) { callBackFunction(GLOBAL.DEFAULT_OK_RESPONSE) }
|
||||
} catch (err) {
|
||||
if (ERROR_LOG === true) { logger.write('[ERROR] initialize -> err.message = ' + err.message) }
|
||||
if (callBackFunction !== undefined) { callBackFunction(GLOBAL.DEFAULT_FAIL_RESPONSE) }
|
||||
}
|
||||
}
|
||||
|
||||
function physicsLoop (callBackFunction) {
|
||||
try {
|
||||
if (INFO_LOG === true) { logger.write('[INFO] initialize -> Entering function.') }
|
||||
|
||||
underlayingObject.physicsLoop()
|
||||
|
||||
if (callBackFunction !== undefined) { callBackFunction(GLOBAL.DEFAULT_OK_RESPONSE) }
|
||||
} catch (err) {
|
||||
if (ERROR_LOG === true) { logger.write('[ERROR] physicsLoop -> err.message = ' + err.message) }
|
||||
if (callBackFunction !== undefined) { callBackFunction(GLOBAL.DEFAULT_FAIL_RESPONSE) }
|
||||
}
|
||||
}
|
||||
|
||||
function onMouseOver () {
|
||||
thisObject.targetRadius = thisObject.rawRadius * 1.5
|
||||
thisObject.targetImageSize = thisObject.rawImageSize * 1.5
|
||||
thisObject.targetFontSize = thisObject.rawFontSize * 1.5
|
||||
|
||||
underlayingObject.onMouseOver()
|
||||
}
|
||||
|
||||
function onMouseNotOver () {
|
||||
thisObject.targetRadius = thisObject.rawRadius * 1
|
||||
thisObject.targetImageSize = thisObject.rawImageSize * 1
|
||||
thisObject.targetFontSize = thisObject.rawFontSize * 1
|
||||
|
||||
underlayingObject.onMouseNotOver()
|
||||
}
|
||||
|
||||
function onMouseClick (pPoint) {
|
||||
underlayingObject.onMouseClick(pPoint, thisObject)
|
||||
}
|
||||
|
||||
function drawBackground () {
|
||||
underlayingObject.drawBackground(thisObject)
|
||||
}
|
||||
|
||||
function drawForeground () {
|
||||
underlayingObject.drawForeground(thisObject)
|
||||
}
|
||||
|
||||
function initializeMass (suggestedValue) {
|
||||
var mass = suggestedValue
|
||||
if (mass < 0.1) {
|
||||
mass = 0.1
|
||||
}
|
||||
|
||||
function initializeImageSize(suggestedValue) {
|
||||
|
||||
var size = suggestedValue;
|
||||
if (size < 2) {
|
||||
size = 2;
|
||||
}
|
||||
|
||||
thisObject.rawImageSize = size;
|
||||
thisObject.targetImageSize = size;
|
||||
thisObject.currentImageSize = size / 3;
|
||||
thisObject.rawMass = mass
|
||||
thisObject.currentMass = mass
|
||||
}
|
||||
|
||||
function initializeRadius (suggestedValue) {
|
||||
var radius = suggestedValue
|
||||
if (radius < 2) {
|
||||
radius = 2
|
||||
}
|
||||
|
||||
function initializeFontSize(suggestedValue) {
|
||||
|
||||
var size = suggestedValue;
|
||||
if (size < 3) {
|
||||
size = 3;
|
||||
}
|
||||
|
||||
thisObject.rawFontSize = size;
|
||||
thisObject.targetFontSize = size;
|
||||
thisObject.currentFontSize = size / 3;
|
||||
thisObject.rawRadius = radius
|
||||
thisObject.targetRadius = radius
|
||||
thisObject.currentRadius = radius / 3
|
||||
}
|
||||
|
||||
function initializeImageSize (suggestedValue) {
|
||||
var size = suggestedValue
|
||||
if (size < 2) {
|
||||
size = 2
|
||||
}
|
||||
|
||||
function radomizeCurrentPosition(arroundPoint) {
|
||||
thisObject.rawImageSize = size
|
||||
thisObject.targetImageSize = size
|
||||
thisObject.currentImageSize = size / 3
|
||||
}
|
||||
|
||||
var position = {
|
||||
x: Math.floor((Math.random() * (200) - 100)) + arroundPoint.x,
|
||||
y: Math.floor((Math.random() * (200) - 100)) + arroundPoint.y
|
||||
};
|
||||
|
||||
thisObject.currentPosition = position;
|
||||
function initializeFontSize (suggestedValue) {
|
||||
var size = suggestedValue
|
||||
if (size < 3) {
|
||||
size = 3
|
||||
}
|
||||
|
||||
function radomizeCurrentSpeed() {
|
||||
thisObject.rawFontSize = size
|
||||
thisObject.targetFontSize = size
|
||||
thisObject.currentFontSize = size / 3
|
||||
}
|
||||
|
||||
var initialXDirection;
|
||||
var randomX = Math.floor((Math.random() * 10) + 1);
|
||||
if (randomX > 5) {
|
||||
initialXDirection = 1;
|
||||
} else {
|
||||
initialXDirection = - 1;
|
||||
}
|
||||
|
||||
var initialYDirection;
|
||||
var randomY = Math.floor((Math.random() * 10) + 1);
|
||||
if (randomY > 5) {
|
||||
initialYDirection = 1;
|
||||
} else {
|
||||
initialYDirection = - 1;
|
||||
}
|
||||
|
||||
var velocity = {
|
||||
x: initialXDirection * Math.floor((Math.random() * 300) + 1) / 100,
|
||||
y: initialYDirection * Math.floor((Math.random() * 300) + 1) / 100
|
||||
};
|
||||
|
||||
thisObject.currentSpeed = velocity;
|
||||
function radomizeCurrentPosition (arroundPoint) {
|
||||
var position = {
|
||||
x: Math.floor((Math.random() * (200) - 100)) + arroundPoint.x,
|
||||
y: Math.floor((Math.random() * (200) - 100)) + arroundPoint.y
|
||||
}
|
||||
|
||||
function updateMass() {
|
||||
|
||||
//thisObject.currentMass = thisObject.rawMass + thisObject.rawMass * thisObject.container.zoom.incrementM * thisObject.container.zoom.levelM;
|
||||
thisObject.currentPosition = position
|
||||
}
|
||||
|
||||
function radomizeCurrentSpeed () {
|
||||
var initialXDirection
|
||||
var randomX = Math.floor((Math.random() * 10) + 1)
|
||||
if (randomX > 5) {
|
||||
initialXDirection = 1
|
||||
} else {
|
||||
initialXDirection = -1
|
||||
}
|
||||
|
||||
function updateRadius() {
|
||||
|
||||
//thisObject.targetRadius = thisObject.rawRadius + thisObject.rawRadius * thisObject.container.zoom.incrementR * thisObject.container.zoom.levelR;
|
||||
|
||||
var initialYDirection
|
||||
var randomY = Math.floor((Math.random() * 10) + 1)
|
||||
if (randomY > 5) {
|
||||
initialYDirection = 1
|
||||
} else {
|
||||
initialYDirection = -1
|
||||
}
|
||||
|
||||
var velocity = {
|
||||
x: initialXDirection * Math.floor((Math.random() * 300) + 1) / 100,
|
||||
y: initialYDirection * Math.floor((Math.random() * 300) + 1) / 100
|
||||
}
|
||||
|
||||
thisObject.currentSpeed = velocity
|
||||
}
|
||||
|
||||
function updateMass () {
|
||||
|
||||
// thisObject.currentMass = thisObject.rawMass + thisObject.rawMass * thisObject.container.zoom.incrementM * thisObject.container.zoom.levelM;
|
||||
|
||||
}
|
||||
|
||||
function updateRadius () {
|
||||
|
||||
// thisObject.targetRadius = thisObject.rawRadius + thisObject.rawRadius * thisObject.container.zoom.incrementR * thisObject.container.zoom.levelR;
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
+212
-244
@@ -1,336 +1,304 @@
|
||||
|
||||
function newNote() {
|
||||
|
||||
function newNote () {
|
||||
var thisObject = {
|
||||
|
||||
var thisObject = {
|
||||
physicsLoop: physicsLoop,
|
||||
onMouseOver: onMouseOver,
|
||||
onMouseClick: onMouseClick,
|
||||
onMouseNotOver: onMouseNotOver,
|
||||
drawBackground: drawBackground,
|
||||
drawForeground: drawForeground,
|
||||
initialize: initialize
|
||||
|
||||
physicsLoop: physicsLoop,
|
||||
onMouseOver: onMouseOver,
|
||||
onMouseClick: onMouseClick,
|
||||
onMouseNotOver: onMouseNotOver,
|
||||
drawBackground: drawBackground,
|
||||
drawForeground: drawForeground,
|
||||
initialize: initialize
|
||||
}
|
||||
|
||||
};
|
||||
return thisObject
|
||||
|
||||
return thisObject;
|
||||
function initialize (callBackFunction) {
|
||||
callBackFunction()
|
||||
}
|
||||
|
||||
function initialize(callBackFunction) {
|
||||
function physicsLoop () {
|
||||
|
||||
callBackFunction();
|
||||
}
|
||||
|
||||
function onMouseOver () {
|
||||
|
||||
}
|
||||
|
||||
function onMouseNotOver () {
|
||||
|
||||
}
|
||||
|
||||
function onMouseClick (pPoint, pFloatingObject) {
|
||||
|
||||
}
|
||||
|
||||
function drawBackground (pFloatingObject) {
|
||||
let point = {
|
||||
x: pFloatingObject.payload.notes[pFloatingObject.payloadNoteIndex].position.x,
|
||||
y: pFloatingObject.payload.notes[pFloatingObject.payloadNoteIndex].position.y
|
||||
}
|
||||
|
||||
function physicsLoop() {
|
||||
|
||||
}
|
||||
|
||||
function onMouseOver() {
|
||||
|
||||
}
|
||||
|
||||
function onMouseNotOver() {
|
||||
|
||||
}
|
||||
|
||||
function onMouseClick(pPoint, pFloatingObject) {
|
||||
|
||||
}
|
||||
|
||||
function drawBackground(pFloatingObject) {
|
||||
|
||||
let point = {
|
||||
x: pFloatingObject.payload.notes[pFloatingObject.payloadNoteIndex].position.x,
|
||||
y: pFloatingObject.payload.notes[pFloatingObject.payloadNoteIndex].position.y
|
||||
};
|
||||
|
||||
point = viewPort.fitIntoVisibleArea(point);
|
||||
|
||||
if (pFloatingObject.currentRadius > 1) {
|
||||
point = viewPort.fitIntoVisibleArea(point)
|
||||
|
||||
if (pFloatingObject.currentRadius > 1) {
|
||||
/* Target Line */
|
||||
|
||||
browserCanvasContext.beginPath();
|
||||
browserCanvasContext.moveTo(pFloatingObject.currentPosition.x, pFloatingObject.currentPosition.y);
|
||||
browserCanvasContext.lineTo(point.x, point.y);
|
||||
browserCanvasContext.strokeStyle = 'rgba(204, 204, 204, 0.5)';
|
||||
browserCanvasContext.setLineDash([4, 2]);
|
||||
browserCanvasContext.lineWidth = 1;
|
||||
browserCanvasContext.stroke();
|
||||
browserCanvasContext.setLineDash([0, 0]);
|
||||
|
||||
}
|
||||
|
||||
if (pFloatingObject.currentRadius > 0.5) {
|
||||
|
||||
/* Target Spot */
|
||||
|
||||
var radius = 1;
|
||||
|
||||
browserCanvasContext.beginPath();
|
||||
browserCanvasContext.arc(point.x, point.y, radius, 0, Math.PI * 2, true);
|
||||
browserCanvasContext.closePath();
|
||||
browserCanvasContext.fillStyle = 'rgba(30, 30, 30, 1)';
|
||||
browserCanvasContext.fill();
|
||||
|
||||
}
|
||||
browserCanvasContext.beginPath()
|
||||
browserCanvasContext.moveTo(pFloatingObject.currentPosition.x, pFloatingObject.currentPosition.y)
|
||||
browserCanvasContext.lineTo(point.x, point.y)
|
||||
browserCanvasContext.strokeStyle = 'rgba(204, 204, 204, 0.5)'
|
||||
browserCanvasContext.setLineDash([4, 2])
|
||||
browserCanvasContext.lineWidth = 1
|
||||
browserCanvasContext.stroke()
|
||||
browserCanvasContext.setLineDash([0, 0])
|
||||
}
|
||||
|
||||
function drawForeground(pFloatingObject) {
|
||||
if (pFloatingObject.currentRadius > 0.5) {
|
||||
/* Target Spot */
|
||||
|
||||
const BUBBLE_CORNERS_RADIOUS = 5;
|
||||
const TITLE_BAR_HEIGHT = 14;
|
||||
var radius = 1
|
||||
|
||||
const BUBBLE_WIDTH = BUBBLE_CORNERS_RADIOUS + pFloatingObject.currentRadius * 4;
|
||||
const BUBBLE_HEIGHT = BUBBLE_CORNERS_RADIOUS + pFloatingObject.currentRadius * 2;
|
||||
browserCanvasContext.beginPath()
|
||||
browserCanvasContext.arc(point.x, point.y, radius, 0, Math.PI * 2, true)
|
||||
browserCanvasContext.closePath()
|
||||
browserCanvasContext.fillStyle = 'rgba(30, 30, 30, 1)'
|
||||
browserCanvasContext.fill()
|
||||
}
|
||||
}
|
||||
|
||||
let borderPoint1;
|
||||
let borderPoint2;
|
||||
let borderPoint3;
|
||||
let borderPoint4;
|
||||
function drawForeground (pFloatingObject) {
|
||||
const BUBBLE_CORNERS_RADIOUS = 5
|
||||
const TITLE_BAR_HEIGHT = 14
|
||||
|
||||
let intialDisplace = {
|
||||
x: pFloatingObject.currentPosition.x - BUBBLE_WIDTH / 2,
|
||||
y: pFloatingObject.currentPosition.y - BUBBLE_HEIGHT / 2
|
||||
}
|
||||
const BUBBLE_WIDTH = BUBBLE_CORNERS_RADIOUS + pFloatingObject.currentRadius * 4
|
||||
const BUBBLE_HEIGHT = BUBBLE_CORNERS_RADIOUS + pFloatingObject.currentRadius * 2
|
||||
|
||||
if (pFloatingObject.currentRadius > 5) {
|
||||
let borderPoint1
|
||||
let borderPoint2
|
||||
let borderPoint3
|
||||
let borderPoint4
|
||||
|
||||
let intialDisplace = {
|
||||
x: pFloatingObject.currentPosition.x - BUBBLE_WIDTH / 2,
|
||||
y: pFloatingObject.currentPosition.y - BUBBLE_HEIGHT / 2
|
||||
}
|
||||
|
||||
if (pFloatingObject.currentRadius > 5) {
|
||||
/* Rounded Background */
|
||||
|
||||
borderPoint1 = {
|
||||
x: intialDisplace.x + BUBBLE_CORNERS_RADIOUS,
|
||||
y: intialDisplace.y + BUBBLE_CORNERS_RADIOUS
|
||||
};
|
||||
borderPoint1 = {
|
||||
x: intialDisplace.x + BUBBLE_CORNERS_RADIOUS,
|
||||
y: intialDisplace.y + BUBBLE_CORNERS_RADIOUS
|
||||
}
|
||||
|
||||
borderPoint2 = {
|
||||
x: intialDisplace.x + BUBBLE_WIDTH - BUBBLE_CORNERS_RADIOUS,
|
||||
y: intialDisplace.y + BUBBLE_CORNERS_RADIOUS
|
||||
};
|
||||
borderPoint2 = {
|
||||
x: intialDisplace.x + BUBBLE_WIDTH - BUBBLE_CORNERS_RADIOUS,
|
||||
y: intialDisplace.y + BUBBLE_CORNERS_RADIOUS
|
||||
}
|
||||
|
||||
borderPoint3 = {
|
||||
x: intialDisplace.x + BUBBLE_WIDTH - BUBBLE_CORNERS_RADIOUS,
|
||||
y: intialDisplace.y + BUBBLE_HEIGHT - BUBBLE_CORNERS_RADIOUS
|
||||
};
|
||||
borderPoint3 = {
|
||||
x: intialDisplace.x + BUBBLE_WIDTH - BUBBLE_CORNERS_RADIOUS,
|
||||
y: intialDisplace.y + BUBBLE_HEIGHT - BUBBLE_CORNERS_RADIOUS
|
||||
}
|
||||
|
||||
borderPoint4 = {
|
||||
x: intialDisplace.x + BUBBLE_CORNERS_RADIOUS,
|
||||
y: intialDisplace.y + + BUBBLE_HEIGHT - BUBBLE_CORNERS_RADIOUS
|
||||
};
|
||||
borderPoint4 = {
|
||||
x: intialDisplace.x + BUBBLE_CORNERS_RADIOUS,
|
||||
y: intialDisplace.y + +BUBBLE_HEIGHT - BUBBLE_CORNERS_RADIOUS
|
||||
}
|
||||
|
||||
titleBarPoint1 = {
|
||||
x: intialDisplace.x + 0,
|
||||
y: intialDisplace.y + TITLE_BAR_HEIGHT
|
||||
};
|
||||
titleBarPoint1 = {
|
||||
x: intialDisplace.x + 0,
|
||||
y: intialDisplace.y + TITLE_BAR_HEIGHT
|
||||
}
|
||||
|
||||
titleBarPoint2 = {
|
||||
x: intialDisplace.x + BUBBLE_WIDTH,
|
||||
y: intialDisplace.y + TITLE_BAR_HEIGHT
|
||||
};
|
||||
titleBarPoint2 = {
|
||||
x: intialDisplace.x + BUBBLE_WIDTH,
|
||||
y: intialDisplace.y + TITLE_BAR_HEIGHT
|
||||
}
|
||||
|
||||
/* We paint the panel background first */
|
||||
|
||||
browserCanvasContext.fillStyle = 'rgba(255, 249, 196, 0.75)';
|
||||
browserCanvasContext.beginPath();
|
||||
browserCanvasContext.fillStyle = 'rgba(255, 249, 196, 0.75)'
|
||||
browserCanvasContext.beginPath()
|
||||
|
||||
browserCanvasContext.arc(borderPoint1.x, borderPoint1.y, BUBBLE_CORNERS_RADIOUS, 1.0 * Math.PI, 1.5 * Math.PI);
|
||||
browserCanvasContext.lineTo(borderPoint2.x, borderPoint2.y - BUBBLE_CORNERS_RADIOUS);
|
||||
browserCanvasContext.arc(borderPoint2.x, borderPoint2.y, BUBBLE_CORNERS_RADIOUS, 1.5 * Math.PI, 2.0 * Math.PI);
|
||||
browserCanvasContext.lineTo(borderPoint3.x + BUBBLE_CORNERS_RADIOUS, borderPoint3.y);
|
||||
browserCanvasContext.arc(borderPoint3.x, borderPoint3.y, BUBBLE_CORNERS_RADIOUS, 0 * Math.PI, 0.5 * Math.PI);
|
||||
browserCanvasContext.lineTo(borderPoint4.x, borderPoint4.y + BUBBLE_CORNERS_RADIOUS);
|
||||
browserCanvasContext.arc(borderPoint4.x, borderPoint4.y, BUBBLE_CORNERS_RADIOUS, 0.5 * Math.PI, 1.0 * Math.PI);
|
||||
browserCanvasContext.lineTo(borderPoint1.x - BUBBLE_CORNERS_RADIOUS, borderPoint1.y);
|
||||
browserCanvasContext.arc(borderPoint1.x, borderPoint1.y, BUBBLE_CORNERS_RADIOUS, 1.0 * Math.PI, 1.5 * Math.PI)
|
||||
browserCanvasContext.lineTo(borderPoint2.x, borderPoint2.y - BUBBLE_CORNERS_RADIOUS)
|
||||
browserCanvasContext.arc(borderPoint2.x, borderPoint2.y, BUBBLE_CORNERS_RADIOUS, 1.5 * Math.PI, 2.0 * Math.PI)
|
||||
browserCanvasContext.lineTo(borderPoint3.x + BUBBLE_CORNERS_RADIOUS, borderPoint3.y)
|
||||
browserCanvasContext.arc(borderPoint3.x, borderPoint3.y, BUBBLE_CORNERS_RADIOUS, 0 * Math.PI, 0.5 * Math.PI)
|
||||
browserCanvasContext.lineTo(borderPoint4.x, borderPoint4.y + BUBBLE_CORNERS_RADIOUS)
|
||||
browserCanvasContext.arc(borderPoint4.x, borderPoint4.y, BUBBLE_CORNERS_RADIOUS, 0.5 * Math.PI, 1.0 * Math.PI)
|
||||
browserCanvasContext.lineTo(borderPoint1.x - BUBBLE_CORNERS_RADIOUS, borderPoint1.y)
|
||||
|
||||
browserCanvasContext.closePath();
|
||||
browserCanvasContext.closePath()
|
||||
|
||||
browserCanvasContext.fill();
|
||||
browserCanvasContext.fill()
|
||||
|
||||
browserCanvasContext.lineWidth = 0.1;
|
||||
browserCanvasContext.strokeStyle = 'rgba(' + UI_COLOR.DARK + ', 0.75)';
|
||||
browserCanvasContext.stroke();
|
||||
browserCanvasContext.lineWidth = 0.1
|
||||
browserCanvasContext.strokeStyle = 'rgba(' + UI_COLOR.DARK + ', 0.75)'
|
||||
browserCanvasContext.stroke()
|
||||
|
||||
/* We paint the title bar now */
|
||||
|
||||
browserCanvasContext.fillStyle = 'rgba(244, 224, 44, 0.75)';
|
||||
browserCanvasContext.beginPath();
|
||||
browserCanvasContext.fillStyle = 'rgba(244, 224, 44, 0.75)'
|
||||
browserCanvasContext.beginPath()
|
||||
|
||||
browserCanvasContext.moveTo(titleBarPoint1.x, titleBarPoint1.y);
|
||||
browserCanvasContext.lineTo(borderPoint1.x - BUBBLE_CORNERS_RADIOUS, borderPoint1.y);
|
||||
browserCanvasContext.arc(borderPoint1.x, borderPoint1.y, BUBBLE_CORNERS_RADIOUS, 1.0 * Math.PI, 1.5 * Math.PI);
|
||||
browserCanvasContext.lineTo(borderPoint2.x, borderPoint2.y - BUBBLE_CORNERS_RADIOUS);
|
||||
browserCanvasContext.arc(borderPoint2.x, borderPoint2.y, BUBBLE_CORNERS_RADIOUS, 1.5 * Math.PI, 2.0 * Math.PI);
|
||||
browserCanvasContext.lineTo(titleBarPoint2.x, titleBarPoint2.y);
|
||||
browserCanvasContext.moveTo(titleBarPoint1.x, titleBarPoint1.y)
|
||||
browserCanvasContext.lineTo(borderPoint1.x - BUBBLE_CORNERS_RADIOUS, borderPoint1.y)
|
||||
browserCanvasContext.arc(borderPoint1.x, borderPoint1.y, BUBBLE_CORNERS_RADIOUS, 1.0 * Math.PI, 1.5 * Math.PI)
|
||||
browserCanvasContext.lineTo(borderPoint2.x, borderPoint2.y - BUBBLE_CORNERS_RADIOUS)
|
||||
browserCanvasContext.arc(borderPoint2.x, borderPoint2.y, BUBBLE_CORNERS_RADIOUS, 1.5 * Math.PI, 2.0 * Math.PI)
|
||||
browserCanvasContext.lineTo(titleBarPoint2.x, titleBarPoint2.y)
|
||||
|
||||
browserCanvasContext.closePath();
|
||||
browserCanvasContext.fill();
|
||||
browserCanvasContext.closePath()
|
||||
browserCanvasContext.fill()
|
||||
|
||||
browserCanvasContext.lineWidth = 0.1;
|
||||
browserCanvasContext.strokeStyle = 'rgba(' + UI_COLOR.RUSTED_RED + ', 0.75)';
|
||||
browserCanvasContext.stroke();
|
||||
|
||||
}
|
||||
|
||||
if (pFloatingObject.currentRadius > 0.5) {
|
||||
browserCanvasContext.lineWidth = 0.1
|
||||
browserCanvasContext.strokeStyle = 'rgba(' + UI_COLOR.RUSTED_RED + ', 0.75)'
|
||||
browserCanvasContext.stroke()
|
||||
}
|
||||
|
||||
if (pFloatingObject.currentRadius > 0.5) {
|
||||
/* Image */
|
||||
|
||||
let imagePosition = {
|
||||
x: pFloatingObject.currentPosition.x,
|
||||
y: pFloatingObject.currentPosition.y + BUBBLE_HEIGHT / 2
|
||||
};
|
||||
let imagePosition = {
|
||||
x: pFloatingObject.currentPosition.x,
|
||||
y: pFloatingObject.currentPosition.y + BUBBLE_HEIGHT / 2
|
||||
}
|
||||
|
||||
if (pFloatingObject.payloadImageId !== undefined) {
|
||||
if (pFloatingObject.payloadImageId !== undefined) {
|
||||
let image = document.getElementById(pFloatingObject.payloadImageId)
|
||||
|
||||
let image = document.getElementById(pFloatingObject.payloadImageId);
|
||||
|
||||
if (image !== null) {
|
||||
|
||||
browserCanvasContext.drawImage(image, imagePosition.x - pFloatingObject.currentImageSize / 2, imagePosition.y - pFloatingObject.currentImageSize / 2, pFloatingObject.currentImageSize, pFloatingObject.currentImageSize);
|
||||
|
||||
}
|
||||
}
|
||||
if (image !== null) {
|
||||
browserCanvasContext.drawImage(image, imagePosition.x - pFloatingObject.currentImageSize / 2, imagePosition.y - pFloatingObject.currentImageSize / 2, pFloatingObject.currentImageSize, pFloatingObject.currentImageSize)
|
||||
}
|
||||
}
|
||||
|
||||
/* Image Contourn */
|
||||
|
||||
browserCanvasContext.beginPath();
|
||||
browserCanvasContext.arc(imagePosition.x, imagePosition.y, pFloatingObject.currentImageSize / 2, 0, Math.PI * 2, true);
|
||||
browserCanvasContext.closePath();
|
||||
browserCanvasContext.strokeStyle = 'rgba(30, 30, 30, 0.25)';
|
||||
browserCanvasContext.lineWidth = 1;
|
||||
browserCanvasContext.stroke();
|
||||
browserCanvasContext.beginPath()
|
||||
browserCanvasContext.arc(imagePosition.x, imagePosition.y, pFloatingObject.currentImageSize / 2, 0, Math.PI * 2, true)
|
||||
browserCanvasContext.closePath()
|
||||
browserCanvasContext.strokeStyle = 'rgba(30, 30, 30, 0.25)'
|
||||
browserCanvasContext.lineWidth = 1
|
||||
browserCanvasContext.stroke()
|
||||
|
||||
/* Labels */
|
||||
|
||||
if (pFloatingObject.currentRadius > 6) {
|
||||
if (pFloatingObject.currentRadius > 6) {
|
||||
browserCanvasContext.strokeStyle = pFloatingObject.labelStrokeStyle
|
||||
|
||||
browserCanvasContext.strokeStyle = pFloatingObject.labelStrokeStyle;
|
||||
const SIZE_PERCENTAGE = Math.trunc(pFloatingObject.currentRadius / pFloatingObject.targetRadius * 100) / 100
|
||||
let ALPHA
|
||||
|
||||
const SIZE_PERCENTAGE = Math.trunc(pFloatingObject.currentRadius / pFloatingObject.targetRadius * 100) / 100;
|
||||
let ALPHA;
|
||||
if (pFloatingObject.targetRadius > 0) {
|
||||
ALPHA = 0.5 - (1 - SIZE_PERCENTAGE) * 5
|
||||
} else {
|
||||
// Object is dying...
|
||||
|
||||
if (pFloatingObject.targetRadius > 0) {
|
||||
ALPHA = Math.trunc((0.5 - (100 - pFloatingObject.currentRadius / 100)) * 100) / 100
|
||||
|
||||
ALPHA = 0.5 - (1 - SIZE_PERCENTAGE) * 5;
|
||||
if (ALPHA < 0) { ALPHA = 0 }
|
||||
}
|
||||
|
||||
} else { // Object is dying...
|
||||
let labelPoint
|
||||
let fontSize = 10
|
||||
|
||||
ALPHA = Math.trunc((0.5 - (100 - pFloatingObject.currentRadius / 100) ) * 100) / 100;
|
||||
|
||||
if (ALPHA < 0) { ALPHA = 0}
|
||||
|
||||
}
|
||||
|
||||
let labelPoint;
|
||||
let fontSize = 10;
|
||||
|
||||
let label;
|
||||
let label
|
||||
|
||||
/* print the title */
|
||||
|
||||
label = pFloatingObject.payload.notes[pFloatingObject.payloadNoteIndex].title;
|
||||
label = pFloatingObject.payload.notes[pFloatingObject.payloadNoteIndex].title
|
||||
|
||||
if (label !== undefined) {
|
||||
if (label !== undefined) {
|
||||
if (SIZE_PERCENTAGE > 0.9) {
|
||||
browserCanvasContext.font = fontSize + 'px ' + UI_FONT.SECONDARY + ' Saira'
|
||||
|
||||
if (SIZE_PERCENTAGE > 0.9) {
|
||||
let xOffset = label.length / 2 * fontSize * FONT_ASPECT_RATIO
|
||||
let yOffset = (TITLE_BAR_HEIGHT - fontSize) / 2 + 2
|
||||
|
||||
browserCanvasContext.font = fontSize + 'px ' + UI_FONT.SECONDARY;
|
||||
labelPoint = {
|
||||
x: intialDisplace.x + BUBBLE_WIDTH / 2 - xOffset,
|
||||
y: intialDisplace.y + TITLE_BAR_HEIGHT - yOffset
|
||||
}
|
||||
|
||||
let xOffset = label.length / 2 * fontSize * FONT_ASPECT_RATIO;
|
||||
let yOffset = (TITLE_BAR_HEIGHT - fontSize) / 2 + 2;
|
||||
|
||||
labelPoint = {
|
||||
x: intialDisplace.x + BUBBLE_WIDTH / 2 - xOffset,
|
||||
y: intialDisplace.y + TITLE_BAR_HEIGHT - yOffset
|
||||
};
|
||||
|
||||
browserCanvasContext.fillStyle = 'rgba(30, 30, 30, ' + ALPHA + ')'
|
||||
browserCanvasContext.fillText(label, labelPoint.x, labelPoint.y);
|
||||
|
||||
}
|
||||
}
|
||||
browserCanvasContext.fillStyle = 'rgba(30, 30, 30, ' + ALPHA + ')'
|
||||
browserCanvasContext.fillText(label, labelPoint.x, labelPoint.y)
|
||||
}
|
||||
}
|
||||
|
||||
/* Message Body */
|
||||
|
||||
label = pFloatingObject.payload.notes[pFloatingObject.payloadNoteIndex].body;
|
||||
label = pFloatingObject.payload.notes[pFloatingObject.payloadNoteIndex].body
|
||||
|
||||
if (label !== undefined) {
|
||||
if (label !== undefined) {
|
||||
const WORDS_PER_ROW = 5
|
||||
const TOTAL_ROWS = 5
|
||||
|
||||
const WORDS_PER_ROW = 5;
|
||||
const TOTAL_ROWS = 5;
|
||||
|
||||
if (SIZE_PERCENTAGE > 0.9) {
|
||||
|
||||
let rawLabelArray = label.split(" ");
|
||||
let labelArray = [];
|
||||
if (SIZE_PERCENTAGE > 0.9) {
|
||||
let rawLabelArray = label.split(' ')
|
||||
let labelArray = []
|
||||
|
||||
/* Lets check when words are to long we add an empty space to the same line so as to roll all other words forward. */
|
||||
|
||||
for (let i = 0; i < rawLabelArray.length; i++) {
|
||||
for (let i = 0; i < rawLabelArray.length; i++) {
|
||||
let word = rawLabelArray[i]
|
||||
|
||||
let word = rawLabelArray[i];
|
||||
labelArray.push(word)
|
||||
|
||||
labelArray.push(word);
|
||||
if (word.length > 8) {
|
||||
labelArray.push('')
|
||||
}
|
||||
|
||||
if (word.length > 8) {
|
||||
labelArray.push("");
|
||||
}
|
||||
|
||||
if (word.length > 10) {
|
||||
labelArray.push("");
|
||||
}
|
||||
}
|
||||
if (word.length > 10) {
|
||||
labelArray.push('')
|
||||
}
|
||||
}
|
||||
|
||||
/* Calculate each ROW */
|
||||
|
||||
let labelRows = [];
|
||||
let labelRows = []
|
||||
|
||||
for (let i = 0; i < TOTAL_ROWS; i++) {
|
||||
for (let i = 0; i < TOTAL_ROWS; i++) {
|
||||
let labelRow = ''
|
||||
|
||||
let labelRow = "";
|
||||
for (let j = 0; j < WORDS_PER_ROW; j++) {
|
||||
let newWord = labelArray[j + i * WORDS_PER_ROW]
|
||||
|
||||
for (let j = 0; j < WORDS_PER_ROW; j++) {
|
||||
if (newWord !== undefined && newWord !== '') {
|
||||
labelRow = labelRow + ' ' + newWord
|
||||
}
|
||||
}
|
||||
|
||||
let newWord = labelArray[j + i * WORDS_PER_ROW];
|
||||
|
||||
if (newWord !== undefined && newWord !== "") {
|
||||
|
||||
labelRow = labelRow + " " + newWord;
|
||||
}
|
||||
}
|
||||
|
||||
if (labelRow !== "") {
|
||||
|
||||
labelRows.push(labelRow);
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
if (labelRow !== '') {
|
||||
labelRows.push(labelRow)
|
||||
}
|
||||
}
|
||||
|
||||
/* Now we plot each row. */
|
||||
|
||||
for (let i = 0; i < labelRows.length; i++) {
|
||||
for (let i = 0; i < labelRows.length; i++) {
|
||||
let labelRow = labelRows[i]
|
||||
|
||||
let labelRow = labelRows[i];
|
||||
let startingPosition = {
|
||||
x: pFloatingObject.currentPosition.x,
|
||||
y: pFloatingObject.currentPosition.y - labelRows.length / 2 * (fontSize * FONT_ASPECT_RATIO + 10)
|
||||
}
|
||||
|
||||
let startingPosition = {
|
||||
x: pFloatingObject.currentPosition.x,
|
||||
y: pFloatingObject.currentPosition.y - labelRows.length / 2 * (fontSize * FONT_ASPECT_RATIO + 10)
|
||||
};
|
||||
labelPoint = {
|
||||
x: startingPosition.x - labelRow.length / 2 * fontSize * FONT_ASPECT_RATIO,
|
||||
y: startingPosition.y + (i + 1) * (fontSize * FONT_ASPECT_RATIO + 10)
|
||||
}
|
||||
|
||||
labelPoint = {
|
||||
x: startingPosition.x - labelRow.length / 2 * fontSize * FONT_ASPECT_RATIO,
|
||||
y: startingPosition.y + (i + 1) * (fontSize * FONT_ASPECT_RATIO + 10)
|
||||
};
|
||||
|
||||
browserCanvasContext.font = fontSize + 'px ' + UI_FONT.SECONDARY;
|
||||
browserCanvasContext.fillStyle = 'rgba(60, 60, 60, ' + ALPHA + ')'
|
||||
browserCanvasContext.fillText(labelRow, labelPoint.x, labelPoint.y);
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
browserCanvasContext.font = fontSize + 'px ' + UI_FONT.SECONDARY + ' Saira'
|
||||
browserCanvasContext.fillStyle = 'rgba(60, 60, 60, ' + ALPHA + ')'
|
||||
browserCanvasContext.fillText(labelRow, labelPoint.x, labelPoint.y)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
+186
-222
@@ -1,6 +1,5 @@
|
||||
|
||||
function newNoteSets() {
|
||||
|
||||
|
||||
function newNoteSets () {
|
||||
/*
|
||||
Different plotters will identify sets of notes whithin the data they are plotting. They will create with them arrays of Notes data.
|
||||
On the other hand the floating space, and a floting layer in particular, manages Notes floating objects, which are visible entities
|
||||
@@ -14,48 +13,43 @@ function newNoteSets() {
|
||||
This module is capable of managing an array of NoteSets.
|
||||
*/
|
||||
|
||||
const MODULE_NAME = "Note Sets";
|
||||
const INFO_LOG = false;
|
||||
const INFO_WARN = true;
|
||||
const ERROR_LOG = true;
|
||||
const logger = newWebDebugLog();
|
||||
logger.fileName = MODULE_NAME;
|
||||
const MODULE_NAME = 'Note Sets'
|
||||
const INFO_LOG = false
|
||||
const INFO_WARN = true
|
||||
const ERROR_LOG = true
|
||||
const logger = newWebDebugLog()
|
||||
logger.fileName = MODULE_NAME
|
||||
|
||||
let thisObject = {
|
||||
createNoteSet: createNoteSet,
|
||||
destroyNoteSet: destroyNoteSet,
|
||||
initialize: initialize
|
||||
};
|
||||
let thisObject = {
|
||||
createNoteSet: createNoteSet,
|
||||
destroyNoteSet: destroyNoteSet,
|
||||
initialize: initialize
|
||||
}
|
||||
|
||||
let noteSets = [];
|
||||
let floatingLayer;
|
||||
let noteSets = []
|
||||
let floatingLayer
|
||||
|
||||
return thisObject;
|
||||
|
||||
function initialize(pFloatingLayer, callBackFunction) {
|
||||
return thisObject
|
||||
|
||||
function initialize (pFloatingLayer, callBackFunction) {
|
||||
/*
|
||||
During the initialization process, we receive the floatingLayer where all the floatingObjects we will be creating here will live at.
|
||||
*/
|
||||
|
||||
try {
|
||||
try {
|
||||
if (INFO_LOG === true) { logger.write('[INFO] initialize -> Entering function.') }
|
||||
|
||||
if (INFO_LOG === true) { logger.write("[INFO] initialize -> Entering function."); }
|
||||
floatingLayer = pFloatingLayer
|
||||
|
||||
floatingLayer = pFloatingLayer;
|
||||
|
||||
callBackFunction(GLOBAL.CUSTOM_OK_RESPONSE);
|
||||
|
||||
} catch (err) {
|
||||
|
||||
if (ERROR_LOG === true) { logger.write("[ERROR] initialize -> err = " + err); }
|
||||
callBackFunction(GLOBAL.DEFAULT_FAIL_RESPONSE);
|
||||
}
|
||||
callBackFunction(GLOBAL.CUSTOM_OK_RESPONSE)
|
||||
} catch (err) {
|
||||
if (ERROR_LOG === true) { logger.write('[ERROR] initialize -> err = ' + err) }
|
||||
callBackFunction(GLOBAL.DEFAULT_FAIL_RESPONSE)
|
||||
}
|
||||
}
|
||||
|
||||
function createNoteSet(pPayload, pEventHandler, callBackFunction) {
|
||||
|
||||
try {
|
||||
function createNoteSet (pPayload, pEventHandler, callBackFunction) {
|
||||
try {
|
||||
/*
|
||||
During the creating of a NoteSet, no floating objects are created yet. What we do here is to create the data structure which will allocate
|
||||
the Notes floating objects, once we receive the array of notes raw data from the plotter. This array will come as an event raised by the
|
||||
@@ -63,41 +57,39 @@ function newNoteSets() {
|
||||
position the user gives to the viewport, but also, the plotter can be receiving actually new notes from its datasource.
|
||||
*/
|
||||
|
||||
if (INFO_LOG === true) { logger.write("[INFO] createNoteSet -> Entering function."); }
|
||||
if (INFO_LOG === true) { logger.write('[INFO] createNoteSet -> Entering function.') }
|
||||
|
||||
let noteSet = {
|
||||
imageId: pPayload.profile.imageId,
|
||||
floatingNotes: [],
|
||||
payload: pPayload,
|
||||
handle: Math.floor((Math.random() * 10000000) + 1)
|
||||
};
|
||||
let noteSet = {
|
||||
imageId: pPayload.profile.imageId,
|
||||
floatingNotes: [],
|
||||
payload: pPayload,
|
||||
handle: Math.floor((Math.random() * 10000000) + 1)
|
||||
}
|
||||
|
||||
noteSets.push(noteSet);
|
||||
noteSets.push(noteSet)
|
||||
|
||||
pEventHandler.listenToEvent("Notes Changed", onNotesChanged, noteSets.length - 1)
|
||||
pEventHandler.listenToEvent('Notes Changed', onNotesChanged, noteSets.length - 1)
|
||||
|
||||
callBackFunction(GLOBAL.CUSTOM_OK_RESPONSE, noteSet.handle);
|
||||
callBackFunction(GLOBAL.CUSTOM_OK_RESPONSE, noteSet.handle)
|
||||
|
||||
function onNotesChanged(pNewNotes, pNoteSetIndex) {
|
||||
function onNotesChanged (pNewNotes, pNoteSetIndex) {
|
||||
try {
|
||||
if (INFO_LOG === true) { logger.write('[INFO] createNoteSet -> onNotesChanged -> Entering function.') }
|
||||
if (INFO_LOG === true) { logger.write('[INFO] createNoteSet -> onNotesChanged -> pNewNotes.length = ' + pNewNotes.length) }
|
||||
if (INFO_LOG === true) { logger.write('[INFO] createNoteSet -> onNotesChanged -> pNoteSetIndex = ' + pNoteSetIndex) }
|
||||
|
||||
try {
|
||||
let noteSet = noteSets[pNoteSetIndex]
|
||||
let found = false
|
||||
let newFloatingNotes
|
||||
|
||||
if (INFO_LOG === true) { logger.write("[INFO] createNoteSet -> onNotesChanged -> Entering function."); }
|
||||
if (INFO_LOG === true) { logger.write("[INFO] createNoteSet -> onNotesChanged -> pNewNotes.length = " + pNewNotes.length); }
|
||||
if (INFO_LOG === true) { logger.write("[INFO] createNoteSet -> onNotesChanged -> pNoteSetIndex = " + pNoteSetIndex); }
|
||||
|
||||
let noteSet = noteSets[pNoteSetIndex];
|
||||
let found = false;
|
||||
let newFloatingNotes;
|
||||
|
||||
/*
|
||||
/*
|
||||
First we remove the old notes. This means that we are going to scan all the floating objects that we have, and see one by one if they
|
||||
are still present on the raw data sent by the plotter. If it is not there, that means that the floating object must be discarded.
|
||||
*/
|
||||
|
||||
if (INFO_LOG === true) { logger.write("[INFO] createNoteSet -> onNotesChanged -> Remove old Notes."); }
|
||||
if (INFO_LOG === true) { logger.write('[INFO] createNoteSet -> onNotesChanged -> Remove old Notes.') }
|
||||
|
||||
newFloatingNotes = []; // We will create a new array of Floating Notes as a result of this operation.
|
||||
newFloatingNotes = [] // We will create a new array of Floating Notes as a result of this operation.
|
||||
|
||||
/*
|
||||
Here we scan the curren array of floating objects. We use the date + rate to create a unique key for each one, in order to be able to
|
||||
@@ -105,171 +97,156 @@ function newNoteSets() {
|
||||
that are still at the raw data array to a new array, and not adding the ones that are not.
|
||||
*/
|
||||
|
||||
for (let j = 0; j < noteSet.floatingNotes.length; j++) {
|
||||
for (let j = 0; j < noteSet.floatingNotes.length; j++) {
|
||||
found = false
|
||||
|
||||
found = false;
|
||||
let floatingNote = noteSet.floatingNotes[j]
|
||||
let floatingNoteKey = floatingNote.date.toString() + floatingNote.rate.toString()
|
||||
|
||||
let floatingNote = noteSet.floatingNotes[j];
|
||||
let floatingNoteKey = floatingNote.date.toString() + floatingNote.rate.toString();
|
||||
if (INFO_LOG === true) { logger.write('[INFO] createNoteSet -> onNotesChanged -> Remove old Notes -> j = ' + j) }
|
||||
|
||||
if (INFO_LOG === true) { logger.write("[INFO] createNoteSet -> onNotesChanged -> Remove old Notes -> j = " + j); }
|
||||
let i
|
||||
|
||||
let i;
|
||||
for (i = 0; i < pNewNotes.length; i++) {
|
||||
let plotterNote = pNewNotes[i]
|
||||
let plotterNoteKey = plotterNote.date.toString() + plotterNote.rate.toString()
|
||||
|
||||
for (i = 0; i < pNewNotes.length; i++) {
|
||||
if (INFO_LOG === true) { logger.write('[INFO] createNoteSet -> onNotesChanged -> Remove old Notes -> i = ' + i) }
|
||||
if (INFO_LOG === true) { logger.write('[INFO] createNoteSet -> onNotesChanged -> Remove old Notes -> floatingNoteKey = ' + floatingNoteKey) }
|
||||
if (INFO_LOG === true) { logger.write('[INFO] createNoteSet -> onNotesChanged -> Remove old Notes -> plotterNoteKey = ' + plotterNoteKey) }
|
||||
|
||||
let plotterNote = pNewNotes[i];
|
||||
let plotterNoteKey = plotterNote.date.toString() + plotterNote.rate.toString();
|
||||
if (plotterNoteKey === floatingNoteKey) {
|
||||
found = true
|
||||
|
||||
if (INFO_LOG === true) { logger.write("[INFO] createNoteSet -> onNotesChanged -> Remove old Notes -> i = " + i); }
|
||||
if (INFO_LOG === true) { logger.write("[INFO] createNoteSet -> onNotesChanged -> Remove old Notes -> floatingNoteKey = " + floatingNoteKey); }
|
||||
if (INFO_LOG === true) { logger.write("[INFO] createNoteSet -> onNotesChanged -> Remove old Notes -> plotterNoteKey = " + plotterNoteKey); }
|
||||
if (INFO_LOG === true) { logger.write('[INFO] createNoteSet -> onNotesChanged -> found = ' + found) }
|
||||
break
|
||||
}
|
||||
}
|
||||
|
||||
if (plotterNoteKey === floatingNoteKey) {
|
||||
|
||||
found = true;
|
||||
|
||||
if (INFO_LOG === true) { logger.write("[INFO] createNoteSet -> onNotesChanged -> found = " + found); }
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (INFO_LOG === true) { logger.write("[INFO] createNoteSet -> onNotesChanged -> Remove old Notes -> End of For i."); }
|
||||
if (INFO_LOG === true) { logger.write("[INFO] createNoteSet -> onNotesChanged -> Remove old Notes -> found = " + found); }
|
||||
|
||||
if (found === false) {
|
||||
if (INFO_LOG === true) { logger.write('[INFO] createNoteSet -> onNotesChanged -> Remove old Notes -> End of For i.') }
|
||||
if (INFO_LOG === true) { logger.write('[INFO] createNoteSet -> onNotesChanged -> Remove old Notes -> found = ' + found) }
|
||||
|
||||
if (found === false) {
|
||||
/*
|
||||
Each time we identify a floatingObject that is not at the raw data anymore, we request the floatinglayer to kill it.
|
||||
*/
|
||||
|
||||
floatingLayer.killFloatingObject(floatingNote.floatingHandle, onObjectKilled);
|
||||
floatingLayer.killFloatingObject(floatingNote.floatingHandle, onObjectKilled)
|
||||
|
||||
function onObjectKilled(err) {
|
||||
function onObjectKilled (err) {
|
||||
if (err.result !== GLOBAL.DEFAULT_OK_RESPONSE.result) {
|
||||
if (ERROR_LOG === true) { logger.write('[ERROR] createNoteSet -> onNotesChanged -> Remove old Notes -> Floating Object Not Found.') }
|
||||
if (ERROR_LOG === true) { logger.write('[ERROR] createNoteSet -> onNotesChanged -> Remove old Notes -> Floating Object cannot be killed.') }
|
||||
if (ERROR_LOG === true) { logger.write('[ERROR] createNoteSet -> onNotesChanged -> Remove old Notes -> floatingNote.floatingHandle = ' + floatingNote.floatingHandle) }
|
||||
return
|
||||
}
|
||||
|
||||
if (err.result !== GLOBAL.DEFAULT_OK_RESPONSE.result) {
|
||||
if (INFO_LOG === true) { logger.write('[INFO] createNoteSet -> onNotesChanged -> Remove old Notes -> floatingNote.floatingHandle = ' + floatingNote.floatingHandle) }
|
||||
if (INFO_LOG === true) { logger.write('[INFO] createNoteSet -> onNotesChanged -> Remove old Notes -> Removed from Layer.') }
|
||||
}
|
||||
} else {
|
||||
newFloatingNotes.push(floatingNote)
|
||||
|
||||
if (ERROR_LOG === true) { logger.write("[ERROR] createNoteSet -> onNotesChanged -> Remove old Notes -> Floating Object Not Found."); }
|
||||
if (ERROR_LOG === true) { logger.write("[ERROR] createNoteSet -> onNotesChanged -> Remove old Notes -> Floating Object cannot be killed."); }
|
||||
if (ERROR_LOG === true) { logger.write("[ERROR] createNoteSet -> onNotesChanged -> Remove old Notes -> floatingNote.floatingHandle = " + floatingNote.floatingHandle); }
|
||||
return;
|
||||
}
|
||||
|
||||
if (INFO_LOG === true) { logger.write("[INFO] createNoteSet -> onNotesChanged -> Remove old Notes -> floatingNote.floatingHandle = " + floatingNote.floatingHandle); }
|
||||
if (INFO_LOG === true) { logger.write("[INFO] createNoteSet -> onNotesChanged -> Remove old Notes -> Removed from Layer."); }
|
||||
}
|
||||
|
||||
} else {
|
||||
|
||||
newFloatingNotes.push(floatingNote);
|
||||
|
||||
if (INFO_LOG === true) { logger.write("[INFO] createNoteSet -> onNotesChanged -> Remove old Notes -> floatingNote.floatingHandle = " + floatingNote.floatingHandle); }
|
||||
if (INFO_LOG === true) { logger.write("[INFO] createNoteSet -> onNotesChanged -> Remove old Notes -> Added to newFloatingNotes."); }
|
||||
if (INFO_LOG === true) { logger.write("[INFO] createNoteSet -> onNotesChanged -> Remove old Notes -> newFloatingNotes.length = " + newFloatingNotes.length); }
|
||||
if (INFO_LOG === true) { logger.write('[INFO] createNoteSet -> onNotesChanged -> Remove old Notes -> floatingNote.floatingHandle = ' + floatingNote.floatingHandle) }
|
||||
if (INFO_LOG === true) { logger.write('[INFO] createNoteSet -> onNotesChanged -> Remove old Notes -> Added to newFloatingNotes.') }
|
||||
if (INFO_LOG === true) { logger.write('[INFO] createNoteSet -> onNotesChanged -> Remove old Notes -> newFloatingNotes.length = ' + newFloatingNotes.length) }
|
||||
|
||||
/*
|
||||
We set a property at each floatingObject of which is the index of the note at the raw data array, so that it can later evaluate its position or its visibility.
|
||||
*/
|
||||
|
||||
let floatingObject = floatingLayer.getFloatingObject(floatingNote.floatingHandle);
|
||||
floatingObject.payloadNoteIndex = i;
|
||||
let floatingObject = floatingLayer.getFloatingObject(floatingNote.floatingHandle)
|
||||
floatingObject.payloadNoteIndex = i
|
||||
|
||||
if (INFO_LOG === true) { logger.write("[INFO] createNoteSet -> onNotesChanged -> Remove old Notes -> floatingObject index updated."); }
|
||||
if (INFO_LOG === true) { logger.write("[INFO] createNoteSet -> onNotesChanged -> Remove old Notes -> floatingObject.payloadNoteIndex = " + i); }
|
||||
|
||||
}
|
||||
}
|
||||
if (INFO_LOG === true) { logger.write('[INFO] createNoteSet -> onNotesChanged -> Remove old Notes -> floatingObject index updated.') }
|
||||
if (INFO_LOG === true) { logger.write('[INFO] createNoteSet -> onNotesChanged -> Remove old Notes -> floatingObject.payloadNoteIndex = ' + i) }
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
We replace the current array, with the new one that only contains the surviving floating objects, meaning the ones that are still at the raw data received.
|
||||
*/
|
||||
|
||||
noteSet.floatingNotes = newFloatingNotes;
|
||||
noteSet.floatingNotes = newFloatingNotes
|
||||
|
||||
if (INFO_LOG === true) { logger.write("[INFO] createNoteSet -> onNotesChanged -> Remove old Notes -> noteSet.floatingNotes.length = " + noteSet.floatingNotes.length); }
|
||||
if (INFO_LOG === true) { logger.write('[INFO] createNoteSet -> onNotesChanged -> Remove old Notes -> noteSet.floatingNotes.length = ' + noteSet.floatingNotes.length) }
|
||||
|
||||
/*
|
||||
/*
|
||||
Second we add the new notes. There might be new notes at the raw data received that we didnt have before at the NodeSet array. To figure out which
|
||||
ones are, we need to scan the raw data array and compare each element with the ones of the NodeSet array. Whenever we find one that is not there,
|
||||
we add it.
|
||||
*/
|
||||
|
||||
if (INFO_LOG === true) { logger.write("[INFO] createNoteSet -> onNotesChanged -> Add new Notes."); }
|
||||
if (INFO_LOG === true) { logger.write('[INFO] createNoteSet -> onNotesChanged -> Add new Notes.') }
|
||||
|
||||
newFloatingNotes = []; // We will create a new array of Floating Notes as a result of this operation.
|
||||
newFloatingNotes = [] // We will create a new array of Floating Notes as a result of this operation.
|
||||
|
||||
/*
|
||||
We are using the date and rate as a unique key to identify each note. To prevent the cases of duplicate keys, we will check that at
|
||||
least to consecutive records dont have the same key, and if they do, will ignore the second one.
|
||||
*/
|
||||
|
||||
let lastPlotterKey = "";
|
||||
let lastPlotterKey = ''
|
||||
|
||||
for (let i = 0; i < pNewNotes.length; i++) {
|
||||
for (let i = 0; i < pNewNotes.length; i++) {
|
||||
found = false
|
||||
|
||||
found = false;
|
||||
let plotterNote = pNewNotes[i]
|
||||
let plotterNoteKey = plotterNote.date.toString() + plotterNote.rate.toString()
|
||||
let floatingNote
|
||||
let floatingNoteKey
|
||||
|
||||
let plotterNote = pNewNotes[i];
|
||||
let plotterNoteKey = plotterNote.date.toString() + plotterNote.rate.toString();
|
||||
let floatingNote;
|
||||
let floatingNoteKey;
|
||||
if (lastPlotterKey === plotterNoteKey) {
|
||||
if (INFO_WARN === true) { logger.write('[WARN] createNoteSet -> onNotesChanged -> Add new Notes -> Duplicate record detected. Discarding it.') }
|
||||
if (INFO_WARN === true) { logger.write('[WARN] createNoteSet -> onNotesChanged -> Add new Notes -> i = ' + i) }
|
||||
continue
|
||||
}
|
||||
|
||||
if (lastPlotterKey === plotterNoteKey) {
|
||||
lastPlotterKey = plotterNoteKey
|
||||
|
||||
if (INFO_WARN=== true) { logger.write("[WARN] createNoteSet -> onNotesChanged -> Add new Notes -> Duplicate record detected. Discarding it."); }
|
||||
if (INFO_WARN === true) { logger.write("[WARN] createNoteSet -> onNotesChanged -> Add new Notes -> i = " + i); }
|
||||
continue;
|
||||
}
|
||||
if (INFO_LOG === true) { logger.write('[INFO] createNoteSet -> onNotesChanged -> Add new Notes -> i = ' + i) }
|
||||
|
||||
lastPlotterKey = plotterNoteKey;
|
||||
for (let j = 0; j < noteSet.floatingNotes.length; j++) {
|
||||
floatingNote = noteSet.floatingNotes[j]
|
||||
floatingNoteKey = floatingNote.date.toString() + floatingNote.rate.toString()
|
||||
|
||||
if (INFO_LOG === true) { logger.write("[INFO] createNoteSet -> onNotesChanged -> Add new Notes -> i = " + i); }
|
||||
if (INFO_LOG === true) { logger.write('[INFO] createNoteSet -> onNotesChanged -> Add new Notes -> j = ' + j) }
|
||||
if (INFO_LOG === true) { logger.write('[INFO] createNoteSet -> onNotesChanged -> Add new Notes -> floatingNoteKey = ' + floatingNoteKey) }
|
||||
if (INFO_LOG === true) { logger.write('[INFO] createNoteSet -> onNotesChanged -> Add new Notes -> plotterNoteKey = ' + plotterNoteKey) }
|
||||
|
||||
for (let j = 0; j < noteSet.floatingNotes.length; j++) {
|
||||
if (plotterNoteKey === floatingNoteKey) {
|
||||
found = true
|
||||
|
||||
floatingNote = noteSet.floatingNotes[j];
|
||||
floatingNoteKey = floatingNote.date.toString() + floatingNote.rate.toString();
|
||||
if (INFO_LOG === true) { logger.write('[INFO] createNoteSet -> onNotesChanged -> Add new Notes -> found = ' + found) }
|
||||
break
|
||||
}
|
||||
}
|
||||
|
||||
if (INFO_LOG === true) { logger.write("[INFO] createNoteSet -> onNotesChanged -> Add new Notes -> j = " + j); }
|
||||
if (INFO_LOG === true) { logger.write("[INFO] createNoteSet -> onNotesChanged -> Add new Notes -> floatingNoteKey = " + floatingNoteKey); }
|
||||
if (INFO_LOG === true) { logger.write("[INFO] createNoteSet -> onNotesChanged -> Add new Notes -> plotterNoteKey = " + plotterNoteKey); }
|
||||
|
||||
if (plotterNoteKey === floatingNoteKey) {
|
||||
|
||||
found = true;
|
||||
|
||||
if (INFO_LOG === true) { logger.write("[INFO] createNoteSet -> onNotesChanged -> Add new Notes -> found = " + found); }
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (INFO_LOG === true) { logger.write("[INFO] createNoteSet -> onNotesChanged -> Add new Notes -> End of For j."); }
|
||||
if (INFO_LOG === true) { logger.write("[INFO] createNoteSet -> onNotesChanged -> Add new Notes -> found = " + found); }
|
||||
|
||||
if (found === false) {
|
||||
if (INFO_LOG === true) { logger.write('[INFO] createNoteSet -> onNotesChanged -> Add new Notes -> End of For j.') }
|
||||
if (INFO_LOG === true) { logger.write('[INFO] createNoteSet -> onNotesChanged -> Add new Notes -> found = ' + found) }
|
||||
|
||||
if (found === false) {
|
||||
/*
|
||||
Before adding a new item to the array, we need to create a floatingObject of type Note. Once we set its basic parameters
|
||||
we can it to our array and to the floating layer.
|
||||
*/
|
||||
|
||||
let floatingObject = newFloatingObject();
|
||||
floatingObject.initialize("Note", onInitialized);
|
||||
let floatingObject = newFloatingObject()
|
||||
floatingObject.initialize('Note', onInitialized)
|
||||
|
||||
function onInitialized(err) {
|
||||
function onInitialized (err) {
|
||||
if (INFO_LOG === true) { logger.write('[INFO] createNoteSet -> onNotesChanged -> Add new Notes -> onInitialized -> Entering function.') }
|
||||
|
||||
if (INFO_LOG === true) { logger.write("[INFO] createNoteSet -> onNotesChanged -> Add new Notes -> onInitialized -> Entering function."); }
|
||||
floatingObject.payload = noteSet.payload
|
||||
floatingObject.payloadNoteIndex = i
|
||||
floatingObject.payloadImageId = noteSet.imageId
|
||||
|
||||
floatingObject.payload = noteSet.payload;
|
||||
floatingObject.payloadNoteIndex = i;
|
||||
floatingObject.payloadImageId = noteSet.imageId;
|
||||
floatingObject.friction = 0.995
|
||||
|
||||
floatingObject.friction = .995;
|
||||
floatingObject.initializeMass(200)
|
||||
|
||||
floatingObject.initializeMass(200);
|
||||
|
||||
//let bodyText = pNewNotes[i].body;
|
||||
let radius;
|
||||
// let bodyText = pNewNotes[i].body;
|
||||
let radius
|
||||
|
||||
/*
|
||||
if (bodyText.length < 100) {
|
||||
@@ -278,96 +255,83 @@ function newNoteSets() {
|
||||
radius = bodyText.length;
|
||||
}
|
||||
*/
|
||||
radius = 50;
|
||||
radius = 50
|
||||
|
||||
floatingObject.initializeRadius(radius);
|
||||
floatingObject.initializeImageSize(15);
|
||||
floatingObject.initializeRadius(radius)
|
||||
floatingObject.initializeImageSize(15)
|
||||
|
||||
floatingObject.fillStyle = 'rgba(' + UI_COLOR.WHITE + ', 0.5)';
|
||||
floatingObject.labelStrokeStyle = 'rgba(60, 60, 60, 0.50)';
|
||||
floatingObject.fillStyle = 'rgba(' + UI_COLOR.WHITE + ', 0.5)'
|
||||
floatingObject.labelStrokeStyle = 'rgba(60, 60, 60, 0.50)'
|
||||
|
||||
floatingLayer.addFloatingObject(floatingObject);
|
||||
floatingLayer.addFloatingObject(floatingObject)
|
||||
|
||||
if (INFO_LOG === true) { logger.write("[INFO] createNoteSet -> onNotesChanged -> Add new Notes -> onInitialized -> New Note added to Layer."); }
|
||||
if (INFO_LOG === true) { logger.write('[INFO] createNoteSet -> onNotesChanged -> Add new Notes -> onInitialized -> New Note added to Layer.') }
|
||||
|
||||
plotterNote.floatingHandle = floatingObject.handle;
|
||||
plotterNote.floatingHandle = floatingObject.handle
|
||||
|
||||
if (INFO_LOG === true) { logger.write("[INFO] createNoteSet -> onNotesChanged -> Add new Notes -> plotterNote.floatingHandle = " + plotterNote.floatingHandle); }
|
||||
if (INFO_LOG === true) { logger.write('[INFO] createNoteSet -> onNotesChanged -> Add new Notes -> plotterNote.floatingHandle = ' + plotterNote.floatingHandle) }
|
||||
|
||||
newFloatingNotes.push(plotterNote);
|
||||
newFloatingNotes.push(plotterNote)
|
||||
|
||||
if (INFO_LOG === true) { logger.write("[INFO] createNoteSet -> onNotesChanged -> Add new Notes -> onInitialized -> Added to newFloatingNotes."); }
|
||||
if (INFO_LOG === true) { logger.write("[INFO] createNoteSet -> onNotesChanged -> Add new Notes -> onInitialized -> newFloatingNotes.length = " + newFloatingNotes.length); }
|
||||
if (INFO_LOG === true) { logger.write('[INFO] createNoteSet -> onNotesChanged -> Add new Notes -> onInitialized -> Added to newFloatingNotes.') }
|
||||
if (INFO_LOG === true) { logger.write('[INFO] createNoteSet -> onNotesChanged -> Add new Notes -> onInitialized -> newFloatingNotes.length = ' + newFloatingNotes.length) }
|
||||
}
|
||||
} else {
|
||||
newFloatingNotes.push(floatingNote)
|
||||
|
||||
}
|
||||
if (INFO_LOG === true) { logger.write('[INFO] createNoteSet -> onNotesChanged -> Add new Notes -> onInitialized -> Old Note Kept.') }
|
||||
if (INFO_LOG === true) { logger.write('[INFO] createNoteSet -> onNotesChanged -> Add new Notes -> onInitialized -> floatingNote.floatingHandle = ' + floatingNote.floatingHandle) }
|
||||
if (INFO_LOG === true) { logger.write('[INFO] createNoteSet -> onNotesChanged -> Add new Notes -> onInitialized -> Added to newFloatingNotes.') }
|
||||
if (INFO_LOG === true) { logger.write('[INFO] createNoteSet -> onNotesChanged -> Add new Notes -> onInitialized -> newFloatingNotes.length = ' + newFloatingNotes.length) }
|
||||
|
||||
} else {
|
||||
let floatingObject = floatingLayer.getFloatingObject(floatingNote.floatingHandle)
|
||||
floatingObject.payloadNoteIndex = i
|
||||
|
||||
newFloatingNotes.push(floatingNote);
|
||||
|
||||
if (INFO_LOG === true) { logger.write("[INFO] createNoteSet -> onNotesChanged -> Add new Notes -> onInitialized -> Old Note Kept."); }
|
||||
if (INFO_LOG === true) { logger.write("[INFO] createNoteSet -> onNotesChanged -> Add new Notes -> onInitialized -> floatingNote.floatingHandle = " + floatingNote.floatingHandle); }
|
||||
if (INFO_LOG === true) { logger.write("[INFO] createNoteSet -> onNotesChanged -> Add new Notes -> onInitialized -> Added to newFloatingNotes."); }
|
||||
if (INFO_LOG === true) { logger.write("[INFO] createNoteSet -> onNotesChanged -> Add new Notes -> onInitialized -> newFloatingNotes.length = " + newFloatingNotes.length); }
|
||||
|
||||
let floatingObject = floatingLayer.getFloatingObject(floatingNote.floatingHandle);
|
||||
floatingObject.payloadNoteIndex = i;
|
||||
|
||||
if (INFO_LOG === true) { logger.write("[INFO] createNoteSet -> onNotesChanged -> Add new Notes -> onInitialized -> floatingObject index updated."); }
|
||||
if (INFO_LOG === true) { logger.write("[INFO] createNoteSet -> onNotesChanged -> Add new Notes -> onInitialized -> floatingObject.payloadNoteIndex = " + i); }
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
noteSet.floatingNotes = newFloatingNotes;
|
||||
|
||||
if (INFO_LOG === true) { logger.write("[INFO] createNoteSet -> onNotesChanged -> Add new Notes -> noteSet.floatingNotes.length = " + noteSet.floatingNotes.length); }
|
||||
|
||||
} catch (err) {
|
||||
|
||||
if (ERROR_LOG === true) { logger.write("[ERROR] createNoteSet -> onNotesChanged -> err = " + err); }
|
||||
}
|
||||
if (INFO_LOG === true) { logger.write('[INFO] createNoteSet -> onNotesChanged -> Add new Notes -> onInitialized -> floatingObject index updated.') }
|
||||
if (INFO_LOG === true) { logger.write('[INFO] createNoteSet -> onNotesChanged -> Add new Notes -> onInitialized -> floatingObject.payloadNoteIndex = ' + i) }
|
||||
}
|
||||
}
|
||||
|
||||
noteSet.floatingNotes = newFloatingNotes
|
||||
|
||||
if (INFO_LOG === true) { logger.write('[INFO] createNoteSet -> onNotesChanged -> Add new Notes -> noteSet.floatingNotes.length = ' + noteSet.floatingNotes.length) }
|
||||
} catch (err) {
|
||||
|
||||
if (ERROR_LOG === true) { logger.write("[ERROR] createNoteSet -> err = " + err); }
|
||||
callBackFunction(GLOBAL.DEFAULT_FAIL_RESPONSE);
|
||||
if (ERROR_LOG === true) { logger.write('[ERROR] createNoteSet -> onNotesChanged -> err = ' + err) }
|
||||
}
|
||||
}
|
||||
} catch (err) {
|
||||
if (ERROR_LOG === true) { logger.write('[ERROR] createNoteSet -> err = ' + err) }
|
||||
callBackFunction(GLOBAL.DEFAULT_FAIL_RESPONSE)
|
||||
}
|
||||
}
|
||||
|
||||
function destroyNoteSet(pHandle) {
|
||||
|
||||
try {
|
||||
function destroyNoteSet (pHandle) {
|
||||
try {
|
||||
/*
|
||||
Usually when a bot is disabled by the end user, or the zoom level changes to one where the notes must not be seen, this method
|
||||
to destroy an entire NoteSet is executed. What we do in this situation is to localize the NoteSet to be destroyed and we need to
|
||||
kill, one by one the floating objects in it. Finally we remove this NoteSet item from the NoteSets array.
|
||||
*/
|
||||
|
||||
if (INFO_LOG === true) { logger.write("[INFO] destroyNoteSet -> Entering function."); }
|
||||
if (INFO_LOG === true) { logger.write('[INFO] destroyNoteSet -> Entering function.') }
|
||||
|
||||
for (let i = 0; i < noteSets.length; i++) {
|
||||
for (let i = 0; i < noteSets.length; i++) {
|
||||
let noteSet = noteSets[i]
|
||||
|
||||
let noteSet = noteSets[i];
|
||||
if (noteSet.handle === pHandle) {
|
||||
for (let j = 0; j < noteSet.floatingNotes.length; j++) {
|
||||
let floatingNote = noteSet.floatingNotes[j]
|
||||
|
||||
if (noteSet.handle === pHandle) {
|
||||
floatingLayer.killFloatingObject(floatingNote.floatingHandle)
|
||||
}
|
||||
|
||||
for (let j = 0; j < noteSet.floatingNotes.length; j++) {
|
||||
|
||||
let floatingNote = noteSet.floatingNotes[j];
|
||||
|
||||
floatingLayer.killFloatingObject(floatingNote.floatingHandle);
|
||||
}
|
||||
|
||||
noteSets.splice(i, 1); // Delete item from array.
|
||||
return;
|
||||
}
|
||||
}
|
||||
} catch (err) {
|
||||
|
||||
if (ERROR_LOG === true) { logger.write("[ERROR] destroyNoteSet -> err = " + err); }
|
||||
noteSets.splice(i, 1) // Delete item from array.
|
||||
return
|
||||
}
|
||||
}
|
||||
} catch (err) {
|
||||
if (ERROR_LOG === true) { logger.write('[ERROR] destroyNoteSet -> err = ' + err) }
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
+208
-252
@@ -1,28 +1,27 @@
|
||||
|
||||
function newProfileBall() {
|
||||
|
||||
let thisObject = {
|
||||
function newProfileBall () {
|
||||
let thisObject = {
|
||||
|
||||
physicsLoop: physicsLoop,
|
||||
onMouseOver: onMouseOver,
|
||||
onMouseClick: onMouseClick,
|
||||
onMouseNotOver: onMouseNotOver,
|
||||
drawBackground: drawBackground,
|
||||
drawForeground: drawForeground,
|
||||
initialize: initialize
|
||||
physicsLoop: physicsLoop,
|
||||
onMouseOver: onMouseOver,
|
||||
onMouseClick: onMouseClick,
|
||||
onMouseNotOver: onMouseNotOver,
|
||||
drawBackground: drawBackground,
|
||||
drawForeground: drawForeground,
|
||||
initialize: initialize
|
||||
|
||||
};
|
||||
}
|
||||
|
||||
let ballStringMenu = [
|
||||
{
|
||||
visible: false,
|
||||
imagePathOn: "Images/menu.icon.on.1.gif",
|
||||
imagePathOff: "Images/menu.icon.off.1.gif",
|
||||
rawRadius: 8,
|
||||
targetRadius: 0,
|
||||
currentRadius: 0,
|
||||
angle: 60
|
||||
},
|
||||
let ballStringMenu = [
|
||||
{
|
||||
visible: false,
|
||||
imagePathOn: 'Images/menu.icon.on.1.gif',
|
||||
imagePathOff: 'Images/menu.icon.off.1.gif',
|
||||
rawRadius: 8,
|
||||
targetRadius: 0,
|
||||
currentRadius: 0,
|
||||
angle: 60
|
||||
}/*,
|
||||
{
|
||||
visible: false,
|
||||
imagePathOn: "Images/menu.icon.on.2.gif",
|
||||
@@ -49,308 +48,265 @@ function newProfileBall() {
|
||||
targetRadius: 0,
|
||||
currentRadius: 0,
|
||||
angle: -60
|
||||
}
|
||||
];
|
||||
} */
|
||||
]
|
||||
|
||||
return thisObject;
|
||||
return thisObject
|
||||
|
||||
function initialize(callBackFunction) {
|
||||
function initialize (callBackFunction) {
|
||||
for (let i = 0; i < ballStringMenu.length; i++) {
|
||||
let menuItem = ballStringMenu[i]
|
||||
|
||||
for (let i = 0; i < ballStringMenu.length; i++) {
|
||||
menuItem.iconOn = new Image()
|
||||
|
||||
let menuItem = ballStringMenu[i];
|
||||
menuItem.iconOn.onload = onImageLoad
|
||||
|
||||
menuItem.iconOn = new Image();
|
||||
function onImageLoad () {
|
||||
menuItem.iconOff = new Image()
|
||||
|
||||
menuItem.iconOn.onload = onImageLoad;
|
||||
|
||||
function onImageLoad() {
|
||||
|
||||
menuItem.iconOff = new Image();
|
||||
|
||||
menuItem.iconOff.onload = onImageLoad;
|
||||
|
||||
function onImageLoad() {
|
||||
menuItem.canDrawIcon = true;
|
||||
}
|
||||
|
||||
menuItem.iconOff.src = window.canvasApp.urlPrefix + menuItem.imagePathOff;
|
||||
|
||||
}
|
||||
|
||||
menuItem.iconOn.src = window.canvasApp.urlPrefix + menuItem.imagePathOn;
|
||||
|
||||
menuItem.icon = menuItem.iconOn; // The default value is ON.
|
||||
menuItem.iconOff.onload = onImageLoad
|
||||
|
||||
function onImageLoad () {
|
||||
menuItem.canDrawIcon = true
|
||||
}
|
||||
|
||||
callBackFunction();
|
||||
menuItem.iconOff.src = window.canvasApp.urlPrefix + menuItem.imagePathOff
|
||||
}
|
||||
|
||||
menuItem.iconOn.src = window.canvasApp.urlPrefix + menuItem.imagePathOn
|
||||
|
||||
menuItem.icon = menuItem.iconOn // The default value is ON.
|
||||
}
|
||||
|
||||
function physicsLoop() {
|
||||
callBackFunction()
|
||||
}
|
||||
|
||||
function physicsLoop () {
|
||||
// The menuItems also have a target.
|
||||
|
||||
for (let i = 0; i < ballStringMenu.length; i++) {
|
||||
for (let i = 0; i < ballStringMenu.length; i++) {
|
||||
let menuItem = ballStringMenu[i]
|
||||
|
||||
let menuItem = ballStringMenu[i];
|
||||
|
||||
if (Math.abs(menuItem.currentRadius - menuItem.targetRadius) >= 0.5) {
|
||||
|
||||
if (menuItem.currentRadius < menuItem.targetRadius) {
|
||||
menuItem.currentRadius = menuItem.currentRadius + 0.5;
|
||||
} else {
|
||||
menuItem.currentRadius = menuItem.currentRadius - 0.5;
|
||||
}
|
||||
}
|
||||
if (Math.abs(menuItem.currentRadius - menuItem.targetRadius) >= 0.5) {
|
||||
if (menuItem.currentRadius < menuItem.targetRadius) {
|
||||
menuItem.currentRadius = menuItem.currentRadius + 0.5
|
||||
} else {
|
||||
menuItem.currentRadius = menuItem.currentRadius - 0.5
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function onMouseOver() {
|
||||
function onMouseOver () {
|
||||
for (let i = 0; i < ballStringMenu.length; i++) {
|
||||
let menuItem = ballStringMenu[i]
|
||||
|
||||
for (let i = 0; i < ballStringMenu.length; i++) {
|
||||
|
||||
let menuItem = ballStringMenu[i];
|
||||
|
||||
menuItem.targetRadius = menuItem.rawRadius * 1.5;
|
||||
}
|
||||
}
|
||||
|
||||
function onMouseNotOver() {
|
||||
|
||||
for (let i = 0; i < ballStringMenu.length; i++) {
|
||||
|
||||
let menuItem = ballStringMenu[i];
|
||||
|
||||
menuItem.targetRadius = menuItem.rawRadius * 0 - i * 5;
|
||||
}
|
||||
menuItem.targetRadius = menuItem.rawRadius * 1.5
|
||||
}
|
||||
}
|
||||
|
||||
function onMouseClick(pPoint, pFloatingObject) {
|
||||
function onMouseNotOver () {
|
||||
for (let i = 0; i < ballStringMenu.length; i++) {
|
||||
let menuItem = ballStringMenu[i]
|
||||
|
||||
menuItem.targetRadius = menuItem.rawRadius * 0 - i * 5
|
||||
}
|
||||
}
|
||||
|
||||
function onMouseClick (pPoint, pFloatingObject) {
|
||||
/* What we need to do here is to check which menu item was clicked, if any. */
|
||||
|
||||
let menuItemIndex;
|
||||
let menuItemIndex
|
||||
|
||||
for (let i = 0; i < ballStringMenu.length; i++) {
|
||||
for (let i = 0; i < ballStringMenu.length; i++) {
|
||||
let menuItem = ballStringMenu[i]
|
||||
|
||||
let menuItem = ballStringMenu[i];
|
||||
|
||||
if (menuItem.canDrawIcon === true && menuItem.currentRadius > 1) {
|
||||
|
||||
let position = {
|
||||
x: pFloatingObject.currentPosition.x + pFloatingObject.currentImageSize / 2 * Math.cos(toRadians(menuItem.angle)),
|
||||
y: pFloatingObject.currentPosition.y - pFloatingObject.currentImageSize / 2 * Math.sin(toRadians(menuItem.angle))
|
||||
};
|
||||
|
||||
browserCanvasContext.drawImage(menuItem.icon, position.x, position.y, menuItem.currentRadius * 2, menuItem.currentRadius * 2);
|
||||
|
||||
let distance = Math.sqrt(Math.pow(position.x - pPoint.x, 2) + Math.pow(position.y - pPoint.y, 2));
|
||||
|
||||
if (distance < menuItem.currentRadius) {
|
||||
menuItemIndex = i;
|
||||
}
|
||||
}
|
||||
if (menuItem.canDrawIcon === true && menuItem.currentRadius > 1) {
|
||||
let position = {
|
||||
x: pFloatingObject.currentPosition.x + pFloatingObject.currentImageSize / 2 * Math.cos(toRadians(menuItem.angle)),
|
||||
y: pFloatingObject.currentPosition.y - pFloatingObject.currentImageSize / 2 * Math.sin(toRadians(menuItem.angle))
|
||||
}
|
||||
|
||||
if (menuItemIndex !== undefined) {
|
||||
browserCanvasContext.drawImage(menuItem.icon, position.x, position.y, menuItem.currentRadius * 2, menuItem.currentRadius * 2)
|
||||
|
||||
switch (menuItemIndex) {
|
||||
|
||||
case 0: { // This menu item is to turn ON / OFF the plotting of this bot.
|
||||
|
||||
if (pFloatingObject.payload.profile.plot === true) {
|
||||
|
||||
pFloatingObject.payload.profile.plot = false;
|
||||
|
||||
let menuItem = ballStringMenu[0];
|
||||
menuItem.icon = menuItem.iconOff;
|
||||
|
||||
} else {
|
||||
|
||||
pFloatingObject.payload.profile.plot = true;
|
||||
|
||||
let menuItem = ballStringMenu[0];
|
||||
menuItem.icon = menuItem.iconOn;
|
||||
|
||||
}
|
||||
|
||||
break;
|
||||
}
|
||||
|
||||
case 1: { // This menu item is to turn ON the Debug Log pannel for the bot.
|
||||
|
||||
break;
|
||||
}
|
||||
}
|
||||
let distance = Math.sqrt(Math.pow(position.x - pPoint.x, 2) + Math.pow(position.y - pPoint.y, 2))
|
||||
|
||||
if (distance < menuItem.currentRadius) {
|
||||
menuItemIndex = i
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function drawBackground(pFloatingObject) {
|
||||
if (menuItemIndex !== undefined) {
|
||||
switch (menuItemIndex) {
|
||||
|
||||
let point = {
|
||||
x: pFloatingObject.payload.profile.position.x,
|
||||
y: pFloatingObject.payload.profile.position.y
|
||||
};
|
||||
case 0: {
|
||||
// This menu item is to turn ON / OFF the plotting of this bot.
|
||||
|
||||
point = viewPort.fitIntoVisibleArea(point);
|
||||
if (pFloatingObject.payload.profile.plot === true) {
|
||||
pFloatingObject.payload.profile.plot = false
|
||||
|
||||
if (pFloatingObject.currentRadius > 1) {
|
||||
let menuItem = ballStringMenu[0]
|
||||
menuItem.icon = menuItem.iconOff
|
||||
} else {
|
||||
pFloatingObject.payload.profile.plot = true
|
||||
|
||||
let menuItem = ballStringMenu[0]
|
||||
menuItem.icon = menuItem.iconOn
|
||||
}
|
||||
|
||||
break
|
||||
}
|
||||
|
||||
case 1: {
|
||||
// This menu item is to turn ON the Debug Log pannel for the bot.
|
||||
|
||||
break
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function drawBackground (pFloatingObject) {
|
||||
let point = {
|
||||
x: pFloatingObject.payload.profile.position.x,
|
||||
y: pFloatingObject.payload.profile.position.y
|
||||
}
|
||||
|
||||
point = viewPort.fitIntoVisibleArea(point)
|
||||
|
||||
if (pFloatingObject.currentRadius > 1) {
|
||||
/* Target Line */
|
||||
|
||||
browserCanvasContext.beginPath();
|
||||
browserCanvasContext.moveTo(pFloatingObject.currentPosition.x, pFloatingObject.currentPosition.y);
|
||||
browserCanvasContext.lineTo(point.x, point.y);
|
||||
browserCanvasContext.strokeStyle = 'rgba(204, 204, 204, 0.5)';
|
||||
browserCanvasContext.setLineDash([4, 2]);
|
||||
browserCanvasContext.lineWidth = 1;
|
||||
browserCanvasContext.stroke();
|
||||
browserCanvasContext.setLineDash([0, 0]);
|
||||
|
||||
}
|
||||
|
||||
if (pFloatingObject.currentRadius > 0.5) {
|
||||
|
||||
/* Target Spot */
|
||||
|
||||
var radius = 1;
|
||||
|
||||
browserCanvasContext.beginPath();
|
||||
browserCanvasContext.arc(point.x, point.y, radius, 0, Math.PI * 2, true);
|
||||
browserCanvasContext.closePath();
|
||||
browserCanvasContext.fillStyle = 'rgba(30, 30, 30, 1)';
|
||||
browserCanvasContext.fill();
|
||||
|
||||
}
|
||||
browserCanvasContext.beginPath()
|
||||
browserCanvasContext.moveTo(pFloatingObject.currentPosition.x, pFloatingObject.currentPosition.y)
|
||||
browserCanvasContext.lineTo(point.x, point.y)
|
||||
browserCanvasContext.strokeStyle = 'rgba(204, 204, 204, 0.5)'
|
||||
browserCanvasContext.setLineDash([4, 2])
|
||||
browserCanvasContext.lineWidth = 1
|
||||
browserCanvasContext.stroke()
|
||||
browserCanvasContext.setLineDash([0, 0])
|
||||
}
|
||||
|
||||
function drawForeground(pFloatingObject) {
|
||||
if (pFloatingObject.currentRadius > 0.5) {
|
||||
/* Target Spot */
|
||||
|
||||
if (pFloatingObject.currentRadius > 5) {
|
||||
var radius = 1
|
||||
|
||||
browserCanvasContext.beginPath()
|
||||
browserCanvasContext.arc(point.x, point.y, radius, 0, Math.PI * 2, true)
|
||||
browserCanvasContext.closePath()
|
||||
browserCanvasContext.fillStyle = 'rgba(30, 30, 30, 1)'
|
||||
browserCanvasContext.fill()
|
||||
}
|
||||
}
|
||||
|
||||
function drawForeground (pFloatingObject) {
|
||||
if (pFloatingObject.currentRadius > 5) {
|
||||
/* Contourn */
|
||||
|
||||
browserCanvasContext.beginPath();
|
||||
browserCanvasContext.arc(pFloatingObject.currentPosition.x, pFloatingObject.currentPosition.y, pFloatingObject.currentRadius, 0, Math.PI * 2, true);
|
||||
browserCanvasContext.closePath();
|
||||
browserCanvasContext.strokeStyle = 'rgba(30, 30, 30, 0.75)';
|
||||
browserCanvasContext.lineWidth = 1;
|
||||
browserCanvasContext.stroke();
|
||||
|
||||
}
|
||||
|
||||
if (pFloatingObject.currentRadius > 0.5) {
|
||||
browserCanvasContext.beginPath()
|
||||
browserCanvasContext.arc(pFloatingObject.currentPosition.x, pFloatingObject.currentPosition.y, pFloatingObject.currentRadius, 0, Math.PI * 2, true)
|
||||
browserCanvasContext.closePath()
|
||||
browserCanvasContext.strokeStyle = 'rgba(30, 30, 30, 0.75)'
|
||||
browserCanvasContext.lineWidth = 1
|
||||
browserCanvasContext.stroke()
|
||||
}
|
||||
|
||||
if (pFloatingObject.currentRadius > 0.5) {
|
||||
/* Main FloatingObject */
|
||||
|
||||
var alphaA;
|
||||
var alphaA
|
||||
|
||||
if (pFloatingObject.currentRadius < 3) {
|
||||
alphaA = 1;
|
||||
} else {
|
||||
alphaA = 0.75;
|
||||
}
|
||||
if (pFloatingObject.currentRadius < 3) {
|
||||
alphaA = 1
|
||||
} else {
|
||||
alphaA = 0.75
|
||||
}
|
||||
|
||||
alphaA = 0.75;
|
||||
alphaA = 0.75
|
||||
|
||||
browserCanvasContext.beginPath();
|
||||
browserCanvasContext.arc(pFloatingObject.currentPosition.x, pFloatingObject.currentPosition.y, pFloatingObject.currentRadius, 0, Math.PI * 2, true);
|
||||
browserCanvasContext.closePath();
|
||||
browserCanvasContext.beginPath()
|
||||
browserCanvasContext.arc(pFloatingObject.currentPosition.x, pFloatingObject.currentPosition.y, pFloatingObject.currentRadius, 0, Math.PI * 2, true)
|
||||
browserCanvasContext.closePath()
|
||||
|
||||
browserCanvasContext.fillStyle = pFloatingObject.fillStyle;
|
||||
browserCanvasContext.fillStyle = pFloatingObject.fillStyle
|
||||
|
||||
browserCanvasContext.fill();
|
||||
|
||||
}
|
||||
browserCanvasContext.fill()
|
||||
}
|
||||
|
||||
/* Image */
|
||||
|
||||
if (pFloatingObject.payload.profile.imageId !== undefined) {
|
||||
|
||||
let image = pFloatingObject.payload.profile.botAvatar;
|
||||
|
||||
if (image !== null && image !== undefined) {
|
||||
|
||||
browserCanvasContext.save();
|
||||
browserCanvasContext.beginPath();
|
||||
browserCanvasContext.arc(pFloatingObject.currentPosition.x , pFloatingObject.currentPosition.y , pFloatingObject.currentImageSize / 2, 0, Math.PI * 2, true);
|
||||
browserCanvasContext.closePath();
|
||||
browserCanvasContext.clip();
|
||||
browserCanvasContext.drawImage(image, pFloatingObject.currentPosition.x - pFloatingObject.currentImageSize / 2, pFloatingObject.currentPosition.y - pFloatingObject.currentImageSize / 2, pFloatingObject.currentImageSize, pFloatingObject.currentImageSize);
|
||||
browserCanvasContext.beginPath();
|
||||
browserCanvasContext.arc(pFloatingObject.currentPosition.x - pFloatingObject.currentImageSize / 2, pFloatingObject.currentPosition.y - pFloatingObject.currentImageSize / 2, pFloatingObject.currentImageSize / 2, 0, Math.PI * 2, true);
|
||||
browserCanvasContext.clip();
|
||||
browserCanvasContext.closePath();
|
||||
browserCanvasContext.restore();
|
||||
}
|
||||
}
|
||||
if (pFloatingObject.payload.profile.imageId !== undefined) {
|
||||
let image = pFloatingObject.payload.profile.botAvatar
|
||||
|
||||
if (image !== null && image !== undefined) {
|
||||
browserCanvasContext.save()
|
||||
browserCanvasContext.beginPath()
|
||||
browserCanvasContext.arc(pFloatingObject.currentPosition.x, pFloatingObject.currentPosition.y, pFloatingObject.currentImageSize / 2, 0, Math.PI * 2, true)
|
||||
browserCanvasContext.closePath()
|
||||
browserCanvasContext.clip()
|
||||
browserCanvasContext.drawImage(image, pFloatingObject.currentPosition.x - pFloatingObject.currentImageSize / 2, pFloatingObject.currentPosition.y - pFloatingObject.currentImageSize / 2, pFloatingObject.currentImageSize, pFloatingObject.currentImageSize)
|
||||
browserCanvasContext.beginPath()
|
||||
browserCanvasContext.arc(pFloatingObject.currentPosition.x - pFloatingObject.currentImageSize / 2, pFloatingObject.currentPosition.y - pFloatingObject.currentImageSize / 2, pFloatingObject.currentImageSize / 2, 0, Math.PI * 2, true)
|
||||
browserCanvasContext.clip()
|
||||
browserCanvasContext.closePath()
|
||||
browserCanvasContext.restore()
|
||||
}
|
||||
}
|
||||
|
||||
/* StringBall Menu */
|
||||
|
||||
for (let i = 0; i < ballStringMenu.length; i++) {
|
||||
for (let i = 0; i < ballStringMenu.length; i++) {
|
||||
let menuItem = ballStringMenu[i]
|
||||
|
||||
let menuItem = ballStringMenu[i];
|
||||
|
||||
if (menuItem.canDrawIcon === true && menuItem.currentRadius > 1) {
|
||||
|
||||
let position = {
|
||||
x: pFloatingObject.currentPosition.x + pFloatingObject.currentImageSize / 2 * Math.cos(toRadians(menuItem.angle)),
|
||||
y: pFloatingObject.currentPosition.y - pFloatingObject.currentImageSize / 2 * Math.sin(toRadians(menuItem.angle))
|
||||
};
|
||||
|
||||
browserCanvasContext.drawImage(menuItem.icon, position.x - menuItem.currentRadius, position.y - menuItem.currentRadius, menuItem.currentRadius * 2, menuItem.currentRadius * 2);
|
||||
}
|
||||
if (menuItem.canDrawIcon === true && menuItem.currentRadius > 1) {
|
||||
let position = {
|
||||
x: pFloatingObject.currentPosition.x + pFloatingObject.currentImageSize / 2 * Math.cos(toRadians(menuItem.angle)),
|
||||
y: pFloatingObject.currentPosition.y - pFloatingObject.currentImageSize / 2 * Math.sin(toRadians(menuItem.angle))
|
||||
}
|
||||
|
||||
browserCanvasContext.drawImage(menuItem.icon, position.x - menuItem.currentRadius, position.y - menuItem.currentRadius, menuItem.currentRadius * 2, menuItem.currentRadius * 2)
|
||||
}
|
||||
}
|
||||
|
||||
/* Label Text */
|
||||
|
||||
if (pFloatingObject.currentRadius > 6) {
|
||||
if (pFloatingObject.currentRadius > 6) {
|
||||
browserCanvasContext.strokeStyle = pFloatingObject.labelStrokeStyle
|
||||
|
||||
browserCanvasContext.strokeStyle = pFloatingObject.labelStrokeStyle;
|
||||
let labelPoint
|
||||
let fontSize = pFloatingObject.currentFontSize
|
||||
|
||||
let labelPoint;
|
||||
let fontSize = pFloatingObject.currentFontSize;
|
||||
browserCanvasContext.font = fontSize + 'px ' + UI_FONT.SECONDARY + ' Saira'
|
||||
|
||||
browserCanvasContext.font = fontSize + 'px ' + UI_FONT.SECONDARY;
|
||||
let label
|
||||
|
||||
let label;
|
||||
label = pFloatingObject.payload.profile.upLabel
|
||||
|
||||
label = pFloatingObject.payload.profile.upLabel;
|
||||
|
||||
if (label !== undefined) {
|
||||
|
||||
labelPoint = {
|
||||
x: pFloatingObject.currentPosition.x - label.length / 2 * fontSize * FONT_ASPECT_RATIO,
|
||||
y: pFloatingObject.currentPosition.y - pFloatingObject.currentImageSize / 2 - fontSize * FONT_ASPECT_RATIO - 10
|
||||
};
|
||||
|
||||
browserCanvasContext.font = fontSize + 'px ' + UI_FONT.SECONDARY;
|
||||
browserCanvasContext.fillStyle = pFloatingObject.labelStrokeStyle;
|
||||
browserCanvasContext.fillText(label, labelPoint.x, labelPoint.y);
|
||||
|
||||
}
|
||||
|
||||
label = pFloatingObject.payload.profile.downLabel;
|
||||
|
||||
if (label !== undefined) {
|
||||
|
||||
labelPoint = {
|
||||
x: pFloatingObject.currentPosition.x - label.length / 2 * fontSize * FONT_ASPECT_RATIO,
|
||||
y: pFloatingObject.currentPosition.y + pFloatingObject.currentImageSize / 2 + fontSize * FONT_ASPECT_RATIO + 15
|
||||
};
|
||||
|
||||
browserCanvasContext.font = fontSize + 'px ' + UI_FONT.SECONDARY;
|
||||
browserCanvasContext.fillStyle = pFloatingObject.labelStrokeStyle;
|
||||
browserCanvasContext.fillText(label, labelPoint.x, labelPoint.y);
|
||||
|
||||
}
|
||||
if (label !== undefined) {
|
||||
labelPoint = {
|
||||
x: pFloatingObject.currentPosition.x - label.length / 2 * fontSize * FONT_ASPECT_RATIO,
|
||||
y: pFloatingObject.currentPosition.y - pFloatingObject.currentImageSize / 2 - fontSize * FONT_ASPECT_RATIO - 10
|
||||
}
|
||||
|
||||
browserCanvasContext.font = fontSize + 'px ' + UI_FONT.SECONDARY + ' Saira'
|
||||
browserCanvasContext.fillStyle = pFloatingObject.labelStrokeStyle
|
||||
browserCanvasContext.fillText(label, labelPoint.x, labelPoint.y)
|
||||
}
|
||||
|
||||
label = pFloatingObject.payload.profile.downLabel
|
||||
|
||||
if (label !== undefined) {
|
||||
labelPoint = {
|
||||
x: pFloatingObject.currentPosition.x - label.length / 2 * fontSize * FONT_ASPECT_RATIO,
|
||||
y: pFloatingObject.currentPosition.y + pFloatingObject.currentImageSize / 2 + fontSize * FONT_ASPECT_RATIO + 15
|
||||
}
|
||||
|
||||
browserCanvasContext.font = fontSize + 'px ' + UI_FONT.SECONDARY + ' Saira'
|
||||
browserCanvasContext.fillStyle = pFloatingObject.labelStrokeStyle
|
||||
browserCanvasContext.fillText(label, labelPoint.x, labelPoint.y)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -1,11 +1,10 @@
|
||||
|
||||
function newProfileBalls() {
|
||||
|
||||
const MODULE_NAME = "Profile Balls";
|
||||
const INFO_LOG = false;
|
||||
const ERROR_LOG = true;
|
||||
const logger = newWebDebugLog();
|
||||
logger.fileName = MODULE_NAME;
|
||||
|
||||
function newProfileBalls () {
|
||||
const MODULE_NAME = 'Profile Balls'
|
||||
const INFO_LOG = false
|
||||
const ERROR_LOG = true
|
||||
const logger = newWebDebugLog()
|
||||
logger.fileName = MODULE_NAME
|
||||
|
||||
/*
|
||||
|
||||
@@ -13,65 +12,67 @@ function newProfileBalls() {
|
||||
|
||||
*/
|
||||
|
||||
let thisObject = {
|
||||
let thisObject = {
|
||||
|
||||
createNewProfileBall: createNewProfileBall,
|
||||
destroyProfileBall: destroyProfileBall,
|
||||
initialize: initialize
|
||||
createNewProfileBall: createNewProfileBall,
|
||||
destroyProfileBall: destroyProfileBall,
|
||||
initialize: initialize,
|
||||
finalize: finalize
|
||||
|
||||
}
|
||||
|
||||
let floatingLayer
|
||||
|
||||
return thisObject
|
||||
|
||||
function finalize () {
|
||||
try {
|
||||
if (INFO_LOG === true) { logger.write('[INFO] finalize -> Entering function.') }
|
||||
|
||||
floatingLayer.finalize()
|
||||
} catch (err) {
|
||||
if (ERROR_LOG === true) { logger.write('[ERROR] finalize -> err = ' + err) }
|
||||
}
|
||||
}
|
||||
|
||||
let floatingLayer;
|
||||
function initialize (pFloatingLayer, callBackFunction) {
|
||||
try {
|
||||
if (INFO_LOG === true) { logger.write('[INFO] initialize -> Entering function.') }
|
||||
|
||||
return thisObject;
|
||||
floatingLayer = pFloatingLayer
|
||||
|
||||
function initialize(pFloatingLayer, callBackFunction) {
|
||||
|
||||
try {
|
||||
|
||||
if (INFO_LOG === true) { logger.write("[INFO] initialize -> Entering function."); }
|
||||
|
||||
floatingLayer = pFloatingLayer;
|
||||
|
||||
callBackFunction(GLOBAL.CUSTOM_OK_RESPONSE);
|
||||
|
||||
} catch (err) {
|
||||
|
||||
if (ERROR_LOG === true) { logger.write("[ERROR] initialize -> err = " + err); }
|
||||
callBackFunction(GLOBAL.DEFAULT_FAIL_RESPONSE);
|
||||
}
|
||||
callBackFunction(GLOBAL.CUSTOM_OK_RESPONSE)
|
||||
} catch (err) {
|
||||
if (ERROR_LOG === true) { logger.write('[ERROR] initialize -> err = ' + err) }
|
||||
callBackFunction(GLOBAL.DEFAULT_FAIL_RESPONSE)
|
||||
}
|
||||
}
|
||||
|
||||
function createNewProfileBall(pPayload, callBackFunction) {
|
||||
function createNewProfileBall (pPayload, callBackFunction) {
|
||||
let floatingObject = newFloatingObject()
|
||||
floatingObject.initialize('Profile Ball', onInitialized)
|
||||
|
||||
let floatingObject = newFloatingObject();
|
||||
floatingObject.initialize("Profile Ball", onInitialized);
|
||||
function onInitialized (err) {
|
||||
floatingObject.payload = pPayload
|
||||
|
||||
function onInitialized(err) {
|
||||
floatingObject.friction = 0.995
|
||||
|
||||
floatingObject.payload = pPayload;
|
||||
floatingObject.initializeMass(100)
|
||||
floatingObject.initializeRadius(30)
|
||||
floatingObject.initializeImageSize(50)
|
||||
floatingObject.initializeFontSize(10)
|
||||
|
||||
floatingObject.friction = .995;
|
||||
floatingObject.fillStyle = 'rgba(' + UI_COLOR.WHITE + ', 0.5)'
|
||||
floatingObject.labelStrokeStyle = 'rgba(60, 60, 60, 0.50)'
|
||||
|
||||
floatingObject.initializeMass(100);
|
||||
floatingObject.initializeRadius(30);
|
||||
floatingObject.initializeImageSize(50);
|
||||
floatingObject.initializeFontSize(10);
|
||||
floatingLayer.addFloatingObject(floatingObject)
|
||||
|
||||
floatingObject.fillStyle = 'rgba(' + UI_COLOR.WHITE + ', 0.5)';
|
||||
floatingObject.labelStrokeStyle = 'rgba(60, 60, 60, 0.50)';
|
||||
|
||||
floatingLayer.addFloatingObject(floatingObject);
|
||||
|
||||
callBackFunction(GLOBAL.CUSTOM_OK_RESPONSE, floatingObject.handle);
|
||||
|
||||
}
|
||||
callBackFunction(GLOBAL.CUSTOM_OK_RESPONSE, floatingObject.handle)
|
||||
}
|
||||
}
|
||||
|
||||
function destroyProfileBall(pFloatingObjectHandle) {
|
||||
|
||||
floatingLayer.killFloatingObject(pFloatingObjectHandle);
|
||||
|
||||
}
|
||||
function destroyProfileBall (pFloatingObjectHandle) {
|
||||
floatingLayer.killFloatingObject(pFloatingObjectHandle)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,130 +1,110 @@
|
||||
|
||||
function newFrame() {
|
||||
|
||||
function newFrame () {
|
||||
const PANEL_CORNERS_RADIOUS = 5
|
||||
const TITLE_BAR_HEIGHT = 14 // this must be grater than radius
|
||||
|
||||
const PANEL_CORNERS_RADIOUS = 5;
|
||||
const TITLE_BAR_HEIGHT = 14; // this must be grater than radius
|
||||
var frame = {
|
||||
containerName: '', // This is for debugging purposes only.
|
||||
parentFrame: undefined, // Here we store the parent cointainer zoom object.
|
||||
width: browserCanvas.width,
|
||||
height: browserCanvas.height,
|
||||
position: undefined,
|
||||
getBodyHeight: getBodyHeight,
|
||||
draw: draw,
|
||||
container: undefined,
|
||||
frameThisPoint: frameThisPoint, // This function changes the actual frame coordinate system to the screen coordinate system.
|
||||
unframeThisPoint: unframeThisPoint,
|
||||
fitIntoFrame: fitIntoFrame,
|
||||
isThisPointHere: isThisPointHere, // This function return true is the point received as parameter lives within this frame.
|
||||
isInViewPort: isInViewPort,
|
||||
canYouMoveHere: canYouMoveHere,
|
||||
canYouZoomHere: canYouZoomHere,
|
||||
initialize: initialize
|
||||
}
|
||||
|
||||
var frame = {
|
||||
containerName: "", // This is for debugging purposes only.
|
||||
parentFrame: undefined, // Here we store the parent cointainer zoom object.
|
||||
width: browserCanvas.width,
|
||||
height: browserCanvas.height,
|
||||
position: undefined,
|
||||
getBodyHeight: getBodyHeight,
|
||||
draw: draw,
|
||||
container: undefined,
|
||||
frameThisPoint: frameThisPoint, // This function changes the actual frame coordinate system to the screen coordinate system.
|
||||
unframeThisPoint: unframeThisPoint,
|
||||
fitIntoFrame: fitIntoFrame,
|
||||
isThisPointHere: isThisPointHere, // This function return true is the point received as parameter lives within this frame.
|
||||
isInViewPort: isInViewPort,
|
||||
canYouMoveHere: canYouMoveHere,
|
||||
canYouZoomHere: canYouZoomHere,
|
||||
initialize: initialize
|
||||
};
|
||||
return frame
|
||||
|
||||
return frame;
|
||||
|
||||
function initialize() {
|
||||
|
||||
var position = {
|
||||
x: 0,
|
||||
y: 0
|
||||
};
|
||||
|
||||
this.position = position;
|
||||
function initialize () {
|
||||
var position = {
|
||||
x: 0,
|
||||
y: 0
|
||||
}
|
||||
|
||||
this.position = position
|
||||
}
|
||||
|
||||
function getBodyHeight() {
|
||||
|
||||
return frame.height - TITLE_BAR_HEIGHT;
|
||||
function getBodyHeight () {
|
||||
return frame.height - TITLE_BAR_HEIGHT
|
||||
}
|
||||
|
||||
function isInViewPort () {
|
||||
point1 = {
|
||||
x: 0,
|
||||
y: 0
|
||||
}
|
||||
|
||||
function isInViewPort() {
|
||||
|
||||
point1 = {
|
||||
x: 0,
|
||||
y: 0
|
||||
};
|
||||
|
||||
point3 = {
|
||||
x: frame.width,
|
||||
y: frame.height
|
||||
};
|
||||
|
||||
point3 = {
|
||||
x: frame.width,
|
||||
y: frame.height
|
||||
}
|
||||
|
||||
/* Now the transformations. */
|
||||
|
||||
point1 = transformThisPoint(point1, frame.container);
|
||||
point3 = transformThisPoint(point3, frame.container);
|
||||
|
||||
if (point1.x < viewPort.visibleArea.topRight.x && point1.y < viewPort.visibleArea.bottomRight.y && point3.x > viewPort.visibleArea.bottomLeft.x && point3.y > viewPort.visibleArea.topLeft.y ) {
|
||||
|
||||
return true;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
point1 = transformThisPoint(point1, frame.container)
|
||||
point3 = transformThisPoint(point3, frame.container)
|
||||
|
||||
if (point1.x < viewPort.visibleArea.topRight.x && point1.y < viewPort.visibleArea.bottomRight.y && point3.x > viewPort.visibleArea.bottomLeft.x && point3.y > viewPort.visibleArea.topLeft.y) {
|
||||
return true
|
||||
} else {
|
||||
return false
|
||||
}
|
||||
}
|
||||
|
||||
function fitIntoFrame(point) {
|
||||
|
||||
|
||||
function fitIntoFrame (point) {
|
||||
/* Here we check the boundaries of the resulting points, so they dont go out of the visible area. */
|
||||
|
||||
if (point.x > frame.width) {
|
||||
point.x = frame.width;
|
||||
}
|
||||
|
||||
if (point.x < 0) {
|
||||
point.x = 0;
|
||||
}
|
||||
|
||||
if (point.y > frame.height) {
|
||||
point.y = frame.height;
|
||||
}
|
||||
|
||||
if (point.y < 0) {
|
||||
point.y = 0;
|
||||
}
|
||||
|
||||
return point;
|
||||
if (point.x > frame.width) {
|
||||
point.x = frame.width
|
||||
}
|
||||
|
||||
|
||||
|
||||
function frameThisPoint(point) {
|
||||
|
||||
if (this.parentFrame !== undefined) {
|
||||
|
||||
point = this.parentFrame.frameThisPoint(point);
|
||||
|
||||
}
|
||||
|
||||
point.x = point.x + frame.position.x;
|
||||
point.y = point.y + frame.position.y;
|
||||
|
||||
return point;
|
||||
if (point.x < 0) {
|
||||
point.x = 0
|
||||
}
|
||||
|
||||
function unframeThisPoint(point) {
|
||||
|
||||
if (this.parentFrame !== undefined) {
|
||||
|
||||
point = this.parentFrame.unframeThisPoint(point);
|
||||
|
||||
}
|
||||
|
||||
point.x = point.x - this.position.x;
|
||||
point.y = point.y - this.position.y;
|
||||
|
||||
return point;
|
||||
if (point.y > frame.height) {
|
||||
point.y = frame.height
|
||||
}
|
||||
|
||||
function canYouMoveHere(tempDisplacement) {
|
||||
if (point.y < 0) {
|
||||
point.y = 0
|
||||
}
|
||||
|
||||
return point
|
||||
}
|
||||
|
||||
function frameThisPoint (point) {
|
||||
if (this.parentFrame !== undefined) {
|
||||
point = this.parentFrame.frameThisPoint(point)
|
||||
}
|
||||
|
||||
point.x = point.x + frame.position.x
|
||||
point.y = point.y + frame.position.y
|
||||
|
||||
return point
|
||||
}
|
||||
|
||||
function unframeThisPoint (point) {
|
||||
if (this.parentFrame !== undefined) {
|
||||
point = this.parentFrame.unframeThisPoint(point)
|
||||
}
|
||||
|
||||
point.x = point.x - this.position.x
|
||||
point.y = point.y - this.position.y
|
||||
|
||||
return point
|
||||
}
|
||||
|
||||
function canYouMoveHere (tempDisplacement) {
|
||||
/*
|
||||
|
||||
The current frame has a position and a displacement. We need to check that none of the boundaries points of the frame fall outside of its container frame.
|
||||
@@ -132,459 +112,427 @@ function newFrame() {
|
||||
|
||||
*/
|
||||
|
||||
point1 = {
|
||||
x: this.position.x,
|
||||
y: this.position.y
|
||||
};
|
||||
point1 = {
|
||||
x: this.position.x,
|
||||
y: this.position.y
|
||||
}
|
||||
|
||||
point2 = {
|
||||
x: this.position.x + this.width,
|
||||
y: this.position.y
|
||||
};
|
||||
point2 = {
|
||||
x: this.position.x + this.width,
|
||||
y: this.position.y
|
||||
}
|
||||
|
||||
point3 = {
|
||||
x: this.position.x + this.width,
|
||||
y: this.position.y + this.height
|
||||
};
|
||||
point3 = {
|
||||
x: this.position.x + this.width,
|
||||
y: this.position.y + this.height
|
||||
}
|
||||
|
||||
point4 = {
|
||||
x: this.position.x,
|
||||
y: this.position.y + this.height
|
||||
};
|
||||
point4 = {
|
||||
x: this.position.x,
|
||||
y: this.position.y + this.height
|
||||
}
|
||||
|
||||
/* Now the transformations. */
|
||||
|
||||
if (this.parentFrame !== undefined) { // If there is not a parent then there is no point to check bounderies.
|
||||
if (this.parentFrame !== undefined) {
|
||||
// If there is not a parent then there is no point to check bounderies.
|
||||
|
||||
point1 = this.parentFrame.frameThisPoint(point1);
|
||||
point2 = this.parentFrame.frameThisPoint(point2);
|
||||
point3 = this.parentFrame.frameThisPoint(point3);
|
||||
point4 = this.parentFrame.frameThisPoint(point4);
|
||||
point1 = this.parentFrame.frameThisPoint(point1)
|
||||
point2 = this.parentFrame.frameThisPoint(point2)
|
||||
point3 = this.parentFrame.frameThisPoint(point3)
|
||||
point4 = this.parentFrame.frameThisPoint(point4)
|
||||
|
||||
/* We apply the temporary displacement. */
|
||||
|
||||
point1 = tempDisplacement.displaceThisPoint(point1);
|
||||
point2 = tempDisplacement.displaceThisPoint(point2);
|
||||
point3 = tempDisplacement.displaceThisPoint(point3);
|
||||
point4 = tempDisplacement.displaceThisPoint(point4);
|
||||
point1 = tempDisplacement.displaceThisPoint(point1)
|
||||
point2 = tempDisplacement.displaceThisPoint(point2)
|
||||
point3 = tempDisplacement.displaceThisPoint(point3)
|
||||
point4 = tempDisplacement.displaceThisPoint(point4)
|
||||
|
||||
/* We add the actual displacement. */
|
||||
|
||||
point1 = this.container.displacement.displaceThisPoint(point1);
|
||||
point2 = this.container.displacement.displaceThisPoint(point2);
|
||||
point3 = this.container.displacement.displaceThisPoint(point3);
|
||||
point4 = this.container.displacement.displaceThisPoint(point4);
|
||||
point1 = this.container.displacement.displaceThisPoint(point1)
|
||||
point2 = this.container.displacement.displaceThisPoint(point2)
|
||||
point3 = this.container.displacement.displaceThisPoint(point3)
|
||||
point4 = this.container.displacement.displaceThisPoint(point4)
|
||||
|
||||
if (this.parentFrame.isThisPointHere(point1) === false) {
|
||||
return false;
|
||||
}
|
||||
if (this.parentFrame.isThisPointHere(point1) === false) {
|
||||
return false
|
||||
}
|
||||
|
||||
if (this.parentFrame.isThisPointHere(point2) === false) {
|
||||
return false;
|
||||
}
|
||||
if (this.parentFrame.isThisPointHere(point2) === false) {
|
||||
return false
|
||||
}
|
||||
|
||||
if (this.parentFrame.isThisPointHere(point3) === false) {
|
||||
return false;
|
||||
}
|
||||
if (this.parentFrame.isThisPointHere(point3) === false) {
|
||||
return false
|
||||
}
|
||||
|
||||
if (this.parentFrame.isThisPointHere(point4) === false) {
|
||||
return false;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
return true;
|
||||
if (this.parentFrame.isThisPointHere(point4) === false) {
|
||||
return false
|
||||
}
|
||||
}
|
||||
|
||||
function canYouZoomHere(tempZoom) {
|
||||
return true
|
||||
}
|
||||
|
||||
point1 = {
|
||||
x: this.position.x,
|
||||
y: this.position.y
|
||||
};
|
||||
function canYouZoomHere (tempZoom) {
|
||||
point1 = {
|
||||
x: this.position.x,
|
||||
y: this.position.y
|
||||
}
|
||||
|
||||
point2 = {
|
||||
x: this.position.x + this.width,
|
||||
y: this.position.y
|
||||
};
|
||||
point2 = {
|
||||
x: this.position.x + this.width,
|
||||
y: this.position.y
|
||||
}
|
||||
|
||||
point3 = {
|
||||
x: this.position.x + this.width,
|
||||
y: this.position.y + this.height
|
||||
};
|
||||
point3 = {
|
||||
x: this.position.x + this.width,
|
||||
y: this.position.y + this.height
|
||||
}
|
||||
|
||||
point4 = {
|
||||
x: this.position.x,
|
||||
y: this.position.y + this.height
|
||||
};
|
||||
point4 = {
|
||||
x: this.position.x,
|
||||
y: this.position.y + this.height
|
||||
}
|
||||
|
||||
/* Now the transformations. */
|
||||
|
||||
if (this.parentFrame !== undefined) { // If there is not a parent then there is no point to check bounderies.
|
||||
if (this.parentFrame !== undefined) {
|
||||
// If there is not a parent then there is no point to check bounderies.
|
||||
|
||||
point1 = this.parentFrame.frameThisPoint(point1);
|
||||
point2 = this.parentFrame.frameThisPoint(point2);
|
||||
point3 = this.parentFrame.frameThisPoint(point3);
|
||||
point4 = this.parentFrame.frameThisPoint(point4);
|
||||
point1 = this.parentFrame.frameThisPoint(point1)
|
||||
point2 = this.parentFrame.frameThisPoint(point2)
|
||||
point3 = this.parentFrame.frameThisPoint(point3)
|
||||
point4 = this.parentFrame.frameThisPoint(point4)
|
||||
|
||||
/* We add the actual displacement. */
|
||||
|
||||
point1 = this.container.displacement.displaceThisPoint(point1);
|
||||
point2 = this.container.displacement.displaceThisPoint(point2);
|
||||
point3 = this.container.displacement.displaceThisPoint(point3);
|
||||
point4 = this.container.displacement.displaceThisPoint(point4);
|
||||
point1 = this.container.displacement.displaceThisPoint(point1)
|
||||
point2 = this.container.displacement.displaceThisPoint(point2)
|
||||
point3 = this.container.displacement.displaceThisPoint(point3)
|
||||
point4 = this.container.displacement.displaceThisPoint(point4)
|
||||
|
||||
/* We temp zoom. */
|
||||
|
||||
point1 = tempZoom.zoomThisPoint(point1);
|
||||
point2 = tempZoom.zoomThisPoint(point2);
|
||||
point3 = tempZoom.zoomThisPoint(point3);
|
||||
point4 = tempZoom.zoomThisPoint(point4);
|
||||
point1 = tempZoom.zoomThisPoint(point1)
|
||||
point2 = tempZoom.zoomThisPoint(point2)
|
||||
point3 = tempZoom.zoomThisPoint(point3)
|
||||
point4 = tempZoom.zoomThisPoint(point4)
|
||||
|
||||
if (this.parentFrame.isThisPointHere(point1) === false) {
|
||||
return false;
|
||||
}
|
||||
if (this.parentFrame.isThisPointHere(point1) === false) {
|
||||
return false
|
||||
}
|
||||
|
||||
if (this.parentFrame.isThisPointHere(point2) === false) {
|
||||
return false;
|
||||
}
|
||||
if (this.parentFrame.isThisPointHere(point2) === false) {
|
||||
return false
|
||||
}
|
||||
|
||||
if (this.parentFrame.isThisPointHere(point3) === false) {
|
||||
return false;
|
||||
}
|
||||
if (this.parentFrame.isThisPointHere(point3) === false) {
|
||||
return false
|
||||
}
|
||||
|
||||
if (this.parentFrame.isThisPointHere(point4) === false) {
|
||||
return false;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
return true;
|
||||
if (this.parentFrame.isThisPointHere(point4) === false) {
|
||||
return false
|
||||
}
|
||||
}
|
||||
|
||||
return true
|
||||
}
|
||||
|
||||
function isThisPointHere(point, outsideViewPort) { // The second parameter is usefull when you want to check a point that you already know is outside the viewport.
|
||||
function isThisPointHere (point, outsideViewPort) {
|
||||
// The second parameter is usefull when you want to check a point that you already know is outside the viewport.
|
||||
|
||||
/* We need not to modify the point received, so me make a copy of it. */
|
||||
|
||||
var checkPoint = {
|
||||
x: point.x,
|
||||
y: point.y
|
||||
};
|
||||
var checkPoint = {
|
||||
x: point.x,
|
||||
y: point.y
|
||||
}
|
||||
|
||||
/* The point received is on the screen coordinates system, which already has zoom and displacement applied. We need to remove the zoom and displacement
|
||||
in order to have the point on the containers coordinate system and be able to compare it with its dimmensions. */
|
||||
|
||||
if (outsideViewPort === true) {
|
||||
|
||||
checkPoint = this.container.displacement.undisplaceThisPoint(checkPoint);
|
||||
checkPoint = this.container.frame.unframeThisPoint(checkPoint);
|
||||
|
||||
} else {
|
||||
checkPoint = unTransformThisPoint(checkPoint, frame.container);
|
||||
}
|
||||
if (outsideViewPort === true) {
|
||||
checkPoint = this.container.displacement.undisplaceThisPoint(checkPoint)
|
||||
checkPoint = this.container.frame.unframeThisPoint(checkPoint)
|
||||
} else {
|
||||
checkPoint = unTransformThisPoint(checkPoint, frame.container)
|
||||
}
|
||||
|
||||
/* Now we check if the resulting point is whin the current Frame. */
|
||||
|
||||
if (checkPoint.x < 0 || checkPoint.y < 0 || checkPoint.x > frame.width || checkPoint.y > frame.height) {
|
||||
|
||||
if (checkPoint.x < 0 || checkPoint.y < 0 || checkPoint.x > frame.width || checkPoint.y > frame.height) {
|
||||
/* The point received is not in this frame */
|
||||
|
||||
return false;
|
||||
|
||||
} else {
|
||||
|
||||
return false
|
||||
} else {
|
||||
/* The point is within this frame. */
|
||||
|
||||
return true;
|
||||
|
||||
}
|
||||
return true
|
||||
}
|
||||
}
|
||||
|
||||
function draw (drawGrid, drawBorders, drawBackground) {
|
||||
if (drawBorders === true) {
|
||||
borders()
|
||||
}
|
||||
|
||||
function draw(drawGrid, drawBorders, drawBackground) {
|
||||
|
||||
|
||||
if (drawBorders === true) {
|
||||
borders();
|
||||
}
|
||||
|
||||
if (drawGrid === true) {
|
||||
grid();
|
||||
}
|
||||
|
||||
if (drawBackground === true) {
|
||||
background();
|
||||
}
|
||||
if (drawGrid === true) {
|
||||
grid()
|
||||
}
|
||||
|
||||
function background() {
|
||||
if (drawBackground === true) {
|
||||
background()
|
||||
}
|
||||
}
|
||||
|
||||
function background () {
|
||||
borderPoint1 = {
|
||||
x: PANEL_CORNERS_RADIOUS,
|
||||
y: PANEL_CORNERS_RADIOUS
|
||||
}
|
||||
|
||||
borderPoint2 = {
|
||||
x: frame.width - PANEL_CORNERS_RADIOUS,
|
||||
y: PANEL_CORNERS_RADIOUS
|
||||
}
|
||||
|
||||
borderPoint1 = {
|
||||
x: PANEL_CORNERS_RADIOUS,
|
||||
y: PANEL_CORNERS_RADIOUS
|
||||
};
|
||||
borderPoint3 = {
|
||||
x: frame.width - PANEL_CORNERS_RADIOUS,
|
||||
y: frame.height - PANEL_CORNERS_RADIOUS
|
||||
}
|
||||
|
||||
borderPoint2 = {
|
||||
x: frame.width - PANEL_CORNERS_RADIOUS,
|
||||
y: PANEL_CORNERS_RADIOUS
|
||||
};
|
||||
borderPoint4 = {
|
||||
x: PANEL_CORNERS_RADIOUS,
|
||||
y: frame.height - PANEL_CORNERS_RADIOUS
|
||||
}
|
||||
|
||||
borderPoint3 = {
|
||||
x: frame.width - PANEL_CORNERS_RADIOUS,
|
||||
y: frame.height - PANEL_CORNERS_RADIOUS
|
||||
};
|
||||
|
||||
borderPoint4 = {
|
||||
x: PANEL_CORNERS_RADIOUS,
|
||||
y: frame.height - PANEL_CORNERS_RADIOUS
|
||||
};
|
||||
|
||||
titleBarPoint1 = {
|
||||
x: 0,
|
||||
y: TITLE_BAR_HEIGHT
|
||||
};
|
||||
|
||||
titleBarPoint2 = {
|
||||
x: frame.width,
|
||||
y: TITLE_BAR_HEIGHT
|
||||
};
|
||||
titleBarPoint1 = {
|
||||
x: 0,
|
||||
y: TITLE_BAR_HEIGHT
|
||||
}
|
||||
|
||||
titleBarPoint2 = {
|
||||
x: frame.width,
|
||||
y: TITLE_BAR_HEIGHT
|
||||
}
|
||||
|
||||
/* Now the transformations. */
|
||||
|
||||
borderPoint1 = frameThisPoint(borderPoint1);
|
||||
borderPoint2 = frameThisPoint(borderPoint2);
|
||||
borderPoint3 = frameThisPoint(borderPoint3);
|
||||
borderPoint4 = frameThisPoint(borderPoint4);
|
||||
borderPoint1 = frameThisPoint(borderPoint1)
|
||||
borderPoint2 = frameThisPoint(borderPoint2)
|
||||
borderPoint3 = frameThisPoint(borderPoint3)
|
||||
borderPoint4 = frameThisPoint(borderPoint4)
|
||||
|
||||
titleBarPoint1 = frameThisPoint(titleBarPoint1);
|
||||
titleBarPoint2 = frameThisPoint(titleBarPoint2);
|
||||
titleBarPoint1 = frameThisPoint(titleBarPoint1)
|
||||
titleBarPoint2 = frameThisPoint(titleBarPoint2)
|
||||
|
||||
/* We paint the panel background first */
|
||||
|
||||
browserCanvasContext.fillStyle = 'rgba(' + UI_COLOR.WHITE + ', 0.75)';
|
||||
browserCanvasContext.beginPath();
|
||||
browserCanvasContext.fillStyle = 'rgba(' + UI_COLOR.WHITE + ', 0.75)'
|
||||
browserCanvasContext.beginPath()
|
||||
|
||||
browserCanvasContext.arc(borderPoint1.x, borderPoint1.y, PANEL_CORNERS_RADIOUS, 1.0 * Math.PI, 1.5 * Math.PI);
|
||||
browserCanvasContext.lineTo(borderPoint2.x, borderPoint2.y - PANEL_CORNERS_RADIOUS);
|
||||
browserCanvasContext.arc(borderPoint2.x, borderPoint2.y, PANEL_CORNERS_RADIOUS, 1.5 * Math.PI, 2.0 * Math.PI);
|
||||
browserCanvasContext.lineTo(borderPoint3.x + PANEL_CORNERS_RADIOUS, borderPoint3.y);
|
||||
browserCanvasContext.arc(borderPoint3.x, borderPoint3.y, PANEL_CORNERS_RADIOUS, 0 * Math.PI, 0.5 * Math.PI);
|
||||
browserCanvasContext.lineTo(borderPoint4.x, borderPoint4.y + PANEL_CORNERS_RADIOUS);
|
||||
browserCanvasContext.arc(borderPoint4.x, borderPoint4.y, PANEL_CORNERS_RADIOUS, 0.5 * Math.PI, 1.0 * Math.PI);
|
||||
browserCanvasContext.lineTo(borderPoint1.x - PANEL_CORNERS_RADIOUS, borderPoint1.y);
|
||||
browserCanvasContext.arc(borderPoint1.x, borderPoint1.y, PANEL_CORNERS_RADIOUS, 1.0 * Math.PI, 1.5 * Math.PI)
|
||||
browserCanvasContext.lineTo(borderPoint2.x, borderPoint2.y - PANEL_CORNERS_RADIOUS)
|
||||
browserCanvasContext.arc(borderPoint2.x, borderPoint2.y, PANEL_CORNERS_RADIOUS, 1.5 * Math.PI, 2.0 * Math.PI)
|
||||
browserCanvasContext.lineTo(borderPoint3.x + PANEL_CORNERS_RADIOUS, borderPoint3.y)
|
||||
browserCanvasContext.arc(borderPoint3.x, borderPoint3.y, PANEL_CORNERS_RADIOUS, 0 * Math.PI, 0.5 * Math.PI)
|
||||
browserCanvasContext.lineTo(borderPoint4.x, borderPoint4.y + PANEL_CORNERS_RADIOUS)
|
||||
browserCanvasContext.arc(borderPoint4.x, borderPoint4.y, PANEL_CORNERS_RADIOUS, 0.5 * Math.PI, 1.0 * Math.PI)
|
||||
browserCanvasContext.lineTo(borderPoint1.x - PANEL_CORNERS_RADIOUS, borderPoint1.y)
|
||||
|
||||
browserCanvasContext.closePath();
|
||||
browserCanvasContext.closePath()
|
||||
|
||||
browserCanvasContext.fill();
|
||||
browserCanvasContext.fill()
|
||||
|
||||
browserCanvasContext.lineWidth = 0.1;
|
||||
browserCanvasContext.strokeStyle = 'rgba(' + UI_COLOR.MANGANESE_PURPLE + ', 0.75)';
|
||||
browserCanvasContext.stroke();
|
||||
|
||||
|
||||
browserCanvasContext.lineWidth = 0.1
|
||||
browserCanvasContext.strokeStyle = 'rgba(' + UI_COLOR.MANGANESE_PURPLE + ', 0.75)'
|
||||
browserCanvasContext.stroke()
|
||||
|
||||
/* We paint the title bar now */
|
||||
|
||||
browserCanvasContext.fillStyle = 'rgba(' + UI_COLOR.DARK + ', 0.75)';
|
||||
browserCanvasContext.beginPath();
|
||||
|
||||
browserCanvasContext.moveTo(titleBarPoint1.x, titleBarPoint1.y);
|
||||
browserCanvasContext.lineTo(borderPoint1.x - PANEL_CORNERS_RADIOUS, borderPoint1.y);
|
||||
browserCanvasContext.arc(borderPoint1.x, borderPoint1.y, PANEL_CORNERS_RADIOUS, 1.0 * Math.PI, 1.5 * Math.PI);
|
||||
browserCanvasContext.lineTo(borderPoint2.x, borderPoint2.y - PANEL_CORNERS_RADIOUS);
|
||||
browserCanvasContext.arc(borderPoint2.x, borderPoint2.y, PANEL_CORNERS_RADIOUS, 1.5 * Math.PI, 2.0 * Math.PI);
|
||||
browserCanvasContext.lineTo(titleBarPoint2.x, titleBarPoint2.y);
|
||||
browserCanvasContext.fillStyle = 'rgba(' + UI_COLOR.DARK + ', 0.75)'
|
||||
browserCanvasContext.beginPath()
|
||||
|
||||
browserCanvasContext.closePath();
|
||||
browserCanvasContext.fill();
|
||||
|
||||
browserCanvasContext.lineWidth = 0.1;
|
||||
browserCanvasContext.strokeStyle = 'rgba(' + UI_COLOR.MANGANESE_PURPLE + ', 0.75)';
|
||||
browserCanvasContext.stroke();
|
||||
browserCanvasContext.moveTo(titleBarPoint1.x, titleBarPoint1.y)
|
||||
browserCanvasContext.lineTo(borderPoint1.x - PANEL_CORNERS_RADIOUS, borderPoint1.y)
|
||||
browserCanvasContext.arc(borderPoint1.x, borderPoint1.y, PANEL_CORNERS_RADIOUS, 1.0 * Math.PI, 1.5 * Math.PI)
|
||||
browserCanvasContext.lineTo(borderPoint2.x, borderPoint2.y - PANEL_CORNERS_RADIOUS)
|
||||
browserCanvasContext.arc(borderPoint2.x, borderPoint2.y, PANEL_CORNERS_RADIOUS, 1.5 * Math.PI, 2.0 * Math.PI)
|
||||
browserCanvasContext.lineTo(titleBarPoint2.x, titleBarPoint2.y)
|
||||
|
||||
browserCanvasContext.closePath()
|
||||
browserCanvasContext.fill()
|
||||
|
||||
browserCanvasContext.lineWidth = 0.1
|
||||
browserCanvasContext.strokeStyle = 'rgba(' + UI_COLOR.MANGANESE_PURPLE + ', 0.75)'
|
||||
browserCanvasContext.stroke()
|
||||
|
||||
/* print the title */
|
||||
|
||||
let labelPoint;
|
||||
let fontSize = 10;
|
||||
let labelPoint
|
||||
let fontSize = 10
|
||||
|
||||
browserCanvasContext.font = fontSize + 'px ' + UI_FONT.SECONDARY;
|
||||
browserCanvasContext.font = fontSize + 'px ' + UI_FONT.SECONDARY + ' Saira'
|
||||
|
||||
let label = frame.containerName;
|
||||
let label = frame.containerName
|
||||
|
||||
let xOffset = label.length / 2 * fontSize * FONT_ASPECT_RATIO;
|
||||
let yOffset = (TITLE_BAR_HEIGHT - fontSize) / 2 + 2;
|
||||
let xOffset = label.length / 2 * fontSize * FONT_ASPECT_RATIO
|
||||
let yOffset = (TITLE_BAR_HEIGHT - fontSize) / 2 + 2
|
||||
|
||||
labelPoint = {
|
||||
x: frame.width / 2 - xOffset,
|
||||
y: TITLE_BAR_HEIGHT - yOffset
|
||||
};
|
||||
|
||||
labelPoint = frame.frameThisPoint(labelPoint);
|
||||
|
||||
browserCanvasContext.fillStyle = 'rgba(' + UI_COLOR.WHITE + ', 1)';
|
||||
browserCanvasContext.fillText(label, labelPoint.x, labelPoint.y);
|
||||
labelPoint = {
|
||||
x: frame.width / 2 - xOffset,
|
||||
y: TITLE_BAR_HEIGHT - yOffset
|
||||
}
|
||||
|
||||
labelPoint = frame.frameThisPoint(labelPoint)
|
||||
|
||||
function borders() {
|
||||
|
||||
browserCanvasContext.fillStyle = 'rgba(' + UI_COLOR.WHITE + ', 1)'
|
||||
browserCanvasContext.fillText(label, labelPoint.x, labelPoint.y)
|
||||
}
|
||||
|
||||
function borders () {
|
||||
/* Lest get the important points of the drawing so as to apply the needed transformations. */
|
||||
|
||||
point1 = {
|
||||
x: 0,
|
||||
y: 0
|
||||
};
|
||||
point1 = {
|
||||
x: 0,
|
||||
y: 0
|
||||
}
|
||||
|
||||
point2 = {
|
||||
x: frame.width,
|
||||
y: 0
|
||||
};
|
||||
point2 = {
|
||||
x: frame.width,
|
||||
y: 0
|
||||
}
|
||||
|
||||
point3 = {
|
||||
x: frame.width,
|
||||
y: frame.height
|
||||
};
|
||||
point3 = {
|
||||
x: frame.width,
|
||||
y: frame.height
|
||||
}
|
||||
|
||||
point4 = {
|
||||
x: 0,
|
||||
y: frame.height
|
||||
};
|
||||
point4 = {
|
||||
x: 0,
|
||||
y: frame.height
|
||||
}
|
||||
|
||||
/* Now the transformations. */
|
||||
|
||||
point1 = transformThisPoint(point1, frame.container);
|
||||
point2 = transformThisPoint(point2, frame.container);
|
||||
point3 = transformThisPoint(point3, frame.container);
|
||||
point4 = transformThisPoint(point4, frame.container);
|
||||
point1 = transformThisPoint(point1, frame.container)
|
||||
point2 = transformThisPoint(point2, frame.container)
|
||||
point3 = transformThisPoint(point3, frame.container)
|
||||
point4 = transformThisPoint(point4, frame.container)
|
||||
|
||||
/* Lets start the drawing. */
|
||||
|
||||
browserCanvasContext.beginPath();
|
||||
browserCanvasContext.moveTo(point1.x, point1.y);
|
||||
browserCanvasContext.lineTo(point2.x, point2.y);
|
||||
browserCanvasContext.lineTo(point3.x, point3.y);
|
||||
browserCanvasContext.lineTo(point4.x, point4.y);
|
||||
browserCanvasContext.lineTo(point1.x, point1.y);
|
||||
browserCanvasContext.closePath();
|
||||
browserCanvasContext.beginPath()
|
||||
browserCanvasContext.moveTo(point1.x, point1.y)
|
||||
browserCanvasContext.lineTo(point2.x, point2.y)
|
||||
browserCanvasContext.lineTo(point3.x, point3.y)
|
||||
browserCanvasContext.lineTo(point4.x, point4.y)
|
||||
browserCanvasContext.lineTo(point1.x, point1.y)
|
||||
browserCanvasContext.closePath()
|
||||
|
||||
browserCanvasContext.strokeStyle = 'rgba(150, 150, 150, 1)'
|
||||
browserCanvasContext.lineWidth = 1
|
||||
browserCanvasContext.stroke()
|
||||
|
||||
browserCanvasContext.strokeStyle = 'rgba(150, 150, 150, 1)';
|
||||
browserCanvasContext.lineWidth = 1;
|
||||
browserCanvasContext.stroke();
|
||||
|
||||
browserCanvasContext.closePath();
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
function grid(smallLines) {
|
||||
|
||||
if (smallLines === true) {
|
||||
browserCanvasContext.closePath()
|
||||
}
|
||||
|
||||
function grid (smallLines) {
|
||||
if (smallLines === true) {
|
||||
/* Small Lines */
|
||||
|
||||
var step = frame.width / 100;
|
||||
var step = frame.width / 100
|
||||
|
||||
browserCanvasContext.beginPath();
|
||||
browserCanvasContext.beginPath()
|
||||
|
||||
for (var i = 0; i < frame.width; i = i + step) {
|
||||
for (var i = 0; i < frame.width; i = i + step) {
|
||||
for (var j = 0; j < frame.height; j = j + step) {
|
||||
let point1 = {
|
||||
x: 0,
|
||||
y: j
|
||||
}
|
||||
|
||||
for (var j = 0; j < frame.height; j = j + step) {
|
||||
let point2 = {
|
||||
x: frame.width,
|
||||
y: j
|
||||
}
|
||||
|
||||
let point1 = {
|
||||
x: 0,
|
||||
y: j
|
||||
};
|
||||
point1 = transformThisPoint(point1, frame.container)
|
||||
point2 = transformThisPoint(point2, frame.container)
|
||||
|
||||
let point2 = {
|
||||
x: frame.width,
|
||||
y: j
|
||||
};
|
||||
|
||||
point1 = transformThisPoint(point1, frame.container);
|
||||
point2 = transformThisPoint(point2, frame.container);
|
||||
|
||||
browserCanvasContext.moveTo(point1.x, point1.y);
|
||||
browserCanvasContext.lineTo(point2.x, point2.y);
|
||||
}
|
||||
|
||||
let point3 = {
|
||||
x: frame.width,
|
||||
y: frame.height
|
||||
};
|
||||
|
||||
let point4 = {
|
||||
x: 0,
|
||||
y: frame.height
|
||||
};
|
||||
|
||||
point3 = transformThisPoint(point3, frame.container);
|
||||
point4 = transformThisPoint(point4, frame.container);
|
||||
|
||||
browserCanvasContext.moveTo(point3.x, point3.y);
|
||||
browserCanvasContext.lineTo(point4.x, point4.y);
|
||||
}
|
||||
browserCanvasContext.closePath();
|
||||
browserCanvasContext.strokeStyle = 'rgba(150, 150, 150, 0.1)';
|
||||
browserCanvasContext.lineWidth = 1;
|
||||
browserCanvasContext.stroke();
|
||||
browserCanvasContext.moveTo(point1.x, point1.y)
|
||||
browserCanvasContext.lineTo(point2.x, point2.y)
|
||||
}
|
||||
|
||||
let point3 = {
|
||||
x: frame.width,
|
||||
y: frame.height
|
||||
}
|
||||
|
||||
let point4 = {
|
||||
x: 0,
|
||||
y: frame.height
|
||||
}
|
||||
|
||||
point3 = transformThisPoint(point3, frame.container)
|
||||
point4 = transformThisPoint(point4, frame.container)
|
||||
|
||||
browserCanvasContext.moveTo(point3.x, point3.y)
|
||||
browserCanvasContext.lineTo(point4.x, point4.y)
|
||||
}
|
||||
browserCanvasContext.closePath()
|
||||
browserCanvasContext.strokeStyle = 'rgba(150, 150, 150, 0.1)'
|
||||
browserCanvasContext.lineWidth = 1
|
||||
browserCanvasContext.stroke()
|
||||
}
|
||||
|
||||
/* Main Lines */
|
||||
|
||||
var step = frame.width / 20;
|
||||
var step = frame.width / 20
|
||||
|
||||
browserCanvasContext.beginPath();
|
||||
browserCanvasContext.beginPath()
|
||||
|
||||
for (var i = 0; i < frame.width; i = i + step) {
|
||||
|
||||
for (var j = 0; j < frame.height; j = j + step) {
|
||||
|
||||
let point1 = {
|
||||
x: 0,
|
||||
y: j
|
||||
};
|
||||
|
||||
let point2 = {
|
||||
x: frame.width,
|
||||
y: j
|
||||
};
|
||||
|
||||
point1 = transformThisPoint(point1, frame.container);
|
||||
point2 = transformThisPoint(point2, frame.container);
|
||||
|
||||
browserCanvasContext.moveTo(point1.x, point1.y);
|
||||
browserCanvasContext.lineTo(point2.x, point2.y);
|
||||
}
|
||||
|
||||
let point3 = {
|
||||
x: i,
|
||||
y: 0
|
||||
};
|
||||
|
||||
let point4 = {
|
||||
x: i,
|
||||
y: frame.height
|
||||
};
|
||||
|
||||
point3 = transformThisPoint(point3, frame.container);
|
||||
point4 = transformThisPoint(point4, frame.container);
|
||||
|
||||
browserCanvasContext.moveTo(point3.x, point3.y);
|
||||
browserCanvasContext.lineTo(point4.x, point4.y);
|
||||
for (var i = 0; i < frame.width; i = i + step) {
|
||||
for (var j = 0; j < frame.height; j = j + step) {
|
||||
let point1 = {
|
||||
x: 0,
|
||||
y: j
|
||||
}
|
||||
browserCanvasContext.closePath();
|
||||
browserCanvasContext.strokeStyle = 'rgba(100, 100, 100, 0.2)';
|
||||
browserCanvasContext.lineWidth = 1;
|
||||
browserCanvasContext.stroke();
|
||||
|
||||
let point2 = {
|
||||
x: frame.width,
|
||||
y: j
|
||||
}
|
||||
|
||||
point1 = transformThisPoint(point1, frame.container)
|
||||
point2 = transformThisPoint(point2, frame.container)
|
||||
|
||||
browserCanvasContext.moveTo(point1.x, point1.y)
|
||||
browserCanvasContext.lineTo(point2.x, point2.y)
|
||||
}
|
||||
|
||||
let point3 = {
|
||||
x: i,
|
||||
y: 0
|
||||
}
|
||||
|
||||
let point4 = {
|
||||
x: i,
|
||||
y: frame.height
|
||||
}
|
||||
|
||||
point3 = transformThisPoint(point3, frame.container)
|
||||
point4 = transformThisPoint(point4, frame.container)
|
||||
|
||||
browserCanvasContext.moveTo(point3.x, point3.y)
|
||||
browserCanvasContext.lineTo(point4.x, point4.y)
|
||||
}
|
||||
}
|
||||
browserCanvasContext.closePath()
|
||||
browserCanvasContext.strokeStyle = 'rgba(100, 100, 100, 0.2)'
|
||||
browserCanvasContext.lineWidth = 1
|
||||
browserCanvasContext.stroke()
|
||||
}
|
||||
}
|
||||
+10
-4
@@ -1,4 +1,4 @@
|
||||
/* User Interface Colors */
|
||||
/* User Interface Colors */
|
||||
|
||||
UI_COLOR = {
|
||||
DARK: "48, 48, 54",
|
||||
@@ -94,8 +94,14 @@ function convertTimePeriodToName(pTimePeriod) {
|
||||
|
||||
window.AT_BREAKPOINT = false;
|
||||
|
||||
const INITIAL_DEFAULT_MARKET = 2; // This is the market that will be shown when loading the site for the first time.
|
||||
const DEFAULT_EXCHANGE = "Poloniex";
|
||||
const SUPPORTED_EXCHANGES = ["Poloniex", "Coss"];
|
||||
const SUPPORTED_MARKETS = [
|
||||
{
|
||||
assetA: "USDT",
|
||||
assetB: "BTC",
|
||||
}
|
||||
];
|
||||
const DEFAULT_EXCHANGE = "Coss";
|
||||
const DEFAULT_MARKET = {
|
||||
assetA: "USDT",
|
||||
assetB: "BTC",
|
||||
@@ -131,7 +137,7 @@ const EARLIEST_DATE = new Date(2014, 0, 18, 4, 26, 8);
|
||||
|
||||
const TOP_SPACE_HEIGHT = 5;
|
||||
const BOTTOM_SPACE_HEIGHT = 35;
|
||||
|
||||
const BREAKPOINT_HEIGHT = 15;
|
||||
|
||||
const PRODUCT_CARD_STATUS = {
|
||||
ON: 'on',
|
||||
|
||||
-127
@@ -1,127 +0,0 @@
|
||||
function newImageButton() {
|
||||
|
||||
var thisObject = {
|
||||
container: undefined,
|
||||
draw: draw,
|
||||
status: 'neutral',
|
||||
type: undefined,
|
||||
getContainer: getContainer,
|
||||
initialize: initialize
|
||||
};
|
||||
|
||||
var container = newContainer();
|
||||
container.initialize();
|
||||
container.isDraggeable = false;
|
||||
container.isClickeable = true;
|
||||
thisObject.container = container;
|
||||
|
||||
let idNeutralImage;
|
||||
let idOnImage;
|
||||
let idOffImage;
|
||||
let idDisabledImage;
|
||||
|
||||
return thisObject;
|
||||
|
||||
function initialize(pX, pY, pWidth, pHeight, pIdNeutralImage, pIdOnImage, pIdOffImage, pIdDisabledImage) {
|
||||
|
||||
idNeutralImage = pIdNeutralImage;
|
||||
idOnImage = pIdOnImage;
|
||||
idOffImage = pIdOffImage;
|
||||
idDisabledImage = pIdDisabledImage;
|
||||
|
||||
/* Lets set the basic dimensions of this thisObject. */
|
||||
|
||||
var position = {
|
||||
x: pX,
|
||||
y: pY
|
||||
};
|
||||
|
||||
thisObject.container.frame.position = position;
|
||||
thisObject.container.frame.width = pWidth;
|
||||
thisObject.container.frame.height = pHeight;
|
||||
|
||||
/* Now we start listening to the onClick event from the mouse, so that we can allow users operate this thisObject. */
|
||||
|
||||
thisObject.container.eventHandler.listenToEvent('onMouseClick', buttonPressed, undefined);
|
||||
|
||||
}
|
||||
|
||||
function getContainer(point) {
|
||||
|
||||
var container;
|
||||
|
||||
/* First we check if this point is inside this space. */
|
||||
|
||||
if (this.container.frame.isThisPointHere(point, true) === true) {
|
||||
|
||||
return this.container;
|
||||
|
||||
} else {
|
||||
|
||||
/* This point does not belong to this space. */
|
||||
|
||||
return undefined;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
function buttonPressed(event, extraData) {
|
||||
|
||||
switch (thisObject.status) {
|
||||
|
||||
case 'neutral':
|
||||
browserCanvasContext.fillStyle = onFillStyle;
|
||||
return;
|
||||
|
||||
case 'on':
|
||||
thisObject.status = 'off';
|
||||
break;
|
||||
|
||||
case 'off':
|
||||
thisObject.status = 'on';
|
||||
break;
|
||||
|
||||
case 'disabled':
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
function draw() {
|
||||
|
||||
drawImage();
|
||||
|
||||
}
|
||||
|
||||
function drawImage() {
|
||||
|
||||
let image;
|
||||
|
||||
let imagePoint = {
|
||||
x: 0,
|
||||
y: 0
|
||||
};
|
||||
|
||||
imagePoint = thisObject.container.frame.frameThisPoint(imagePoint);
|
||||
|
||||
switch (thisObject.status) {
|
||||
|
||||
case 'neutral':
|
||||
image = document.getElementById(idNeutralImage);
|
||||
break;
|
||||
|
||||
case 'on':
|
||||
image = document.getElementById(idOnImage);
|
||||
break;
|
||||
|
||||
case 'off':
|
||||
image = document.getElementById(idOffImage);
|
||||
break;
|
||||
|
||||
case 'disabled':
|
||||
image = document.getElementById(idDisabledImage);
|
||||
break;
|
||||
|
||||
}
|
||||
browserCanvasContext.drawImage(image, imagePoint.x, imagePoint.y, thisObject.container.frame.width, thisObject.container.frame.height);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,223 @@
|
||||
function newPanelTabButton () {
|
||||
var thisObject = {
|
||||
container: undefined,
|
||||
draw: draw,
|
||||
parentContainer: undefined,
|
||||
getContainer: getContainer, // returns the inner most container that holds the point received by parameter.
|
||||
initialize: initialize
|
||||
}
|
||||
|
||||
let isInitialized = false
|
||||
/* Cointainer stuff */
|
||||
|
||||
var container = newContainer()
|
||||
|
||||
container.name = 'Panel Tab Button'
|
||||
container.initialize()
|
||||
|
||||
container.isClickeable = true
|
||||
|
||||
thisObject.container = container
|
||||
thisObject.container.frame.containerName = 'Panel Tab Button'
|
||||
|
||||
/* Lets listen to our own events to react when we have a Mouse Click */
|
||||
|
||||
thisObject.container.eventHandler.listenToEvent('onMouseClick', buttonPressed)
|
||||
|
||||
/* Animation to hide the pannel */
|
||||
|
||||
let tabStatus = 'visible'
|
||||
let visiblePosition = {}
|
||||
let hiddenPosition = {}
|
||||
let transitionPosition = {}
|
||||
|
||||
return thisObject
|
||||
|
||||
function initialize () {
|
||||
thisObject.container.frame.width = 10
|
||||
thisObject.container.frame.height = 10
|
||||
|
||||
var position = {
|
||||
x: thisObject.parentContainer.frame.width - 15,
|
||||
y: 2
|
||||
}
|
||||
|
||||
thisObject.container.frame.position = position
|
||||
|
||||
visiblePosition.x = thisObject.parentContainer.frame.position.x
|
||||
visiblePosition.y = thisObject.parentContainer.frame.position.y
|
||||
|
||||
hiddenPosition.x = thisObject.parentContainer.frame.position.x
|
||||
hiddenPosition.y = viewPort.visibleArea.bottomRight.y
|
||||
|
||||
transitionPosition.x = visiblePosition.x
|
||||
transitionPosition.y = visiblePosition.y
|
||||
|
||||
isInitialized = true
|
||||
}
|
||||
|
||||
function buttonPressed (event) {
|
||||
if (tabStatus === 'visible') {
|
||||
visiblePosition.x = thisObject.parentContainer.frame.position.x
|
||||
visiblePosition.y = thisObject.parentContainer.frame.position.y
|
||||
|
||||
hiddenPosition.x = thisObject.parentContainer.frame.position.x
|
||||
hiddenPosition.y = viewPort.visibleArea.bottomRight.y
|
||||
|
||||
transitionPosition.x = visiblePosition.x
|
||||
transitionPosition.y = visiblePosition.y
|
||||
|
||||
thisObject.parentContainer.isDraggeable = false
|
||||
thisObject.parentContainer.isWheelable = false
|
||||
tabStatus = 'going down'
|
||||
} else {
|
||||
thisObject.parentContainer.isDraggeable = true
|
||||
thisObject.parentContainer.isWheelable = true
|
||||
tabStatus = 'going up'
|
||||
}
|
||||
}
|
||||
|
||||
function draw () {
|
||||
if (isInitialized === false) { return }
|
||||
|
||||
drawButton()
|
||||
|
||||
if (tabStatus === 'going down') {
|
||||
if (transitionPosition.y < hiddenPosition.y) {
|
||||
transitionPosition.y = transitionPosition.y + 50
|
||||
thisObject.parentContainer.frame.position.y = transitionPosition.y
|
||||
} else {
|
||||
thisObject.parentContainer.frame.position.y = hiddenPosition.y
|
||||
tabStatus = 'hidden'
|
||||
}
|
||||
}
|
||||
if (tabStatus === 'going up') {
|
||||
if (transitionPosition.y > visiblePosition.y) {
|
||||
transitionPosition.y = transitionPosition.y - 50
|
||||
thisObject.parentContainer.frame.position.y = transitionPosition.y
|
||||
} else {
|
||||
thisObject.parentContainer.frame.position.y = visiblePosition.y
|
||||
tabStatus = 'visible'
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function getContainer (point) {
|
||||
var container
|
||||
|
||||
/* First we check if thisObject point is inside thisObject space. */
|
||||
|
||||
if (thisObject.container.frame.isThisPointHere(point, true) === true) {
|
||||
/* Now we see which is the inner most container that has it */
|
||||
|
||||
return thisObject.container
|
||||
} else {
|
||||
/* This point does not belong to thisObject space. */
|
||||
|
||||
return undefined
|
||||
}
|
||||
}
|
||||
|
||||
function drawButton () {
|
||||
let point1
|
||||
let point2
|
||||
let point3
|
||||
|
||||
switch (tabStatus) {
|
||||
case 'visible': {
|
||||
point1 = {
|
||||
x: 3,
|
||||
y: 3
|
||||
}
|
||||
|
||||
point2 = {
|
||||
x: container.frame.width - 3,
|
||||
y: 3
|
||||
}
|
||||
|
||||
point3 = {
|
||||
x: container.frame.width / 2,
|
||||
y: container.frame.height - 3
|
||||
}
|
||||
break
|
||||
}
|
||||
|
||||
case 'going down': {
|
||||
point1 = {
|
||||
x: 4,
|
||||
y: 4
|
||||
}
|
||||
|
||||
point2 = {
|
||||
x: container.frame.width - 4,
|
||||
y: 4
|
||||
}
|
||||
|
||||
point3 = {
|
||||
x: container.frame.width / 2,
|
||||
y: container.frame.height - 4
|
||||
}
|
||||
break
|
||||
}
|
||||
|
||||
case 'going up': {
|
||||
point1 = {
|
||||
x: 4,
|
||||
y: container.frame.height - 4
|
||||
}
|
||||
|
||||
point2 = {
|
||||
x: container.frame.width - 4,
|
||||
y: container.frame.height - 4
|
||||
}
|
||||
|
||||
point3 = {
|
||||
x: container.frame.width / 2,
|
||||
y: 4
|
||||
}
|
||||
break
|
||||
}
|
||||
|
||||
case 'hidden': {
|
||||
point1 = {
|
||||
x: 3,
|
||||
y: container.frame.height - 3
|
||||
}
|
||||
|
||||
point2 = {
|
||||
x: container.frame.width - 3,
|
||||
y: container.frame.height - 3
|
||||
}
|
||||
|
||||
point3 = {
|
||||
x: container.frame.width / 2,
|
||||
y: 3
|
||||
}
|
||||
break
|
||||
}
|
||||
}
|
||||
|
||||
/* Now the transformations. */
|
||||
|
||||
point1 = thisObject.container.frame.frameThisPoint(point1)
|
||||
point2 = thisObject.container.frame.frameThisPoint(point2)
|
||||
point3 = thisObject.container.frame.frameThisPoint(point3)
|
||||
|
||||
/* Lets start the drawing. */
|
||||
|
||||
browserCanvasContext.beginPath()
|
||||
browserCanvasContext.moveTo(point1.x, point1.y)
|
||||
browserCanvasContext.lineTo(point2.x, point2.y)
|
||||
browserCanvasContext.lineTo(point3.x, point3.y)
|
||||
browserCanvasContext.lineTo(point1.x, point1.y)
|
||||
browserCanvasContext.closePath()
|
||||
|
||||
browserCanvasContext.strokeStyle = 'rgba(250, 250, 250, 1)'
|
||||
browserCanvasContext.lineWidth = 1
|
||||
browserCanvasContext.stroke()
|
||||
|
||||
browserCanvasContext.fillStyle = 'rgba(250, 250, 250, 1)'
|
||||
browserCanvasContext.fill()
|
||||
}
|
||||
}
|
||||
|
||||
+142
-153
@@ -1,240 +1,229 @@
|
||||
function newProductsPanel() {
|
||||
|
||||
var thisObject = {
|
||||
container: undefined,
|
||||
getLoadingProductCards: getLoadingProductCards,
|
||||
draw: draw,
|
||||
getContainer: getContainer, // returns the inner most container that holds the point received by parameter.
|
||||
initialize: initialize
|
||||
};
|
||||
function newProductsPanel () {
|
||||
var thisObject = {
|
||||
container: undefined,
|
||||
getLoadingProductCards: getLoadingProductCards,
|
||||
draw: draw,
|
||||
getContainer: getContainer, // returns the inner most container that holds the point received by parameter.
|
||||
initialize: initialize
|
||||
}
|
||||
|
||||
/* Cointainer stuff */
|
||||
|
||||
var container = newContainer();
|
||||
var container = newContainer()
|
||||
|
||||
container.name = "Indicators and Algobots Product Panel";
|
||||
container.initialize();
|
||||
container.initialize()
|
||||
|
||||
container.isDraggeable = true;
|
||||
container.isWheelable = true;
|
||||
container.isDraggeable = true
|
||||
container.isWheelable = true
|
||||
|
||||
thisObject.container = container;
|
||||
thisObject.container.frame.containerName = "Indicators and Algobots's Products";
|
||||
thisObject.container = container
|
||||
|
||||
let isInitialized = false;
|
||||
let productCards = [];
|
||||
let isInitialized = false
|
||||
let productCards = []
|
||||
|
||||
let visibleProductCards = [];
|
||||
let firstVisibleCard = 1;
|
||||
let visibleProductCards = []
|
||||
let firstVisibleCard = 1
|
||||
|
||||
/* Needed Variables */
|
||||
|
||||
var lastY = 5;
|
||||
let lastY = 5
|
||||
let panelTabButton
|
||||
|
||||
return thisObject;
|
||||
let exchange
|
||||
let market
|
||||
|
||||
function initialize() {
|
||||
return thisObject
|
||||
|
||||
thisObject.container.frame.width = UI_PANEL.WIDTH.LARGE;
|
||||
thisObject.container.frame.height = viewPort.visibleArea.bottomLeft.y - viewPort.visibleArea.topLeft.y; //UI_PANEL.HEIGHT.LARGE;
|
||||
function initialize (pExchange, pMarket) {
|
||||
exchange = pExchange
|
||||
market = pMarket
|
||||
|
||||
var position = {
|
||||
x: viewPort.visibleArea.topLeft.x,
|
||||
y: viewPort.visibleArea.bottomLeft.y - thisObject.container.frame.height
|
||||
};
|
||||
thisObject.container.name = exchange + ' ' + market.assetB + '/' + market.assetA + ' ' + 'Indicators'
|
||||
thisObject.container.frame.containerName = thisObject.container.name
|
||||
thisObject.container.frame.width = UI_PANEL.WIDTH.LARGE
|
||||
thisObject.container.frame.height = viewPort.visibleArea.bottomLeft.y - viewPort.visibleArea.topLeft.y // UI_PANEL.HEIGHT.LARGE;
|
||||
|
||||
thisObject.container.frame.position = position;
|
||||
var position = {
|
||||
x: viewPort.visibleArea.topLeft.x,
|
||||
y: viewPort.visibleArea.bottomLeft.y - thisObject.container.frame.height
|
||||
}
|
||||
|
||||
thisObject.container.frame.position = position
|
||||
|
||||
panelTabButton = newPanelTabButton()
|
||||
panelTabButton.parentContainer = thisObject.container
|
||||
panelTabButton.container.frame.parentFrame = thisObject.container.frame
|
||||
panelTabButton.initialize()
|
||||
|
||||
/* First thing is to build the productCards array */
|
||||
|
||||
let devTeams = ecosystem.getTeams();
|
||||
let devTeams = ecosystem.getTeams()
|
||||
|
||||
for (let i = 0; i < devTeams.length; i++) {
|
||||
for (let i = 0; i < devTeams.length; i++) {
|
||||
let devTeam = devTeams[i]
|
||||
|
||||
let devTeam = devTeams[i];
|
||||
for (let j = 0; j < devTeam.bots.length; j++) {
|
||||
let bot = devTeam.bots[j]
|
||||
|
||||
for (let j = 0; j < devTeam.bots.length; j++) {
|
||||
if (bot.type !== 'Indicator' && bot.cloneId === undefined) { continue }
|
||||
|
||||
let bot = devTeam.bots[j];
|
||||
|
||||
if (bot.products !== undefined) {
|
||||
|
||||
for (let k = 0; k < bot.products.length; k++) {
|
||||
|
||||
let product = bot.products[k];
|
||||
if (bot.products !== undefined) {
|
||||
for (let k = 0; k < bot.products.length; k++) {
|
||||
let product = bot.products[k]
|
||||
|
||||
/* Now we create Product objects */
|
||||
|
||||
let productCard = newProductCard();
|
||||
let productCard = newProductCard()
|
||||
|
||||
productCard.devTeam = devTeam;
|
||||
productCard.bot = bot;
|
||||
productCard.product = product;
|
||||
productCard.devTeam = devTeam
|
||||
productCard.bot = bot
|
||||
productCard.product = product
|
||||
|
||||
productCard.code = devTeam.codeName + '-' + bot.codeName + '-' + product.codeName;
|
||||
productCard.code = exchange + '-' + market.assetB + '/' + market.assetA + '-' + devTeam.codeName + '-' + bot.codeName + '-' + product.codeName
|
||||
|
||||
/* Initialize it */
|
||||
|
||||
productCard.initialize();
|
||||
productCard.initialize()
|
||||
|
||||
/* Container Stuff */
|
||||
|
||||
productCard.container.displacement.parentDisplacement = thisObject.container.displacement;
|
||||
productCard.container.frame.parentFrame = thisObject.container.frame;
|
||||
productCard.container.parentContainer = thisObject.container;
|
||||
productCard.container.isWheelable = true;
|
||||
productCard.container.displacement.parentDisplacement = thisObject.container.displacement
|
||||
productCard.container.frame.parentFrame = thisObject.container.frame
|
||||
productCard.container.parentContainer = thisObject.container
|
||||
productCard.container.isWheelable = true
|
||||
|
||||
/* Positioning within thisObject Panel */
|
||||
|
||||
let position = {
|
||||
x: 10,
|
||||
y: thisObject.container.frame.height - thisObject.container.frame.getBodyHeight()
|
||||
};
|
||||
let position = {
|
||||
x: 10,
|
||||
y: thisObject.container.frame.height - thisObject.container.frame.getBodyHeight()
|
||||
}
|
||||
|
||||
productCard.container.frame.position.x = position.x;
|
||||
productCard.container.frame.position.y = position.y + lastY;
|
||||
productCard.container.frame.position.x = position.x
|
||||
productCard.container.frame.position.y = position.y + lastY
|
||||
|
||||
lastY = lastY + productCard.container.frame.height;
|
||||
lastY = lastY + productCard.container.frame.height
|
||||
|
||||
/* Add to the Product Array */
|
||||
|
||||
productCards.push(productCard);
|
||||
productCards.push(productCard)
|
||||
|
||||
/* Add to Visible Product Array */
|
||||
|
||||
if (productCard.container.frame.position.y + productCard.container.frame.height < thisObject.container.frame.height) {
|
||||
|
||||
visibleProductCards.push(productCard);
|
||||
|
||||
}
|
||||
if (productCard.container.frame.position.y + productCard.container.frame.height < thisObject.container.frame.height) {
|
||||
visibleProductCards.push(productCard)
|
||||
}
|
||||
|
||||
/* Listen to Status Changes Events */
|
||||
|
||||
productCard.container.eventHandler.listenToEvent('Status Changed', onProductCardStatusChanged);
|
||||
productCard.container.eventHandler.listenToEvent('Mouse Wheel', onMouseWheel);
|
||||
productCard.container.eventHandler.listenToEvent('Status Changed', onProductCardStatusChanged)
|
||||
productCard.container.eventHandler.listenToEvent('Mouse Wheel', onMouseWheel)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
thisObject.container.eventHandler.listenToEvent('Mouse Wheel', onMouseWheel)
|
||||
isInitialized = true
|
||||
}
|
||||
|
||||
thisObject.container.eventHandler.listenToEvent("Mouse Wheel", onMouseWheel);
|
||||
isInitialized = true;
|
||||
function onMouseWheel (pDelta) {
|
||||
if (pDelta > 0) {
|
||||
pDelta = -1
|
||||
} else {
|
||||
pDelta = 1
|
||||
}
|
||||
|
||||
}
|
||||
firstVisibleCard = firstVisibleCard + pDelta
|
||||
|
||||
function onMouseWheel(pDelta) {
|
||||
let availableSlots = visibleProductCards.length
|
||||
|
||||
if (pDelta > 0) {
|
||||
pDelta = -1;
|
||||
} else {
|
||||
pDelta = 1;
|
||||
}
|
||||
if (firstVisibleCard < 1) { firstVisibleCard = 1 }
|
||||
if (firstVisibleCard > (productCards.length - availableSlots + 1)) { firstVisibleCard = productCards.length - availableSlots + 1 }
|
||||
|
||||
firstVisibleCard = firstVisibleCard + pDelta;
|
||||
visibleProductCards = []
|
||||
var lastY = 5
|
||||
|
||||
let availableSlots = visibleProductCards.length;
|
||||
|
||||
if (firstVisibleCard < 1) { firstVisibleCard = 1; }
|
||||
if (firstVisibleCard > (productCards.length - availableSlots + 1)) { firstVisibleCard = productCards.length - availableSlots + 1; }
|
||||
|
||||
visibleProductCards = [];
|
||||
var lastY = 5;
|
||||
|
||||
for (let i = 0; i < productCards.length; i++) {
|
||||
|
||||
if (i + 1 >= firstVisibleCard && i + 1 < firstVisibleCard + availableSlots) {
|
||||
|
||||
let productCard = productCards[i];
|
||||
for (let i = 0; i < productCards.length; i++) {
|
||||
if (i + 1 >= firstVisibleCard && i + 1 < firstVisibleCard + availableSlots) {
|
||||
let productCard = productCards[i]
|
||||
|
||||
/* Positioning within thisObject Panel */
|
||||
|
||||
let position = {
|
||||
x: 10,
|
||||
y: thisObject.container.frame.height - thisObject.container.frame.getBodyHeight()
|
||||
};
|
||||
productCard.container.frame.position.x = position.x;
|
||||
productCard.container.frame.position.y = position.y + lastY;
|
||||
let position = {
|
||||
x: 10,
|
||||
y: thisObject.container.frame.height - thisObject.container.frame.getBodyHeight()
|
||||
}
|
||||
productCard.container.frame.position.x = position.x
|
||||
productCard.container.frame.position.y = position.y + lastY
|
||||
|
||||
lastY = lastY + productCard.container.frame.height;
|
||||
lastY = lastY + productCard.container.frame.height
|
||||
|
||||
/* Add to Visible Product Array */
|
||||
|
||||
visibleProductCards.push(productCard);
|
||||
}
|
||||
}
|
||||
}
|
||||
visibleProductCards.push(productCard)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function onProductCardStatusChanged(pProductCard) {
|
||||
|
||||
thisObject.container.eventHandler.raiseEvent('Product Card Status Changed', pProductCard);
|
||||
|
||||
}
|
||||
|
||||
function getLoadingProductCards() {
|
||||
function onProductCardStatusChanged (pProductCard) {
|
||||
thisObject.container.eventHandler.raiseEvent('Product Card Status Changed', pProductCard)
|
||||
}
|
||||
|
||||
function getLoadingProductCards () {
|
||||
/* Returns all productCards which status is LOADING */
|
||||
|
||||
let onProducts = [];
|
||||
let onProducts = []
|
||||
|
||||
for (let i = 0; i < productCards.length; i++) {
|
||||
for (let i = 0; i < productCards.length; i++) {
|
||||
if (productCards[i].status === PRODUCT_CARD_STATUS.LOADING) {
|
||||
onProducts.push(productCards[i])
|
||||
}
|
||||
}
|
||||
|
||||
if (productCards[i].status === PRODUCT_CARD_STATUS.LOADING) {
|
||||
return onProducts
|
||||
}
|
||||
|
||||
onProducts.push(productCards[i]);
|
||||
}
|
||||
}
|
||||
function getContainer (point) {
|
||||
var container
|
||||
|
||||
return onProducts;
|
||||
}
|
||||
|
||||
function getContainer(point) {
|
||||
|
||||
var container;
|
||||
container = panelTabButton.getContainer(point)
|
||||
if (container !== undefined) { return container }
|
||||
|
||||
/* First we check if thisObject point is inside thisObject space. */
|
||||
|
||||
if (thisObject.container.frame.isThisPointHere(point, true) === true) {
|
||||
|
||||
if (thisObject.container.frame.isThisPointHere(point, true) === true) {
|
||||
/* Now we see which is the inner most container that has it */
|
||||
|
||||
for (var i = 0; i < visibleProductCards.length; i++) {
|
||||
container = visibleProductCards[i].getContainer(point)
|
||||
|
||||
for (var i = 0; i < visibleProductCards.length; i++) {
|
||||
|
||||
container = visibleProductCards[i].getContainer(point);
|
||||
|
||||
if (container !== undefined) {
|
||||
|
||||
if (container !== undefined) {
|
||||
/* We found an inner container which has the point. We return it. */
|
||||
|
||||
return container;
|
||||
}
|
||||
}
|
||||
return container
|
||||
}
|
||||
}
|
||||
|
||||
/* The point does not belong to any inner container, so we return the current container. */
|
||||
|
||||
return thisObject.container;
|
||||
|
||||
} else {
|
||||
|
||||
return thisObject.container
|
||||
} else {
|
||||
/* This point does not belong to thisObject space. */
|
||||
|
||||
return undefined;
|
||||
}
|
||||
return undefined
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
function draw () {
|
||||
if (isInitialized === false) { return }
|
||||
|
||||
thisObject.container.frame.draw(false, false, true)
|
||||
|
||||
function draw() {
|
||||
for (let i = 0; i < visibleProductCards.length; i++) {
|
||||
visibleProductCards[i].draw()
|
||||
}
|
||||
|
||||
if (isInitialized === false) {return;}
|
||||
|
||||
thisObject.container.frame.draw(false, false, true);
|
||||
|
||||
for (let i = 0; i < visibleProductCards.length; i++) {
|
||||
visibleProductCards[i].draw();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
panelTabButton.draw()
|
||||
}
|
||||
}
|
||||
+114
-134
@@ -1,177 +1,157 @@
|
||||
|
||||
function newTimeControlPanel() {
|
||||
|
||||
function newTimeControlPanel () {
|
||||
let thisObject = {
|
||||
container: undefined,
|
||||
setDatetime: setDatetime,
|
||||
datetimeDisplay: undefined,
|
||||
stepDisplay: undefined,
|
||||
draw: draw,
|
||||
getContainer: getContainer, // returns the inner most container that holds the point received by parameter.
|
||||
initialize: initialize
|
||||
}
|
||||
|
||||
let thisObject = {
|
||||
container: undefined,
|
||||
setDatetime: setDatetime,
|
||||
datetimeDisplay: undefined,
|
||||
stepDisplay: undefined,
|
||||
draw: draw,
|
||||
getContainer: getContainer, // returns the inner most container that holds the point received by parameter.
|
||||
initialize: initialize
|
||||
};
|
||||
let container = newContainer()
|
||||
container.initialize()
|
||||
container.isDraggeable = true
|
||||
thisObject.container = container
|
||||
thisObject.container.frame.containerName = 'Current Datetime'
|
||||
|
||||
let container = newContainer();
|
||||
container.initialize();
|
||||
container.isDraggeable = true;
|
||||
thisObject.container = container;
|
||||
thisObject.container.frame.containerName = "Current Datetime";
|
||||
let timePeriod
|
||||
let panelTabButton
|
||||
|
||||
let timePeriod;
|
||||
return thisObject
|
||||
|
||||
return thisObject;
|
||||
function initialize () {
|
||||
thisObject.container.frame.width = UI_PANEL.WIDTH.SMALL
|
||||
thisObject.container.frame.height = UI_PANEL.HEIGHT.SMALL
|
||||
|
||||
function initialize() {
|
||||
|
||||
thisObject.container.frame.width = UI_PANEL.WIDTH.SMALL;
|
||||
thisObject.container.frame.height = UI_PANEL.HEIGHT.SMALL;
|
||||
|
||||
let position = {
|
||||
x: (viewPort.visibleArea.topRight.x - viewPort.visibleArea.topLeft.x) / 2 - thisObject.container.frame.width / 2,
|
||||
y: viewPort.visibleArea.bottomLeft.y - thisObject.container.frame.height
|
||||
};
|
||||
|
||||
thisObject.container.frame.position = position;
|
||||
|
||||
let buttonPosition;
|
||||
|
||||
let buttonNames = ['Fast Backwards', 'Play Backwards', 'Step Backwards', 'Pause', 'Step Forward', 'Play Forward', 'Fast Forward'];
|
||||
let lastX = 0;
|
||||
|
||||
let datetime = INITIAL_DATE;
|
||||
|
||||
let datetimeDisplay = {
|
||||
currentDatetime: datetime,
|
||||
addTime: addTime,
|
||||
draw: drawTimeDisplay
|
||||
};
|
||||
|
||||
thisObject.datetimeDisplay = datetimeDisplay;
|
||||
|
||||
/* Here we will listen to the event when time was changed due to a Bot Execution. */
|
||||
|
||||
canvas.bottomSpace.playStopButton.container.eventHandler.listenToEvent("Bot Execution Changed Datetime", onBotChangedTime);
|
||||
canvas.bottomSpace.playStopButton.setDatetime(datetime);
|
||||
|
||||
viewPort.eventHandler.listenToEvent("Zoom Changed", onZoomChanged);
|
||||
timePeriod = INITIAL_TIME_PERIOD;
|
||||
let position = {
|
||||
x: (viewPort.visibleArea.topRight.x - viewPort.visibleArea.topLeft.x) / 2 - thisObject.container.frame.width / 2,
|
||||
y: viewPort.visibleArea.bottomLeft.y - thisObject.container.frame.height
|
||||
}
|
||||
|
||||
function onBotChangedTime(pNewDatetime) {
|
||||
thisObject.container.frame.position = position
|
||||
|
||||
let newDatetime = new Date(pNewDatetime);
|
||||
panelTabButton = newPanelTabButton()
|
||||
panelTabButton.parentContainer = thisObject.container
|
||||
panelTabButton.container.frame.parentFrame = thisObject.container.frame
|
||||
panelTabButton.initialize()
|
||||
|
||||
thisObject.container.eventHandler.raiseEvent("Datetime Changed", newDatetime);
|
||||
let datetime = INITIAL_DATE
|
||||
|
||||
let datetimeDisplay = {
|
||||
currentDatetime: datetime,
|
||||
addTime: addTime,
|
||||
draw: drawTimeDisplay
|
||||
}
|
||||
|
||||
function onZoomChanged(event) {
|
||||
thisObject.datetimeDisplay = datetimeDisplay
|
||||
|
||||
timePeriod = recalculatePeriod(event.newLevel);
|
||||
viewPort.eventHandler.listenToEvent('Zoom Changed', onZoomChanged)
|
||||
timePeriod = INITIAL_TIME_PERIOD
|
||||
}
|
||||
|
||||
}
|
||||
function onBotChangedTime (pNewDatetime) {
|
||||
let newDatetime = new Date(pNewDatetime)
|
||||
|
||||
function getContainer(point) {
|
||||
thisObject.container.eventHandler.raiseEvent('Datetime Changed', newDatetime)
|
||||
}
|
||||
|
||||
let container;
|
||||
function onZoomChanged (event) {
|
||||
timePeriod = recalculatePeriod(event.newLevel)
|
||||
}
|
||||
|
||||
function getContainer (point) {
|
||||
let container
|
||||
|
||||
container = panelTabButton.getContainer(point)
|
||||
if (container !== undefined) { return container }
|
||||
|
||||
/* First we check if thisObject point is inside thisObject space. */
|
||||
|
||||
if (thisObject.container.frame.isThisPointHere(point, true) === true) {
|
||||
|
||||
if (thisObject.container.frame.isThisPointHere(point, true) === true) {
|
||||
/* The point does not belong to any inner container, so we return the current container. */
|
||||
|
||||
return thisObject.container;
|
||||
|
||||
} else {
|
||||
|
||||
return thisObject.container
|
||||
} else {
|
||||
/* This point does not belong to thisObject space. */
|
||||
|
||||
return undefined;
|
||||
}
|
||||
|
||||
return undefined
|
||||
}
|
||||
}
|
||||
|
||||
function setDatetime(pDatetime) {
|
||||
function setDatetime (pDatetime) {
|
||||
thisObject.datetimeDisplay.currentDatetime = new Date(pDatetime)
|
||||
}
|
||||
|
||||
thisObject.datetimeDisplay.currentDatetime = new Date(pDatetime);
|
||||
canvas.bottomSpace.playStopButton.setDatetime(pDatetime);
|
||||
}
|
||||
function addTime (seconds) {
|
||||
let newDate = thisObject.datetimeDisplay.currentDatetime
|
||||
|
||||
function addTime(seconds) {
|
||||
newDate.setSeconds(newDate.getSeconds() + seconds)
|
||||
thisObject.datetimeDisplay.currentDatetime = newDate
|
||||
}
|
||||
|
||||
let newDate = thisObject.datetimeDisplay.currentDatetime;
|
||||
function draw () {
|
||||
thisObject.container.frame.draw(false, false, true)
|
||||
thisObject.datetimeDisplay.draw()
|
||||
panelTabButton.draw()
|
||||
}
|
||||
|
||||
newDate.setSeconds(newDate.getSeconds() + seconds);
|
||||
thisObject.datetimeDisplay.currentDatetime = newDate;
|
||||
function drawTimeDisplay () {
|
||||
let fontSize = 10
|
||||
|
||||
}
|
||||
let label = thisObject.datetimeDisplay.currentDatetime.toUTCString()
|
||||
let labelArray = label.split(' ')
|
||||
|
||||
function draw() {
|
||||
|
||||
thisObject.container.frame.draw(false, false, true);
|
||||
|
||||
thisObject.datetimeDisplay.draw();
|
||||
|
||||
}
|
||||
|
||||
function drawTimeDisplay() {
|
||||
|
||||
let fontSize = 10;
|
||||
|
||||
let label = thisObject.datetimeDisplay.currentDatetime.toUTCString();
|
||||
let labelArray = label.split(" ");
|
||||
|
||||
label = labelArray[0] + " " + labelArray[1] + " " + labelArray[2] + " " + labelArray[3];
|
||||
label = labelArray[0] + ' ' + labelArray[1] + ' ' + labelArray[2] + ' ' + labelArray[3]
|
||||
|
||||
/* Now we transform x on the actual coordinate on the canvas. */
|
||||
|
||||
let labelPoint = {
|
||||
x: thisObject.container.frame.width / 2 - label.length / 2 * fontSize * FONT_ASPECT_RATIO,
|
||||
y: thisObject.container.frame.height * 4.4 / 10
|
||||
};
|
||||
let labelPoint = {
|
||||
x: thisObject.container.frame.width / 2 - label.length / 2 * fontSize * FONT_ASPECT_RATIO,
|
||||
y: thisObject.container.frame.height * 4.4 / 10
|
||||
}
|
||||
|
||||
labelPoint = thisObject.container.frame.frameThisPoint(labelPoint);
|
||||
labelPoint = thisObject.container.frame.frameThisPoint(labelPoint)
|
||||
|
||||
browserCanvasContext.font = fontSize + 'px ' + UI_FONT.SECONDARY;
|
||||
browserCanvasContext.fillStyle = 'rgba(60, 60, 60, 0.50)';
|
||||
browserCanvasContext.fillText(label, labelPoint.x, labelPoint.y);
|
||||
browserCanvasContext.font = fontSize + 'px ' + UI_FONT.SECONDARY + ' Saira'
|
||||
browserCanvasContext.fillStyle = 'rgba(60, 60, 60, 0.50)'
|
||||
browserCanvasContext.fillText(label, labelPoint.x, labelPoint.y)
|
||||
|
||||
/* The time */
|
||||
|
||||
label = labelArray[4] + " " + labelArray[5];
|
||||
label = labelArray[4] + ' ' + labelArray[5]
|
||||
|
||||
/* Now we transform x on the actual coordinate on the canvas. */
|
||||
|
||||
labelPoint = {
|
||||
x: thisObject.container.frame.width / 2 - label.length / 2 * fontSize * FONT_ASPECT_RATIO,
|
||||
y: thisObject.container.frame.height * 6.5 / 10
|
||||
};
|
||||
|
||||
labelPoint = thisObject.container.frame.frameThisPoint(labelPoint);
|
||||
|
||||
browserCanvasContext.font = fontSize + 'px ' + UI_FONT.SECONDARY;
|
||||
browserCanvasContext.fillStyle = 'rgba(60, 60, 60, 0.50)';
|
||||
browserCanvasContext.fillText(label, labelPoint.x, labelPoint.y);
|
||||
|
||||
if (timePeriod > _45_MINUTES_IN_MILISECONDS) {
|
||||
label = timePeriod / _1_HOUR_IN_MILISECONDS + ' hs';
|
||||
} else {
|
||||
label = timePeriod / _1_MINUTE_IN_MILISECONDS + ' min';
|
||||
}
|
||||
|
||||
/* Now we transform x on the actual coordinate on the canvas. */
|
||||
|
||||
labelPoint = {
|
||||
x: thisObject.container.frame.width / 2 - label.length / 2 * fontSize * FONT_ASPECT_RATIO,
|
||||
y: thisObject.container.frame.height * 8.5 / 10
|
||||
};
|
||||
|
||||
labelPoint = thisObject.container.frame.frameThisPoint(labelPoint);
|
||||
|
||||
browserCanvasContext.font = fontSize + 'px ' + UI_FONT.SECONDARY;
|
||||
browserCanvasContext.fillStyle = 'rgba(60, 60, 60, 0.50)';
|
||||
browserCanvasContext.fillText(label, labelPoint.x, labelPoint.y);
|
||||
|
||||
labelPoint = {
|
||||
x: thisObject.container.frame.width / 2 - label.length / 2 * fontSize * FONT_ASPECT_RATIO,
|
||||
y: thisObject.container.frame.height * 6.5 / 10
|
||||
}
|
||||
}
|
||||
|
||||
labelPoint = thisObject.container.frame.frameThisPoint(labelPoint)
|
||||
|
||||
browserCanvasContext.font = fontSize + 'px ' + UI_FONT.SECONDARY + ' Saira'
|
||||
browserCanvasContext.fillStyle = 'rgba(60, 60, 60, 0.50)'
|
||||
browserCanvasContext.fillText(label, labelPoint.x, labelPoint.y)
|
||||
|
||||
if (timePeriod > _45_MINUTES_IN_MILISECONDS) {
|
||||
label = timePeriod / _1_HOUR_IN_MILISECONDS + ' hs'
|
||||
} else {
|
||||
label = timePeriod / _1_MINUTE_IN_MILISECONDS + ' min'
|
||||
}
|
||||
|
||||
/* Now we transform x on the actual coordinate on the canvas. */
|
||||
|
||||
labelPoint = {
|
||||
x: thisObject.container.frame.width / 2 - label.length / 2 * fontSize * FONT_ASPECT_RATIO,
|
||||
y: thisObject.container.frame.height * 8.5 / 10
|
||||
}
|
||||
|
||||
labelPoint = thisObject.container.frame.frameThisPoint(labelPoint)
|
||||
|
||||
browserCanvasContext.font = fontSize + 'px ' + UI_FONT.SECONDARY + ' Saira'
|
||||
browserCanvasContext.fillStyle = 'rgba(60, 60, 60, 0.50)'
|
||||
browserCanvasContext.fillText(label, labelPoint.x, labelPoint.y)
|
||||
}
|
||||
}
|
||||
+702
-748
File diff suppressed because it is too large.
Load diff
+607
-666
File diff suppressed because it is too large.
Load diff
+342
-411
@@ -1,18 +1,17 @@
|
||||
|
||||
function newProductStorage(pName) {
|
||||
|
||||
const MODULE_NAME = "Product Storage";
|
||||
const INFO_LOG = false;
|
||||
const ERROR_LOG = true;
|
||||
const logger = newWebDebugLog();
|
||||
logger.fileName = MODULE_NAME;
|
||||
|
||||
function newProductStorage (pName) {
|
||||
const MODULE_NAME = 'Product Storage'
|
||||
const INFO_LOG = false
|
||||
const ERROR_LOG = true
|
||||
const logger = newWebDebugLog()
|
||||
logger.fileName = MODULE_NAME
|
||||
|
||||
/*
|
||||
|
||||
This object will initialize children objects that will end up loading the data of each set defined at each product of the bot received at initialization.
|
||||
Once all the underlaying objects are fully initialized it will callback.
|
||||
|
||||
At the same time it will raise an event for each underlaying file being loaded, so that the UI can reflect the progress to the end user.
|
||||
At the same time it will raise an event for each underlaying file being loaded, so that the UI can reflect the progress to the end user.
|
||||
|
||||
Product Storage
|
||||
|
|
||||
@@ -26,471 +25,403 @@ function newProductStorage(pName) {
|
||||
|
||||
*/
|
||||
|
||||
let thisObject = {
|
||||
let thisObject = {
|
||||
|
||||
marketFiles: [],
|
||||
dailyFiles: [],
|
||||
singleFile: [],
|
||||
fileSequences: [],
|
||||
marketFiles: [],
|
||||
dailyFiles: [],
|
||||
singleFile: [],
|
||||
fileSequences: [],
|
||||
|
||||
setDatetime: setDatetime,
|
||||
setTimePeriod: setTimePeriod,
|
||||
setDatetime: setDatetime,
|
||||
setTimePeriod: setTimePeriod,
|
||||
|
||||
eventHandler: undefined,
|
||||
initialize: initialize,
|
||||
finalize: finalize
|
||||
eventHandler: undefined,
|
||||
initialize: initialize,
|
||||
finalize: finalize
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
thisObject.eventHandler = newEventHandler();
|
||||
thisObject.eventHandler = newEventHandler()
|
||||
|
||||
/* We name the event Handler to easy debugging. */
|
||||
|
||||
thisObject.eventHandler.name = "Storage-" + pName;
|
||||
thisObject.eventHandler.name = 'Storage-' + pName
|
||||
|
||||
let datetime;
|
||||
let timePeriod;
|
||||
let datetime
|
||||
let timePeriod
|
||||
|
||||
return thisObject;
|
||||
return thisObject
|
||||
|
||||
function finalize() {
|
||||
function finalize () {
|
||||
try {
|
||||
if (INFO_LOG === true) { logger.write('[INFO] finalize -> Entering function.') }
|
||||
|
||||
try {
|
||||
for (let i = 0; i < thisObject.marketFiles.length; i++) {
|
||||
let marketFile = thisObject.marketFiles[i]
|
||||
marketFile.finalize()
|
||||
}
|
||||
|
||||
if (INFO_LOG === true) { logger.write("[INFO] finalize -> Entering function."); }
|
||||
thisObject.marketFiles = undefined
|
||||
|
||||
for (let i = 0; i < thisObject.marketFiles.length; i++) {
|
||||
for (let i = 0; i < thisObject.dailyFiles.length; i++) {
|
||||
let dailyFile = thisObject.dailyFiles[i]
|
||||
dailyFile.finalize()
|
||||
}
|
||||
|
||||
let marketFile = thisObject.marketFiles[i];
|
||||
marketFile.finalize();
|
||||
}
|
||||
thisObject.dailyFiles = undefined
|
||||
|
||||
thisObject.marketFiles = undefined;
|
||||
for (let i = 0; i < thisObject.fileSequences.length; i++) {
|
||||
let fileSequence = thisObject.fileSequences[i]
|
||||
fileSequence.finalize()
|
||||
}
|
||||
|
||||
for (let i = 0; i < thisObject.dailyFiles.length; i++) {
|
||||
|
||||
let dailyFile = thisObject.dailyFiles[i];
|
||||
dailyFile.finalize();
|
||||
}
|
||||
|
||||
thisObject.dailyFile = undefined;
|
||||
|
||||
for (let i = 0; i < thisObject.fileSequences.length; i++) {
|
||||
|
||||
let fileSequence = thisObject.fileSequences[i];
|
||||
fileSequence.finalize();
|
||||
}
|
||||
|
||||
thisObject.dailyFile = undefined;
|
||||
|
||||
} catch (err) {
|
||||
|
||||
if (ERROR_LOG === true) { logger.write("[ERROR] finalize -> err = " + err); }
|
||||
}
|
||||
thisObject.fileSequences = undefined
|
||||
} catch (err) {
|
||||
if (ERROR_LOG === true) { logger.write('[ERROR] finalize -> err = ' + err) }
|
||||
}
|
||||
|
||||
function initialize(pDevTeam, pBot, pProduct, pExchange, pMarket, pDatetime, pTimePeriod, callBackFunction) {
|
||||
}
|
||||
|
||||
try {
|
||||
function initialize (pDevTeam, pBot, pProduct, pExchange, pMarket, pDatetime, pTimePeriod, callBackFunction) {
|
||||
try {
|
||||
if (INFO_LOG === true) { logger.write('[INFO] initialize -> Entering function.') }
|
||||
if (INFO_LOG === true) { logger.write('[INFO] initialize -> key = ' + pDevTeam.codeName + '-' + pBot.codeName + '-' + pProduct.codeName) }
|
||||
|
||||
if (INFO_LOG === true) { logger.write("[INFO] initialize -> Entering function."); }
|
||||
if (INFO_LOG === true) { logger.write("[INFO] initialize -> key = " + pDevTeam.codeName + "-" + pBot.codeName + "-" + pProduct.codeName); }
|
||||
datetime = pDatetime
|
||||
timePeriod = pTimePeriod
|
||||
|
||||
datetime = pDatetime;
|
||||
timePeriod = pTimePeriod;
|
||||
let dataSetsToLoad = 0
|
||||
let dataSetsLoaded = 0
|
||||
|
||||
let dataSetsToLoad = 0;
|
||||
let dataSetsLoaded = 0;
|
||||
if (INFO_LOG === true) { logger.write('[INFO] initialize -> dataSetsToLoad = ' + dataSetsToLoad) }
|
||||
if (INFO_LOG === true) { logger.write('[INFO] initialize -> dataSetsLoaded = ' + dataSetsLoaded) }
|
||||
|
||||
if (INFO_LOG === true) { logger.write("[INFO] initialize -> dataSetsToLoad = " + dataSetsToLoad); }
|
||||
if (INFO_LOG === true) { logger.write("[INFO] initialize -> dataSetsLoaded = " + dataSetsLoaded); }
|
||||
for (let i = 0; i < pProduct.dataSets.length; i++) {
|
||||
let thisSet = pProduct.dataSets[i]
|
||||
|
||||
switch (thisSet.type) {
|
||||
case 'Market Files': {
|
||||
if (INFO_LOG === true) { logger.write('[INFO] initialize -> Market Files -> key = ' + pDevTeam.codeName + '-' + pBot.codeName + '-' + pProduct.codeName) }
|
||||
|
||||
for (let i = 0; i < pProduct.dataSets.length; i++) {
|
||||
dataSetsToLoad++
|
||||
|
||||
let thisSet = pProduct.dataSets[i];
|
||||
if (INFO_LOG === true) { logger.write('[INFO] initialize -> dataSetsToLoad = ' + dataSetsToLoad) }
|
||||
|
||||
switch (thisSet.type) {
|
||||
case 'Market Files': {
|
||||
let marketFiles = newMarketFiles()
|
||||
marketFiles.initialize(pDevTeam, pBot, pProduct, thisSet, pExchange, pMarket, onMarketFileReady)
|
||||
thisObject.marketFiles.push(marketFiles)
|
||||
}
|
||||
break
|
||||
|
||||
if (INFO_LOG === true) { logger.write("[INFO] initialize -> Market Files -> key = " + pDevTeam.codeName + "-" + pBot.codeName + "-" + pProduct.codeName); }
|
||||
case 'Daily Files': {
|
||||
if (INFO_LOG === true) { logger.write('[INFO] initialize -> Daily Files -> key = ' + pDevTeam.codeName + '-' + pBot.codeName + '-' + pProduct.codeName) }
|
||||
|
||||
dataSetsToLoad++;
|
||||
dataSetsToLoad++
|
||||
|
||||
if (INFO_LOG === true) { logger.write("[INFO] initialize -> dataSetsToLoad = " + dataSetsToLoad); }
|
||||
if (INFO_LOG === true) { logger.write('[INFO] initialize -> dataSetsToLoad = ' + dataSetsToLoad) }
|
||||
|
||||
let marketFiles = newMarketFiles();
|
||||
marketFiles.initialize(pDevTeam, pBot, pProduct, thisSet, pExchange, pMarket, onMarketFileReady);
|
||||
thisObject.marketFiles.push(marketFiles);
|
||||
}
|
||||
break;
|
||||
let dailyFiles = newDailyFiles()
|
||||
dailyFiles.initialize(pDevTeam, pBot, pProduct, thisSet, pExchange, pMarket, pDatetime, pTimePeriod, onDailyFileReady)
|
||||
thisObject.dailyFiles.push(dailyFiles)
|
||||
}
|
||||
break
|
||||
|
||||
case 'Daily Files': {
|
||||
case 'Single File': {
|
||||
if (INFO_LOG === true) { logger.write('[INFO] initialize -> Single File -> key = ' + pDevTeam.codeName + '-' + pBot.codeName + '-' + pProduct.codeName) }
|
||||
|
||||
if (INFO_LOG === true) { logger.write("[INFO] initialize -> Daily Files -> key = " + pDevTeam.codeName + "-" + pBot.codeName + "-" + pProduct.codeName); }
|
||||
dataSetsToLoad++
|
||||
|
||||
dataSetsToLoad++;
|
||||
if (INFO_LOG === true) { logger.write('[INFO] initialize -> dataSetsToLoad = ' + dataSetsToLoad) }
|
||||
|
||||
if (INFO_LOG === true) { logger.write("[INFO] initialize -> dataSetsToLoad = " + dataSetsToLoad); }
|
||||
let singleFile = newSingleFile()
|
||||
singleFile.initialize(pDevTeam, pBot, pProduct, thisSet, pExchange, pMarket, onSingleFileReady)
|
||||
thisObject.singleFile.push(singleFile)
|
||||
}
|
||||
break
|
||||
|
||||
let dailyFiles = newDailyFiles();
|
||||
dailyFiles.initialize(pDevTeam, pBot, pProduct, thisSet, pExchange, pMarket, pDatetime, pTimePeriod, onDailyFileReady);
|
||||
thisObject.dailyFiles.push(dailyFiles);
|
||||
}
|
||||
break;
|
||||
case 'File Sequence': {
|
||||
if (INFO_LOG === true) { logger.write('[INFO] initialize -> File Sequence -> key = ' + pDevTeam.codeName + '-' + pBot.codeName + '-' + pProduct.codeName) }
|
||||
|
||||
case 'Single File': {
|
||||
dataSetsToLoad++
|
||||
|
||||
if (INFO_LOG === true) { logger.write("[INFO] initialize -> Single File -> key = " + pDevTeam.codeName + "-" + pBot.codeName + "-" + pProduct.codeName); }
|
||||
if (INFO_LOG === true) { logger.write('[INFO] initialize -> dataSetsToLoad = ' + dataSetsToLoad) }
|
||||
|
||||
dataSetsToLoad++;
|
||||
let fileSequences = newFileSequence()
|
||||
fileSequences.initialize(pDevTeam, pBot, pProduct, thisSet, pExchange, pMarket, onFileSequenceReady)
|
||||
thisObject.fileSequences.push(fileSequences)
|
||||
}
|
||||
break
|
||||
}
|
||||
|
||||
if (INFO_LOG === true) { logger.write("[INFO] initialize -> dataSetsToLoad = " + dataSetsToLoad); }
|
||||
function onMarketFileReady (err, pCaller) {
|
||||
try {
|
||||
if (INFO_LOG === true) { logger.write('[INFO] initialize -> onMarketFileReady -> Entering function.') }
|
||||
if (INFO_LOG === true) { logger.write('[INFO] initialize -> onMarketFileReady -> key = ' + pDevTeam.codeName + '-' + pBot.codeName + '-' + pProduct.codeName) }
|
||||
|
||||
let singleFile = newSingleFile();
|
||||
singleFile.initialize(pDevTeam, pBot, pProduct, thisSet, pExchange, pMarket, onSingleFileReady);
|
||||
thisObject.singleFile.push(singleFile);
|
||||
}
|
||||
break;
|
||||
switch (err.result) {
|
||||
case GLOBAL.DEFAULT_OK_RESPONSE.result: {
|
||||
if (INFO_LOG === true) { logger.write('[INFO] initialize -> onMarketFileReady -> Received OK Response.') }
|
||||
break
|
||||
}
|
||||
|
||||
case 'File Sequence': {
|
||||
case GLOBAL.DEFAULT_FAIL_RESPONSE.result: {
|
||||
if (INFO_LOG === true) { logger.write('[INFO] initialize -> onMarketFileReady -> Received FAIL Response.') }
|
||||
callBackFunction(GLOBAL.DEFAULT_FAIL_RESPONSE)
|
||||
return
|
||||
}
|
||||
|
||||
if (INFO_LOG === true) { logger.write("[INFO] initialize -> File Sequence -> key = " + pDevTeam.codeName + "-" + pBot.codeName + "-" + pProduct.codeName); }
|
||||
case GLOBAL.CUSTOM_FAIL_RESPONSE.result: {
|
||||
if (INFO_LOG === true) { logger.write('[INFO] initialize -> onMarketFileReady -> Received CUSTOM FAIL Response.') }
|
||||
if (INFO_LOG === true) { logger.write('[INFO] initialize -> onMarketFileReady -> err.message = ' + err.message) }
|
||||
|
||||
dataSetsToLoad++;
|
||||
callBackFunction(err)
|
||||
return
|
||||
}
|
||||
|
||||
if (INFO_LOG === true) { logger.write("[INFO] initialize -> dataSetsToLoad = " + dataSetsToLoad); }
|
||||
|
||||
let fileSequences = newFileSequence();
|
||||
fileSequences.initialize(pDevTeam, pBot, pProduct, thisSet, pExchange, pMarket, onFileSequenceReady);
|
||||
thisObject.fileSequences.push(fileSequences);
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
function onMarketFileReady(err, pCaller) {
|
||||
|
||||
try {
|
||||
|
||||
if (INFO_LOG === true) { logger.write("[INFO] initialize -> onMarketFileReady -> Entering function."); }
|
||||
if (INFO_LOG === true) { logger.write("[INFO] initialize -> onMarketFileReady -> key = " + pDevTeam.codeName + "-" + pBot.codeName + "-" + pProduct.codeName); }
|
||||
|
||||
switch (err.result) {
|
||||
case GLOBAL.DEFAULT_OK_RESPONSE.result: {
|
||||
|
||||
if (INFO_LOG === true) { logger.write("[INFO] initialize -> onMarketFileReady -> Received OK Response."); }
|
||||
break;
|
||||
}
|
||||
|
||||
case GLOBAL.DEFAULT_FAIL_RESPONSE.result: {
|
||||
|
||||
if (INFO_LOG === true) { logger.write("[INFO] initialize -> onMarketFileReady -> Received FAIL Response."); }
|
||||
callBackFunction(GLOBAL.DEFAULT_FAIL_RESPONSE);
|
||||
return;
|
||||
}
|
||||
|
||||
case GLOBAL.CUSTOM_FAIL_RESPONSE.result: {
|
||||
|
||||
if (INFO_LOG === true) { logger.write("[INFO] initialize -> onMarketFileReady -> Received CUSTOM FAIL Response."); }
|
||||
if (INFO_LOG === true) { logger.write("[INFO] initialize -> onMarketFileReady -> err.message = " + err.message); }
|
||||
|
||||
callBackFunction(err);
|
||||
return;
|
||||
}
|
||||
|
||||
default: {
|
||||
|
||||
if (INFO_LOG === true) { logger.write("[INFO] initialize -> onMarketFileReady -> Received Unexpected Response."); }
|
||||
callBackFunction(err);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
let event = {
|
||||
totalValue: pCaller.getExpectedFiles(),
|
||||
currentValue: pCaller.getFilesLoaded()
|
||||
}
|
||||
|
||||
thisObject.eventHandler.raiseEvent('Market File Loaded', event);
|
||||
|
||||
if (INFO_LOG === true) { logger.write("[INFO] initialize -> onMarketFileReady -> event.currentValue = " + event.currentValue); }
|
||||
if (INFO_LOG === true) { logger.write("[INFO] initialize -> onMarketFileReady -> event.totalValue = " + event.totalValue); }
|
||||
|
||||
if (event.currentValue === event.totalValue) {
|
||||
|
||||
dataSetsLoaded++;
|
||||
|
||||
if (INFO_LOG === true) { logger.write("[INFO] initialize -> onMarketFileReady -> dataSetsLoaded = " + dataSetsLoaded); }
|
||||
|
||||
checkInitializeComplete();
|
||||
}
|
||||
|
||||
} catch (err) {
|
||||
|
||||
if (ERROR_LOG === true) { logger.write("[ERROR] initialize -> onMarketFileReady -> err = " + err); }
|
||||
callBackFunction(GLOBAL.DEFAULT_FAIL_RESPONSE);
|
||||
}
|
||||
}
|
||||
|
||||
function onDailyFileReady(err, pCaller) {
|
||||
|
||||
try {
|
||||
|
||||
if (INFO_LOG === true) { logger.write("[INFO] initialize -> onDailyFileReady -> Entering function."); }
|
||||
if (INFO_LOG === true) { logger.write("[INFO] initialize -> onDailyFileReady -> key = " + pDevTeam.codeName + "-" + pBot.codeName + "-" + pProduct.codeName); }
|
||||
|
||||
switch (err.result) {
|
||||
case GLOBAL.DEFAULT_OK_RESPONSE.result: {
|
||||
|
||||
if (INFO_LOG === true) { logger.write("[INFO] initialize -> onDailyFileReady -> Received OK Response."); }
|
||||
break;
|
||||
}
|
||||
|
||||
case GLOBAL.DEFAULT_FAIL_RESPONSE.result: {
|
||||
|
||||
if (INFO_LOG === true) { logger.write("[INFO] initialize -> onDailyFileReady -> Received FAIL Response."); }
|
||||
callBackFunction(GLOBAL.DEFAULT_FAIL_RESPONSE);
|
||||
return;
|
||||
}
|
||||
|
||||
case GLOBAL.CUSTOM_FAIL_RESPONSE.result: {
|
||||
|
||||
if (INFO_LOG === true) { logger.write("[INFO] initialize -> onDailyFileReady -> Received CUSTOM FAIL Response."); }
|
||||
if (INFO_LOG === true) { logger.write("[INFO] initialize -> onDailyFileReady -> err.message = " + err.message); }
|
||||
|
||||
callBackFunction(err);
|
||||
return;
|
||||
}
|
||||
|
||||
default: {
|
||||
|
||||
if (INFO_LOG === true) { logger.write("[INFO] initialize -> onDailyFileReady -> Received Unexpected Response."); }
|
||||
callBackFunction(err);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
let event = {
|
||||
totalValue: pCaller.getExpectedFiles(),
|
||||
currentValue: pCaller.getFilesLoaded()
|
||||
}
|
||||
|
||||
thisObject.eventHandler.raiseEvent('Daily File Loaded', event);
|
||||
|
||||
if (INFO_LOG === true) { logger.write("[INFO] initialize -> onDailyFileReady -> event.currentValue = " + event.currentValue); }
|
||||
if (INFO_LOG === true) { logger.write("[INFO] initialize -> onDailyFileReady -> event.totalValue = " + event.totalValue); }
|
||||
|
||||
if (event.currentValue === event.totalValue) {
|
||||
|
||||
dataSetsLoaded++;
|
||||
|
||||
if (INFO_LOG === true) { logger.write("[INFO] initialize -> onDailyFileReady -> dataSetsLoaded = " + dataSetsLoaded); }
|
||||
|
||||
checkInitializeComplete();
|
||||
}
|
||||
|
||||
} catch (err) {
|
||||
|
||||
if (ERROR_LOG === true) { logger.write("[ERROR] initialize -> onDailyFileReady -> err = " + err); }
|
||||
callBackFunction(GLOBAL.DEFAULT_FAIL_RESPONSE);
|
||||
}
|
||||
}
|
||||
|
||||
function onSingleFileReady(err, pCaller) {
|
||||
|
||||
try {
|
||||
|
||||
if (INFO_LOG === true) { logger.write("[INFO] initialize -> onSingleFileReady -> Entering function."); }
|
||||
if (INFO_LOG === true) { logger.write("[INFO] initialize -> onSingleFileReady -> key = " + pDevTeam.codeName + "-" + pBot.codeName + "-" + pProduct.codeName); }
|
||||
|
||||
switch (err.result) {
|
||||
case GLOBAL.DEFAULT_OK_RESPONSE.result: {
|
||||
|
||||
if (INFO_LOG === true) { logger.write("[INFO] initialize -> onSingleFileReady -> Received OK Response."); }
|
||||
break;
|
||||
}
|
||||
|
||||
case GLOBAL.DEFAULT_FAIL_RESPONSE.result: {
|
||||
|
||||
if (INFO_LOG === true) { logger.write("[INFO] initialize -> onSingleFileReady -> Received FAIL Response."); }
|
||||
callBackFunction(GLOBAL.DEFAULT_FAIL_RESPONSE);
|
||||
return;
|
||||
}
|
||||
|
||||
case GLOBAL.CUSTOM_FAIL_RESPONSE.result: {
|
||||
|
||||
if (INFO_LOG === true) { logger.write("[INFO] initialize -> onSingleFileReady -> Received CUSTOM FAIL Response."); }
|
||||
if (INFO_LOG === true) { logger.write("[INFO] initialize -> onSingleFileReady -> err.message = " + err.message); }
|
||||
|
||||
callBackFunction(err);
|
||||
return;
|
||||
}
|
||||
|
||||
default: {
|
||||
|
||||
if (INFO_LOG === true) { logger.write("[INFO] initialize -> onSingleFileReady -> Received Unexpected Response."); }
|
||||
callBackFunction(err);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
let event = {
|
||||
totalValue: 1,
|
||||
currentValue: 1
|
||||
}
|
||||
|
||||
thisObject.eventHandler.raiseEvent('Single File Loaded', event);
|
||||
|
||||
if (event.currentValue === event.totalValue) {
|
||||
|
||||
dataSetsLoaded++;
|
||||
|
||||
if (INFO_LOG === true) { logger.write("[INFO] initialize -> onSingleFileReady -> dataSetsLoaded = " + dataSetsLoaded); }
|
||||
|
||||
checkInitializeComplete();
|
||||
}
|
||||
|
||||
} catch (err) {
|
||||
|
||||
if (ERROR_LOG === true) { logger.write("[ERROR] initialize -> onSingleFileReady -> err = " + err); }
|
||||
callBackFunction(GLOBAL.DEFAULT_FAIL_RESPONSE);
|
||||
}
|
||||
}
|
||||
|
||||
function onFileSequenceReady(err, pCaller) {
|
||||
|
||||
try {
|
||||
|
||||
if (INFO_LOG === true) { logger.write("[INFO] initialize -> onFileSequenceReady -> Entering function."); }
|
||||
if (INFO_LOG === true) { logger.write("[INFO] initialize -> onFileSequenceReady -> key = " + pDevTeam.codeName + "-" + pBot.codeName + "-" + pProduct.codeName); }
|
||||
|
||||
switch (err.result) {
|
||||
case GLOBAL.DEFAULT_OK_RESPONSE.result: {
|
||||
|
||||
if (INFO_LOG === true) { logger.write("[INFO] initialize -> onFileSequenceReady -> Received OK Response."); }
|
||||
break;
|
||||
}
|
||||
|
||||
case GLOBAL.DEFAULT_FAIL_RESPONSE.result: {
|
||||
|
||||
if (INFO_LOG === true) { logger.write("[INFO] initialize -> onFileSequenceReady -> Received FAIL Response."); }
|
||||
callBackFunction(GLOBAL.DEFAULT_FAIL_RESPONSE);
|
||||
return;
|
||||
}
|
||||
|
||||
case GLOBAL.CUSTOM_FAIL_RESPONSE.result: {
|
||||
|
||||
if (INFO_LOG === true) { logger.write("[INFO] initialize -> onFileSequenceReady -> Received CUSTOM FAIL Response."); }
|
||||
if (INFO_LOG === true) { logger.write("[INFO] initialize -> onFileSequenceReady -> err.message = " + err.message); }
|
||||
|
||||
callBackFunction(err);
|
||||
return;
|
||||
}
|
||||
|
||||
default: {
|
||||
|
||||
if (INFO_LOG === true) { logger.write("[INFO] initialize -> onFileSequenceReady -> Received Unexpected Response."); }
|
||||
callBackFunction(err);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
let event = {
|
||||
totalValue: pCaller.getExpectedFiles(),
|
||||
currentValue: pCaller.getFilesLoaded()
|
||||
}
|
||||
|
||||
thisObject.eventHandler.raiseEvent('File Sequence Loaded', event);
|
||||
|
||||
if (event.currentValue === event.totalValue) {
|
||||
|
||||
dataSetsLoaded++;
|
||||
|
||||
if (INFO_LOG === true) { logger.write("[INFO] initialize -> onFileSequenceReady = " + dataSetsLoaded); }
|
||||
|
||||
checkInitializeComplete();
|
||||
}
|
||||
|
||||
} catch (err) {
|
||||
|
||||
if (ERROR_LOG === true) { logger.write("[ERROR] initialize -> onFileSequenceReady -> err = " + err); }
|
||||
callBackFunction(GLOBAL.DEFAULT_FAIL_RESPONSE);
|
||||
}
|
||||
}
|
||||
|
||||
function checkInitializeComplete() {
|
||||
|
||||
try {
|
||||
|
||||
if (INFO_LOG === true) { logger.write("[INFO] initialize -> checkInitializeComplete -> Entering function."); }
|
||||
if (INFO_LOG === true) { logger.write("[INFO] initialize -> checkInitializeComplete -> key = " + pDevTeam.codeName + "-" + pBot.codeName + "-" + pProduct.codeName); }
|
||||
|
||||
if (INFO_LOG === true) { logger.write("[INFO] initialize -> checkInitializeComplete -> dataSetsToLoad = " + dataSetsToLoad); }
|
||||
if (INFO_LOG === true) { logger.write("[INFO] initialize -> checkInitializeComplete -> dataSetsLoaded = " + dataSetsLoaded); }
|
||||
|
||||
if (dataSetsLoaded === dataSetsToLoad) {
|
||||
|
||||
callBackFunction(GLOBAL.DEFAULT_OK_RESPONSE);
|
||||
|
||||
}
|
||||
|
||||
} catch (err) {
|
||||
|
||||
if (ERROR_LOG === true) { logger.write("[ERROR] initialize -> checkInitializeComplete -> err = " + err); }
|
||||
callBackFunction(GLOBAL.DEFAULT_FAIL_RESPONSE);
|
||||
}
|
||||
}
|
||||
default: {
|
||||
if (INFO_LOG === true) { logger.write('[INFO] initialize -> onMarketFileReady -> Received Unexpected Response.') }
|
||||
callBackFunction(err)
|
||||
return
|
||||
}
|
||||
}
|
||||
|
||||
} catch (err) {
|
||||
|
||||
if (ERROR_LOG === true) { logger.write("[ERROR] initialize -> err = " + err); }
|
||||
callBackFunction(GLOBAL.DEFAULT_FAIL_RESPONSE);
|
||||
let event = {
|
||||
totalValue: pCaller.getExpectedFiles(),
|
||||
currentValue: pCaller.getFilesLoaded()
|
||||
}
|
||||
|
||||
thisObject.eventHandler.raiseEvent('Market File Loaded', event)
|
||||
|
||||
if (INFO_LOG === true) { logger.write('[INFO] initialize -> onMarketFileReady -> event.currentValue = ' + event.currentValue) }
|
||||
if (INFO_LOG === true) { logger.write('[INFO] initialize -> onMarketFileReady -> event.totalValue = ' + event.totalValue) }
|
||||
|
||||
if (event.currentValue === event.totalValue) {
|
||||
dataSetsLoaded++
|
||||
|
||||
if (INFO_LOG === true) { logger.write('[INFO] initialize -> onMarketFileReady -> dataSetsLoaded = ' + dataSetsLoaded) }
|
||||
|
||||
checkInitializeComplete()
|
||||
}
|
||||
} catch (err) {
|
||||
if (ERROR_LOG === true) { logger.write('[ERROR] initialize -> onMarketFileReady -> err = ' + err) }
|
||||
callBackFunction(GLOBAL.DEFAULT_FAIL_RESPONSE)
|
||||
}
|
||||
}
|
||||
|
||||
function onDailyFileReady (err, pCaller) {
|
||||
try {
|
||||
if (INFO_LOG === true) { logger.write('[INFO] initialize -> onDailyFileReady -> Entering function.') }
|
||||
if (INFO_LOG === true) { logger.write('[INFO] initialize -> onDailyFileReady -> key = ' + pDevTeam.codeName + '-' + pBot.codeName + '-' + pProduct.codeName) }
|
||||
|
||||
switch (err.result) {
|
||||
case GLOBAL.DEFAULT_OK_RESPONSE.result: {
|
||||
if (INFO_LOG === true) { logger.write('[INFO] initialize -> onDailyFileReady -> Received OK Response.') }
|
||||
break
|
||||
}
|
||||
|
||||
case GLOBAL.DEFAULT_FAIL_RESPONSE.result: {
|
||||
if (INFO_LOG === true) { logger.write('[INFO] initialize -> onDailyFileReady -> Received FAIL Response.') }
|
||||
callBackFunction(GLOBAL.DEFAULT_FAIL_RESPONSE)
|
||||
return
|
||||
}
|
||||
|
||||
case GLOBAL.CUSTOM_FAIL_RESPONSE.result: {
|
||||
if (INFO_LOG === true) { logger.write('[INFO] initialize -> onDailyFileReady -> Received CUSTOM FAIL Response.') }
|
||||
if (INFO_LOG === true) { logger.write('[INFO] initialize -> onDailyFileReady -> err.message = ' + err.message) }
|
||||
|
||||
callBackFunction(err)
|
||||
return
|
||||
}
|
||||
|
||||
default: {
|
||||
if (INFO_LOG === true) { logger.write('[INFO] initialize -> onDailyFileReady -> Received Unexpected Response.') }
|
||||
callBackFunction(err)
|
||||
return
|
||||
}
|
||||
}
|
||||
|
||||
let event = {
|
||||
totalValue: pCaller.getExpectedFiles(),
|
||||
currentValue: pCaller.getFilesLoaded()
|
||||
}
|
||||
|
||||
thisObject.eventHandler.raiseEvent('Daily File Loaded', event)
|
||||
|
||||
if (INFO_LOG === true) { logger.write('[INFO] initialize -> onDailyFileReady -> event.currentValue = ' + event.currentValue) }
|
||||
if (INFO_LOG === true) { logger.write('[INFO] initialize -> onDailyFileReady -> event.totalValue = ' + event.totalValue) }
|
||||
|
||||
if (event.currentValue === event.totalValue) {
|
||||
dataSetsLoaded++
|
||||
|
||||
if (INFO_LOG === true) { logger.write('[INFO] initialize -> onDailyFileReady -> dataSetsLoaded = ' + dataSetsLoaded) }
|
||||
|
||||
checkInitializeComplete()
|
||||
}
|
||||
} catch (err) {
|
||||
if (ERROR_LOG === true) { logger.write('[ERROR] initialize -> onDailyFileReady -> err = ' + err) }
|
||||
callBackFunction(GLOBAL.DEFAULT_FAIL_RESPONSE)
|
||||
}
|
||||
}
|
||||
|
||||
function onSingleFileReady (err, pCaller) {
|
||||
try {
|
||||
if (INFO_LOG === true) { logger.write('[INFO] initialize -> onSingleFileReady -> Entering function.') }
|
||||
if (INFO_LOG === true) { logger.write('[INFO] initialize -> onSingleFileReady -> key = ' + pDevTeam.codeName + '-' + pBot.codeName + '-' + pProduct.codeName) }
|
||||
|
||||
switch (err.result) {
|
||||
case GLOBAL.DEFAULT_OK_RESPONSE.result: {
|
||||
if (INFO_LOG === true) { logger.write('[INFO] initialize -> onSingleFileReady -> Received OK Response.') }
|
||||
break
|
||||
}
|
||||
|
||||
case GLOBAL.DEFAULT_FAIL_RESPONSE.result: {
|
||||
if (INFO_LOG === true) { logger.write('[INFO] initialize -> onSingleFileReady -> Received FAIL Response.') }
|
||||
callBackFunction(GLOBAL.DEFAULT_FAIL_RESPONSE)
|
||||
return
|
||||
}
|
||||
|
||||
case GLOBAL.CUSTOM_FAIL_RESPONSE.result: {
|
||||
if (INFO_LOG === true) { logger.write('[INFO] initialize -> onSingleFileReady -> Received CUSTOM FAIL Response.') }
|
||||
if (INFO_LOG === true) { logger.write('[INFO] initialize -> onSingleFileReady -> err.message = ' + err.message) }
|
||||
|
||||
callBackFunction(err)
|
||||
return
|
||||
}
|
||||
|
||||
default: {
|
||||
if (INFO_LOG === true) { logger.write('[INFO] initialize -> onSingleFileReady -> Received Unexpected Response.') }
|
||||
callBackFunction(err)
|
||||
return
|
||||
}
|
||||
}
|
||||
|
||||
let event = {
|
||||
totalValue: 1,
|
||||
currentValue: 1
|
||||
}
|
||||
|
||||
thisObject.eventHandler.raiseEvent('Single File Loaded', event)
|
||||
|
||||
if (event.currentValue === event.totalValue) {
|
||||
dataSetsLoaded++
|
||||
|
||||
if (INFO_LOG === true) { logger.write('[INFO] initialize -> onSingleFileReady -> dataSetsLoaded = ' + dataSetsLoaded) }
|
||||
|
||||
checkInitializeComplete()
|
||||
}
|
||||
} catch (err) {
|
||||
if (ERROR_LOG === true) { logger.write('[ERROR] initialize -> onSingleFileReady -> err = ' + err) }
|
||||
callBackFunction(GLOBAL.DEFAULT_FAIL_RESPONSE)
|
||||
}
|
||||
}
|
||||
|
||||
function onFileSequenceReady (err, pCaller) {
|
||||
try {
|
||||
if (INFO_LOG === true) { logger.write('[INFO] initialize -> onFileSequenceReady -> Entering function.') }
|
||||
if (INFO_LOG === true) { logger.write('[INFO] initialize -> onFileSequenceReady -> key = ' + pDevTeam.codeName + '-' + pBot.codeName + '-' + pProduct.codeName) }
|
||||
|
||||
switch (err.result) {
|
||||
case GLOBAL.DEFAULT_OK_RESPONSE.result: {
|
||||
if (INFO_LOG === true) { logger.write('[INFO] initialize -> onFileSequenceReady -> Received OK Response.') }
|
||||
break
|
||||
}
|
||||
|
||||
case GLOBAL.DEFAULT_FAIL_RESPONSE.result: {
|
||||
if (INFO_LOG === true) { logger.write('[INFO] initialize -> onFileSequenceReady -> Received FAIL Response.') }
|
||||
callBackFunction(GLOBAL.DEFAULT_FAIL_RESPONSE)
|
||||
return
|
||||
}
|
||||
|
||||
case GLOBAL.CUSTOM_FAIL_RESPONSE.result: {
|
||||
if (INFO_LOG === true) { logger.write('[INFO] initialize -> onFileSequenceReady -> Received CUSTOM FAIL Response.') }
|
||||
if (INFO_LOG === true) { logger.write('[INFO] initialize -> onFileSequenceReady -> err.message = ' + err.message) }
|
||||
|
||||
callBackFunction(err)
|
||||
return
|
||||
}
|
||||
|
||||
default: {
|
||||
if (INFO_LOG === true) { logger.write('[INFO] initialize -> onFileSequenceReady -> Received Unexpected Response.') }
|
||||
callBackFunction(err)
|
||||
return
|
||||
}
|
||||
}
|
||||
|
||||
let event = {
|
||||
totalValue: pCaller.getExpectedFiles(),
|
||||
currentValue: pCaller.getFilesLoaded()
|
||||
}
|
||||
|
||||
thisObject.eventHandler.raiseEvent('File Sequence Loaded', event)
|
||||
|
||||
if (event.currentValue === event.totalValue) {
|
||||
dataSetsLoaded++
|
||||
|
||||
if (INFO_LOG === true) { logger.write('[INFO] initialize -> onFileSequenceReady = ' + dataSetsLoaded) }
|
||||
|
||||
checkInitializeComplete()
|
||||
}
|
||||
} catch (err) {
|
||||
if (ERROR_LOG === true) { logger.write('[ERROR] initialize -> onFileSequenceReady -> err = ' + err) }
|
||||
callBackFunction(GLOBAL.DEFAULT_FAIL_RESPONSE)
|
||||
}
|
||||
}
|
||||
|
||||
function checkInitializeComplete () {
|
||||
try {
|
||||
if (INFO_LOG === true) { logger.write('[INFO] initialize -> checkInitializeComplete -> Entering function.') }
|
||||
if (INFO_LOG === true) { logger.write('[INFO] initialize -> checkInitializeComplete -> key = ' + pDevTeam.codeName + '-' + pBot.codeName + '-' + pProduct.codeName) }
|
||||
|
||||
if (INFO_LOG === true) { logger.write('[INFO] initialize -> checkInitializeComplete -> dataSetsToLoad = ' + dataSetsToLoad) }
|
||||
if (INFO_LOG === true) { logger.write('[INFO] initialize -> checkInitializeComplete -> dataSetsLoaded = ' + dataSetsLoaded) }
|
||||
|
||||
if (dataSetsLoaded === dataSetsToLoad) {
|
||||
callBackFunction(GLOBAL.DEFAULT_OK_RESPONSE)
|
||||
}
|
||||
} catch (err) {
|
||||
if (ERROR_LOG === true) { logger.write('[ERROR] initialize -> checkInitializeComplete -> err = ' + err) }
|
||||
callBackFunction(GLOBAL.DEFAULT_FAIL_RESPONSE)
|
||||
}
|
||||
}
|
||||
}
|
||||
} catch (err) {
|
||||
if (ERROR_LOG === true) { logger.write('[ERROR] initialize -> err = ' + err) }
|
||||
callBackFunction(GLOBAL.DEFAULT_FAIL_RESPONSE)
|
||||
}
|
||||
}
|
||||
|
||||
function setDatetime(pDatetime) {
|
||||
|
||||
if (INFO_LOG === true) { logger.write("[INFO] setDatetime -> Entering function."); }
|
||||
function setDatetime (pDatetime) {
|
||||
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. */
|
||||
|
||||
let currentDate = Math.trunc(datetime.valueOf() / ONE_DAY_IN_MILISECONDS);
|
||||
let newDate = Math.trunc(pDatetime.valueOf() / ONE_DAY_IN_MILISECONDS);
|
||||
let currentDate = Math.trunc(datetime.valueOf() / ONE_DAY_IN_MILISECONDS)
|
||||
let newDate = Math.trunc(pDatetime.valueOf() / ONE_DAY_IN_MILISECONDS)
|
||||
|
||||
datetime = new Date(pDatetime);
|
||||
datetime = new Date(pDatetime)
|
||||
|
||||
if (currentDate !== newDate) {
|
||||
|
||||
if (timePeriod <= _1_HOUR_IN_MILISECONDS) {
|
||||
|
||||
for (let i = 0; i < thisObject.dailyFiles.length; i++) {
|
||||
|
||||
thisObject.dailyFiles[i].setDatetime(pDatetime);
|
||||
}
|
||||
}
|
||||
if (currentDate !== newDate) {
|
||||
if (timePeriod <= _1_HOUR_IN_MILISECONDS) {
|
||||
for (let i = 0; i < thisObject.dailyFiles.length; i++) {
|
||||
thisObject.dailyFiles[i].setDatetime(pDatetime)
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function setTimePeriod(pTimePeriod) {
|
||||
|
||||
if (INFO_LOG === true) { logger.write("[INFO] setTimePeriod -> Entering function."); }
|
||||
function setTimePeriod (pTimePeriod) {
|
||||
if (INFO_LOG === true) { logger.write('[INFO] setTimePeriod -> Entering function.') }
|
||||
|
||||
/* We are going to filter out the cases in which the timePeriod received is the same that the one we already know. */
|
||||
|
||||
if (timePeriod !== pTimePeriod) {
|
||||
if (timePeriod !== pTimePeriod) {
|
||||
timePeriod = pTimePeriod
|
||||
|
||||
timePeriod = pTimePeriod;
|
||||
|
||||
if (timePeriod <= _1_HOUR_IN_MILISECONDS) {
|
||||
|
||||
for (let i = 0; i < thisObject.dailyFiles.length; i++) {
|
||||
|
||||
thisObject.dailyFiles[i].setTimePeriod(pTimePeriod, datetime);
|
||||
}
|
||||
}
|
||||
if (timePeriod <= _1_HOUR_IN_MILISECONDS) {
|
||||
for (let i = 0; i < thisObject.dailyFiles.length; i++) {
|
||||
thisObject.dailyFiles[i].setTimePeriod(pTimePeriod, datetime)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
+4
-3
@@ -47,7 +47,6 @@
|
||||
<Compile Include="CloudVM\CloudVM.js">
|
||||
<SubType>Code</SubType>
|
||||
</Compile>
|
||||
<Compile Include="CloudVM\Exchange\ExchangeAPI.js" />
|
||||
<Compile Include="Exchange\ExchangeAPI.js" />
|
||||
<Compile Include="Globals.js">
|
||||
<SubType>Code</SubType>
|
||||
@@ -104,6 +103,9 @@
|
||||
<Compile Include="TopSpace\CurrentStartMode.js">
|
||||
<SubType>Code</SubType>
|
||||
</Compile>
|
||||
<Compile Include="TopSpace\CurrentEvent.js">
|
||||
<SubType>Code</SubType>
|
||||
</Compile>
|
||||
<Compile Include="TopSpace\DevTeam.js">
|
||||
<SubType>Code</SubType>
|
||||
</Compile>
|
||||
@@ -172,7 +174,6 @@
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Folder Include="CloudVM\" />
|
||||
<Folder Include="CloudVM\Exchange\" />
|
||||
<Folder Include="Exchange\" />
|
||||
<Folder Include="Files\" />
|
||||
<Folder Include="FloatingSpace\" />
|
||||
@@ -223,4 +224,4 @@
|
||||
</FlavorProperties>
|
||||
</VisualStudio>
|
||||
</ProjectExtensions>
|
||||
</Project>
|
||||
</Project>
|
||||
+480
-537
File diff suppressed because it is too large.
Load diff
+40
-51
@@ -1,67 +1,56 @@
|
||||
function newRigthScale() {
|
||||
function newRigthScale () {
|
||||
let thisObject = {
|
||||
container: undefined,
|
||||
draw: draw,
|
||||
getContainer: getContainer,
|
||||
initialize: initialize
|
||||
}
|
||||
|
||||
let thisObject = {
|
||||
container: undefined,
|
||||
draw: draw,
|
||||
getContainer: getContainer,
|
||||
initialize: initialize
|
||||
};
|
||||
const RIGHT_MARGIN = 50
|
||||
|
||||
const RIGHT_MARGIN = 50;
|
||||
let container = newContainer()
|
||||
container.initialize()
|
||||
thisObject.container = container
|
||||
|
||||
let container = newContainer();
|
||||
container.initialize();
|
||||
thisObject.container = container;
|
||||
thisObject.container.frame.width = RIGHT_MARGIN
|
||||
thisObject.container.frame.height = viewPort.visibleArea.bottomRight.y - viewPort.visibleArea.topRight.y
|
||||
|
||||
thisObject.container.frame.width = RIGHT_MARGIN;
|
||||
thisObject.container.frame.height = viewPort.visibleArea.bottomRight.y - viewPort.visibleArea.topRight.y;
|
||||
container.frame.position.x = viewPort.visibleArea.bottomRight.x
|
||||
container.frame.position.y = TOP_SPACE_HEIGHT
|
||||
|
||||
container.frame.position.x = viewPort.visibleArea.bottomRight.x;
|
||||
container.frame.position.y = TOP_SPACE_HEIGHT;
|
||||
container.isDraggeable = false
|
||||
container.isClickeable = false
|
||||
container.isWheeleable = true
|
||||
|
||||
container.isDraggeable = false;
|
||||
container.isClickeable = false;
|
||||
container.isWheeleable = true;
|
||||
return thisObject
|
||||
|
||||
return thisObject;
|
||||
function initialize () {
|
||||
thisObject.container.eventHandler.listenToEvent('Mouse Wheel', onMouseWheel)
|
||||
}
|
||||
|
||||
function initialize() {
|
||||
function onMouseWheel (pDelta) {
|
||||
if (pDelta < 0) {
|
||||
pDelta = -0.1
|
||||
} else {
|
||||
pDelta = 0.1
|
||||
}
|
||||
}
|
||||
|
||||
thisObject.container.eventHandler.listenToEvent('Mouse Wheel', onMouseWheel);
|
||||
|
||||
}
|
||||
|
||||
function onMouseWheel(pDelta) {
|
||||
|
||||
if (pDelta < 0) {
|
||||
pDelta = -0.1;
|
||||
} else {
|
||||
pDelta = 0.1;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
function getContainer(point) {
|
||||
|
||||
let container;
|
||||
function getContainer (point) {
|
||||
let container
|
||||
|
||||
/* First we check if this point is inside this object UI. */
|
||||
|
||||
if (thisObject.container.frame.isThisPointHere(point, true) === true) {
|
||||
|
||||
return this.container;
|
||||
|
||||
} else {
|
||||
|
||||
if (thisObject.container.frame.isThisPointHere(point, true) === true) {
|
||||
return this.container
|
||||
} else {
|
||||
/* This point does not belong to this space. */
|
||||
|
||||
return undefined;
|
||||
}
|
||||
}
|
||||
return undefined
|
||||
}
|
||||
}
|
||||
|
||||
function draw() {
|
||||
function draw () {
|
||||
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,56 @@
|
||||
function newRigthScale () {
|
||||
let thisObject = {
|
||||
container: undefined,
|
||||
draw: draw,
|
||||
getContainer: getContainer,
|
||||
initialize: initialize
|
||||
}
|
||||
|
||||
const RIGHT_MARGIN = 50
|
||||
|
||||
let container = newContainer()
|
||||
container.initialize()
|
||||
thisObject.container = container
|
||||
|
||||
thisObject.container.frame.width = RIGHT_MARGIN
|
||||
thisObject.container.frame.height = viewPort.visibleArea.bottomRight.y - viewPort.visibleArea.topRight.y
|
||||
|
||||
container.frame.position.x = viewPort.visibleArea.bottomRight.x
|
||||
container.frame.position.y = TOP_SPACE_HEIGHT
|
||||
|
||||
container.isDraggeable = false
|
||||
container.isClickeable = false
|
||||
container.isWheeleable = true
|
||||
|
||||
return thisObject
|
||||
|
||||
function initialize () {
|
||||
thisObject.container.eventHandler.listenToEvent('Mouse Wheel', onMouseWheel)
|
||||
}
|
||||
|
||||
function onMouseWheel (pDelta) {
|
||||
if (pDelta < 0) {
|
||||
pDelta = -0.1
|
||||
} else {
|
||||
pDelta = 0.1
|
||||
}
|
||||
}
|
||||
|
||||
function getContainer (point) {
|
||||
let container
|
||||
|
||||
/* First we check if this point is inside this object UI. */
|
||||
|
||||
if (thisObject.container.frame.isThisPointHere(point, true) === true) {
|
||||
return this.container
|
||||
} else {
|
||||
/* This point does not belong to this space. */
|
||||
|
||||
return undefined
|
||||
}
|
||||
}
|
||||
|
||||
function draw () {
|
||||
|
||||
}
|
||||
}
|
||||
+66
-84
@@ -1,105 +1,87 @@
|
||||
|
||||
function newBottomSpace() {
|
||||
|
||||
function newBottomSpace () {
|
||||
var thisObject = {
|
||||
deleteTradingHistory: undefined,
|
||||
chartAspectRatio: undefined,
|
||||
container: undefined,
|
||||
draw: draw,
|
||||
getContainer: getContainer, // returns the inner most container that holds the point received by parameter.
|
||||
initialize: initialize
|
||||
}
|
||||
|
||||
var thisObject = {
|
||||
deleteTradingHistory: undefined,
|
||||
chartAspectRatio: undefined,
|
||||
playStopButton: undefined,
|
||||
container: undefined,
|
||||
draw: draw,
|
||||
getContainer: getContainer, // returns the inner most container that holds the point received by parameter.
|
||||
initialize: initialize
|
||||
};
|
||||
var container = newContainer()
|
||||
container.initialize()
|
||||
thisObject.container = container
|
||||
|
||||
var container = newContainer();
|
||||
container.initialize();
|
||||
thisObject.container = container;
|
||||
container.isDraggeable = false
|
||||
|
||||
container.isDraggeable = false;
|
||||
resize()
|
||||
|
||||
resize();
|
||||
return thisObject
|
||||
|
||||
return thisObject;
|
||||
function initialize () {
|
||||
thisObject.deleteTradingHistory = newDeleteTradingHistory()
|
||||
thisObject.deleteTradingHistory.initialize()
|
||||
|
||||
function initialize() {
|
||||
thisObject.chartAspectRatio = newChartAspectRatio()
|
||||
thisObject.chartAspectRatio.initialize()
|
||||
|
||||
thisObject.deleteTradingHistory = newDeleteTradingHistory();
|
||||
thisObject.deleteTradingHistory.initialize();
|
||||
window.canvasApp.eventHandler.listenToEvent('Browser Resized', resize)
|
||||
}
|
||||
|
||||
thisObject.chartAspectRatio = newChartAspectRatio();
|
||||
thisObject.chartAspectRatio.initialize();
|
||||
function resize () {
|
||||
container.frame.position.x = 0
|
||||
container.frame.position.y = viewPort.visibleArea.bottomLeft.y
|
||||
|
||||
thisObject.playStopButton = newPlayStopButton();
|
||||
thisObject.playStopButton.initialize();
|
||||
thisObject.container.frame.width = browserCanvas.width
|
||||
thisObject.container.frame.height = BOTTOM_SPACE_HEIGHT
|
||||
}
|
||||
|
||||
window.canvasApp.eventHandler.listenToEvent("Browser Resized", resize);
|
||||
function getContainer (point) {
|
||||
let container
|
||||
|
||||
}
|
||||
container = thisObject.deleteTradingHistory.getContainer(point)
|
||||
if (container !== undefined) { return container }
|
||||
|
||||
function resize() {
|
||||
|
||||
container.frame.position.x = 0;
|
||||
container.frame.position.y = viewPort.visibleArea.bottomLeft.y;
|
||||
|
||||
thisObject.container.frame.width = browserCanvas.width;
|
||||
thisObject.container.frame.height = BOTTOM_SPACE_HEIGHT;
|
||||
|
||||
}
|
||||
|
||||
function getContainer(point) {
|
||||
|
||||
let container;
|
||||
|
||||
container = thisObject.deleteTradingHistory.getContainer(point);
|
||||
if (container !== undefined) { return container; }
|
||||
|
||||
container = thisObject.chartAspectRatio.getContainer(point);
|
||||
if (container !== undefined) { return container; }
|
||||
|
||||
container = thisObject.playStopButton.getContainer(point);
|
||||
if (container !== undefined) { return container; }
|
||||
container = thisObject.chartAspectRatio.getContainer(point)
|
||||
if (container !== undefined) { return container }
|
||||
|
||||
/* The point does not belong to any inner container, so we return the current container. */
|
||||
|
||||
return thisObject.container;
|
||||
return thisObject.container
|
||||
}
|
||||
|
||||
function draw () {
|
||||
thisObject.container.frame.draw(false, false)
|
||||
|
||||
drawBackground()
|
||||
thisObject.deleteTradingHistory.draw()
|
||||
thisObject.chartAspectRatio.draw()
|
||||
}
|
||||
|
||||
function drawBackground () {
|
||||
let opacity = 1
|
||||
|
||||
let zeroPoint = {
|
||||
x: 0,
|
||||
y: 0
|
||||
}
|
||||
|
||||
function draw() {
|
||||
zeroPoint = thisObject.container.frame.frameThisPoint(zeroPoint)
|
||||
|
||||
thisObject.container.frame.draw(false, false);
|
||||
let breakpointsHeight = 15
|
||||
const RED_LINE_HIGHT = 5
|
||||
|
||||
drawBackground();
|
||||
thisObject.deleteTradingHistory.draw();
|
||||
thisObject.chartAspectRatio.draw();
|
||||
thisObject.playStopButton.draw();
|
||||
browserCanvasContext.beginPath()
|
||||
browserCanvasContext.rect(zeroPoint.x, zeroPoint.y + breakpointsHeight, thisObject.container.frame.width, thisObject.container.frame.height)
|
||||
browserCanvasContext.fillStyle = 'rgba(' + UI_COLOR.DARK + ', ' + opacity + ')'
|
||||
browserCanvasContext.closePath()
|
||||
browserCanvasContext.fill()
|
||||
|
||||
}
|
||||
|
||||
function drawBackground() {
|
||||
|
||||
let opacity = 1;
|
||||
|
||||
let zeroPoint = {
|
||||
x: 0,
|
||||
y: 0
|
||||
};
|
||||
|
||||
zeroPoint = thisObject.container.frame.frameThisPoint(zeroPoint);
|
||||
|
||||
let breakpointsHeight = 15;
|
||||
const RED_LINE_HIGHT = 5;
|
||||
|
||||
browserCanvasContext.beginPath();
|
||||
browserCanvasContext.rect(zeroPoint.x, zeroPoint.y + breakpointsHeight, thisObject.container.frame.width, thisObject.container.frame.height );
|
||||
browserCanvasContext.fillStyle = 'rgba(' + UI_COLOR.DARK + ', ' + opacity + ')';
|
||||
browserCanvasContext.closePath();
|
||||
browserCanvasContext.fill();
|
||||
|
||||
browserCanvasContext.beginPath();
|
||||
browserCanvasContext.rect(zeroPoint.x, zeroPoint.y + breakpointsHeight, thisObject.container.frame.width,RED_LINE_HIGHT);
|
||||
browserCanvasContext.fillStyle = 'rgba(' + UI_COLOR.RUSTED_RED + ', ' + opacity + ')';
|
||||
browserCanvasContext.closePath();
|
||||
browserCanvasContext.fill();
|
||||
}
|
||||
}
|
||||
browserCanvasContext.beginPath()
|
||||
browserCanvasContext.rect(zeroPoint.x, zeroPoint.y + breakpointsHeight, thisObject.container.frame.width, RED_LINE_HIGHT)
|
||||
browserCanvasContext.fillStyle = 'rgba(' + UI_COLOR.RUSTED_RED + ', ' + opacity + ')'
|
||||
browserCanvasContext.closePath()
|
||||
browserCanvasContext.fill()
|
||||
}
|
||||
}
|
||||
+90
-84
@@ -1,132 +1,138 @@
|
||||
/*
|
||||
/*
|
||||
|
||||
The chart space is where all the charts live. What this space contains is a type of object we call Time Machine. A Time Machine is a cointainer of
|
||||
charts objects. The idea is simple, all the chart objects are ploted according to the time of the Time Machine object. When the time of the Time Machine
|
||||
charts objects. The idea is simple, all the chart objects are ploted according to the time of the Time Machine object. When the time of the Time Machine
|
||||
changes, then all charts in it are replotted with the corresponging data.
|
||||
|
||||
*/
|
||||
|
||||
function newChartSpace() {
|
||||
function newChartSpace () {
|
||||
const MODULE_NAME = 'Chart Space'
|
||||
const INFO_LOG = false
|
||||
const ERROR_LOG = true
|
||||
const logger = newWebDebugLog()
|
||||
logger.fileName = MODULE_NAME
|
||||
|
||||
const MODULE_NAME = "Chart Space";
|
||||
const INFO_LOG = false;
|
||||
const logger = newWebDebugLog();
|
||||
logger.fileName = MODULE_NAME;
|
||||
var thisObject = {
|
||||
container: undefined,
|
||||
drawBackground: drawBackground,
|
||||
draw: draw,
|
||||
timeMachines: [],
|
||||
getContainer: getContainer, // returns the inner most container that holds the point received by parameter.
|
||||
initialize: initialize,
|
||||
finalize: finalize
|
||||
}
|
||||
|
||||
var thisObject = {
|
||||
container: undefined,
|
||||
draw: draw,
|
||||
timeMachines: [],
|
||||
getContainer: getContainer, // returns the inner most container that holds the point received by parameter.
|
||||
initialize: initialize
|
||||
};
|
||||
var container = newContainer()
|
||||
container.initialize()
|
||||
thisObject.container = container
|
||||
|
||||
thisObject.container.frame.width = CHART_SPACE_WIDTH
|
||||
thisObject.container.frame.height = CHART_SPACE_HEIGHT
|
||||
|
||||
var container = newContainer();
|
||||
container.initialize();
|
||||
thisObject.container = container;
|
||||
container.displacement.containerName = 'Chart Space'
|
||||
container.frame.containerName = 'Chart Space'
|
||||
|
||||
thisObject.container.frame.width = CHART_SPACE_WIDTH;
|
||||
thisObject.container.frame.height = CHART_SPACE_HEIGHT;
|
||||
container.frame.position.x = browserCanvas.width / 2 - thisObject.container.frame.width / 2
|
||||
container.frame.position.y = browserCanvas.height / 2 - thisObject.container.frame.height / 2
|
||||
|
||||
container.displacement.containerName = "Chart Space";
|
||||
container.frame.containerName = "Chart Space";
|
||||
container.isDraggeable = false
|
||||
|
||||
container.frame.position.x = browserCanvas.width / 2 - thisObject.container.frame.width / 2;
|
||||
container.frame.position.y = browserCanvas.height / 2 - thisObject.container.frame.height / 2;
|
||||
return thisObject
|
||||
|
||||
container.isDraggeable = false;
|
||||
function finalize () {
|
||||
try {
|
||||
if (INFO_LOG === true) { logger.write('[INFO] finalize -> Entering function.') }
|
||||
|
||||
return thisObject;
|
||||
for (let i = 0; i < thisObject.timeMachines.length; i++) {
|
||||
let timeMachine = thisObject.timeMachines[i]
|
||||
timeMachine.finalize()
|
||||
}
|
||||
} catch (err) {
|
||||
if (ERROR_LOG === true) { logger.write('[ERROR] finalize -> err = ' + err) }
|
||||
}
|
||||
}
|
||||
|
||||
function initialize(callBackFunction) {
|
||||
function initialize (callBackFunction) {
|
||||
if (INFO_LOG === true) { logger.write('[INFO] initialize -> Entering function.') }
|
||||
|
||||
if (INFO_LOG === true) { logger.write("[INFO] initialize -> Entering function."); }
|
||||
|
||||
let initializedCounter = 0;
|
||||
let toInitialize = 1;
|
||||
let initializedCounter = 0
|
||||
let toInitialize = 1
|
||||
|
||||
/* We create the first of many possible time machines that could live at the Chart Space. */
|
||||
|
||||
var timeMachine = newTimeMachine();
|
||||
var timeMachine = newTimeMachine()
|
||||
|
||||
timeMachine.container.displacement.parentDisplacement = this.container.displacement;
|
||||
timeMachine.container.frame.parentFrame = this.container.frame;
|
||||
timeMachine.container.displacement.parentDisplacement = this.container.displacement
|
||||
timeMachine.container.frame.parentFrame = this.container.frame
|
||||
|
||||
timeMachine.container.parentContainer = this.container;
|
||||
timeMachine.container.parentContainer = this.container
|
||||
|
||||
/* We make the time machine a little bit smaller than the current space. */
|
||||
|
||||
timeMachine.container.frame.width = this.container.frame.width * 1;
|
||||
timeMachine.container.frame.height = this.container.frame.height * 1;
|
||||
timeMachine.container.frame.width = this.container.frame.width * 1
|
||||
timeMachine.container.frame.height = this.container.frame.height * 1
|
||||
|
||||
timeMachine.container.frame.position.x = this.container.frame.width / 2 - timeMachine.container.frame.width / 2;
|
||||
timeMachine.container.frame.position.y = this.container.frame.height / 2 - timeMachine.container.frame.height / 2;
|
||||
timeMachine.container.frame.position.x = this.container.frame.width / 2 - timeMachine.container.frame.width / 2
|
||||
timeMachine.container.frame.position.y = this.container.frame.height / 2 - timeMachine.container.frame.height / 2
|
||||
|
||||
timeMachine.initialize(onTimeMachineInitialized);
|
||||
timeMachine.initialize(onTimeMachineInitialized)
|
||||
|
||||
function onTimeMachineInitialized(err) {
|
||||
function onTimeMachineInitialized (err) {
|
||||
if (INFO_LOG === true) { logger.write('[INFO] initialize -> onTimeMachineInitialized -> Entering function.') }
|
||||
|
||||
if (INFO_LOG === true) { logger.write("[INFO] initialize -> onTimeMachineInitialized -> Entering function."); }
|
||||
initializedCounter++
|
||||
|
||||
initializedCounter++;
|
||||
if (err.result !== GLOBAL.DEFAULT_OK_RESPONSE.result) {
|
||||
if (INFO_LOG === true) { logger.write('[INFO] initialize -> onTimeMachineInitialized -> Initialization of a Time Machine failed.') }
|
||||
|
||||
if (err.result !== GLOBAL.DEFAULT_OK_RESPONSE.result) {
|
||||
callBackFunction(err)
|
||||
return
|
||||
}
|
||||
|
||||
if (INFO_LOG === true) { logger.write("[INFO] initialize -> onTimeMachineInitialized -> Initialization of a Time Machine failed."); }
|
||||
thisObject.timeMachines.push(timeMachine)
|
||||
|
||||
callBackFunction(err);
|
||||
return;
|
||||
}
|
||||
|
||||
thisObject.timeMachines.push(timeMachine);
|
||||
|
||||
if (initializedCounter === toInitialize) {
|
||||
|
||||
callBackFunction(GLOBAL.DEFAULT_OK_RESPONSE);
|
||||
|
||||
}
|
||||
}
|
||||
if (initializedCounter === toInitialize) {
|
||||
callBackFunction(GLOBAL.DEFAULT_OK_RESPONSE)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function draw() {
|
||||
|
||||
thisObject.container.frame.draw(false, false);
|
||||
|
||||
/* When we draw the chart space, that means we draw all the time machines in it. */
|
||||
|
||||
for (var i = 0; i < thisObject.timeMachines.length; i++ ) {
|
||||
|
||||
var timeMachine = thisObject.timeMachines[i];
|
||||
timeMachine.draw();
|
||||
|
||||
}
|
||||
|
||||
function drawBackground () {
|
||||
for (var i = 0; i < thisObject.timeMachines.length; i++) {
|
||||
var timeMachine = thisObject.timeMachines[i]
|
||||
timeMachine.drawBackground()
|
||||
}
|
||||
}
|
||||
|
||||
function getContainer(point) {
|
||||
function draw () {
|
||||
thisObject.container.frame.draw(false, false)
|
||||
|
||||
if (INFO_LOG === true) { logger.write("[INFO] getContainer -> Entering function."); }
|
||||
for (var i = 0; i < thisObject.timeMachines.length; i++) {
|
||||
var timeMachine = thisObject.timeMachines[i]
|
||||
timeMachine.draw()
|
||||
}
|
||||
}
|
||||
|
||||
let container;
|
||||
function getContainer (point) {
|
||||
if (INFO_LOG === true) { logger.write('[INFO] getContainer -> Entering function.') }
|
||||
|
||||
let container
|
||||
|
||||
/* Now we see which is the inner most container that has it */
|
||||
|
||||
for (var i = 0; i < this.timeMachines.length; i++) {
|
||||
|
||||
container = this.timeMachines[i].getContainer(point);
|
||||
|
||||
if (container !== undefined) {
|
||||
for (var i = 0; i < this.timeMachines.length; i++) {
|
||||
container = this.timeMachines[i].getContainer(point)
|
||||
|
||||
if (container !== undefined) {
|
||||
/* We found an inner container which has the point. We return it. */
|
||||
|
||||
return container;
|
||||
}
|
||||
}
|
||||
return container
|
||||
}
|
||||
}
|
||||
|
||||
/* The point does not belong to any inner container, so we return the current container. */
|
||||
|
||||
return this.container;
|
||||
|
||||
}
|
||||
}
|
||||
return this.container
|
||||
}
|
||||
}
|
||||
+40
-33
@@ -1,44 +1,51 @@
|
||||
|
||||
function newFloatingSpace() {
|
||||
|
||||
|
||||
function newFloatingSpace () {
|
||||
const MODULE_NAME = 'Floating Space'
|
||||
const INFO_LOG = false
|
||||
const ERROR_LOG = true
|
||||
/*
|
||||
The Floating Space is the place where floating elements like floatingObjects, live and are rendered.
|
||||
This space has its own physics which helps with the animation of these objects and also preventing them to overlap.
|
||||
*/
|
||||
|
||||
let thisObject = {
|
||||
floatingLayer: undefined, // This is the array of floatingObjects being displayed
|
||||
profileBalls: undefined,
|
||||
noteSets: undefined,
|
||||
initialize: initialize
|
||||
};
|
||||
let thisObject = {
|
||||
floatingLayer: undefined, // This is the array of floatingObjects being displayed
|
||||
profileBalls: undefined,
|
||||
noteSets: undefined,
|
||||
initialize: initialize,
|
||||
finalize: finalize
|
||||
}
|
||||
|
||||
return thisObject;
|
||||
return thisObject
|
||||
|
||||
function initialize(callBackFunction) {
|
||||
function finalize () {
|
||||
try {
|
||||
if (INFO_LOG === true) { logger.write('[INFO] finalize -> Entering function.') }
|
||||
|
||||
thisObject.floatingLayer = newFloatingLayer();
|
||||
thisObject.floatingLayer.initialize(onFloatingLayerInitialized);
|
||||
|
||||
function onFloatingLayerInitialized(err) {
|
||||
|
||||
thisObject.profileBalls = newProfileBalls();
|
||||
thisObject.profileBalls.initialize(thisObject.floatingLayer, onProfileBallsInitialized);
|
||||
|
||||
function onProfileBallsInitialized(err) {
|
||||
|
||||
thisObject.noteSets = newNoteSets();
|
||||
thisObject.noteSets.initialize(thisObject.floatingLayer, onNoteSetsInitialized);
|
||||
|
||||
function onNoteSetsInitialized(err) {
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
thisObject.floatingLayer.finalize()
|
||||
thisObject.profileBalls.finalize()
|
||||
} catch (err) {
|
||||
if (ERROR_LOG === true) { logger.write('[ERROR] finalize -> err = ' + err) }
|
||||
}
|
||||
}
|
||||
|
||||
function initialize (callBackFunction) {
|
||||
thisObject.floatingLayer = newFloatingLayer()
|
||||
thisObject.floatingLayer.initialize(onFloatingLayerInitialized)
|
||||
|
||||
function onFloatingLayerInitialized (err) {
|
||||
thisObject.profileBalls = newProfileBalls()
|
||||
thisObject.profileBalls.initialize(thisObject.floatingLayer, onProfileBallsInitialized)
|
||||
|
||||
function onProfileBallsInitialized (err) {
|
||||
thisObject.noteSets = newNoteSets()
|
||||
thisObject.noteSets.initialize(thisObject.floatingLayer, onNoteSetsInitialized)
|
||||
|
||||
function onNoteSetsInitialized (err) {
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
+102
-95
@@ -1,114 +1,124 @@
|
||||
/*
|
||||
/*
|
||||
|
||||
The Panel Space y the place wehre all panels live, no matter who create them.
|
||||
The Panel Space y the place wehre all panels live, no matter who create them.
|
||||
|
||||
*/
|
||||
|
||||
function newPanelsSpace() {
|
||||
function newPanelsSpace () {
|
||||
var thisObject = {
|
||||
container: undefined,
|
||||
createNewPanel: createNewPanel,
|
||||
destroyPanel: destroyPanel,
|
||||
getPanel: getPanel,
|
||||
draw: draw,
|
||||
panels: [],
|
||||
getContainer: getContainer, // returns the inner most container that holds the point received by parameter.
|
||||
initialize: initialize
|
||||
}
|
||||
|
||||
var thisObject = {
|
||||
container: undefined,
|
||||
createNewPanel: createNewPanel,
|
||||
destroyPanel: destroyPanel,
|
||||
getPanel: getPanel,
|
||||
draw: draw,
|
||||
panels: [],
|
||||
getContainer: getContainer, // returns the inner most container that holds the point received by parameter.
|
||||
initialize: initialize
|
||||
};
|
||||
var container = newContainer()
|
||||
container.initialize()
|
||||
thisObject.container = container
|
||||
thisObject.container.isDraggeable = false
|
||||
|
||||
var container = newContainer();
|
||||
container.initialize();
|
||||
thisObject.container = container;
|
||||
thisObject.container.isDraggeable = false;
|
||||
container.displacement.containerName = 'Panels Space'
|
||||
container.frame.containerName = 'Panels Space'
|
||||
|
||||
container.displacement.containerName = "Panels Space";
|
||||
container.frame.containerName = "Panels Space";
|
||||
panelsMap = new Map()
|
||||
return thisObject
|
||||
|
||||
return thisObject;
|
||||
|
||||
function initialize() {
|
||||
function initialize () {
|
||||
|
||||
/* The space does not create any Panels for itself, it just sits and waits others need panels. */
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
function createNewPanel(pType, pParameters) {
|
||||
function createNewPanel (pType, pParameters, pOwner) {
|
||||
let panel
|
||||
|
||||
let panel;
|
||||
switch (pType) {
|
||||
|
||||
switch (pType) {
|
||||
|
||||
case "Time Control Panel":
|
||||
{
|
||||
panel = newTimeControlPanel();
|
||||
panel.initialize();
|
||||
break;
|
||||
}
|
||||
|
||||
case "Products Panel":
|
||||
{
|
||||
panel = newProductsPanel();
|
||||
panel.initialize();
|
||||
break;
|
||||
}
|
||||
case "Plotter Panel":
|
||||
{
|
||||
panel = getNewPlotterPanel(pParameters.devTeam, pParameters.plotterCodeName, pParameters.moduleCodeName, pParameters.panelCodeName);
|
||||
panel.initialize();
|
||||
break;
|
||||
}
|
||||
case 'Time Control Panel':
|
||||
{
|
||||
panel = newTimeControlPanel()
|
||||
panel.initialize()
|
||||
break
|
||||
}
|
||||
|
||||
thisObject.panels.push(panel);
|
||||
|
||||
panel.handle = Math.floor((Math.random() * 10000000) + 1);
|
||||
|
||||
return panel.handle;
|
||||
}
|
||||
|
||||
function destroyPanel(pPanelHandle) {
|
||||
|
||||
for (let i = 0; i < thisObject.panels.length; i++) {
|
||||
|
||||
let panel = thisObject.panels[i];
|
||||
|
||||
if (panel.handle === pPanelHandle) {
|
||||
thisObject.panels.splice(i, 1); // Delete item from array.
|
||||
return;
|
||||
}
|
||||
case 'Products Panel':
|
||||
{
|
||||
panel = newProductsPanel()
|
||||
break
|
||||
}
|
||||
case 'Plotter Panel':
|
||||
{
|
||||
panel = getNewPlotterPanel(pParameters.devTeam, pParameters.plotterCodeName, pParameters.moduleCodeName, pParameters.panelCodeName)
|
||||
panel.initialize()
|
||||
break
|
||||
}
|
||||
}
|
||||
|
||||
function getPanel(pPanelHandle) {
|
||||
|
||||
for (let i = 0; i < thisObject.panels.length; i++) {
|
||||
|
||||
let panel = thisObject.panels[i];
|
||||
|
||||
if (panel.handle === pPanelHandle) {
|
||||
return panel;
|
||||
}
|
||||
}
|
||||
let panelArray = panelsMap.get(pOwner)
|
||||
if (panelArray === undefined) {
|
||||
panelArray = []
|
||||
panelsMap.set(pOwner, panelArray)
|
||||
}
|
||||
|
||||
function draw() {
|
||||
panelArray.push(panel)
|
||||
|
||||
thisObject.container.frame.draw(false, false);
|
||||
panel.handle = Math.floor((Math.random() * 10000000) + 1)
|
||||
|
||||
return panel.handle
|
||||
}
|
||||
|
||||
function destroyPanel (pPanelHandle) {
|
||||
for (let i = 0; i < thisObject.panels.length; i++) {
|
||||
let panel = thisObject.panels[i]
|
||||
|
||||
if (panel.handle === pPanelHandle) {
|
||||
thisObject.panels.splice(i, 1) // Delete item from array.
|
||||
return
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function getPanel (pPanelHandle, pOwner) {
|
||||
thisObject.panels = panelsMap.get(pOwner)
|
||||
if (thisObject.panels != undefined) {
|
||||
for (let i = 0; i < thisObject.panels.length; i++) {
|
||||
let panel = thisObject.panels[i]
|
||||
|
||||
if (panel.handle === pPanelHandle) {
|
||||
return panel
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function draw () {
|
||||
thisObject.container.frame.draw(false, false)
|
||||
|
||||
/* When we draw a time machine, that means also to draw all the charts in it. */
|
||||
|
||||
for (var i = 0; i < thisObject.panels.length; i++) {
|
||||
|
||||
let panel = thisObject.panels[i];
|
||||
panel.draw();
|
||||
|
||||
}
|
||||
thisObject.panels = panelsMap.get('Global')
|
||||
if (thisObject.panels != undefined) {
|
||||
for (var i = 0; i < thisObject.panels.length; i++) {
|
||||
let panel = thisObject.panels[i]
|
||||
panel.draw()
|
||||
}
|
||||
}
|
||||
|
||||
function getContainer(point) {
|
||||
thisObject.panels = panelsMap.get(window.CHART_ON_FOCUS)
|
||||
if (thisObject.panels !== undefined) {
|
||||
for (var i = 0; i < thisObject.panels.length; i++) {
|
||||
let panel = thisObject.panels[i]
|
||||
panel.draw()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
let container;
|
||||
function getContainer (point) {
|
||||
let container
|
||||
|
||||
/*
|
||||
|
||||
@@ -117,21 +127,18 @@ function newPanelsSpace() {
|
||||
|
||||
*/
|
||||
|
||||
for (var i = thisObject.panels.length - 1; i >= 0; i--) {
|
||||
|
||||
container = thisObject.panels[i].getContainer(point);
|
||||
|
||||
if (container !== undefined) {
|
||||
for (var i = thisObject.panels.length - 1; i >= 0; i--) {
|
||||
container = thisObject.panels[i].getContainer(point)
|
||||
|
||||
if (container !== undefined) {
|
||||
/* We found an inner container which has the point. We return it. */
|
||||
|
||||
return container;
|
||||
}
|
||||
}
|
||||
return container
|
||||
}
|
||||
}
|
||||
|
||||
/* The point does not belong to any inner container, so we return the current container. */
|
||||
|
||||
return thisObject.container;
|
||||
|
||||
}
|
||||
}
|
||||
return thisObject.container
|
||||
}
|
||||
}
|
||||
+60
-107
@@ -1,132 +1,85 @@
|
||||
|
||||
function newTopSpace() {
|
||||
|
||||
var thisObject = {
|
||||
container: undefined,
|
||||
draw: draw,
|
||||
getContainer: getContainer, // returns the inner most container that holds the point received by parameter.
|
||||
companyLogo: undefined,
|
||||
endUser: undefined,
|
||||
devTeam: undefined,
|
||||
currentBot: undefined,
|
||||
currentProcess: undefined,
|
||||
currentStartMode: undefined,
|
||||
login: undefined,
|
||||
initialize: initialize
|
||||
};
|
||||
function newTopSpace () {
|
||||
var thisObject = {
|
||||
container: undefined,
|
||||
draw: draw,
|
||||
getContainer: getContainer, // returns the inner most container that holds the point received by parameter.
|
||||
endUser: undefined,
|
||||
currentEvent: undefined,
|
||||
login: undefined,
|
||||
initialize: initialize
|
||||
}
|
||||
|
||||
var container = newContainer();
|
||||
container.initialize();
|
||||
thisObject.container = container;
|
||||
var container = newContainer()
|
||||
container.initialize()
|
||||
thisObject.container = container
|
||||
|
||||
resize();
|
||||
resize()
|
||||
|
||||
container.isDraggeable = false;
|
||||
container.isDraggeable = false
|
||||
|
||||
return thisObject;
|
||||
return thisObject
|
||||
|
||||
function initialize() {
|
||||
|
||||
let sharedStatus = {
|
||||
currentDevTeamIndex: 0,
|
||||
currentUserBotIndex: 0,
|
||||
currentProcessIndex: 0,
|
||||
currentBotType: "",
|
||||
eventHandler: newEventHandler()
|
||||
};
|
||||
|
||||
thisObject.login = newLogin();
|
||||
thisObject.login.initialize(onLoginInitialized);
|
||||
|
||||
thisObject.companyLogo = newCompanyLogo();
|
||||
thisObject.endUser = newEndUser();
|
||||
thisObject.currentBot = newCurrentBot();
|
||||
thisObject.currentProcess = newCurrentProcess();
|
||||
thisObject.currentStartMode = newCurrentStartMode();
|
||||
thisObject.devTeam = newDevTeam();
|
||||
|
||||
window.canvasApp.eventHandler.listenToEvent("Browser Resized", resize);
|
||||
|
||||
function onLoginInitialized() {
|
||||
|
||||
thisObject.companyLogo.initialize();
|
||||
thisObject.endUser.initialize();
|
||||
thisObject.currentBot.initialize(sharedStatus);
|
||||
thisObject.currentProcess.initialize(sharedStatus);
|
||||
thisObject.currentStartMode.initialize(sharedStatus);
|
||||
thisObject.devTeam.initialize(sharedStatus);
|
||||
|
||||
}
|
||||
async function initialize () {
|
||||
let sharedStatus = {
|
||||
currentDevTeamIndex: 0,
|
||||
currentEventIndex: 0,
|
||||
currentUserBotIndex: 0,
|
||||
currentProcessIndex: 0,
|
||||
currentBotType: '',
|
||||
eventHandler: newEventHandler()
|
||||
}
|
||||
|
||||
function resize() {
|
||||
thisObject.login = newLogin()
|
||||
await thisObject.login.initialize(sharedStatus)
|
||||
|
||||
thisObject.container.frame.width = browserCanvas.width;
|
||||
thisObject.container.frame.height = TOP_SPACE_HEIGHT;
|
||||
window.canvasApp.eventHandler.listenToEvent('Browser Resized', resize)
|
||||
}
|
||||
|
||||
container.frame.position.x = 0;
|
||||
container.frame.position.y = viewPort.visibleArea.bottomLeft.y;
|
||||
function resize () {
|
||||
thisObject.container.frame.width = browserCanvas.width
|
||||
thisObject.container.frame.height = TOP_SPACE_HEIGHT
|
||||
|
||||
}
|
||||
container.frame.position.x = 0
|
||||
container.frame.position.y = viewPort.visibleArea.bottomLeft.y
|
||||
}
|
||||
|
||||
function getContainer(point) {
|
||||
function getContainer (point) {
|
||||
let container
|
||||
return
|
||||
|
||||
let container;
|
||||
container = thisObject.currentEvent.getContainer(point)
|
||||
if (container !== undefined) { return container }
|
||||
|
||||
container = thisObject.companyLogo.getContainer(point);
|
||||
if (container !== undefined) { return container; }
|
||||
|
||||
container = thisObject.endUser.getContainer(point);
|
||||
if (container !== undefined) { return container; }
|
||||
|
||||
container = thisObject.devTeam.getContainer(point);
|
||||
if (container !== undefined) { return container; }
|
||||
|
||||
container = thisObject.currentBot.getContainer(point);
|
||||
if (container !== undefined) { return container; }
|
||||
|
||||
container = thisObject.currentProcess.getContainer(point);
|
||||
if (container !== undefined) { return container; }
|
||||
|
||||
container = thisObject.currentStartMode.getContainer(point);
|
||||
if (container !== undefined) { return container; }
|
||||
|
||||
container = thisObject.login.getContainer(point);
|
||||
if (container !== undefined) { return container; }
|
||||
container = thisObject.login.getContainer(point)
|
||||
if (container !== undefined) { return container }
|
||||
|
||||
/* The point does not belong to any inner container, so we return the current container. */
|
||||
|
||||
return thisObject.container;
|
||||
return thisObject.container
|
||||
}
|
||||
|
||||
}
|
||||
function draw () {
|
||||
thisObject.container.frame.draw(false, false)
|
||||
|
||||
function draw() {
|
||||
drawBackground()
|
||||
return
|
||||
|
||||
thisObject.container.frame.draw(false, false);
|
||||
thisObject.endUser.draw()
|
||||
thisObject.currentEvent.draw()
|
||||
thisObject.login.draw()
|
||||
}
|
||||
|
||||
drawBackground();
|
||||
thisObject.companyLogo.draw();
|
||||
thisObject.endUser.draw();
|
||||
thisObject.devTeam.draw();
|
||||
thisObject.currentBot.draw();
|
||||
thisObject.currentProcess.draw();
|
||||
thisObject.currentStartMode.draw();
|
||||
thisObject.login.draw();
|
||||
function drawBackground () {
|
||||
let opacity = 1
|
||||
|
||||
}
|
||||
browserCanvasContext.beginPath()
|
||||
|
||||
function drawBackground() {
|
||||
browserCanvasContext.rect(0, 0, thisObject.container.frame.width, thisObject.container.frame.height)
|
||||
browserCanvasContext.fillStyle = 'rgba(' + UI_COLOR.RUSTED_RED + ', ' + opacity + ')'
|
||||
|
||||
let opacity = 1;
|
||||
browserCanvasContext.closePath()
|
||||
|
||||
browserCanvasContext.beginPath();
|
||||
|
||||
browserCanvasContext.rect(0, 0, thisObject.container.frame.width, thisObject.container.frame.height);
|
||||
browserCanvasContext.fillStyle = 'rgba(' + UI_COLOR.RUSTED_RED + ', ' + opacity + ')';
|
||||
|
||||
browserCanvasContext.closePath();
|
||||
|
||||
browserCanvasContext.fill();
|
||||
|
||||
}
|
||||
}
|
||||
browserCanvasContext.fill()
|
||||
}
|
||||
}
|
||||
+97
-117
@@ -1,180 +1,160 @@
|
||||
/*
|
||||
/*
|
||||
|
||||
The Splash Screen is to show some 'loading...' controls while the app is being loaded on the background. After the loading is complete the Splash Screens dissapears for good.
|
||||
|
||||
*/
|
||||
|
||||
function newSplashScreen() {
|
||||
function newSplashScreen () {
|
||||
var thisObject = {
|
||||
container: undefined,
|
||||
draw: draw,
|
||||
timeMachines: [],
|
||||
getContainer: getContainer, // returns the inner most container that holds the point received by parameter.
|
||||
initialize: initialize
|
||||
}
|
||||
|
||||
var thisObject = {
|
||||
container: undefined,
|
||||
draw: draw,
|
||||
timeMachines: [],
|
||||
getContainer: getContainer, // returns the inner most container that holds the point received by parameter.
|
||||
initialize: initialize
|
||||
};
|
||||
var container = newContainer()
|
||||
container.initialize()
|
||||
thisObject.container = container
|
||||
|
||||
resize()
|
||||
|
||||
var container = newContainer();
|
||||
container.initialize();
|
||||
thisObject.container = container;
|
||||
container.displacement.containerName = 'Splash Screen'
|
||||
container.frame.containerName = 'Splash Screen'
|
||||
|
||||
resize();
|
||||
container.frame.position.x = 0
|
||||
container.frame.position.y = 0
|
||||
|
||||
container.displacement.containerName = "Splash Screen";
|
||||
container.frame.containerName = "Splash Screen";
|
||||
container.isDraggeable = false
|
||||
|
||||
container.frame.position.x = 0;
|
||||
container.frame.position.y = 0;
|
||||
let fadeOutCounter = 0
|
||||
let opacity = 1
|
||||
|
||||
container.isDraggeable = false;
|
||||
let logo
|
||||
let canDrawLogo = false
|
||||
|
||||
return thisObject
|
||||
|
||||
let fadeOutCounter = 0;
|
||||
let opacity = 1;
|
||||
function initialize () {
|
||||
logo = new Image()
|
||||
|
||||
let logo;
|
||||
let canDrawLogo = false;
|
||||
|
||||
return thisObject;
|
||||
|
||||
function initialize() {
|
||||
|
||||
logo = new Image();
|
||||
|
||||
logo.onload = onImageLoad;
|
||||
|
||||
function onImageLoad() {
|
||||
canDrawLogo = true;
|
||||
}
|
||||
|
||||
logo.src = window.canvasApp.urlPrefix + "Images/aa-logo.png";
|
||||
|
||||
window.canvasApp.eventHandler.listenToEvent("Browser Resized", resize);
|
||||
logo.onload = onImageLoad
|
||||
|
||||
function onImageLoad () {
|
||||
canDrawLogo = true
|
||||
}
|
||||
|
||||
function resize() {
|
||||
logo.src = window.canvasApp.urlPrefix + 'Images/Superalgos-logo-horz-sm-t.png'
|
||||
|
||||
thisObject.container.frame.width = browserCanvas.width;
|
||||
thisObject.container.frame.height = browserCanvas.height;
|
||||
window.canvasApp.eventHandler.listenToEvent('Browser Resized', resize)
|
||||
}
|
||||
|
||||
function resize () {
|
||||
thisObject.container.frame.width = browserCanvas.width
|
||||
thisObject.container.frame.height = browserCanvas.height
|
||||
}
|
||||
|
||||
function draw () {
|
||||
if (splashScreenNeeded === false) {
|
||||
stepsInitializationCounter = 100
|
||||
|
||||
fadeOutCounter++
|
||||
|
||||
if (fadeOutCounter > 20) {
|
||||
return
|
||||
}
|
||||
opacity = opacity - 0.1
|
||||
}
|
||||
|
||||
|
||||
function draw() {
|
||||
|
||||
if (splashScreenNeeded === false) {
|
||||
|
||||
stepsInitializationCounter = 100;
|
||||
|
||||
fadeOutCounter++;
|
||||
|
||||
if (fadeOutCounter > 20) {
|
||||
return;
|
||||
}
|
||||
opacity = opacity - 0.1;
|
||||
}
|
||||
|
||||
thisObject.container.frame.draw(false, false);
|
||||
thisObject.container.frame.draw(false, false)
|
||||
|
||||
/* Set the background. */
|
||||
|
||||
browserCanvasContext.beginPath();
|
||||
browserCanvasContext.beginPath()
|
||||
|
||||
browserCanvasContext.rect(0, 0, thisObject.container.frame.width, thisObject.container.frame.height);
|
||||
browserCanvasContext.fillStyle = 'rgba(' + UI_COLOR.WHITE + ', ' + opacity + ')';
|
||||
browserCanvasContext.rect(0, 0, thisObject.container.frame.width, thisObject.container.frame.height)
|
||||
browserCanvasContext.fillStyle = 'rgba(' + UI_COLOR.WHITE + ', ' + opacity + ')'
|
||||
|
||||
browserCanvasContext.closePath();
|
||||
browserCanvasContext.closePath()
|
||||
|
||||
browserCanvasContext.fill();
|
||||
browserCanvasContext.fill()
|
||||
|
||||
if (canDrawLogo === false) { return; }
|
||||
if (canDrawLogo === false) { return }
|
||||
|
||||
/* First the AA Logo. */
|
||||
|
||||
let imageHeight = 96;
|
||||
let imageWidth = 480;
|
||||
let yDisplacement = -50;
|
||||
let imageHeight = 192 / 2
|
||||
let imageWidth = 720 / 2
|
||||
let yDisplacement = -60
|
||||
let xDisplacement = -60
|
||||
|
||||
let imagePoint = {
|
||||
x: thisObject.container.frame.width * 1 / 2 - imageWidth / 2,
|
||||
y: thisObject.container.frame.height * 1 / 2 - imageHeight / 2 + yDisplacement
|
||||
};
|
||||
let imagePoint = {
|
||||
x: thisObject.container.frame.width * 1 / 2 - imageWidth / 2 + xDisplacement,
|
||||
y: thisObject.container.frame.height * 1 / 2 - imageHeight / 2 + yDisplacement
|
||||
}
|
||||
|
||||
imagePoint = thisObject.container.frame.frameThisPoint(imagePoint);
|
||||
imagePoint = thisObject.container.frame.frameThisPoint(imagePoint)
|
||||
|
||||
browserCanvasContext.drawImage(logo, imagePoint.x, imagePoint.y, imageWidth, imageHeight);
|
||||
browserCanvasContext.drawImage(logo, imagePoint.x, imagePoint.y, imageWidth, imageHeight)
|
||||
|
||||
/* Second the % of Advance. */
|
||||
|
||||
let label = '' + Math.trunc(stepsInitializationCounter) + ' %';
|
||||
stepsInitializationCounter = stepsInitializationCounter + 0.5;
|
||||
let label = '' + Math.trunc(stepsInitializationCounter) + ' %'
|
||||
stepsInitializationCounter = stepsInitializationCounter + 0.1
|
||||
|
||||
if (stepsInitializationCounter > 99) {
|
||||
if (stepsInitializationCounter > 99) {
|
||||
splashScreenNeeded = false
|
||||
stepsInitializationCounter = 99
|
||||
}
|
||||
|
||||
splashScreenNeeded = false;
|
||||
stepsInitializationCounter = 99;
|
||||
}
|
||||
let fontSize = 10
|
||||
|
||||
let labelPoint = {
|
||||
x: thisObject.container.frame.width / 2 - label.length / 2 * fontSize * FONT_ASPECT_RATIO - 25,
|
||||
y: thisObject.container.frame.height / 2 + fontSize / 2 + fontSize * 0.1 + 80 + yDisplacement
|
||||
}
|
||||
|
||||
let fontSize = 10;
|
||||
browserCanvasContext.font = fontSize + 'px ' + UI_FONT.PRIMARY
|
||||
browserCanvasContext.fillStyle = 'rgba(0, 0, 0, ' + opacity + ')'
|
||||
browserCanvasContext.fillText(label, labelPoint.x, labelPoint.y)
|
||||
|
||||
let labelPoint = {
|
||||
x: thisObject.container.frame.width / 2 - label.length / 2 * fontSize * FONT_ASPECT_RATIO - 25,
|
||||
y: thisObject.container.frame.height / 2 + fontSize / 2 + fontSize * 0.1 + 80 + yDisplacement
|
||||
};
|
||||
|
||||
browserCanvasContext.font = fontSize + 'px ' + UI_FONT.PRIMARY;
|
||||
browserCanvasContext.fillStyle = 'rgba(0, 0, 0, ' + opacity + ')';
|
||||
browserCanvasContext.fillText(label, labelPoint.x, labelPoint.y);
|
||||
|
||||
let title;
|
||||
let titlePoint;
|
||||
let title
|
||||
let titlePoint
|
||||
|
||||
/* Algo Bots Competitions Sub Title */
|
||||
|
||||
fontSize = 15;
|
||||
fontSize = 15
|
||||
|
||||
title = "Trading Bots Competitions Platform"
|
||||
title = 'Trading Bots Competitions Platform'
|
||||
|
||||
titlePoint = {
|
||||
x: thisObject.container.frame.width / 2 - title.length / 2 * fontSize * FONT_ASPECT_RATIO - 20,
|
||||
y: thisObject.container.frame.height / 2 - fontSize * 2 + 80 + yDisplacement
|
||||
};
|
||||
|
||||
browserCanvasContext.font = fontSize + 'px ' + UI_FONT.PRIMARY;
|
||||
browserCanvasContext.fillStyle = 'rgba(0, 0, 0, ' + opacity + ')';
|
||||
browserCanvasContext.fillText(title, titlePoint.x, titlePoint.y);
|
||||
|
||||
|
||||
titlePoint = {
|
||||
x: thisObject.container.frame.width / 2 - title.length / 2 * fontSize * FONT_ASPECT_RATIO - 20,
|
||||
y: thisObject.container.frame.height / 2 - fontSize * 2 + 80 + yDisplacement
|
||||
}
|
||||
|
||||
browserCanvasContext.font = fontSize + 'px ' + UI_FONT.PRIMARY
|
||||
browserCanvasContext.font = 'Saira'
|
||||
browserCanvasContext.fillStyle = 'rgba(0, 0, 0, ' + opacity + ')'
|
||||
browserCanvasContext.fillText(title, titlePoint.x, titlePoint.y)
|
||||
}
|
||||
|
||||
|
||||
function getContainer(point) {
|
||||
|
||||
var container;
|
||||
function getContainer (point) {
|
||||
var container
|
||||
|
||||
/* First we check if this point is inside this space. */
|
||||
|
||||
if (this.container.frame.isThisPointHere(point) === true) {
|
||||
|
||||
if (this.container.frame.isThisPointHere(point) === true) {
|
||||
/* Now we see which is the inner most container that has it */
|
||||
|
||||
// add validation of inner most containers here.
|
||||
|
||||
/* The point does not belong to any inner container, so we return the current container. */
|
||||
|
||||
return this.container;
|
||||
|
||||
} else {
|
||||
|
||||
return this.container
|
||||
} else {
|
||||
/* This point does not belong to this space. */
|
||||
|
||||
return undefined;
|
||||
}
|
||||
|
||||
return undefined
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
-140
@@ -1,140 +0,0 @@
|
||||
function newTextButton() {
|
||||
|
||||
var textButton = {
|
||||
container: undefined,
|
||||
draw: draw,
|
||||
status: 'off',
|
||||
type: undefined,
|
||||
getContainer: getContainer, // returns the inner most container that holds the point received by parameter.
|
||||
initialize: initialize
|
||||
};
|
||||
|
||||
var container = newContainer();
|
||||
container.initialize();
|
||||
container.isDraggeable = false;
|
||||
container.isClickeable = true;
|
||||
textButton.container = container;
|
||||
|
||||
return textButton;
|
||||
|
||||
function initialize() {
|
||||
|
||||
/* Lets set the basic dimensions of this textButton. */
|
||||
|
||||
var position = {
|
||||
x: 0,
|
||||
y: 0
|
||||
};
|
||||
|
||||
this.container.frame.position = position;
|
||||
this.container.frame.width = 180;
|
||||
this.container.frame.height = 14;
|
||||
|
||||
/* Now we start listening to the onClick event from the mouse, so that we can allow users operate this textButton. */
|
||||
|
||||
|
||||
}
|
||||
|
||||
function getContainer(point) {
|
||||
|
||||
var container;
|
||||
|
||||
/* First we check if this point is inside this space. */
|
||||
|
||||
if (this.container.frame.isThisPointHere(point, true) === true) {
|
||||
|
||||
return this.container;
|
||||
|
||||
} else {
|
||||
|
||||
/* This point does not belong to this space. */
|
||||
|
||||
return undefined;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
function draw() {
|
||||
|
||||
drawIcon();
|
||||
|
||||
}
|
||||
|
||||
|
||||
function drawIcon() {
|
||||
|
||||
centerPoint = {
|
||||
x: 7,
|
||||
y: 7
|
||||
};
|
||||
|
||||
/* Now the transformations. */
|
||||
|
||||
centerPoint = textButton.container.frame.frameThisPoint(centerPoint);
|
||||
|
||||
/* Lets start the drawing. */
|
||||
|
||||
browserCanvasContext.beginPath();
|
||||
browserCanvasContext.arc(centerPoint.x, centerPoint.y, 3, 0, 2 * Math.PI);
|
||||
browserCanvasContext.closePath();
|
||||
|
||||
let offFillStyle = 'rgba(232, 28, 28, 1)';
|
||||
let onFillStyle = 'rgba(45, 232, 28, 1)';
|
||||
let invisibleFillStyle = 'rgba(247, 244, 27, 1)';
|
||||
|
||||
switch (textButton.status) {
|
||||
|
||||
case 'on':
|
||||
browserCanvasContext.fillStyle = onFillStyle;
|
||||
break;
|
||||
|
||||
case 'invisible':
|
||||
browserCanvasContext.fillStyle = invisibleFillStyle;
|
||||
break;
|
||||
|
||||
case 'off':
|
||||
browserCanvasContext.fillStyle = offFillStyle;
|
||||
break;
|
||||
|
||||
}
|
||||
|
||||
|
||||
browserCanvasContext.fill();
|
||||
|
||||
browserCanvasContext.strokeStyle = 'rgba(150, 150, 150, 1)';
|
||||
browserCanvasContext.lineWidth = 1;
|
||||
browserCanvasContext.stroke();
|
||||
|
||||
browserCanvasContext.closePath();
|
||||
|
||||
|
||||
/* print the text */
|
||||
|
||||
let labelPoint;
|
||||
let fontSize = 10;
|
||||
|
||||
browserCanvasContext.font = fontSize + 'px ' + UI_FONT.PRIMARY;
|
||||
|
||||
let label = textButton.type;
|
||||
|
||||
let xOffset = 0;
|
||||
let yOffset = 0;
|
||||
|
||||
labelPoint = {
|
||||
x: 20,
|
||||
y: textButton.container.frame.height - 5
|
||||
};
|
||||
|
||||
labelPoint = textButton.container.frame.frameThisPoint(labelPoint);
|
||||
|
||||
browserCanvasContext.fillStyle = 'rgba(60, 60, 60, 0.50)';
|
||||
browserCanvasContext.fillText(label, labelPoint.x, labelPoint.y);
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
+75
-103
@@ -1,4 +1,4 @@
|
||||
/*
|
||||
/*
|
||||
|
||||
This Object object is responsible for defining the coordinate system in a TimeLine.
|
||||
|
||||
@@ -7,85 +7,77 @@ The scale on the Y axis depends on the data that wants to be plotted. Usually we
|
||||
|
||||
*/
|
||||
|
||||
function newTimeLineCoordinateSystem() {
|
||||
function newTimeLineCoordinateSystem () {
|
||||
var thisObject = {
|
||||
min: undefined,
|
||||
max: undefined,
|
||||
scale: undefined,
|
||||
transformThisPoint: transformThisPoint,
|
||||
transformThisPoint2: transformThisPoint2,
|
||||
unInverseTransform: unInverseTransform,
|
||||
inverseTransformUncappedY: inverseTransformUncappedY,
|
||||
initializeX: initializeX,
|
||||
initializeY: initializeY,
|
||||
initialize: initialize
|
||||
}
|
||||
|
||||
var thisObject = {
|
||||
min: undefined,
|
||||
max: undefined,
|
||||
scale: undefined,
|
||||
transformThisPoint: transformThisPoint,
|
||||
transformThisPoint2: transformThisPoint2,
|
||||
unInverseTransform: unInverseTransform,
|
||||
inverseTransformUncappedY: inverseTransformUncappedY,
|
||||
initializeX: initializeX,
|
||||
initializeY: initializeY,
|
||||
initialize: initialize
|
||||
};
|
||||
var min = {
|
||||
x: 0,
|
||||
y: 0
|
||||
}
|
||||
|
||||
var min = {
|
||||
x: 0,
|
||||
y: 0
|
||||
};
|
||||
var max = {
|
||||
x: 0,
|
||||
y: 0
|
||||
}
|
||||
|
||||
var max = {
|
||||
x: 0,
|
||||
y: 0
|
||||
};
|
||||
var scale = {
|
||||
x: 0,
|
||||
y: 0
|
||||
}
|
||||
|
||||
var scale = {
|
||||
x: 0,
|
||||
y: 0
|
||||
};
|
||||
thisObject.min = min
|
||||
thisObject.max = max
|
||||
thisObject.scale = scale
|
||||
|
||||
thisObject.min = min;
|
||||
thisObject.max = max;
|
||||
thisObject.scale = scale;
|
||||
let maxHeight
|
||||
|
||||
let maxHeight;
|
||||
|
||||
return thisObject;
|
||||
|
||||
function initialize(minValue, maxValue, maxWidth, pMaxHeight) {
|
||||
return thisObject
|
||||
|
||||
function initialize (minValue, maxValue, maxWidth, pMaxHeight) {
|
||||
/* Defines the min and max value of rate that we are going to transport to the available screen at the center position. */
|
||||
|
||||
thisObject.min.x = minValue.x; // * 0.999; // 0.1% less
|
||||
thisObject.max.x = maxValue.x; // * 1.001; // 0.1% more
|
||||
thisObject.min.x = minValue.x // * 0.999; // 0.1% less
|
||||
thisObject.max.x = maxValue.x // * 1.001; // 0.1% more
|
||||
|
||||
thisObject.min.y = minValue.y; // * 0.999; // 0.1% less
|
||||
thisObject.max.y = maxValue.y; // * 1.001; // 0.1% more
|
||||
thisObject.min.y = minValue.y // * 0.999; // 0.1% less
|
||||
thisObject.max.y = maxValue.y // * 1.001; // 0.1% more
|
||||
|
||||
/* Defines the initial Zoom level at center position. */
|
||||
|
||||
thisObject.scale.x = maxWidth / (thisObject.max.x - thisObject.min.x);
|
||||
thisObject.scale.y = pMaxHeight / (thisObject.max.y - thisObject.min.y);
|
||||
thisObject.scale.x = maxWidth / (thisObject.max.x - thisObject.min.x)
|
||||
thisObject.scale.y = pMaxHeight / (thisObject.max.y - thisObject.min.y)
|
||||
|
||||
maxHeight = pMaxHeight;
|
||||
maxHeight = pMaxHeight
|
||||
}
|
||||
|
||||
}
|
||||
function initializeX (minValue, maxValue, maxWidth) {
|
||||
thisObject.min.x = minValue.x // * 0.999; // 0.1% less
|
||||
thisObject.max.x = maxValue.x // * 1.001; // 0.1% more
|
||||
|
||||
function initializeX(minValue, maxValue, maxWidth) {
|
||||
thisObject.scale.x = maxWidth / (thisObject.max.x - thisObject.min.x)
|
||||
}
|
||||
|
||||
thisObject.min.x = minValue.x; // * 0.999; // 0.1% less
|
||||
thisObject.max.x = maxValue.x; // * 1.001; // 0.1% more
|
||||
function initializeY (minValue, maxValue, pMaxHeight) {
|
||||
thisObject.min.y = minValue.y // * 0.999; // 0.1% less
|
||||
thisObject.max.y = maxValue.y // * 1.001; // 0.1% more
|
||||
|
||||
thisObject.scale.x = maxWidth / (thisObject.max.x - thisObject.min.x);
|
||||
thisObject.scale.y = pMaxHeight / (thisObject.max.y - thisObject.min.y)
|
||||
|
||||
}
|
||||
|
||||
function initializeY(minValue, maxValue, pMaxHeight) {
|
||||
|
||||
thisObject.min.y = minValue.y; // * 0.999; // 0.1% less
|
||||
thisObject.max.y = maxValue.y; // * 1.001; // 0.1% more
|
||||
|
||||
thisObject.scale.y = pMaxHeight / (thisObject.max.y - thisObject.min.y);
|
||||
|
||||
maxHeight = pMaxHeight;
|
||||
}
|
||||
|
||||
|
||||
function transformThisPoint(point) {
|
||||
maxHeight = pMaxHeight
|
||||
}
|
||||
|
||||
function transformThisPoint (point) {
|
||||
/*
|
||||
|
||||
This is the straigh fordward transformation this object provides. The input is a point on the data set that wants to be plotted in a timeline.
|
||||
@@ -99,59 +91,39 @@ function newTimeLineCoordinateSystem() {
|
||||
|
||||
*/
|
||||
|
||||
point = {
|
||||
x: (point.x - this.min.x) * this.scale.x,
|
||||
y: maxHeight - (point.y - this.min.y) * this.scale.y
|
||||
};
|
||||
|
||||
return point;
|
||||
point = {
|
||||
x: (point.x - this.min.x) * this.scale.x,
|
||||
y: maxHeight - (point.y - this.min.y) * this.scale.y
|
||||
}
|
||||
|
||||
return point
|
||||
}
|
||||
|
||||
function transformThisPoint2(point) {
|
||||
|
||||
point = {
|
||||
x: (point.x - this.min.x) * this.scale.x,
|
||||
y: (maxHeight- point.y - this.min.y) * this.scale.y
|
||||
};
|
||||
|
||||
return point;
|
||||
function transformThisPoint2 (point) {
|
||||
point = {
|
||||
x: (point.x - this.min.x) * this.scale.x,
|
||||
y: (maxHeight - point.y - this.min.y) * this.scale.y
|
||||
}
|
||||
|
||||
return point
|
||||
}
|
||||
|
||||
function unInverseTransform(point, inverseY) {
|
||||
|
||||
point = {
|
||||
x: (point.x / this.scale.x) + this.min.x,
|
||||
y: (inverseY - point.y) / this.scale.y + this.min.y
|
||||
};
|
||||
|
||||
return point;
|
||||
function unInverseTransform (point, inverseY) {
|
||||
point = {
|
||||
x: (point.x / this.scale.x) + this.min.x,
|
||||
y: (inverseY - point.y) / this.scale.y + this.min.y
|
||||
}
|
||||
|
||||
return point
|
||||
}
|
||||
|
||||
function inverseTransformUncappedY(point, inverseY) {
|
||||
|
||||
point = {
|
||||
x: (point.x - this.min.x) * this.scale.x,
|
||||
y: (inverseY - point.y) * this.scale.y
|
||||
};
|
||||
|
||||
return point;
|
||||
function inverseTransformUncappedY (point, inverseY) {
|
||||
point = {
|
||||
x: (point.x - this.min.x) * this.scale.x,
|
||||
y: (inverseY - point.y) * this.scale.y
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
return point
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
+144
-125
@@ -1,180 +1,199 @@
|
||||
/*
|
||||
/*
|
||||
|
||||
Markets are a function of time. When watching them, end users must be positioned at one particular point in time. The system currently allows users
|
||||
to position themselves at any time they like.
|
||||
|
||||
In the future, it will be usefull to explore markets and compare them at different times simultaneously. Anticipating that future this module exists.
|
||||
All the charts that depand on a datetime are children of this object Time Machine. In the future we will allow users to have more than one Time Machine,
|
||||
each one with it own charts, and each one positioned at an especific point in titme.
|
||||
each one with it own charts, and each one positioned at an especific point in titme.
|
||||
|
||||
*/
|
||||
|
||||
function newTimeMachine() {
|
||||
function newTimeMachine () {
|
||||
const MODULE_NAME = 'Time Machine'
|
||||
const INFO_LOG = false
|
||||
const logger = newWebDebugLog()
|
||||
logger.fileName = MODULE_NAME
|
||||
|
||||
const MODULE_NAME = "Time Machine";
|
||||
const INFO_LOG = false;
|
||||
const logger = newWebDebugLog();
|
||||
logger.fileName = MODULE_NAME;
|
||||
let thisObject = {
|
||||
container: undefined,
|
||||
drawBackground: drawBackground,
|
||||
draw: draw,
|
||||
charts: [],
|
||||
getContainer: getContainer, // returns the inner most container that holds the point received by parameter.
|
||||
initialize: initialize,
|
||||
finalize: finalize
|
||||
}
|
||||
|
||||
let thisObject = {
|
||||
container: undefined,
|
||||
draw: draw,
|
||||
charts: [],
|
||||
getContainer: getContainer, // returns the inner most container that holds the point received by parameter.
|
||||
initialize: initialize
|
||||
};
|
||||
let container = newContainer()
|
||||
container.initialize()
|
||||
thisObject.container = container
|
||||
thisObject.container.isDraggeable = false
|
||||
|
||||
let container = newContainer();
|
||||
container.initialize();
|
||||
thisObject.container = container;
|
||||
thisObject.container.isDraggeable = false;
|
||||
container.displacement.containerName = 'Time Machine'
|
||||
container.frame.containerName = 'Time Machine'
|
||||
|
||||
container.displacement.containerName = "Time Machine";
|
||||
container.frame.containerName = "Time Machine";
|
||||
let controlPanelHandle // We need this to destroy the Panel when this object is itself destroyed or no longer needs it...
|
||||
// ... also to request a reference to the object for the cases we need it.
|
||||
const SEPARATION_BETWEEN_TIMELINE_CHARTS = 1.5
|
||||
|
||||
let controlPanelHandle; // We need this to destroy the Panel when this object is itself destroyed or no longer needs it...
|
||||
let productsPanelHandle; // ... also to request a reference to the object for the cases we need it.
|
||||
return thisObject
|
||||
|
||||
return thisObject;
|
||||
function finalize () {
|
||||
try {
|
||||
if (INFO_LOG === true) { logger.write('[INFO] finalize -> Entering function.') }
|
||||
|
||||
function initialize(callBackFunction) {
|
||||
for (let i = 0; i < thisObject.charts.length; i++) {
|
||||
let chart = thisObject.charts[i]
|
||||
chart.finalize()
|
||||
}
|
||||
} catch (err) {
|
||||
if (ERROR_LOG === true) { logger.write('[ERROR] finalize -> err = ' + err) }
|
||||
}
|
||||
}
|
||||
|
||||
if (INFO_LOG === true) { logger.write("[INFO] initialize -> Entering function."); }
|
||||
function initialize (callBackFunction) {
|
||||
if (INFO_LOG === true) { logger.write('[INFO] initialize -> Entering function.') }
|
||||
|
||||
/* Each Time Machine has a Control Panel. */
|
||||
|
||||
controlPanelHandle = canvas.panelsSpace.createNewPanel("Time Control Panel");
|
||||
let controlPanel = canvas.panelsSpace.getPanel(controlPanelHandle);
|
||||
|
||||
productsPanelHandle = canvas.panelsSpace.createNewPanel("Products Panel");
|
||||
let productsPanel = canvas.panelsSpace.getPanel(productsPanelHandle);
|
||||
|
||||
let iteration = 0;
|
||||
let panelOwner = 'Global'
|
||||
controlPanelHandle = canvas.panelsSpace.createNewPanel('Time Control Panel', undefined, panelOwner)
|
||||
let controlPanel = canvas.panelsSpace.getPanel(controlPanelHandle, panelOwner)
|
||||
|
||||
/* First, we initialize the market that we are going to show first on screen. Later all the other markets will be initialized on the background. */
|
||||
|
||||
let timelineChart = newTimelineChart();
|
||||
let position = 0 // This defines the position of each chart respect to each other.
|
||||
|
||||
timelineChart.container.displacement.parentDisplacement = thisObject.container.displacement;
|
||||
timelineChart.container.frame.parentFrame = thisObject.container.frame;
|
||||
let timelineChart = newTimelineChart()
|
||||
|
||||
timelineChart.container.parentContainer = thisObject.container;
|
||||
timelineChart.container.displacement.parentDisplacement = thisObject.container.displacement
|
||||
timelineChart.container.frame.parentFrame = thisObject.container.frame
|
||||
|
||||
timelineChart.container.frame.width = thisObject.container.frame.width * 1;
|
||||
timelineChart.container.frame.height = thisObject.container.frame.height * 1 * canvas.bottomSpace.chartAspectRatio.aspectRatio.y;
|
||||
timelineChart.container.parentContainer = thisObject.container
|
||||
|
||||
timelineChart.container.frame.position.x = thisObject.container.frame.width / 2 - timelineChart.container.frame.width / 2;
|
||||
timelineChart.container.frame.position.y = timelineChart.container.frame.height * 1.5 * iteration;
|
||||
timelineChart.container.frame.width = thisObject.container.frame.width * 1
|
||||
timelineChart.container.frame.height = thisObject.container.frame.height * 1 * canvas.bottomSpace.chartAspectRatio.aspectRatio.y
|
||||
|
||||
timelineChart.initialize(productsPanel, onDefaultMarketInitialized);
|
||||
timelineChart.container.frame.position.x = thisObject.container.frame.width / 2 - timelineChart.container.frame.width / 2
|
||||
timelineChart.container.frame.position.y = timelineChart.container.frame.height * SEPARATION_BETWEEN_TIMELINE_CHARTS * position
|
||||
|
||||
iteration++;
|
||||
position++
|
||||
|
||||
function onDefaultMarketInitialized(err) {
|
||||
timelineChart.initialize(DEFAULT_EXCHANGE, DEFAULT_MARKET, onDefaultInitialized)
|
||||
|
||||
if (INFO_LOG === true) { logger.write("[INFO] initialize -> onDefaultMarketInitialized -> Entering function."); }
|
||||
function onDefaultInitialized (err) {
|
||||
if (INFO_LOG === true) { logger.write('[INFO] initialize -> onDefaultInitialized -> Entering function.') }
|
||||
|
||||
if (err.result !== GLOBAL.DEFAULT_OK_RESPONSE.result) {
|
||||
if (err.result !== GLOBAL.DEFAULT_OK_RESPONSE.result) {
|
||||
if (INFO_LOG === true) { logger.write('[INFO] initialize -> onDefaultInitialized -> Initialization of the only market failed.') }
|
||||
|
||||
if (INFO_LOG === true) { logger.write("[INFO] initialize -> onDefaultMarketInitialized -> Initialization of the only market failed."); }
|
||||
callBackFunction(err)
|
||||
return
|
||||
}
|
||||
|
||||
callBackFunction(err);
|
||||
return;
|
||||
}
|
||||
thisObject.charts.push(timelineChart)
|
||||
|
||||
thisObject.charts.push(timelineChart);
|
||||
controlPanel.container.eventHandler.listenToEvent('Datetime Changed', timelineChart.setDatetime, undefined)
|
||||
timelineChart.container.eventHandler.listenToEvent('Datetime Changed', controlPanel.setDatetime)
|
||||
|
||||
controlPanel.container.eventHandler.listenToEvent('Datetime Changed', timelineChart.setDatetime, undefined);
|
||||
timelineChart.container.eventHandler.listenToEvent('Datetime Changed', controlPanel.setDatetime);
|
||||
|
||||
callBackFunction(GLOBAL.DEFAULT_OK_RESPONSE);
|
||||
|
||||
//initializeTheRestOfTheMarkets();
|
||||
|
||||
}
|
||||
|
||||
function initializeTheRestOfTheMarkets() {
|
||||
|
||||
if (INFO_LOG === true) { logger.write("[INFO] initialize -> initializeTheRestOfTheMarkets -> Entering function."); }
|
||||
|
||||
markets.forEach(initializeTimelineChart);
|
||||
|
||||
function initializeTimelineChart(item, key, mapObj) {
|
||||
|
||||
if (INFO_LOG === true) { logger.write("[INFO] initialize -> initializeTheRestOfTheMarkets -> initializeTimelineChart -> Entering function."); }
|
||||
|
||||
if (key === INITIAL_DEFAULT_MARKET) { // We skip this market since it has already been initialized.
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
let timelineChart = newTimelineChart();
|
||||
|
||||
timelineChart.container.displacement.parentDisplacement = thisObject.container.displacement;
|
||||
timelineChart.container.frame.parentFrame = thisObject.container.frame;
|
||||
|
||||
timelineChart.container.parentContainer = thisObject.container;
|
||||
|
||||
timelineChart.container.frame.width = thisObject.container.frame.width * 1;
|
||||
timelineChart.container.frame.height = thisObject.container.frame.height * 1 * canvas.bottomSpace.chartAspectRatio.aspectRatio.y;
|
||||
|
||||
timelineChart.container.frame.position.x = thisObject.container.frame.width / 2 - timelineChart.container.frame.width / 2;
|
||||
timelineChart.container.frame.position.y = timelineChart.container.frame.height * 1.5 * iteration;
|
||||
|
||||
timelineChart.initialize(productsPanel, finalSteps);
|
||||
|
||||
iteration++;
|
||||
|
||||
function finalSteps() {
|
||||
|
||||
if (INFO_LOG === true) { logger.write("[INFO] initialize -> initializeTheRestOfTheMarkets -> initializeTimelineChart -> finalSteps -> Entering function."); }
|
||||
|
||||
thisObject.charts.push(timelineChart);
|
||||
|
||||
controlPanel.container.eventHandler.listenToEvent('Datetime Changed', timelineChart.setDatetime, undefined);
|
||||
timelineChart.container.eventHandler.listenToEvent('Datetime Changed', controlPanel.setDatetime);
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
initializeTheRest()
|
||||
}
|
||||
|
||||
function draw() {
|
||||
function initializeTheRest () {
|
||||
if (INFO_LOG === true) { logger.write('[INFO] initialize -> initializeTheRest -> Entering function.') }
|
||||
|
||||
this.container.frame.draw(false, false);
|
||||
let leftToInitialize = SUPPORTED_EXCHANGES.length * SUPPORTED_MARKETS.length - 1 // The default exchange and market was already initialized.
|
||||
let alreadyInitialized = 0
|
||||
|
||||
/* When we draw a time machine, that means also to draw all the charts in it. */
|
||||
for (let i = 0; i < SUPPORTED_EXCHANGES.length; i++) {
|
||||
for (let j = 0; j < SUPPORTED_MARKETS.length; j++) {
|
||||
let exchange = SUPPORTED_EXCHANGES[i]
|
||||
let market = SUPPORTED_MARKETS[j]
|
||||
|
||||
for (let i = 0; i < this.charts.length; i++) {
|
||||
|
||||
let chart = this.charts[i];
|
||||
chart.draw();
|
||||
if (
|
||||
exchange === DEFAULT_EXCHANGE &&
|
||||
market.assetA === DEFAULT_MARKET.assetA &&
|
||||
market.assetB === DEFAULT_MARKET.assetB
|
||||
) { continue }
|
||||
|
||||
initializeTimelineChart(exchange, market)
|
||||
}
|
||||
}
|
||||
|
||||
function initializeTimelineChart (exchange, market) {
|
||||
if (INFO_LOG === true) { logger.write('[INFO] initialize -> initializeTheRest -> initializeTimelineChart -> Entering function.') }
|
||||
|
||||
let timelineChart = newTimelineChart()
|
||||
|
||||
timelineChart.container.displacement.parentDisplacement = thisObject.container.displacement
|
||||
timelineChart.container.frame.parentFrame = thisObject.container.frame
|
||||
|
||||
timelineChart.container.parentContainer = thisObject.container
|
||||
|
||||
timelineChart.container.frame.width = thisObject.container.frame.width * 1
|
||||
timelineChart.container.frame.height = thisObject.container.frame.height * 1 * canvas.bottomSpace.chartAspectRatio.aspectRatio.y
|
||||
|
||||
timelineChart.container.frame.position.x = thisObject.container.frame.width / 2 - timelineChart.container.frame.width / 2
|
||||
timelineChart.container.frame.position.y = timelineChart.container.frame.height * SEPARATION_BETWEEN_TIMELINE_CHARTS * position
|
||||
|
||||
position++
|
||||
|
||||
timelineChart.initialize(exchange, market, finalSteps)
|
||||
|
||||
function finalSteps () {
|
||||
if (INFO_LOG === true) { logger.write('[INFO] initialize -> initializeTheRest -> initializeTimelineChart -> finalSteps -> Entering function.') }
|
||||
|
||||
thisObject.charts.push(timelineChart)
|
||||
|
||||
controlPanel.container.eventHandler.listenToEvent('Datetime Changed', timelineChart.setDatetime, undefined)
|
||||
timelineChart.container.eventHandler.listenToEvent('Datetime Changed', controlPanel.setDatetime)
|
||||
|
||||
alreadyInitialized++
|
||||
|
||||
if (alreadyInitialized === leftToInitialize) {
|
||||
callBackFunction(GLOBAL.DEFAULT_OK_RESPONSE)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function getContainer(point) {
|
||||
function drawBackground () {
|
||||
for (let i = 0; i < this.charts.length; i++) {
|
||||
let chart = this.charts[i]
|
||||
chart.drawBackground()
|
||||
}
|
||||
}
|
||||
|
||||
if (INFO_LOG === true) { logger.write("[INFO] getContainer -> Entering function."); }
|
||||
function draw () {
|
||||
this.container.frame.draw(false, false)
|
||||
|
||||
let container;
|
||||
for (let i = 0; i < this.charts.length; i++) {
|
||||
let chart = this.charts[i]
|
||||
chart.draw()
|
||||
}
|
||||
}
|
||||
|
||||
function getContainer (point) {
|
||||
if (INFO_LOG === true) { logger.write('[INFO] getContainer -> Entering function.') }
|
||||
|
||||
let container
|
||||
|
||||
/* Now we see which is the inner most container that has it */
|
||||
|
||||
for (let i = 0; i < this.charts.length; i++) {
|
||||
|
||||
container = this.charts[i].getContainer(point);
|
||||
|
||||
if (container !== undefined) {
|
||||
for (let i = 0; i < this.charts.length; i++) {
|
||||
container = this.charts[i].getContainer(point)
|
||||
|
||||
if (container !== undefined) {
|
||||
/* We found an inner container which has the point. We return it. */
|
||||
|
||||
return container;
|
||||
}
|
||||
}
|
||||
|
||||
return container
|
||||
}
|
||||
}
|
||||
|
||||
/* The point does not belong to any inner container, so we return the current container. */
|
||||
|
||||
return this.container;
|
||||
}
|
||||
}
|
||||
return this.container
|
||||
}
|
||||
}
|
||||
+373
-397
@@ -1,226 +1,224 @@
|
||||
function newTimelineChart() {
|
||||
function newTimelineChart () {
|
||||
const MODULE_NAME = 'Timeline Chart'
|
||||
const INFO_LOG = false
|
||||
const INTENSIVE_LOG = false
|
||||
const ERROR_LOG = true
|
||||
const logger = newWebDebugLog()
|
||||
logger.fileName = MODULE_NAME
|
||||
|
||||
const MODULE_NAME = "Timeline Chart";
|
||||
const INFO_LOG = false;
|
||||
const INTENSIVE_LOG = false;
|
||||
const ERROR_LOG = true;
|
||||
const logger = newWebDebugLog();
|
||||
logger.fileName = MODULE_NAME;
|
||||
let timeLineCoordinateSystem = newTimeLineCoordinateSystem()
|
||||
|
||||
let timeLineCoordinateSystem = newTimeLineCoordinateSystem();
|
||||
let timePeriod = INITIAL_TIME_PERIOD
|
||||
let datetime = INITIAL_DATE
|
||||
|
||||
let timePeriod = INITIAL_TIME_PERIOD;
|
||||
let datetime = INITIAL_DATE;
|
||||
let thisObject = {
|
||||
setDatetime: setDatetime,
|
||||
container: undefined,
|
||||
drawBackground: drawBackground,
|
||||
draw: draw,
|
||||
getContainer: getContainer,
|
||||
initialize: initialize,
|
||||
finalize: finalize
|
||||
}
|
||||
|
||||
let thisObject = {
|
||||
setDatetime: setDatetime,
|
||||
container: undefined,
|
||||
draw: draw,
|
||||
getContainer: getContainer,
|
||||
initialize: initialize
|
||||
};
|
||||
let container = newContainer()
|
||||
container.initialize()
|
||||
thisObject.container = container
|
||||
|
||||
let container = newContainer();
|
||||
container.initialize();
|
||||
thisObject.container = container;
|
||||
container.displacement.containerName = 'Timeline Chart'
|
||||
container.frame.containerName = 'Timeline Chart'
|
||||
|
||||
container.displacement.containerName = "Timeline Chart";
|
||||
container.frame.containerName = "Timeline Chart";
|
||||
let chartGrid
|
||||
let breakpointsBar
|
||||
|
||||
let chartGrid;
|
||||
let breakpointsBar;
|
||||
let initializationReady = false
|
||||
|
||||
let initializationReady = false;
|
||||
|
||||
let productsPanel;
|
||||
let productsPanel
|
||||
|
||||
/* Background */
|
||||
let logoAssetA;
|
||||
let logoAssetB;
|
||||
let logoExchange;
|
||||
let logoAA;
|
||||
let canDrawLogoA = false;
|
||||
let canDrawLogoB = false;
|
||||
let canDrawLogoExchange = false;
|
||||
let canDrawLogoAA = false;
|
||||
let logoAssetA
|
||||
let logoAssetB
|
||||
let logoExchange
|
||||
let logoAA
|
||||
let canDrawLogoA = false
|
||||
let canDrawLogoB = false
|
||||
let canDrawLogoExchange = false
|
||||
let canDrawLogoAA = false
|
||||
|
||||
let plotterManager;
|
||||
let plotterManager
|
||||
let exchange
|
||||
let market
|
||||
|
||||
return thisObject;
|
||||
let productsPanelHandle
|
||||
|
||||
function initialize(pProductsPanel, callBackFunction) {
|
||||
return thisObject
|
||||
|
||||
try {
|
||||
function finalize () {
|
||||
try {
|
||||
if (INFO_LOG === true) { logger.write('[INFO] finalize -> Entering function.') }
|
||||
|
||||
if (INFO_LOG === true) { logger.write("[INFO] initialize -> Entering function."); }
|
||||
plotterManager.finalize()
|
||||
} catch (err) {
|
||||
if (ERROR_LOG === true) { logger.write('[ERROR] finalize -> err = ' + err) }
|
||||
}
|
||||
}
|
||||
|
||||
function initialize (pExchange, pMarket, callBackFunction) {
|
||||
try {
|
||||
if (INFO_LOG === true) { logger.write('[INFO] initialize -> Entering function.') }
|
||||
|
||||
/* We load the logow we will need for the background. */
|
||||
exchange = pExchange
|
||||
market = pMarket
|
||||
|
||||
logoA = new Image();
|
||||
logoB = new Image();
|
||||
logoExchange = new Image();
|
||||
logoAA = new Image();
|
||||
let panelOwner = exchange + ' ' + market.assetB + '/' + market.assetA
|
||||
productsPanelHandle = canvas.panelsSpace.createNewPanel('Products Panel', undefined, panelOwner)
|
||||
let productsPanel = canvas.panelsSpace.getPanel(productsPanelHandle, panelOwner)
|
||||
productsPanel.initialize(exchange, market)
|
||||
|
||||
logoA.onload = onImageALoaded;
|
||||
logoA = new Image()
|
||||
logoB = new Image()
|
||||
logoExchange = new Image()
|
||||
logoAA = new Image()
|
||||
|
||||
function onImageALoaded() {
|
||||
canDrawLogoA = true;
|
||||
}
|
||||
logoA.onload = onImageALoaded
|
||||
|
||||
logoB.onload = onImageBLoaded;
|
||||
function onImageALoaded () {
|
||||
canDrawLogoA = true
|
||||
}
|
||||
|
||||
function onImageBLoaded() {
|
||||
canDrawLogoB = true;
|
||||
}
|
||||
logoB.onload = onImageBLoaded
|
||||
|
||||
logoExchange.onload = onImageExchangeLoaded;
|
||||
function onImageBLoaded () {
|
||||
canDrawLogoB = true
|
||||
}
|
||||
|
||||
function onImageExchangeLoaded() {
|
||||
canDrawLogoExchange = true;
|
||||
}
|
||||
logoExchange.onload = onImageExchangeLoaded
|
||||
|
||||
logoAA.onload = onImageAALoaded;
|
||||
function onImageExchangeLoaded () {
|
||||
canDrawLogoExchange = true
|
||||
}
|
||||
|
||||
function onImageAALoaded() {
|
||||
canDrawLogoAA = true;
|
||||
}
|
||||
logoAA.onload = onImageAALoaded
|
||||
|
||||
logoA.src = window.canvasApp.urlPrefix + "Images/tether-logo-background.png";
|
||||
logoB.src = window.canvasApp.urlPrefix + "Images/bitcoin-logo-background.png";
|
||||
logoExchange.src = window.canvasApp.urlPrefix + "Images/poloniex-logo-background.png";
|
||||
logoAA.src = window.canvasApp.urlPrefix + "Images/aa-logo-background.png";
|
||||
function onImageAALoaded () {
|
||||
canDrawLogoAA = true
|
||||
}
|
||||
|
||||
/* Remember the Products Panel */
|
||||
logoA.src = window.canvasApp.urlPrefix + 'Images/tether-logo-background.png'
|
||||
logoB.src = window.canvasApp.urlPrefix + 'Images/bitcoin-logo-background.png'
|
||||
logoExchange.src = window.canvasApp.urlPrefix + 'Images/' + exchange + '-logo-background.png'
|
||||
logoAA.src = window.canvasApp.urlPrefix + 'Images/sa-logo-background.png'
|
||||
|
||||
productsPanel = pProductsPanel;
|
||||
chartGrid = newChartGrid()
|
||||
chartGrid.initialize()
|
||||
|
||||
chartGrid = newChartGrid();
|
||||
chartGrid.initialize();
|
||||
breakpointsBar = newBreakpointsBar()
|
||||
breakpointsBar.initialize(container, timeLineCoordinateSystem)
|
||||
|
||||
breakpointsBar = newBreakpointsBar();
|
||||
breakpointsBar.initialize(container, timeLineCoordinateSystem);
|
||||
recalculateScale()
|
||||
|
||||
// moveViewPortToCurrentDatetime();
|
||||
moveToUserPosition(container, timeLineCoordinateSystem)
|
||||
timePeriod = INITIAL_TIME_PERIOD
|
||||
datetime = INITIAL_DATE
|
||||
|
||||
recalculateScale();
|
||||
|
||||
//moveViewPortToCurrentDatetime();
|
||||
moveToUserPosition(container, timeLineCoordinateSystem);
|
||||
timePeriod = INITIAL_TIME_PERIOD;
|
||||
datetime = INITIAL_DATE;
|
||||
|
||||
/* Event Subscriptions - we need this events to be fired first here and then in active Plotters. */
|
||||
|
||||
viewPort.eventHandler.listenToEvent("Offset Changed", onOffsetChanged);
|
||||
viewPort.eventHandler.listenToEvent("Zoom Changed", onZoomChanged);
|
||||
viewPort.eventHandler.listenToEvent('Offset Changed', onOffsetChanged)
|
||||
viewPort.eventHandler.listenToEvent('Zoom Changed', onZoomChanged)
|
||||
|
||||
/* Initialize the Plotter Manager */
|
||||
|
||||
plotterManager = newPlottersManager();
|
||||
plotterManager = newPlottersManager()
|
||||
|
||||
plotterManager.container.displacement.parentDisplacement = thisObject.container.displacement;
|
||||
plotterManager.container.frame.parentFrame = thisObject.container.frame;
|
||||
plotterManager.container.displacement.parentDisplacement = thisObject.container.displacement
|
||||
plotterManager.container.frame.parentFrame = thisObject.container.frame
|
||||
|
||||
plotterManager.container.parentContainer = thisObject.container;
|
||||
plotterManager.container.parentContainer = thisObject.container
|
||||
|
||||
plotterManager.container.frame.width = thisObject.container.frame.width;
|
||||
plotterManager.container.frame.height = thisObject.container.frame.height;
|
||||
plotterManager.container.frame.width = thisObject.container.frame.width
|
||||
plotterManager.container.frame.height = thisObject.container.frame.height
|
||||
|
||||
plotterManager.container.frame.position.x = thisObject.container.frame.position.x;
|
||||
plotterManager.container.frame.position.y = thisObject.container.frame.position.y;
|
||||
plotterManager.container.frame.position.x = 0
|
||||
plotterManager.container.frame.position.y = 0
|
||||
|
||||
plotterManager.initialize(pProductsPanel, onPlotterManagerReady);
|
||||
plotterManager.initialize(productsPanel, pExchange, pMarket, onPlotterManagerReady)
|
||||
|
||||
function onPlotterManagerReady(err) {
|
||||
function onPlotterManagerReady (err) {
|
||||
if (INFO_LOG === true) { logger.write('[INFO] initialize -> onPlotterManagerReady -> Entering function.') }
|
||||
|
||||
if (INFO_LOG === true) { logger.write("[INFO] initialize -> onPlotterManagerReady -> Entering function."); }
|
||||
if (err.result !== GLOBAL.DEFAULT_OK_RESPONSE.result) {
|
||||
if (ERROR_LOG === true) { logger.write('[ERROR] initialize -> onPlotterManagerReady -> Plotter Manager Initialization Failed. ') }
|
||||
if (ERROR_LOG === true) { logger.write('[ERROR] initialize -> onPlotterManagerReady -> err.message = ' + err.message) }
|
||||
|
||||
if (err.result !== GLOBAL.DEFAULT_OK_RESPONSE.result) {
|
||||
callBackFunction(GLOBAL.DEFAULT_FAIL_RESPONSE)
|
||||
return
|
||||
}
|
||||
|
||||
if (ERROR_LOG === true) { logger.write("[ERROR] initialize -> onPlotterManagerReady -> Plotter Manager Initialization Failed. "); }
|
||||
if (ERROR_LOG === true) { logger.write("[ERROR] initialize -> onPlotterManagerReady -> err.message = " + err.message); }
|
||||
initializationReady = true
|
||||
callBackFunction(GLOBAL.DEFAULT_OK_RESPONSE)
|
||||
return
|
||||
}
|
||||
|
||||
callBackFunction(GLOBAL.DEFAULT_FAIL_RESPONSE);
|
||||
return;
|
||||
}
|
||||
canvas.bottomSpace.chartAspectRatio.container.eventHandler.listenToEvent('Chart Aspect Ratio Changed', onAspectRatioChanged)
|
||||
|
||||
initializationReady = true;
|
||||
callBackFunction(GLOBAL.DEFAULT_OK_RESPONSE);
|
||||
return;
|
||||
}
|
||||
function onAspectRatioChanged (pAspectRatio) {
|
||||
thisObject.container.frame.height = CHART_SPACE_HEIGHT * pAspectRatio.y
|
||||
recalculateScale()
|
||||
}
|
||||
} catch (err) {
|
||||
if (ERROR_LOG === true) { logger.write('[ERROR] initialize -> err = ' + err) }
|
||||
callBackFunction(GLOBAL.DEFAULT_FAIL_RESPONSE)
|
||||
}
|
||||
}
|
||||
|
||||
canvas.bottomSpace.chartAspectRatio.container.eventHandler.listenToEvent("Chart Aspect Ratio Changed", onAspectRatioChanged);
|
||||
|
||||
function onAspectRatioChanged(pAspectRatio) {
|
||||
function onZoomChanged (event) {
|
||||
if (INFO_LOG === true) { logger.write('[INFO] onZoomChanged -> Entering function.') }
|
||||
|
||||
thisObject.container.frame.height = CHART_SPACE_HEIGHT * pAspectRatio.y;
|
||||
recalculateScale();
|
||||
if (initializationReady === true) {
|
||||
let currentTimePeriod = timePeriod
|
||||
|
||||
}
|
||||
|
||||
} catch (err) {
|
||||
|
||||
if (ERROR_LOG === true) { logger.write("[ERROR] initialize -> err = " + err); }
|
||||
callBackFunction(GLOBAL.DEFAULT_FAIL_RESPONSE);
|
||||
}
|
||||
}
|
||||
|
||||
function onZoomChanged(event) {
|
||||
|
||||
if (INFO_LOG === true) { logger.write("[INFO] onZoomChanged -> Entering function."); }
|
||||
|
||||
if (initializationReady === true) {
|
||||
|
||||
let currentTimePeriod = timePeriod;
|
||||
|
||||
timePeriod = recalculatePeriod(event.newLevel);
|
||||
timePeriod = recalculatePeriod(event.newLevel)
|
||||
|
||||
/* If the period changes, we need to spread the word in cascade towards all the depending objects. */
|
||||
|
||||
if (timePeriod !== currentTimePeriod) {
|
||||
if (timePeriod !== currentTimePeriod) {
|
||||
plotterManager.setTimePeriod(timePeriod)
|
||||
}
|
||||
|
||||
plotterManager.setTimePeriod(timePeriod);
|
||||
recalculateCurrentDatetime()
|
||||
|
||||
}
|
||||
saveUserPosition(thisObject.container, timeLineCoordinateSystem)
|
||||
}
|
||||
}
|
||||
|
||||
recalculateCurrentDatetime();
|
||||
|
||||
saveUserPosition(thisObject.container, timeLineCoordinateSystem);
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
function setDatetime(pDatetime) {
|
||||
|
||||
if (INFO_LOG === true) { logger.write("[INFO] setDatetime -> Entering function."); }
|
||||
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()) {
|
||||
if (thisObject.container.frame.isInViewPort()) {
|
||||
plotterManager.setDatetime(pDatetime)
|
||||
plotterManager.positionAtDatetime(pDatetime)
|
||||
breakpointsBar.setDatetime(pDatetime)
|
||||
}
|
||||
}
|
||||
|
||||
plotterManager.setDatetime(pDatetime);
|
||||
plotterManager.positionAtDatetime(pDatetime);
|
||||
breakpointsBar.setDatetime(pDatetime);
|
||||
}
|
||||
}
|
||||
function onOffsetChanged () {
|
||||
if (INFO_LOG === true) { logger.write('[INFO] onOffsetChanged -> Entering function.') }
|
||||
|
||||
function onOffsetChanged() {
|
||||
if (initializationReady === true) {
|
||||
if (thisObject.container.frame.isInViewPort()) {
|
||||
recalculateCurrentDatetime()
|
||||
saveUserPosition(thisObject.container, timeLineCoordinateSystem)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (INFO_LOG === true) { logger.write("[INFO] onOffsetChanged -> Entering function."); }
|
||||
|
||||
if (initializationReady === true) {
|
||||
|
||||
if (thisObject.container.frame.isInViewPort()) {
|
||||
|
||||
recalculateCurrentDatetime();
|
||||
saveUserPosition(thisObject.container, timeLineCoordinateSystem);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
function recalculateCurrentDatetime() {
|
||||
|
||||
if (INFO_LOG === true) { logger.write("[INFO] recalculateCurrentDatetime -> Entering function."); }
|
||||
function recalculateCurrentDatetime () {
|
||||
if (INFO_LOG === true) { logger.write('[INFO] recalculateCurrentDatetime -> Entering function.') }
|
||||
|
||||
/*
|
||||
|
||||
@@ -229,298 +227,276 @@
|
||||
|
||||
*/
|
||||
|
||||
let center = {
|
||||
x: (viewPort.visibleArea.bottomRight.x - viewPort.visibleArea.bottomLeft.x) / 2,
|
||||
y: (viewPort.visibleArea.bottomRight.y - viewPort.visibleArea.topRight.y) / 2
|
||||
};
|
||||
let center = {
|
||||
x: (viewPort.visibleArea.bottomRight.x - viewPort.visibleArea.bottomLeft.x) / 2,
|
||||
y: (viewPort.visibleArea.bottomRight.y - viewPort.visibleArea.topRight.y) / 2
|
||||
}
|
||||
|
||||
center = unTransformThisPoint(center, thisObject.container);
|
||||
center = timeLineCoordinateSystem.unInverseTransform(center, thisObject.container.frame.height);
|
||||
center = unTransformThisPoint(center, thisObject.container)
|
||||
center = timeLineCoordinateSystem.unInverseTransform(center, thisObject.container.frame.height)
|
||||
|
||||
let newDate = new Date(0);
|
||||
newDate.setUTCSeconds(center.x / 1000);
|
||||
let newDate = new Date(0)
|
||||
newDate.setUTCSeconds(center.x / 1000)
|
||||
|
||||
datetime = newDate;
|
||||
datetime = newDate
|
||||
|
||||
plotterManager.setDatetime(datetime);
|
||||
plotterManager.setDatetime(datetime)
|
||||
|
||||
breakpointsBar.setDatetime(datetime);
|
||||
breakpointsBar.setDatetime(datetime)
|
||||
|
||||
thisObject.container.eventHandler.raiseEvent("Datetime Changed", datetime);
|
||||
|
||||
}
|
||||
thisObject.container.eventHandler.raiseEvent('Datetime Changed', datetime)
|
||||
}
|
||||
|
||||
function getContainer(point) {
|
||||
function getContainer (point) {
|
||||
if (INFO_LOG === true) { logger.write('[INFO] getContainer -> Entering function.') }
|
||||
|
||||
if (INFO_LOG === true) { logger.write("[INFO] getContainer -> Entering function."); }
|
||||
let container
|
||||
|
||||
let container;
|
||||
container = chartGrid.getContainer(point)
|
||||
|
||||
container = chartGrid.getContainer(point);
|
||||
if (container !== undefined) { return container }
|
||||
|
||||
if (container !== undefined) { return container;}
|
||||
container = breakpointsBar.getContainer(point)
|
||||
|
||||
container = breakpointsBar.getContainer(point);
|
||||
return container
|
||||
}
|
||||
|
||||
return container;
|
||||
function recalculateScale () {
|
||||
if (INFO_LOG === true) { logger.write('[INFO] recalculateScale -> Entering function.') }
|
||||
|
||||
}
|
||||
let minValue = {
|
||||
x: EARLIEST_DATE.valueOf(),
|
||||
y: 0
|
||||
}
|
||||
|
||||
function recalculateScale() {
|
||||
let maxValue = {
|
||||
x: MAX_PLOTABLE_DATE.valueOf(),
|
||||
y: nextPorwerOf10(USDT_BTC_HTH) / 4
|
||||
}
|
||||
|
||||
if (INFO_LOG === true) { logger.write("[INFO] recalculateScale -> Entering function."); }
|
||||
|
||||
let minValue = {
|
||||
x: EARLIEST_DATE.valueOf(),
|
||||
y: 0
|
||||
};
|
||||
|
||||
let maxValue = {
|
||||
x: MAX_PLOTABLE_DATE.valueOf(),
|
||||
y: nextPorwerOf10(USDT_BTC_HTH) / 4
|
||||
};
|
||||
|
||||
timeLineCoordinateSystem.initialize(
|
||||
timeLineCoordinateSystem.initialize(
|
||||
minValue,
|
||||
maxValue,
|
||||
thisObject.container.frame.width,
|
||||
thisObject.container.frame.height
|
||||
);
|
||||
)
|
||||
}
|
||||
|
||||
}
|
||||
function tooTiny () {
|
||||
if (INTENSIVE_LOG === true) { logger.write('[INFO] tooTiny -> Entering function.') }
|
||||
|
||||
function tooTiny() {
|
||||
if (viewPort.zoomLevel < Math.trunc(-28.25 * 100) / 100) {
|
||||
return true
|
||||
} else {
|
||||
return false
|
||||
}
|
||||
}
|
||||
|
||||
if (INTENSIVE_LOG === true) { logger.write("[INFO] tooTiny -> Entering function."); }
|
||||
function tooSmall () {
|
||||
if (INFO_LOG === true) { logger.write('[INFO] tooSmall -> Entering function.') }
|
||||
|
||||
if (viewPort.zoomLevel < Math.trunc(-28.25 * 100) / 100) {
|
||||
return true;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
if (viewPort.zoomLevel < Math.trunc(-27.25 * 100) / 100) {
|
||||
return true
|
||||
} else {
|
||||
return false
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
function drawBackground () {
|
||||
if (INTENSIVE_LOG === true) { logger.write('[INFO] drawBackground -> Entering function.') }
|
||||
|
||||
function tooSmall() {
|
||||
if (thisObject.container.frame.isInViewPort()) {
|
||||
if (window.CHART_ON_FOCUS === '') {
|
||||
window.CHART_ON_FOCUS = exchange + ' ' + market.assetB + '/' + market.assetA
|
||||
|
||||
if (INFO_LOG === true) { logger.write("[INFO] tooSmall -> Entering function."); }
|
||||
this.container.frame.draw()
|
||||
|
||||
if (viewPort.zoomLevel < Math.trunc(-27.25 * 100) / 100) {
|
||||
return true;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
drawChartsBackgroundImages()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
function draw () {
|
||||
if (INTENSIVE_LOG === true) { logger.write('[INFO] draw -> Entering function.') }
|
||||
|
||||
function draw() {
|
||||
if (thisObject.container.frame.isInViewPort()) {
|
||||
drawChartsBackground()
|
||||
|
||||
if (INTENSIVE_LOG === true) { logger.write("[INFO] draw -> Entering function."); }
|
||||
chartGrid.draw(thisObject.container, timeLineCoordinateSystem)
|
||||
|
||||
if (thisObject.container.frame.isInViewPort()) {
|
||||
plotterManager.draw()
|
||||
|
||||
this.container.frame.draw();
|
||||
|
||||
drawBackground();
|
||||
|
||||
chartGrid.draw(thisObject.container, timeLineCoordinateSystem);
|
||||
|
||||
plotterManager.draw();
|
||||
|
||||
breakpointsBar.draw();
|
||||
}
|
||||
}
|
||||
|
||||
function drawBackground() {
|
||||
|
||||
if (INTENSIVE_LOG === true) { logger.write("[INFO] drawBackground -> Entering function."); }
|
||||
|
||||
if (canDrawLogoA === false || canDrawLogoB === false || canDrawLogoExchange === false || canDrawLogoAA === false) { return; }
|
||||
|
||||
let backgroundLogoPoint1;
|
||||
let backgroundLogoPoint2;
|
||||
|
||||
let imageHeight = 42;
|
||||
let imageWidth = 150;
|
||||
|
||||
let MAX_COLUMNS = 16;
|
||||
let MAX_ROWS = 7;
|
||||
let Y_TOP_MARGIN = 30;
|
||||
|
||||
let point1 = {
|
||||
x: viewPort.visibleArea.topLeft.x,
|
||||
y: viewPort.visibleArea.topLeft.y
|
||||
};
|
||||
|
||||
backgroundLogoPoint1 = {
|
||||
x: getDateFromPoint(point1, thisObject.container, timeLineCoordinateSystem).valueOf(),
|
||||
y: getRateFromPoint(point1, thisObject.container, timeLineCoordinateSystem)
|
||||
};
|
||||
|
||||
let point2 = {
|
||||
x: viewPort.visibleArea.topLeft.x + imageWidth * 8,
|
||||
y: viewPort.visibleArea.topLeft.y
|
||||
};
|
||||
|
||||
backgroundLogoPoint2 = {
|
||||
x: getDateFromPoint(point2, thisObject.container, timeLineCoordinateSystem).valueOf(),
|
||||
y: getRateFromPoint(point2, thisObject.container, timeLineCoordinateSystem)
|
||||
};
|
||||
|
||||
let currentCorner = {
|
||||
x: getDateFromPoint(viewPort.visibleArea.topLeft, thisObject.container, timeLineCoordinateSystem).valueOf(),
|
||||
y: getRateFromPoint(viewPort.visibleArea.topLeft, thisObject.container, timeLineCoordinateSystem)
|
||||
};
|
||||
|
||||
currentCorner.x = Math.trunc(currentCorner.x / (backgroundLogoPoint2.x - backgroundLogoPoint1.x)) * (backgroundLogoPoint2.x - backgroundLogoPoint1.x);
|
||||
|
||||
let rowHight = (viewPort.visibleArea.bottomLeft.y - viewPort.visibleArea.topLeft.y) / 4.5;
|
||||
|
||||
imagePoint = timeLineCoordinateSystem.transformThisPoint(currentCorner);
|
||||
imagePoint = transformThisPoint(imagePoint, thisObject.container);
|
||||
|
||||
let offSet = 0;
|
||||
|
||||
|
||||
for (let j = 0; j < MAX_ROWS; j++) {
|
||||
|
||||
if (offSet === -imageWidth * 8) {
|
||||
|
||||
offSet = -imageWidth * 4 - imageWidth;
|
||||
|
||||
} else {
|
||||
offSet = -imageWidth * 8;
|
||||
}
|
||||
|
||||
for (let i = 0; i < MAX_COLUMNS; i = i + 4) {
|
||||
|
||||
let logo = logoA;
|
||||
|
||||
browserCanvasContext.drawImage(logo, imagePoint.x + i * imageWidth * 2 + offSet, imagePoint.y + j * rowHight + Y_TOP_MARGIN, imageWidth, imageHeight);
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
offSet = 0;
|
||||
|
||||
for (let j = 0; j < MAX_ROWS; j++) {
|
||||
|
||||
if (offSet === -imageWidth * 8) {
|
||||
|
||||
offSet = -imageWidth * 4 - imageWidth;
|
||||
|
||||
} else {
|
||||
offSet = -imageWidth * 8;
|
||||
}
|
||||
|
||||
for (let i = 1; i < MAX_COLUMNS; i = i + 4) {
|
||||
|
||||
let logo = logoB;
|
||||
|
||||
browserCanvasContext.drawImage(logo, imagePoint.x + i * imageWidth * 2 + offSet, imagePoint.y + j * rowHight + Y_TOP_MARGIN, imageWidth, imageHeight);
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
offSet = 0;
|
||||
|
||||
for (let j = 0; j < MAX_ROWS; j++) {
|
||||
|
||||
if (offSet === -imageWidth * 8) {
|
||||
|
||||
offSet = -imageWidth * 4 - imageWidth;
|
||||
|
||||
} else {
|
||||
offSet = -imageWidth * 8;
|
||||
}
|
||||
|
||||
for (let i = 2; i < MAX_COLUMNS; i = i + 4) {
|
||||
|
||||
let logo = logoExchange;
|
||||
|
||||
browserCanvasContext.drawImage(logo, imagePoint.x + i * imageWidth * 2 + offSet, imagePoint.y + j * rowHight + Y_TOP_MARGIN, imageWidth, imageHeight);
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
offSet = 0;
|
||||
|
||||
for (let j = 0; j < MAX_ROWS; j++) {
|
||||
|
||||
if (offSet === -imageWidth * 8) {
|
||||
|
||||
offSet = -imageWidth * 4 - imageWidth;
|
||||
|
||||
} else {
|
||||
offSet = -imageWidth * 8;
|
||||
}
|
||||
|
||||
for (let i = 3; i < MAX_COLUMNS; i = i + 4) {
|
||||
|
||||
let logo = logoAA;
|
||||
|
||||
browserCanvasContext.drawImage(logo, imagePoint.x + i * imageWidth * 2 + offSet, imagePoint.y + j * rowHight + Y_TOP_MARGIN, imageWidth, imageHeight);
|
||||
|
||||
}
|
||||
}
|
||||
breakpointsBar.draw()
|
||||
}
|
||||
}
|
||||
|
||||
function drawChartsBackground () {
|
||||
/* We will paint some transparent background here. */
|
||||
|
||||
let opacity = "0.9";
|
||||
let opacity = '0.9'
|
||||
|
||||
let fromPoint = {
|
||||
x: 0,
|
||||
y: 0
|
||||
};
|
||||
let fromPoint = {
|
||||
x: 0,
|
||||
y: 0
|
||||
}
|
||||
|
||||
let toPoint = {
|
||||
x: 0,
|
||||
y: thisObject.container.frame.height
|
||||
};
|
||||
let toPoint = {
|
||||
x: 0,
|
||||
y: thisObject.container.frame.height
|
||||
}
|
||||
|
||||
fromPoint = transformThisPoint(fromPoint, thisObject.container);
|
||||
toPoint = transformThisPoint(toPoint, thisObject.container);
|
||||
fromPoint = transformThisPoint(fromPoint, thisObject.container)
|
||||
toPoint = transformThisPoint(toPoint, thisObject.container)
|
||||
|
||||
browserCanvasContext.beginPath();
|
||||
browserCanvasContext.beginPath()
|
||||
|
||||
browserCanvasContext.rect(viewPort.visibleArea.topLeft.x, fromPoint.y, viewPort.visibleArea.topRight.x - viewPort.visibleArea.topLeft.x, toPoint.y - fromPoint.y);
|
||||
browserCanvasContext.fillStyle = 'rgba(' + UI_COLOR.WHITE + ', ' + opacity + ')';
|
||||
browserCanvasContext.rect(viewPort.visibleArea.topLeft.x, fromPoint.y, viewPort.visibleArea.topRight.x - viewPort.visibleArea.topLeft.x, toPoint.y - fromPoint.y)
|
||||
browserCanvasContext.fillStyle = 'rgba(' + UI_COLOR.WHITE + ', ' + opacity + ')'
|
||||
|
||||
browserCanvasContext.closePath();
|
||||
browserCanvasContext.closePath()
|
||||
|
||||
browserCanvasContext.fill();
|
||||
browserCanvasContext.fill()
|
||||
}
|
||||
|
||||
}
|
||||
function drawChartsBackgroundImages () {
|
||||
if (INTENSIVE_LOG === true) { logger.write('[INFO] drawChartsBackground -> Entering function.') }
|
||||
|
||||
function moveViewPortToCurrentDatetime() {
|
||||
if (canDrawLogoA === false || canDrawLogoB === false || canDrawLogoExchange === false || canDrawLogoAA === false) { return }
|
||||
|
||||
if (INFO_LOG === true) { logger.write("[INFO] moveViewPortToCurrentDatetime -> Entering function."); }
|
||||
let backgroundLogoPoint1
|
||||
let backgroundLogoPoint2
|
||||
|
||||
let targetPoint = {
|
||||
x: datetime.valueOf(),
|
||||
y: 0 // we wont touch the y axis here.
|
||||
};
|
||||
let imageHeight = 42
|
||||
let imageWidth = 150
|
||||
|
||||
let MAX_COLUMNS = 16
|
||||
let MAX_ROWS = 7
|
||||
let Y_TOP_MARGIN = 30
|
||||
|
||||
let point1 = {
|
||||
x: viewPort.visibleArea.topLeft.x,
|
||||
y: viewPort.visibleArea.topLeft.y
|
||||
}
|
||||
|
||||
backgroundLogoPoint1 = {
|
||||
x: getDateFromPoint(point1, thisObject.container, timeLineCoordinateSystem).valueOf(),
|
||||
y: getRateFromPoint(point1, thisObject.container, timeLineCoordinateSystem)
|
||||
}
|
||||
|
||||
let point2 = {
|
||||
x: viewPort.visibleArea.topLeft.x + imageWidth * 8,
|
||||
y: viewPort.visibleArea.topLeft.y
|
||||
}
|
||||
|
||||
backgroundLogoPoint2 = {
|
||||
x: getDateFromPoint(point2, thisObject.container, timeLineCoordinateSystem).valueOf(),
|
||||
y: getRateFromPoint(point2, thisObject.container, timeLineCoordinateSystem)
|
||||
}
|
||||
|
||||
let currentCorner = {
|
||||
x: getDateFromPoint(viewPort.visibleArea.topLeft, thisObject.container, timeLineCoordinateSystem).valueOf(),
|
||||
y: getRateFromPoint(viewPort.visibleArea.topLeft, thisObject.container, timeLineCoordinateSystem)
|
||||
}
|
||||
|
||||
currentCorner.x = Math.trunc(currentCorner.x / (backgroundLogoPoint2.x - backgroundLogoPoint1.x)) * (backgroundLogoPoint2.x - backgroundLogoPoint1.x)
|
||||
|
||||
let rowHight = (viewPort.visibleArea.bottomLeft.y - viewPort.visibleArea.topLeft.y) / 4.5
|
||||
|
||||
imagePoint = timeLineCoordinateSystem.transformThisPoint(currentCorner)
|
||||
imagePoint = transformThisPoint(imagePoint, thisObject.container)
|
||||
|
||||
let offSet = 0
|
||||
|
||||
for (let j = 0; j < MAX_ROWS; j++) {
|
||||
if (offSet === -imageWidth * 8) {
|
||||
offSet = -imageWidth * 4 - imageWidth
|
||||
} else {
|
||||
offSet = -imageWidth * 8
|
||||
}
|
||||
|
||||
for (let i = 0; i < MAX_COLUMNS; i = i + 4) {
|
||||
let logo = logoA
|
||||
|
||||
browserCanvasContext.drawImage(logo, imagePoint.x + i * imageWidth * 2 + offSet, imagePoint.y + j * rowHight + Y_TOP_MARGIN, imageWidth, imageHeight)
|
||||
}
|
||||
}
|
||||
|
||||
offSet = 0
|
||||
|
||||
for (let j = 0; j < MAX_ROWS; j++) {
|
||||
if (offSet === -imageWidth * 8) {
|
||||
offSet = -imageWidth * 4 - imageWidth
|
||||
} else {
|
||||
offSet = -imageWidth * 8
|
||||
}
|
||||
|
||||
for (let i = 1; i < MAX_COLUMNS; i = i + 4) {
|
||||
let logo = logoB
|
||||
|
||||
browserCanvasContext.drawImage(logo, imagePoint.x + i * imageWidth * 2 + offSet, imagePoint.y + j * rowHight + Y_TOP_MARGIN, imageWidth, imageHeight)
|
||||
}
|
||||
}
|
||||
|
||||
offSet = 0
|
||||
|
||||
for (let j = 0; j < MAX_ROWS; j++) {
|
||||
if (offSet === -imageWidth * 8) {
|
||||
offSet = -imageWidth * 4 - imageWidth
|
||||
} else {
|
||||
offSet = -imageWidth * 8
|
||||
}
|
||||
|
||||
for (let i = 2; i < MAX_COLUMNS; i = i + 4) {
|
||||
let logo = logoExchange
|
||||
|
||||
browserCanvasContext.drawImage(logo, imagePoint.x + i * imageWidth * 2 + offSet, imagePoint.y + j * rowHight + Y_TOP_MARGIN, imageWidth, imageHeight)
|
||||
}
|
||||
}
|
||||
|
||||
offSet = 0
|
||||
|
||||
for (let j = 0; j < MAX_ROWS; j++) {
|
||||
if (offSet === -imageWidth * 8) {
|
||||
offSet = -imageWidth * 4 - imageWidth
|
||||
} else {
|
||||
offSet = -imageWidth * 8
|
||||
}
|
||||
|
||||
for (let i = 3; i < MAX_COLUMNS; i = i + 4) {
|
||||
let logo = logoAA
|
||||
|
||||
browserCanvasContext.drawImage(logo, imagePoint.x + i * imageWidth * 2 + offSet, imagePoint.y + j * rowHight + Y_TOP_MARGIN, imageWidth, imageHeight)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function moveViewPortToCurrentDatetime () {
|
||||
if (INFO_LOG === true) { logger.write('[INFO] moveViewPortToCurrentDatetime -> Entering function.') }
|
||||
|
||||
let targetPoint = {
|
||||
x: datetime.valueOf(),
|
||||
y: 0 // we wont touch the y axis here.
|
||||
}
|
||||
|
||||
/* Lets put this point in the coordinate system of the viewPort */
|
||||
|
||||
targetPoint = timeLineCoordinateSystem.transformThisPoint(targetPoint);
|
||||
targetPoint = transformThisPoint(targetPoint, thisObject.container);
|
||||
targetPoint = timeLineCoordinateSystem.transformThisPoint(targetPoint)
|
||||
targetPoint = transformThisPoint(targetPoint, thisObject.container)
|
||||
|
||||
/* Lets get the point on the viewPort coordinate system of the center of the visible screen */
|
||||
|
||||
let center = {
|
||||
x: (viewPort.visibleArea.bottomRight.x - viewPort.visibleArea.bottomLeft.x) / 2,
|
||||
y: (viewPort.visibleArea.bottomRight.y - viewPort.visibleArea.topRight.y) / 2
|
||||
};
|
||||
let center = {
|
||||
x: (viewPort.visibleArea.bottomRight.x - viewPort.visibleArea.bottomLeft.x) / 2,
|
||||
y: (viewPort.visibleArea.bottomRight.y - viewPort.visibleArea.topRight.y) / 2
|
||||
}
|
||||
|
||||
/* Lets calculate the displace vector, from the point we want at the center, to the current center. */
|
||||
|
||||
let displaceVector = {
|
||||
x: center.x - targetPoint.x,
|
||||
y: 0
|
||||
};
|
||||
|
||||
viewPort.displace(displaceVector);
|
||||
}
|
||||
}
|
||||
let displaceVector = {
|
||||
x: center.x - targetPoint.x,
|
||||
y: 0
|
||||
}
|
||||
|
||||
viewPort.displace(displaceVector)
|
||||
}
|
||||
}
|
||||
@@ -1,84 +0,0 @@
|
||||
|
||||
function newCompanyLogo() {
|
||||
|
||||
var thisObject = {
|
||||
container: undefined,
|
||||
draw: draw,
|
||||
getContainer: getContainer, // returns the inner most container that holds the point received by parameter.
|
||||
initialize: initialize
|
||||
};
|
||||
|
||||
var container = newContainer();
|
||||
container.initialize();
|
||||
thisObject.container = container;
|
||||
|
||||
thisObject.container.frame.width = 150;
|
||||
thisObject.container.frame.height = TOP_SPACE_HEIGHT;
|
||||
|
||||
container.frame.position.x = 0;
|
||||
container.frame.position.y = 0;
|
||||
|
||||
container.isDraggeable = false;
|
||||
|
||||
let logo;
|
||||
let canDrawLogo = false;
|
||||
|
||||
return thisObject;
|
||||
|
||||
function initialize() {
|
||||
|
||||
if (window.canvasApp.executingAt === 'Master App') {
|
||||
currentLabel = "";
|
||||
return;
|
||||
}
|
||||
|
||||
logo = new Image();
|
||||
|
||||
logo.onload = onImageLoad;
|
||||
|
||||
function onImageLoad() {
|
||||
canDrawLogo = true;
|
||||
}
|
||||
|
||||
logo.src = window.canvasApp.urlPrefix + "Images/aa-logo-dark-8.png";
|
||||
|
||||
}
|
||||
|
||||
function getContainer(point) {
|
||||
|
||||
let container;
|
||||
|
||||
/* First we check if this point is inside this object UI. */
|
||||
|
||||
if (thisObject.container.frame.isThisPointHere(point, true) === true) {
|
||||
|
||||
return this.container;
|
||||
|
||||
} else {
|
||||
|
||||
/* This point does not belong to this space. */
|
||||
|
||||
return undefined;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
function draw() {
|
||||
|
||||
thisObject.container.frame.draw(false, false);
|
||||
|
||||
if (canDrawLogo === false) { return;}
|
||||
|
||||
let imageHeight = 24;
|
||||
let imageWidth = 120;
|
||||
|
||||
let imagePoint = {
|
||||
x: 10,
|
||||
y: thisObject.container.frame.height / 2 - imageHeight / 2
|
||||
};
|
||||
|
||||
imagePoint = thisObject.container.frame.frameThisPoint(imagePoint);
|
||||
|
||||
browserCanvasContext.drawImage(logo, imagePoint.x, imagePoint.y, imageWidth, imageHeight);
|
||||
}
|
||||
}
|
||||
@@ -1,156 +0,0 @@
|
||||
|
||||
function newCurrentBot() {
|
||||
|
||||
let thisObject = {
|
||||
container: undefined,
|
||||
draw: draw,
|
||||
getContainer: getContainer,
|
||||
initialize: initialize
|
||||
};
|
||||
|
||||
let container = newContainer();
|
||||
container.initialize();
|
||||
thisObject.container = container;
|
||||
|
||||
thisObject.container.frame.width = 150;
|
||||
thisObject.container.frame.height = BOTTOM_SPACE_HEIGHT;
|
||||
|
||||
resize();
|
||||
|
||||
container.isDraggeable = false;
|
||||
container.isClickeable = true;
|
||||
|
||||
const NOT_FOUND = "";
|
||||
|
||||
let sharedStatus;
|
||||
|
||||
return thisObject;
|
||||
|
||||
function initialize(pSharedStatus) {
|
||||
|
||||
sharedStatus = pSharedStatus;
|
||||
|
||||
if (window.USER_PROFILE.devTeams.length === 0) {
|
||||
window.CURRENT_BOT_DISPLAY_NAME = NOT_FOUND;
|
||||
} else {
|
||||
|
||||
if (window.USER_PROFILE.devTeams[sharedStatus.currentDevTeamIndex].userBots.length === 0) {
|
||||
window.CURRENT_BOT_DISPLAY_NAME = NOT_FOUND;
|
||||
window.CURRENT_BOT_REPO = "NO REPO";
|
||||
window.CURRENT_BOT_CODE_NAME = "";
|
||||
} else {
|
||||
window.CURRENT_BOT_DISPLAY_NAME = window.USER_PROFILE.devTeams[sharedStatus.currentDevTeamIndex].userBots[sharedStatus.currentUserBotIndex].displayName;
|
||||
window.CURRENT_BOT_REPO = window.USER_PROFILE.devTeams[sharedStatus.currentDevTeamIndex].userBots[sharedStatus.currentUserBotIndex].repo;
|
||||
window.CURRENT_BOT_CODE_NAME = window.USER_PROFILE.devTeams[sharedStatus.currentDevTeamIndex].userBots[sharedStatus.currentUserBotIndex].codeName;
|
||||
}
|
||||
}
|
||||
|
||||
thisObject.container.eventHandler.listenToEvent("onMouseClick", onClick);
|
||||
sharedStatus.eventHandler.listenToEvent("devTeam Changed", onDevTeamChanged);
|
||||
|
||||
window.canvasApp.eventHandler.listenToEvent("Browser Resized", resize);
|
||||
}
|
||||
|
||||
function resize() {
|
||||
|
||||
container.frame.position.x = viewPort.visibleArea.topLeft.x + thisObject.container.frame.width * 1;
|
||||
container.frame.position.y = viewPort.visibleArea.bottomLeft.y;
|
||||
|
||||
}
|
||||
|
||||
function onDevTeamChanged() {
|
||||
|
||||
if (window.USER_PROFILE.devTeams[sharedStatus.currentDevTeamIndex].userBots.length > 0) {
|
||||
|
||||
sharedStatus.currentUserBotIndex = 0;
|
||||
window.CURRENT_BOT_DISPLAY_NAME = window.USER_PROFILE.devTeams[sharedStatus.currentDevTeamIndex].userBots[sharedStatus.currentUserBotIndex].displayName;
|
||||
window.CURRENT_BOT_REPO = window.USER_PROFILE.devTeams[sharedStatus.currentDevTeamIndex].userBots[sharedStatus.currentUserBotIndex].repo;
|
||||
window.CURRENT_BOT_CODE_NAME = window.USER_PROFILE.devTeams[sharedStatus.currentDevTeamIndex].userBots[sharedStatus.currentUserBotIndex].codeName;
|
||||
|
||||
sharedStatus.eventHandler.raiseEvent("userBot Changed");
|
||||
|
||||
} else {
|
||||
|
||||
window.CURRENT_BOT_DISPLAY_NAME = NOT_FOUND;
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
function onClick() {
|
||||
|
||||
let sessionToken = window.localStorage.getItem('sessionToken');
|
||||
|
||||
if (sessionToken === null || sessionToken === "") {
|
||||
/* not logged in */
|
||||
return;
|
||||
}
|
||||
|
||||
if (sharedStatus.currentUserBotIndex + 1 === window.USER_PROFILE.devTeams[sharedStatus.currentDevTeamIndex].userBots.length) {
|
||||
|
||||
sharedStatus.currentUserBotIndex = 0;
|
||||
window.CURRENT_BOT_DISPLAY_NAME = window.USER_PROFILE.devTeams[sharedStatus.currentDevTeamIndex].userBots[sharedStatus.currentUserBotIndex].displayName;
|
||||
window.CURRENT_BOT_REPO = window.USER_PROFILE.devTeams[sharedStatus.currentDevTeamIndex].userBots[sharedStatus.currentUserBotIndex].repo;
|
||||
window.CURRENT_BOT_CODE_NAME = window.USER_PROFILE.devTeams[sharedStatus.currentDevTeamIndex].userBots[sharedStatus.currentUserBotIndex].codeName;
|
||||
|
||||
sharedStatus.eventHandler.raiseEvent("userBot Changed");
|
||||
return;
|
||||
}
|
||||
|
||||
if (sharedStatus.currentUserBotIndex + 1 < window.USER_PROFILE.devTeams[sharedStatus.currentDevTeamIndex].userBots.length) {
|
||||
|
||||
sharedStatus.currentUserBotIndex++;
|
||||
window.CURRENT_BOT_DISPLAY_NAME = window.USER_PROFILE.devTeams[sharedStatus.currentDevTeamIndex].userBots[sharedStatus.currentUserBotIndex].displayName;
|
||||
window.CURRENT_BOT_REPO = window.USER_PROFILE.devTeams[sharedStatus.currentDevTeamIndex].userBots[sharedStatus.currentUserBotIndex].repo;
|
||||
window.CURRENT_BOT_CODE_NAME = window.USER_PROFILE.devTeams[sharedStatus.currentDevTeamIndex].userBots[sharedStatus.currentUserBotIndex].codeName;
|
||||
|
||||
sharedStatus.eventHandler.raiseEvent("userBot Changed");
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
function getContainer(point) {
|
||||
|
||||
let container;
|
||||
|
||||
/* First we check if this point is inside this object UI. */
|
||||
|
||||
if (thisObject.container.frame.isThisPointHere(point, true) === true) {
|
||||
|
||||
return this.container;
|
||||
|
||||
} else {
|
||||
|
||||
/* This point does not belong to this space. */
|
||||
|
||||
return undefined;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
function draw() {
|
||||
|
||||
let sessionToken = window.localStorage.getItem('sessionToken');
|
||||
|
||||
if (sessionToken === null || sessionToken === "") {
|
||||
/* not logged in */
|
||||
return;
|
||||
}
|
||||
|
||||
thisObject.container.frame.draw(false, false);
|
||||
|
||||
let breakpointsHeight = 14;
|
||||
let fontSize = 12;
|
||||
let label = window.CURRENT_BOT_DISPLAY_NAME;
|
||||
if (label === undefined) { label = "" };
|
||||
|
||||
let point = {
|
||||
x: thisObject.container.frame.width / 2 - label.length / 2 * fontSize / 3,
|
||||
y: thisObject.container.frame.height / 2 + fontSize / 2 + breakpointsHeight
|
||||
};
|
||||
point = thisObject.container.frame.frameThisPoint(point);
|
||||
|
||||
browserCanvasContext.font = fontSize + 'px ' + UI_FONT.PRIMARY;
|
||||
browserCanvasContext.fillStyle = 'rgba(' + UI_COLOR.WHITE + ', 1)';
|
||||
browserCanvasContext.fillText(label, point.x, point.y);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,195 @@
|
||||
function newCurrentEvent () {
|
||||
let thisObject = {
|
||||
container: undefined,
|
||||
draw: draw,
|
||||
getContainer: getContainer,
|
||||
initialize: initialize
|
||||
}
|
||||
|
||||
function buildEcosystemEventsHack (reload) {
|
||||
let hackedEcosystem = [{
|
||||
'codeName': 'AAArena',
|
||||
'displayName': 'AA Arena',
|
||||
'competitions': [{
|
||||
'codeName': 'Weekend-Deathmatch',
|
||||
'description': 'First AA Internal Competition. Bots will be trading during 3 days at the USDT/BTC market of Poloniex to see who can make the gratest return over investment (ROI).',
|
||||
'displayName': 'AA Internal Challenge',
|
||||
'startDatetime': '2019-03-05T16:00:00.000Z',
|
||||
'finishDatetime': '2019-02-07T16:59:59.999Z',
|
||||
'formula': 'ROI',
|
||||
'plotter': {
|
||||
'codeName': 'PlottersROI',
|
||||
'host': 'AAArena',
|
||||
'repo': 'Plotters-ROI',
|
||||
'moduleName': 'CombinedProfits'
|
||||
},
|
||||
'participants': [
|
||||
],
|
||||
'repo': 'Weekend-Deathmatch',
|
||||
'configFile': 'this.competition.config.json'
|
||||
}],
|
||||
'plotters': [{
|
||||
'displayName': 'Plotters ROI',
|
||||
'codeName': 'PlottersROI',
|
||||
'devTeam': 'AAMasters',
|
||||
'modules': [{
|
||||
'codeName': 'CombinedProfits',
|
||||
'moduleName': 'CombinedProfits',
|
||||
'description': 'Plots participants of a competition by the ROI each one had over time.',
|
||||
'panels': []
|
||||
}],
|
||||
'repo': 'Plotters-ROI',
|
||||
'configFile': 'this.plotter.config.json'
|
||||
}]
|
||||
}]
|
||||
|
||||
let ecosysTemp = window.localStorage.getItem('currentEventObject')
|
||||
if (!(ecosysTemp === null || ecosysTemp === '[]' || ecosysTemp === '')) {
|
||||
let parsedEcosysTemp = JSON.parse(ecosysTemp)
|
||||
hackedEcosystem[0].competitions[0].startDatetime = new Date(parsedEcosysTemp.startDatetime * 1000).toISOString()
|
||||
hackedEcosystem[0].competitions[0].finishDatetime = new Date(parsedEcosysTemp.endDatetime * 1000).toISOString()
|
||||
parsedEcosysTemp.participants.forEach(function (participant) {
|
||||
hackedEcosystem[0].competitions[0].participants.push({
|
||||
devTeam: participant.clone.team.slug,
|
||||
bot: participant.clone.bot.slug,
|
||||
cloneId: participant.clone.id,
|
||||
release: '1.0.0'
|
||||
})
|
||||
})
|
||||
}
|
||||
|
||||
window.localStorage.setItem('ecosystemEventsHack', JSON.stringify(hackedEcosystem))
|
||||
ecosystem.setEvent(hackedEcosystem)
|
||||
if (reload) {
|
||||
dashboard.start()
|
||||
}
|
||||
}
|
||||
|
||||
let container = newContainer()
|
||||
container.initialize()
|
||||
thisObject.container = container
|
||||
|
||||
thisObject.container.frame.width = 150
|
||||
thisObject.container.frame.height = BOTTOM_SPACE_HEIGHT
|
||||
|
||||
resize()
|
||||
|
||||
container.isDraggeable = false
|
||||
container.isClickeable = true
|
||||
|
||||
const NOT_FOUND = 'Event NOT FOUND'
|
||||
|
||||
let sharedStatus
|
||||
let storedEvents
|
||||
let label = 'Event -'
|
||||
|
||||
return thisObject
|
||||
|
||||
function initialize (pSharedStatus) {
|
||||
let sessionToken = window.localStorage.getItem('sessionToken')
|
||||
|
||||
if (sessionToken === null || sessionToken === '') {
|
||||
/* not logged in */
|
||||
return
|
||||
}
|
||||
|
||||
sharedStatus = pSharedStatus
|
||||
|
||||
storedEvents = window.localStorage.getItem('currentEvents')
|
||||
if (storedEvents === null || storedEvents === '[]' || storedEvents === '') {
|
||||
window.EVENTS = ''
|
||||
window.CURRENT_EVENT_TITLE = ''
|
||||
label = NOT_FOUND
|
||||
} else if (sharedStatus.currentEventIndex === -1) {
|
||||
storedEvents = JSON.parse(storedEvents)
|
||||
window.EVENTS = storedEvents
|
||||
window.CURRENT_EVENT_TITLE = ''
|
||||
label = 'Select an event'
|
||||
} else {
|
||||
storedEvents = JSON.parse(storedEvents)
|
||||
window.EVENTS = storedEvents
|
||||
window.CURRENT_EVENT_TITLE = storedEvents[sharedStatus.currentEventIndex].title
|
||||
label = 'Event - ' + storedEvents[sharedStatus.currentEventIndex].title
|
||||
window.localStorage.setItem('currentEventObject', JSON.stringify(storedEvents[sharedStatus.currentEventIndex]))
|
||||
buildEcosystemEventsHack(false)
|
||||
sharedStatus.eventHandler.raiseEvent('Event Changed')
|
||||
}
|
||||
|
||||
thisObject.container.eventHandler.listenToEvent('onMouseClick', onClick)
|
||||
|
||||
window.canvasApp.eventHandler.listenToEvent('Browser Resized', resize)
|
||||
}
|
||||
|
||||
function resize () {
|
||||
container.frame.position.x = viewPort.visibleArea.topLeft.x + thisObject.container.frame.width * 2
|
||||
container.frame.position.y = viewPort.visibleArea.bottomLeft.y + BREAKPOINT_HEIGHT
|
||||
}
|
||||
|
||||
function onClick () {
|
||||
let sessionToken = window.localStorage.getItem('sessionToken')
|
||||
|
||||
if (sessionToken === null || sessionToken === '') {
|
||||
/* not logged in */
|
||||
return
|
||||
}
|
||||
|
||||
if (sharedStatus.currentEventIndex + 1 === window.EVENTS.length) {
|
||||
sharedStatus.currentEventIndex = 0
|
||||
window.CURRENT_EVENT_TITLE = storedEvents[sharedStatus.currentEventIndex].title
|
||||
label = 'Event - ' + storedEvents[sharedStatus.currentEventIndex].title
|
||||
window.localStorage.setItem('currentEventObject', JSON.stringify(storedEvents[sharedStatus.currentEventIndex]))
|
||||
buildEcosystemEventsHack(true)
|
||||
sharedStatus.eventHandler.raiseEvent('Event Changed')
|
||||
return
|
||||
}
|
||||
|
||||
if (sharedStatus.currentEventIndex + 1 < window.EVENTS.length) {
|
||||
sharedStatus.currentEventIndex++
|
||||
window.CURRENT_EVENT_TITLE = storedEvents[sharedStatus.currentEventIndex].title
|
||||
label = 'Event - ' + storedEvents[sharedStatus.currentEventIndex].title
|
||||
window.localStorage.setItem('currentEventObject', JSON.stringify(storedEvents[sharedStatus.currentEventIndex]))
|
||||
buildEcosystemEventsHack(true)
|
||||
sharedStatus.eventHandler.raiseEvent('Event Changed')
|
||||
return
|
||||
}
|
||||
}
|
||||
|
||||
function getContainer (point) {
|
||||
let container
|
||||
|
||||
/* First we check if this point is inside this object UI. */
|
||||
|
||||
if (thisObject.container.frame.isThisPointHere(point, true) === true) {
|
||||
return this.container
|
||||
} else {
|
||||
/* This point does not belong to this space. */
|
||||
|
||||
return undefined
|
||||
}
|
||||
}
|
||||
|
||||
function draw () {
|
||||
let sessionToken = window.localStorage.getItem('sessionToken')
|
||||
|
||||
if (sessionToken === null || sessionToken === '') {
|
||||
/* not logged in */
|
||||
return
|
||||
}
|
||||
|
||||
thisObject.container.frame.draw(false, false)
|
||||
|
||||
let breakpointsHeight = 0
|
||||
let fontSize = 12
|
||||
|
||||
let point = {
|
||||
x: thisObject.container.frame.width / 2 - label.length / 2 * fontSize / 3,
|
||||
y: thisObject.container.frame.height / 2 + fontSize / 2 + breakpointsHeight
|
||||
}
|
||||
|
||||
point = thisObject.container.frame.frameThisPoint(point)
|
||||
|
||||
browserCanvasContext.font = fontSize + 'px ' + UI_FONT.PRIMARY
|
||||
browserCanvasContext.fillStyle = 'rgba(' + UI_COLOR.WHITE + ', 1)'
|
||||
browserCanvasContext.fillText(label, point.x, point.y)
|
||||
}
|
||||
}
|
||||
@@ -1,150 +0,0 @@
|
||||
|
||||
function newCurrentProcess() {
|
||||
|
||||
let thisObject = {
|
||||
container: undefined,
|
||||
draw: draw,
|
||||
getContainer: getContainer,
|
||||
initialize: initialize
|
||||
};
|
||||
|
||||
let container = newContainer();
|
||||
container.initialize();
|
||||
thisObject.container = container;
|
||||
|
||||
thisObject.container.frame.width = 150;
|
||||
thisObject.container.frame.height = BOTTOM_SPACE_HEIGHT;
|
||||
|
||||
resize()
|
||||
|
||||
container.isDraggeable = false;
|
||||
container.isClickeable = true;
|
||||
|
||||
const NOT_FOUND = "";
|
||||
|
||||
let sharedStatus;
|
||||
|
||||
return thisObject;
|
||||
|
||||
function initialize(pSharedStatus) {
|
||||
|
||||
sharedStatus = pSharedStatus;
|
||||
|
||||
if (window.USER_PROFILE.devTeams.length === 0) {
|
||||
window.CURRENT_PROCESS = NOT_FOUND;
|
||||
} else {
|
||||
|
||||
if (window.USER_PROFILE.devTeams[sharedStatus.currentDevTeamIndex].userBots.length === 0) {
|
||||
window.CURRENT_PROCESS = NOT_FOUND;
|
||||
} else {
|
||||
|
||||
if (window.USER_PROFILE.devTeams[sharedStatus.currentDevTeamIndex].userBots[sharedStatus.currentUserBotIndex].processes.length === 0) {
|
||||
window.CURRENT_PROCESS = NOT_FOUND;
|
||||
} else {
|
||||
|
||||
window.CURRENT_PROCESS = window.USER_PROFILE.devTeams[sharedStatus.currentDevTeamIndex].userBots[sharedStatus.currentUserBotIndex].processes[sharedStatus.currentProcessIndex].name;
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
thisObject.container.eventHandler.listenToEvent("onMouseClick", onClick);
|
||||
sharedStatus.eventHandler.listenToEvent("userBot Changed", onUserBotChanged);
|
||||
|
||||
window.canvasApp.eventHandler.listenToEvent("Browser Resized", resize);
|
||||
}
|
||||
|
||||
function resize() {
|
||||
|
||||
container.frame.position.x = viewPort.visibleArea.topLeft.x + thisObject.container.frame.width * 2;
|
||||
container.frame.position.y = viewPort.visibleArea.bottomLeft.y;
|
||||
|
||||
}
|
||||
|
||||
function onUserBotChanged() {
|
||||
|
||||
if ( window.USER_PROFILE.devTeams[sharedStatus.currentDevTeamIndex].userBots.length > 0) {
|
||||
|
||||
if (window.USER_PROFILE.devTeams[sharedStatus.currentDevTeamIndex].userBots[sharedStatus.currentUserBotIndex].processes.length > 0) {
|
||||
|
||||
sharedStatus.currentProcessIndex = 0;
|
||||
window.CURRENT_PROCESS = window.USER_PROFILE.devTeams[sharedStatus.currentDevTeamIndex].userBots[sharedStatus.currentUserBotIndex].processes[sharedStatus.currentProcessIndex].name;
|
||||
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
window.CURRENT_PROCESS = NOT_FOUND;
|
||||
}
|
||||
|
||||
function onClick() {
|
||||
|
||||
let sessionToken = window.localStorage.getItem('sessionToken');
|
||||
|
||||
if (sessionToken === null || sessionToken === "") {
|
||||
/* not logged in */
|
||||
return;
|
||||
}
|
||||
|
||||
if (sharedStatus.currentProcessIndex + 1 === window.USER_PROFILE.devTeams[sharedStatus.currentDevTeamIndex].userBots[sharedStatus.currentUserBotIndex].processes.length) {
|
||||
|
||||
sharedStatus.currentProcessIndex = 0;
|
||||
window.CURRENT_PROCESS = window.USER_PROFILE.devTeams[sharedStatus.currentDevTeamIndex].userBots[sharedStatus.currentUserBotIndex].processes[sharedStatus.currentProcessIndex].name;
|
||||
return;
|
||||
}
|
||||
|
||||
if (sharedStatus.currentProcessIndex + 1 < window.USER_PROFILE.devTeams[sharedStatus.currentDevTeamIndex].userBots[sharedStatus.currentUserBotIndex].processes.length) {
|
||||
|
||||
sharedStatus.currentProcessIndex++;
|
||||
window.CURRENT_PROCESS = window.USER_PROFILE.devTeams[sharedStatus.currentDevTeamIndex].userBots[sharedStatus.currentUserBotIndex].processes[sharedStatus.currentProcessIndex].name;
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
function getContainer(point) {
|
||||
|
||||
let container;
|
||||
|
||||
/* First we check if this point is inside this object UI. */
|
||||
|
||||
if (thisObject.container.frame.isThisPointHere(point, true) === true) {
|
||||
|
||||
return this.container;
|
||||
|
||||
} else {
|
||||
|
||||
/* This point does not belong to this space. */
|
||||
|
||||
return undefined;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
function draw() {
|
||||
|
||||
let sessionToken = window.localStorage.getItem('sessionToken');
|
||||
|
||||
if (sessionToken === null || sessionToken === "") {
|
||||
/* not logged in */
|
||||
return;
|
||||
}
|
||||
|
||||
thisObject.container.frame.draw(false, false);
|
||||
|
||||
let breakpointsHeight = 14;
|
||||
let fontSize = 12;
|
||||
let label = window.CURRENT_PROCESS;
|
||||
if (label === undefined) { label = "" };
|
||||
|
||||
let point = {
|
||||
x: thisObject.container.frame.width / 2 - label.length / 2 * fontSize / 3,
|
||||
y: thisObject.container.frame.height / 2 + fontSize / 2 + breakpointsHeight
|
||||
};
|
||||
|
||||
point = thisObject.container.frame.frameThisPoint(point);
|
||||
|
||||
browserCanvasContext.font = fontSize + 'px ' + UI_FONT.PRIMARY;
|
||||
browserCanvasContext.fillStyle = 'rgba(' + UI_COLOR.WHITE + ', 1)';
|
||||
browserCanvasContext.fillText(label, point.x, point.y);
|
||||
}
|
||||
}
|
||||
@@ -1,122 +0,0 @@
|
||||
|
||||
function newCurrentStartMode() {
|
||||
|
||||
var thisObject = {
|
||||
container: undefined,
|
||||
draw: draw,
|
||||
getContainer: getContainer, // returns the inner most container that holds the point received by parameter.
|
||||
initialize: initialize
|
||||
};
|
||||
|
||||
var container = newContainer();
|
||||
container.initialize();
|
||||
thisObject.container = container;
|
||||
|
||||
thisObject.container.frame.width = 150;
|
||||
thisObject.container.frame.height = BOTTOM_SPACE_HEIGHT;
|
||||
|
||||
resize();
|
||||
|
||||
container.isDraggeable = false;
|
||||
container.isClickeable = true;
|
||||
|
||||
return thisObject;
|
||||
|
||||
function initialize() {
|
||||
|
||||
window.CURRENT_START_MODE = window.localStorage.getItem("currentStartMode");
|
||||
|
||||
if (window.CURRENT_START_MODE === null) {
|
||||
window.CURRENT_START_MODE = "Backtest";
|
||||
}
|
||||
|
||||
thisObject.container.eventHandler.listenToEvent("onMouseClick", onClick);
|
||||
|
||||
window.canvasApp.eventHandler.listenToEvent("Browser Resized", resize);
|
||||
}
|
||||
|
||||
function resize() {
|
||||
|
||||
container.frame.position.x = viewPort.visibleArea.topLeft.x + thisObject.container.frame.width * 3;
|
||||
container.frame.position.y = viewPort.visibleArea.bottomLeft.y;
|
||||
|
||||
}
|
||||
|
||||
function onClick() {
|
||||
|
||||
let sessionToken = window.localStorage.getItem('sessionToken');
|
||||
|
||||
if (sessionToken === null || sessionToken === "") {
|
||||
/* not logged in */
|
||||
return;
|
||||
}
|
||||
|
||||
if (window.CURRENT_BOT_DISPLAY_NAME === "") { return; }
|
||||
|
||||
switch (window.CURRENT_START_MODE) {
|
||||
|
||||
case "Backtest": {
|
||||
window.CURRENT_START_MODE = "Live";
|
||||
break;
|
||||
}
|
||||
case "Live": {
|
||||
window.CURRENT_START_MODE = "Competition";
|
||||
break;
|
||||
}
|
||||
case "Competition": {
|
||||
window.CURRENT_START_MODE = "Backtest";
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
function getContainer(point) {
|
||||
|
||||
let container;
|
||||
|
||||
/* First we check if this point is inside this object UI. */
|
||||
|
||||
if (thisObject.container.frame.isThisPointHere(point, true) === true) {
|
||||
|
||||
return this.container;
|
||||
|
||||
} else {
|
||||
|
||||
/* This point does not belong to this space. */
|
||||
|
||||
return undefined;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
function draw() {
|
||||
|
||||
let sessionToken = window.localStorage.getItem('sessionToken');
|
||||
|
||||
if (sessionToken === null || sessionToken === "") {
|
||||
/* not logged in */
|
||||
return;
|
||||
}
|
||||
|
||||
if (window.CURRENT_BOT_DISPLAY_NAME === "") { return;}
|
||||
|
||||
thisObject.container.frame.draw(false, false);
|
||||
|
||||
let breakpointsHeight = 14;
|
||||
let fontSize = 12;
|
||||
let label = window.CURRENT_START_MODE + " Mode";
|
||||
if (label === "undefined Mode") { label = "" };
|
||||
|
||||
let point = {
|
||||
x: thisObject.container.frame.width / 2 - label.length / 2 * fontSize / 3,
|
||||
y: thisObject.container.frame.height / 2 + fontSize / 2 + breakpointsHeight
|
||||
};
|
||||
|
||||
point = thisObject.container.frame.frameThisPoint(point);
|
||||
|
||||
browserCanvasContext.font = fontSize + 'px ' + UI_FONT.PRIMARY;
|
||||
browserCanvasContext.fillStyle = 'rgba(' + UI_COLOR.WHITE + ', 1)';
|
||||
browserCanvasContext.fillText(label, point.x, point.y);
|
||||
}
|
||||
}
|
||||
@@ -1,140 +0,0 @@
|
||||
|
||||
function newDevTeam() {
|
||||
|
||||
let thisObject = {
|
||||
container: undefined,
|
||||
draw: draw,
|
||||
getContainer: getContainer,
|
||||
initialize: initialize
|
||||
};
|
||||
|
||||
let container = newContainer();
|
||||
container.initialize();
|
||||
thisObject.container = container;
|
||||
|
||||
thisObject.container.frame.width = 150;
|
||||
thisObject.container.frame.height = BOTTOM_SPACE_HEIGHT;
|
||||
|
||||
resize();
|
||||
|
||||
container.isDraggeable = false;
|
||||
container.isClickeable = true;
|
||||
|
||||
const NOT_FOUND = "Team NOT FOUND";
|
||||
|
||||
let sharedStatus;
|
||||
let label = ""
|
||||
|
||||
return thisObject;
|
||||
|
||||
function initialize(pSharedStatus) {
|
||||
|
||||
let sessionToken = window.localStorage.getItem('sessionToken');
|
||||
|
||||
if (sessionToken === null || sessionToken === "") {
|
||||
/* not logged in */
|
||||
return;
|
||||
}
|
||||
|
||||
sharedStatus = pSharedStatus;
|
||||
|
||||
let storedTeams = window.localStorage.getItem('userTeams');
|
||||
|
||||
if (storedTeams === null || storedTeams === "[]" || storedTeams === "") {
|
||||
window.TEAMS = "";
|
||||
window.DEV_TEAM = "";
|
||||
label = NOT_FOUND;
|
||||
} else {
|
||||
storedTeams = JSON.parse(storedTeams)
|
||||
window.TEAMS = storedTeams;
|
||||
window.DEV_TEAM = storedTeams[sharedStatus.currentDevTeamIndex].slug;
|
||||
label = storedTeams[sharedStatus.currentDevTeamIndex].name;
|
||||
sharedStatus.eventHandler.raiseEvent("devTeam Changed");
|
||||
}
|
||||
|
||||
thisObject.container.eventHandler.listenToEvent("onMouseClick", onClick);
|
||||
|
||||
window.canvasApp.eventHandler.listenToEvent("Browser Resized", resize);
|
||||
}
|
||||
|
||||
function resize() {
|
||||
|
||||
container.frame.position.x = viewPort.visibleArea.topLeft.x + thisObject.container.frame.width * 0;
|
||||
container.frame.position.y = viewPort.visibleArea.bottomLeft.y;
|
||||
|
||||
}
|
||||
|
||||
function onClick() {
|
||||
|
||||
let sessionToken = window.localStorage.getItem('sessionToken');
|
||||
|
||||
if (sessionToken === null || sessionToken === "") {
|
||||
/* not logged in */
|
||||
return;
|
||||
}
|
||||
|
||||
if (sharedStatus.currentDevTeamIndex + 1 === window.TEAMS.length) {
|
||||
|
||||
sharedStatus.currentDevTeamIndex = 0;
|
||||
window.DEV_TEAM = window.TEAMS[sharedStatus.currentDevTeamIndex].slug;
|
||||
label = window.TEAMS[sharedStatus.currentDevTeamIndex].name;
|
||||
sharedStatus.eventHandler.raiseEvent("devTeam Changed");
|
||||
return;
|
||||
}
|
||||
|
||||
if (sharedStatus.currentDevTeamIndex + 1 < window.TEAMS.length) {
|
||||
|
||||
sharedStatus.currentDevTeamIndex++;
|
||||
window.DEV_TEAM = window.TEAMS[sharedStatus.currentDevTeamIndex].slug;
|
||||
label = window.TEAMS[sharedStatus.currentDevTeamIndex].name;
|
||||
sharedStatus.eventHandler.raiseEvent("devTeam Changed");
|
||||
return;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
function getContainer(point) {
|
||||
|
||||
let container;
|
||||
|
||||
/* First we check if this point is inside this object UI. */
|
||||
|
||||
if (thisObject.container.frame.isThisPointHere(point, true) === true) {
|
||||
|
||||
return this.container;
|
||||
|
||||
} else {
|
||||
|
||||
/* This point does not belong to this space. */
|
||||
|
||||
return undefined;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
function draw() {
|
||||
|
||||
let sessionToken = window.localStorage.getItem('sessionToken');
|
||||
|
||||
if (sessionToken === null || sessionToken === "") {
|
||||
/* not logged in */
|
||||
return;
|
||||
}
|
||||
|
||||
thisObject.container.frame.draw(false, false);
|
||||
|
||||
let breakpointsHeight = 14;
|
||||
let fontSize = 12;
|
||||
|
||||
let point = {
|
||||
x: thisObject.container.frame.width / 2 - label.length / 2 * fontSize / 3,
|
||||
y: thisObject.container.frame.height / 2 + fontSize / 2 + breakpointsHeight
|
||||
};
|
||||
|
||||
point = thisObject.container.frame.frameThisPoint(point);
|
||||
|
||||
browserCanvasContext.font = fontSize + 'px ' + UI_FONT.PRIMARY;
|
||||
browserCanvasContext.fillStyle = 'rgba(' + UI_COLOR.WHITE + ', 1)';
|
||||
browserCanvasContext.fillText(label, point.x, point.y);
|
||||
}
|
||||
}
|
||||
+57
-69
@@ -1,96 +1,84 @@
|
||||
|
||||
function newEndUser() {
|
||||
|
||||
function newEndUser () {
|
||||
let thisObject = {
|
||||
container: undefined,
|
||||
draw: draw,
|
||||
getContainer: getContainer,
|
||||
initialize: initialize
|
||||
}
|
||||
|
||||
let thisObject = {
|
||||
container: undefined,
|
||||
draw: draw,
|
||||
getContainer: getContainer,
|
||||
initialize: initialize
|
||||
};
|
||||
let container = newContainer()
|
||||
container.initialize()
|
||||
thisObject.container = container
|
||||
|
||||
let container = newContainer();
|
||||
container.initialize();
|
||||
thisObject.container = container;
|
||||
thisObject.container.frame.width = 200
|
||||
thisObject.container.frame.height = BOTTOM_SPACE_HEIGHT
|
||||
|
||||
thisObject.container.frame.width = 200;
|
||||
thisObject.container.frame.height = BOTTOM_SPACE_HEIGHT;
|
||||
container.frame.position.x = viewPort.visibleArea.topRight.x - thisObject.container.frame.width * 5
|
||||
container.frame.position.y = viewPort.visibleArea.bottomLeft.y + BREAKPOINT_HEIGHT
|
||||
|
||||
container.frame.position.x = viewPort.visibleArea.topRight.x - thisObject.container.frame.width * 5;
|
||||
container.frame.position.y = viewPort.visibleArea.bottomLeft.y;
|
||||
container.isDraggeable = false
|
||||
|
||||
container.isDraggeable = false;
|
||||
return thisObject
|
||||
|
||||
return thisObject;
|
||||
|
||||
function initialize() {
|
||||
|
||||
let storedUser = window.localStorage.getItem('loggedInUser');
|
||||
|
||||
if (storedUser === null || storedUser === "") {
|
||||
function initialize () {
|
||||
let storedUser = window.localStorage.getItem('loggedInUser')
|
||||
|
||||
if (storedUser === null || storedUser === '') {
|
||||
// User is currently not logged in.
|
||||
window.USER_LOGGED_IN = "";
|
||||
return;
|
||||
}
|
||||
window.USER_LOGGED_IN = ''
|
||||
return
|
||||
}
|
||||
|
||||
let loggedInUser = JSON.parse(storedUser);
|
||||
let loggedInUser = JSON.parse(storedUser)
|
||||
|
||||
window.USER_LOGGED_IN = loggedInUser.alias;
|
||||
window.USER_LOGGED_IN = loggedInUser.alias
|
||||
|
||||
/* Here we will rearrange the storage permissions array into a map, so that it can be easily consumed when needed. */
|
||||
|
||||
let permissionsMap = new Map;
|
||||
let permissionsMap = new Map()
|
||||
|
||||
for (i = 0; i < window.USER_PROFILE.storagePermissions.length; i++) {
|
||||
|
||||
let permission = window.USER_PROFILE.storagePermissions[i];
|
||||
|
||||
permissionsMap.set(permission[0], permission[1]);
|
||||
|
||||
}
|
||||
|
||||
window.USER_PROFILE.storagePermissions = permissionsMap;
|
||||
for (i = 0; i < window.USER_PROFILE.storagePermissions.length; i++) {
|
||||
let permission = window.USER_PROFILE.storagePermissions[i]
|
||||
|
||||
permissionsMap.set(permission[0], permission[1])
|
||||
}
|
||||
|
||||
function getContainer(point) {
|
||||
window.USER_PROFILE.storagePermissions = permissionsMap
|
||||
}
|
||||
|
||||
let container;
|
||||
function getContainer (point) {
|
||||
let container
|
||||
|
||||
/* First we check if this point is inside this object UI. */
|
||||
|
||||
if (thisObject.container.frame.isThisPointHere(point, true) === true) {
|
||||
|
||||
return this.container;
|
||||
|
||||
} else {
|
||||
|
||||
if (thisObject.container.frame.isThisPointHere(point, true) === true) {
|
||||
return this.container
|
||||
} else {
|
||||
/* This point does not belong to this space. */
|
||||
|
||||
return undefined;
|
||||
}
|
||||
return undefined
|
||||
}
|
||||
}
|
||||
|
||||
function draw () {
|
||||
return // nothing to show
|
||||
|
||||
thisObject.container.frame.draw(false, false)
|
||||
|
||||
let fontSize = 12
|
||||
let label = window.USER_LOGGED_IN
|
||||
if (label === undefined) { label = '' };
|
||||
|
||||
let point = {
|
||||
x: thisObject.container.frame.width * 1 / 3,
|
||||
y: (thisObject.container.frame.height / 2) + 4
|
||||
}
|
||||
|
||||
function draw() {
|
||||
point = thisObject.container.frame.frameThisPoint(point)
|
||||
|
||||
return; // nothing to show
|
||||
|
||||
thisObject.container.frame.draw(false, false);
|
||||
|
||||
let fontSize = 12;
|
||||
let label = window.USER_LOGGED_IN;
|
||||
if (label === undefined) { label = "" };
|
||||
|
||||
let point = {
|
||||
x: thisObject.container.frame.width * 1 / 3,
|
||||
y: (thisObject.container.frame.height / 2) + 4
|
||||
};
|
||||
|
||||
point = thisObject.container.frame.frameThisPoint(point);
|
||||
|
||||
browserCanvasContext.font = fontSize + 'px ' + UI_FONT.PRIMARY;
|
||||
browserCanvasContext.fillStyle = 'rgba(' + UI_COLOR.WHITE + ', 1)';
|
||||
browserCanvasContext.fillText(label, point.x, point.y);
|
||||
}
|
||||
}
|
||||
browserCanvasContext.font = fontSize + 'px ' + UI_FONT.PRIMARY
|
||||
browserCanvasContext.fillStyle = 'rgba(' + UI_COLOR.WHITE + ', 1)'
|
||||
browserCanvasContext.fillText(label, point.x, point.y)
|
||||
}
|
||||
}
|
||||
+294
-157
@@ -1,62 +1,60 @@
|
||||
|
||||
function newLogin() {
|
||||
|
||||
let thisObject = {
|
||||
container: undefined,
|
||||
draw: draw,
|
||||
getContainer: getContainer,
|
||||
initialize: initialize
|
||||
};
|
||||
function newLogin () {
|
||||
let thisObject = {
|
||||
container: undefined,
|
||||
draw: draw,
|
||||
getContainer: getContainer,
|
||||
initialize: initialize
|
||||
}
|
||||
|
||||
let container = newContainer();
|
||||
container.initialize();
|
||||
thisObject.container = container;
|
||||
let container = newContainer()
|
||||
container.initialize()
|
||||
thisObject.container = container
|
||||
|
||||
thisObject.container.frame.width = 200;
|
||||
thisObject.container.frame.height = BOTTOM_SPACE_HEIGHT;
|
||||
thisObject.container.frame.width = 200
|
||||
thisObject.container.frame.height = BOTTOM_SPACE_HEIGHT
|
||||
|
||||
container.frame.position.x = viewPort.visibleArea.topRight.x - thisObject.container.frame.width * 1;
|
||||
container.frame.position.y = viewPort.visibleArea.bottomLeft.y;
|
||||
container.frame.position.x = viewPort.visibleArea.topRight.x - thisObject.container.frame.width * 1
|
||||
container.frame.position.y = viewPort.visibleArea.bottomLeft.y + BREAKPOINT_HEIGHT
|
||||
|
||||
container.isDraggeable = false;
|
||||
container.isClickeable = true;
|
||||
container.isDraggeable = false
|
||||
container.isClickeable = true
|
||||
|
||||
let currentLabel;
|
||||
let currentLabel
|
||||
|
||||
let userAuthorization;
|
||||
let userAuthorization
|
||||
|
||||
return thisObject;
|
||||
return thisObject
|
||||
|
||||
function initialize(callBackFunction) {
|
||||
async function initialize (pSharedStatus) {
|
||||
const accessToken = window.localStorage.getItem('access_token')
|
||||
let user = window.localStorage.getItem('user')
|
||||
|
||||
|
||||
const accessToken = window.localStorage.getItem("access_token");
|
||||
let user = window.localStorage.getItem("user");
|
||||
|
||||
if (user === null) {
|
||||
sharedStatus = pSharedStatus
|
||||
|
||||
if (user === null) {
|
||||
// if there is no user that means that we are logged off, which means it is time to clean the local storage of things from the last log in.
|
||||
|
||||
window.localStorage.removeItem("loggedInUser");
|
||||
window.localStorage.removeItem('sessionToken');
|
||||
return;
|
||||
}
|
||||
window.localStorage.removeItem('loggedInUser')
|
||||
window.localStorage.removeItem('sessionToken')
|
||||
return
|
||||
}
|
||||
|
||||
user = JSON.parse(user);
|
||||
user = JSON.parse(user)
|
||||
|
||||
const authId = user.authId;
|
||||
const authId = user.authId
|
||||
|
||||
let sessionToken;
|
||||
let sessionToken
|
||||
|
||||
const apolloClient = new Apollo.lib.ApolloClient({
|
||||
networkInterface: Apollo.lib.createNetworkInterface({
|
||||
uri: window.canvasApp.graphQL.masterAppApiUrl,
|
||||
transportBatching: true,
|
||||
}),
|
||||
connectToDevTools: true,
|
||||
})
|
||||
const apolloClient = new Apollo.lib.ApolloClient({
|
||||
networkInterface: Apollo.lib.createNetworkInterface({
|
||||
uri: window.canvasApp.graphQL.masterAppApiUrl,
|
||||
transportBatching: true
|
||||
}),
|
||||
connectToDevTools: true
|
||||
})
|
||||
|
||||
const QUERY = Apollo.gql`
|
||||
const USERS_QUERY = Apollo.gql`
|
||||
query($authId: String){
|
||||
users_UserByAuthId (authId: $authId){
|
||||
id
|
||||
@@ -80,46 +78,48 @@ function newLogin() {
|
||||
}
|
||||
}
|
||||
`
|
||||
const getUser = () => {
|
||||
return new Promise((resolve, reject) => {
|
||||
apolloClient.query({
|
||||
query: QUERY,
|
||||
variables: {
|
||||
authId: authId
|
||||
}
|
||||
})
|
||||
const getUser = () => {
|
||||
return new Promise((resolve, reject) => {
|
||||
apolloClient.query({
|
||||
query: USERS_QUERY,
|
||||
variables: {
|
||||
authId: authId
|
||||
}
|
||||
})
|
||||
.then(response => {
|
||||
sessionToken = response.data.users_UserByAuthId.sessionToken;
|
||||
|
||||
window.localStorage.setItem('loggedInUser', JSON.stringify(response.data.users_UserByAuthId));
|
||||
resolve({ user: response.data.users_UserByAuthId})
|
||||
sessionToken = response.data.users_UserByAuthId.sessionToken
|
||||
|
||||
window.localStorage.setItem('loggedInUser', JSON.stringify(response.data.users_UserByAuthId))
|
||||
resolve({ user: response.data.users_UserByAuthId})
|
||||
})
|
||||
.catch(error => {
|
||||
console.log("apolloClient error getting user query", error)
|
||||
reject(error)
|
||||
});
|
||||
});
|
||||
}
|
||||
console.log('apolloClient error getting user query', error)
|
||||
reject(error)
|
||||
})
|
||||
})
|
||||
}
|
||||
|
||||
const networkInterfaceTeams = Apollo.lib.createNetworkInterface({
|
||||
uri: window.canvasApp.graphQL.masterAppApiUrl
|
||||
});
|
||||
/* Getting all Teams */
|
||||
|
||||
networkInterfaceTeams.use([{
|
||||
applyMiddleware(req, next) {
|
||||
req.options.headers = {
|
||||
authorization: `Bearer ${accessToken}`
|
||||
};
|
||||
next();
|
||||
}
|
||||
}]);
|
||||
const networkInterfaceTeams = Apollo.lib.createNetworkInterface({
|
||||
uri: window.canvasApp.graphQL.masterAppApiUrl
|
||||
})
|
||||
|
||||
const apolloClientTeams = new Apollo.lib.ApolloClient({
|
||||
networkInterface: networkInterfaceTeams,
|
||||
connectToDevTools: true,
|
||||
});
|
||||
networkInterfaceTeams.use([{
|
||||
applyMiddleware (req, next) {
|
||||
req.options.headers = {
|
||||
authorization: `Bearer ${accessToken}`
|
||||
}
|
||||
next()
|
||||
}
|
||||
}])
|
||||
|
||||
const TEAM_BY_OWNER_QUERY = Apollo.gql`
|
||||
const apolloClientTeams = new Apollo.lib.ApolloClient({
|
||||
networkInterface: networkInterfaceTeams,
|
||||
connectToDevTools: true
|
||||
})
|
||||
|
||||
const TEAM_BY_OWNER_QUERY = Apollo.gql`
|
||||
query teamsByOwnerQuery {
|
||||
teams_TeamsByOwner {
|
||||
id
|
||||
@@ -153,113 +153,250 @@ function newLogin() {
|
||||
}
|
||||
`
|
||||
|
||||
const getTeamByOwner = () => {
|
||||
return new Promise((resolve, reject) => {
|
||||
apolloClientTeams.query({
|
||||
query: TEAM_BY_OWNER_QUERY
|
||||
})
|
||||
const getTeamByOwner = () => {
|
||||
return new Promise((resolve, reject) => {
|
||||
apolloClientTeams.query({
|
||||
query: TEAM_BY_OWNER_QUERY
|
||||
})
|
||||
.then(response => {
|
||||
window.localStorage.setItem('userTeams', JSON.stringify(response.data.teams_TeamsByOwner));
|
||||
resolve({ teams: response.data.teams_TeamsByOwner})
|
||||
window.localStorage.setItem('userTeams', JSON.stringify(response.data.teams_TeamsByOwner))
|
||||
resolve({ teams: response.data.teams_TeamsByOwner})
|
||||
})
|
||||
.catch(error => {
|
||||
console.log("apolloClient error getting user teams", error)
|
||||
reject (error)
|
||||
});
|
||||
console.log('apolloClient error getting user teams', error)
|
||||
reject(error)
|
||||
})
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
// To avoid race conditions, add asynchronous fetches to array
|
||||
let fetchDataPromises = [];
|
||||
/* Gettings All Events */
|
||||
|
||||
fetchDataPromises.push(getUser(), getTeamByOwner());
|
||||
const networkInterfaceEvents = Apollo.lib.createNetworkInterface({
|
||||
uri: window.canvasApp.graphQL.masterAppApiUrl
|
||||
})
|
||||
|
||||
// When all asynchronous fetches resolve, authenticate user or throw error.
|
||||
Promise.all(fetchDataPromises).then(result => {
|
||||
|
||||
/* this is the time to authenticate the user at AAWeb */
|
||||
|
||||
authenticateUser();
|
||||
|
||||
}, err => {
|
||||
console.error("fetchData error", err)
|
||||
});
|
||||
|
||||
thisObject.container.eventHandler.listenToEvent("onMouseClick", onClick);
|
||||
|
||||
function authenticateUser() {
|
||||
|
||||
if (sessionToken === undefined) { sessionToken = "" }
|
||||
|
||||
let path = window.canvasApp.urlPrefix + "AABrowserAPI/authenticateUser/" + sessionToken;
|
||||
|
||||
callServer(undefined, path, onServerReponded);
|
||||
|
||||
function onServerReponded(pResponseFromServer) {
|
||||
|
||||
let responseFromServer = JSON.parse(pResponseFromServer);
|
||||
|
||||
err = responseFromServer.err;
|
||||
|
||||
if (err.result !== GLOBAL.DEFAULT_OK_RESPONSE.result) {
|
||||
|
||||
console.log("Please make sure you create a new team!");
|
||||
return;
|
||||
const apolloClientEvents = new Apollo.lib.ApolloClient({
|
||||
networkInterface: networkInterfaceEvents,
|
||||
connectToDevTools: true,
|
||||
addTypename: false
|
||||
})
|
||||
|
||||
const EVENTS_QUERY = Apollo.gql`
|
||||
query events($maxStartDate: Int, $minEndDate: Int){
|
||||
events_Events(maxStartDate: $maxStartDate, minEndDate: $minEndDate){
|
||||
id
|
||||
title
|
||||
startDatetime
|
||||
endDatetime
|
||||
participants{
|
||||
clone{
|
||||
id
|
||||
team{
|
||||
slug
|
||||
}
|
||||
bot{
|
||||
slug
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
window.USER_PROFILE = responseFromServer.userProfile;
|
||||
window.localStorage.setItem('sessionToken', sessionToken);
|
||||
|
||||
currentLabel = "Logged In"
|
||||
callBackFunction();
|
||||
}
|
||||
}
|
||||
`
|
||||
|
||||
const getCurrentEvents = () => {
|
||||
var d = new Date()
|
||||
var nowSeconds = Math.round(d.getTime() / 1000)
|
||||
var twoWeeksAgoSeconds = nowSeconds - 1209600
|
||||
return new Promise((resolve, reject) => {
|
||||
apolloClientEvents.query({
|
||||
query: EVENTS_QUERY,
|
||||
variables: { maxStartDate: nowSeconds, minEndDate: twoWeeksAgoSeconds }
|
||||
})
|
||||
.then(response => {
|
||||
window.localStorage.setItem('currentEvents', JSON.stringify(response.data.events_Events))
|
||||
currentEvent = window.localStorage.getItem('currentEventObject')
|
||||
if (currentEvent === null || currentEvent === '[]' || currentEvent === '') {
|
||||
sharedStatus.currentEventIndex = -1
|
||||
} else {
|
||||
currentEvent = JSON.parse(currentEvent)
|
||||
sharedStatus.currentEventIndex = response.data.events_Events.findIndex(function (element) {
|
||||
return element.id == currentEvent.id
|
||||
})
|
||||
}
|
||||
resolve({ currentEvents: response.data.events_Events})
|
||||
})
|
||||
.catch(error => {
|
||||
console.log('apolloClient error getting current events', error)
|
||||
reject(error)
|
||||
})
|
||||
})
|
||||
}
|
||||
|
||||
/* Getting all Clones */
|
||||
|
||||
function onClick() {
|
||||
|
||||
const networkInterfaceClones = Apollo.lib.createNetworkInterface({
|
||||
uri: window.canvasApp.graphQL.masterAppApiUrl
|
||||
})
|
||||
|
||||
networkInterfaceClones.use([{
|
||||
applyMiddleware (req, next) {
|
||||
req.options.headers = {
|
||||
authorization: `Bearer ${accessToken}`
|
||||
}
|
||||
next()
|
||||
}
|
||||
}])
|
||||
|
||||
const apolloClientClones = new Apollo.lib.ApolloClient({
|
||||
networkInterface: networkInterfaceClones,
|
||||
connectToDevTools: true
|
||||
})
|
||||
|
||||
const CLONES_QUERY = Apollo.gql`
|
||||
query Operations_Clones{
|
||||
operations_Clones {
|
||||
id
|
||||
authId
|
||||
teamId
|
||||
botId
|
||||
mode
|
||||
resumeExecution
|
||||
beginDatetime
|
||||
endDatetime
|
||||
waitTime
|
||||
state
|
||||
stateDatetime
|
||||
createDatetime
|
||||
lastLogs
|
||||
runAsTeam
|
||||
summaryDate
|
||||
buyAverage
|
||||
sellAverage
|
||||
marketRate
|
||||
combinedProfitsA
|
||||
combinedProfitsB
|
||||
assetA
|
||||
assetB
|
||||
botType
|
||||
teamName
|
||||
botName
|
||||
botAvatar
|
||||
teamAvatar
|
||||
processName
|
||||
keyId
|
||||
botSlug
|
||||
}
|
||||
}
|
||||
`
|
||||
|
||||
const getClones = () => {
|
||||
return new Promise((resolve, reject) => {
|
||||
apolloClientClones.query({
|
||||
query: CLONES_QUERY
|
||||
})
|
||||
.then(response => {
|
||||
window.localStorage.setItem('userClones', JSON.stringify(response.data.operations_Clones))
|
||||
let clones = response.data.operations_Clones
|
||||
for (let i = 0; i < clones.length; i++) {
|
||||
let clone = clones[i]
|
||||
if (clone.botType === 'Trading') {
|
||||
let teamSlug = clone.teamName.toLowerCase()
|
||||
teamSlug = teamSlug.replace(' ', '-')
|
||||
let devTeam = ecosystem.getTeam(teamSlug)
|
||||
let bot = ecosystem.getBot(devTeam, clone.botSlug)
|
||||
if (bot !== undefined) {
|
||||
bot.cloneId = clone.id
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
resolve({ clones: response.data.operations_Clones})
|
||||
})
|
||||
.catch(error => {
|
||||
console.log('apolloClient error getting user clones', error)
|
||||
reject(error)
|
||||
})
|
||||
})
|
||||
}
|
||||
|
||||
function getContainer(point) {
|
||||
// To avoid race conditions, add asynchronous fetches to array
|
||||
let fetchDataPromises = []
|
||||
|
||||
let container;
|
||||
fetchDataPromises.push(getUser(), getTeamByOwner(), getCurrentEvents(), getClones(), authenticateUser())
|
||||
|
||||
// When all asynchronous fetches resolve, authenticate user or throw error.
|
||||
await Promise.all(fetchDataPromises).then(result => {
|
||||
|
||||
}, err => {
|
||||
console.error('[ERROR] Login -> GraphQL Fetch Error -> err = ', err)
|
||||
})
|
||||
|
||||
thisObject.container.eventHandler.listenToEvent('onMouseClick', onClick)
|
||||
|
||||
async function authenticateUser () {
|
||||
if (sessionToken === undefined) { sessionToken = '' }
|
||||
|
||||
let path = window.canvasApp.urlPrefix + 'AABrowserAPI/authenticateUser/' + sessionToken
|
||||
|
||||
return new Promise(
|
||||
function (resolve, reject) {
|
||||
callServer(undefined, path, (result) => {
|
||||
let responseFromServer = JSON.parse(result)
|
||||
|
||||
err = responseFromServer.err
|
||||
|
||||
if (err.result !== GLOBAL.DEFAULT_OK_RESPONSE.result) {
|
||||
console.log('Please make sure you create a new team!')
|
||||
reject(err)
|
||||
}
|
||||
|
||||
window.USER_PROFILE = responseFromServer.userProfile
|
||||
window.localStorage.setItem('sessionToken', sessionToken)
|
||||
|
||||
currentLabel = 'Logged In'
|
||||
resolve()
|
||||
})
|
||||
}
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
function onClick () {
|
||||
|
||||
}
|
||||
|
||||
function getContainer (point) {
|
||||
let container
|
||||
|
||||
/* First we check if this point is inside this object UI. */
|
||||
|
||||
if (thisObject.container.frame.isThisPointHere(point, true) === true) {
|
||||
|
||||
return this.container;
|
||||
|
||||
} else {
|
||||
|
||||
if (thisObject.container.frame.isThisPointHere(point, true) === true) {
|
||||
return this.container
|
||||
} else {
|
||||
/* This point does not belong to this space. */
|
||||
|
||||
return undefined;
|
||||
}
|
||||
return undefined
|
||||
}
|
||||
}
|
||||
|
||||
function draw () {
|
||||
return // nothing to show.
|
||||
|
||||
thisObject.container.frame.draw(false, false)
|
||||
|
||||
let fontSize = 12
|
||||
let label = currentLabel
|
||||
if (label === undefined) { label = '' };
|
||||
|
||||
let point = {
|
||||
x: thisObject.container.frame.width * 1 / 3,
|
||||
y: (thisObject.container.frame.height / 2) + 4
|
||||
}
|
||||
|
||||
function draw() {
|
||||
point = thisObject.container.frame.frameThisPoint(point)
|
||||
|
||||
return; // nothing to show.
|
||||
|
||||
thisObject.container.frame.draw(false, false);
|
||||
|
||||
let fontSize = 12;
|
||||
let label = currentLabel;
|
||||
if (label === undefined) { label = "" };
|
||||
|
||||
let point = {
|
||||
x: thisObject.container.frame.width * 1 / 3,
|
||||
y: (thisObject.container.frame.height / 2) + 4
|
||||
};
|
||||
|
||||
point = thisObject.container.frame.frameThisPoint(point);
|
||||
|
||||
browserCanvasContext.font = fontSize + 'px ' + UI_FONT.PRIMARY;
|
||||
browserCanvasContext.fillStyle = 'rgba(' + UI_COLOR.WHITE + ', 1)';
|
||||
browserCanvasContext.fillText(label, point.x, point.y);
|
||||
}
|
||||
browserCanvasContext.font = fontSize + 'px ' + UI_FONT.PRIMARY
|
||||
browserCanvasContext.fillStyle = 'rgba(' + UI_COLOR.WHITE + ', 1)'
|
||||
browserCanvasContext.fillText(label, point.x, point.y)
|
||||
}
|
||||
}
|
||||
+78
-91
@@ -1,141 +1,128 @@
|
||||
|
||||
|
||||
function transformThisPoint(point, container) {
|
||||
|
||||
function transformThisPoint (point, container) {
|
||||
/* We make the point relative to the current frame */
|
||||
|
||||
point = container.frame.frameThisPoint(point);
|
||||
point = container.frame.frameThisPoint(point)
|
||||
|
||||
/* We add the possible displacement */
|
||||
|
||||
point = container.displacement.displaceThisPoint(point);
|
||||
point = container.displacement.displaceThisPoint(point)
|
||||
|
||||
/* We viewport Transformation. */
|
||||
|
||||
point = viewPort.zoomThisPoint(point);
|
||||
point = viewPort.zoomThisPoint(point)
|
||||
|
||||
return point;
|
||||
return point
|
||||
}
|
||||
|
||||
function unTransformThisPoint(point, container) {
|
||||
function unTransformThisPoint (point, container) {
|
||||
point = viewPort.unzoomThisPoint(point)
|
||||
point = container.displacement.undisplaceThisPoint(point)
|
||||
point = container.frame.unframeThisPoint(point)
|
||||
|
||||
point = viewPort.unzoomThisPoint(point);
|
||||
point = container.displacement.undisplaceThisPoint(point);
|
||||
point = container.frame.unframeThisPoint(point);
|
||||
|
||||
return point;
|
||||
return point
|
||||
}
|
||||
|
||||
function nextPorwerOf10(number) {
|
||||
|
||||
for (let i = -10; i <= 10; i++) {
|
||||
if (number < Math.pow(10, i)) {
|
||||
return Math.pow(10, i);
|
||||
}
|
||||
function nextPorwerOf10 (number) {
|
||||
for (let i = -10; i <= 10; i++) {
|
||||
if (number < Math.pow(10, i)) {
|
||||
return Math.pow(10, i)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function pad(str, max) {
|
||||
str = str.toString();
|
||||
return str.length < max ? pad("0" + str, max) : str;
|
||||
function pad (str, max) {
|
||||
str = str.toString()
|
||||
return str.length < max ? pad('0' + str, max) : str
|
||||
}
|
||||
|
||||
function getDateFromPoint(point, container, timeLineCoordinateSystem) {
|
||||
function getDateFromPoint (point, container, timeLineCoordinateSystem) {
|
||||
point = unTransformThisPoint(point, container)
|
||||
point = timeLineCoordinateSystem.unInverseTransform(point, container.frame.height)
|
||||
|
||||
point = unTransformThisPoint(point, container);
|
||||
point = timeLineCoordinateSystem.unInverseTransform(point, container.frame.height);
|
||||
let date = new Date(point.x)
|
||||
|
||||
let date = new Date(point.x);
|
||||
|
||||
return date;
|
||||
return date
|
||||
}
|
||||
|
||||
function getRateFromPoint(point, container, timeLineCoordinateSystem) {
|
||||
function getRateFromPoint (point, container, timeLineCoordinateSystem) {
|
||||
point = unTransformThisPoint(point, container)
|
||||
point = timeLineCoordinateSystem.unInverseTransform(point, container.frame.height)
|
||||
|
||||
point = unTransformThisPoint(point, container);
|
||||
point = timeLineCoordinateSystem.unInverseTransform(point, container.frame.height);
|
||||
|
||||
return point.y;
|
||||
return point.y
|
||||
}
|
||||
|
||||
function getMilisecondsFromPoint(point, container, timeLineCoordinateSystem) {
|
||||
function getMilisecondsFromPoint (point, container, timeLineCoordinateSystem) {
|
||||
point = unTransformThisPoint(point, container)
|
||||
point = timeLineCoordinateSystem.unInverseTransform(point, container.frame.height)
|
||||
|
||||
point = unTransformThisPoint(point, container);
|
||||
point = timeLineCoordinateSystem.unInverseTransform(point, container.frame.height);
|
||||
|
||||
return point.x;
|
||||
return point.x
|
||||
}
|
||||
|
||||
function saveUserPosition(container, timeLineCoordinateSystem) {
|
||||
function saveUserPosition (container, timeLineCoordinateSystem) {
|
||||
let centerPoint = {
|
||||
x: (viewPort.visibleArea.bottomRight.x - viewPort.visibleArea.topLeft.x) / 2,
|
||||
y: (viewPort.visibleArea.bottomRight.y - viewPort.visibleArea.topLeft.y) / 2
|
||||
}
|
||||
|
||||
let centerPoint = {
|
||||
x: (viewPort.visibleArea.bottomRight.x - viewPort.visibleArea.topLeft.x) / 2,
|
||||
y: (viewPort.visibleArea.bottomRight.y - viewPort.visibleArea.topLeft.y) / 2
|
||||
};
|
||||
let userPosition = {
|
||||
date: getDateFromPoint(centerPoint, container, timeLineCoordinateSystem),
|
||||
rate: getRateFromPoint(centerPoint, container, timeLineCoordinateSystem),
|
||||
market: DEFAULT_MARKET,
|
||||
zoom: viewPort.zoomTargetLevel
|
||||
}
|
||||
|
||||
let userPosition = {
|
||||
date: getDateFromPoint(centerPoint, container, timeLineCoordinateSystem),
|
||||
rate: getRateFromPoint(centerPoint, container, timeLineCoordinateSystem),
|
||||
market: DEFAULT_MARKET,
|
||||
zoom: viewPort.zoomTargetLevel
|
||||
};
|
||||
|
||||
window.localStorage.setItem('userPosition', JSON.stringify(userPosition));
|
||||
window.localStorage.setItem('userPosition', JSON.stringify(userPosition))
|
||||
}
|
||||
|
||||
function moveToUserPosition(container, timeLineCoordinateSystem) {
|
||||
function moveToUserPosition (container, timeLineCoordinateSystem) {
|
||||
let savedPosition = window.localStorage.getItem('userPosition')
|
||||
let userPosition
|
||||
|
||||
let savedPosition = window.localStorage.getItem('userPosition');
|
||||
let userPosition;
|
||||
|
||||
if (savedPosition === null) {
|
||||
|
||||
userPosition = {
|
||||
date: (new Date()).toString(),
|
||||
rate: timeLineCoordinateSystem.max.y / 2,
|
||||
market: DEFAULT_MARKET,
|
||||
zoom: INITIAL_ZOOM_LEVEL
|
||||
};
|
||||
|
||||
} else {
|
||||
|
||||
userPosition = JSON.parse(savedPosition);
|
||||
if (savedPosition === null) {
|
||||
userPosition = {
|
||||
date: (new Date()).toString(),
|
||||
rate: timeLineCoordinateSystem.max.y / 2,
|
||||
market: DEFAULT_MARKET,
|
||||
zoom: INITIAL_ZOOM_LEVEL
|
||||
}
|
||||
} else {
|
||||
userPosition = JSON.parse(savedPosition)
|
||||
}
|
||||
|
||||
let centerPoint = {
|
||||
x: (viewPort.visibleArea.bottomRight.x - viewPort.visibleArea.topLeft.x) / 2,
|
||||
y: (viewPort.visibleArea.bottomRight.y - viewPort.visibleArea.topLeft.y) / 2
|
||||
};
|
||||
let centerPoint = {
|
||||
x: (viewPort.visibleArea.bottomRight.x - viewPort.visibleArea.topLeft.x) / 2,
|
||||
y: (viewPort.visibleArea.bottomRight.y - viewPort.visibleArea.topLeft.y) / 2
|
||||
}
|
||||
|
||||
viewPort.newZoomLevel(userPosition.zoom);
|
||||
INITIAL_TIME_PERIOD = recalculatePeriod(userPosition.zoom);
|
||||
INITIAL_DATE = new Date (userPosition.date);
|
||||
viewPort.newZoomLevel(userPosition.zoom)
|
||||
INITIAL_TIME_PERIOD = recalculatePeriod(userPosition.zoom)
|
||||
INITIAL_DATE = new Date(userPosition.date)
|
||||
|
||||
let targetPoint = {
|
||||
x: (new Date(userPosition.date)).valueOf(),
|
||||
y: userPosition.rate
|
||||
};
|
||||
let targetPoint = {
|
||||
x: (new Date(userPosition.date)).valueOf(),
|
||||
y: userPosition.rate
|
||||
}
|
||||
|
||||
/* Put this point in the coordinate system of the viewPort */
|
||||
|
||||
targetPoint = timeLineCoordinateSystem.transformThisPoint(targetPoint);
|
||||
targetPoint = transformThisPoint(targetPoint, container);
|
||||
targetPoint = timeLineCoordinateSystem.transformThisPoint(targetPoint)
|
||||
targetPoint = transformThisPoint(targetPoint, container)
|
||||
|
||||
/* Lets calculate the displace vector, from the point we want at the center, to the current center. */
|
||||
|
||||
let displaceVector = {
|
||||
x: centerPoint.x - targetPoint.x,
|
||||
y: centerPoint.y - targetPoint.y
|
||||
};
|
||||
let displaceVector = {
|
||||
x: centerPoint.x - targetPoint.x,
|
||||
y: centerPoint.y - targetPoint.y
|
||||
}
|
||||
|
||||
viewPort.displace(displaceVector);
|
||||
viewPort.displace(displaceVector)
|
||||
}
|
||||
|
||||
function removeTime(datetime) {
|
||||
function removeTime (datetime) {
|
||||
if (datetime === undefined) { return }
|
||||
|
||||
if (datetime === undefined) { return;}
|
||||
let dateOnly = new Date(Math.trunc(datetime.valueOf() / ONE_DAY_IN_MILISECONDS) * ONE_DAY_IN_MILISECONDS)
|
||||
|
||||
let dateOnly = new Date(Math.trunc(datetime.valueOf() / ONE_DAY_IN_MILISECONDS) * ONE_DAY_IN_MILISECONDS);
|
||||
|
||||
return dateOnly;
|
||||
}
|
||||
return dateOnly
|
||||
}
|
||||
+314
-373
@@ -1,100 +1,95 @@
|
||||
|
||||
function newViewPort() {
|
||||
|
||||
function newViewPort () {
|
||||
const CONSOLE_LOG = true
|
||||
|
||||
const CONSOLE_LOG = true;
|
||||
let ANIMATION_INCREMENT = 0.25
|
||||
const TOP_MARGIN = 15 + TOP_SPACE_HEIGHT
|
||||
const BOTTOM_MARGIN = 15 + BOTTOM_SPACE_HEIGHT
|
||||
const LEFT_MARGIN = 50
|
||||
const RIGHT_MARGIN = 50
|
||||
const MIN_ZOOM_LEVEL = -28.25
|
||||
|
||||
let ANIMATION_INCREMENT = 0.25;
|
||||
const TOP_MARGIN = 15 + TOP_SPACE_HEIGHT;
|
||||
const BOTTOM_MARGIN = 15 + BOTTOM_SPACE_HEIGHT;
|
||||
const LEFT_MARGIN = 50;
|
||||
const RIGHT_MARGIN = 50;
|
||||
const MIN_ZOOM_LEVEL = -28.25
|
||||
let thisObject = {
|
||||
visibleArea: undefined,
|
||||
eventHandler: undefined,
|
||||
zoomTargetLevel: undefined,
|
||||
zoomLevel: undefined,
|
||||
mousePosition: undefined,
|
||||
newZoomLevel: newZoomLevel,
|
||||
applyZoom: applyZoom,
|
||||
isMinZoom: isMinZoom,
|
||||
zoomFontSize: zoomFontSize,
|
||||
zoomThisPoint: zoomThisPoint,
|
||||
unzoomThisPoint: unzoomThisPoint,
|
||||
isThisPointVisible: isThisPointVisible,
|
||||
fitIntoVisibleArea: fitIntoVisibleArea,
|
||||
displace: displace,
|
||||
displaceTarget: displaceTarget,
|
||||
animate: animate,
|
||||
draw: draw,
|
||||
raiseEvents: raiseEvents,
|
||||
initialize: initialize
|
||||
}
|
||||
|
||||
let thisObject = {
|
||||
visibleArea: undefined,
|
||||
eventHandler: undefined,
|
||||
zoomTargetLevel:undefined,
|
||||
zoomLevel: undefined,
|
||||
mousePosition: undefined,
|
||||
newZoomLevel: newZoomLevel,
|
||||
applyZoom: applyZoom,
|
||||
isMinZoom: isMinZoom,
|
||||
zoomFontSize: zoomFontSize,
|
||||
zoomThisPoint: zoomThisPoint,
|
||||
unzoomThisPoint: unzoomThisPoint,
|
||||
isThisPointVisible: isThisPointVisible,
|
||||
fitIntoVisibleArea: fitIntoVisibleArea,
|
||||
displace: displace,
|
||||
displaceTarget: displaceTarget,
|
||||
animate: animate,
|
||||
draw: draw,
|
||||
raiseEvents: raiseEvents,
|
||||
initialize: initialize
|
||||
};
|
||||
let increment = 0.035
|
||||
|
||||
let increment = 0.035;
|
||||
var offset = {
|
||||
x: 0,
|
||||
y: 0
|
||||
}
|
||||
|
||||
var offset = {
|
||||
x: 0,
|
||||
y: 0
|
||||
};
|
||||
var targetOffset = {
|
||||
x: 0,
|
||||
y: 0
|
||||
}
|
||||
|
||||
var targetOffset = {
|
||||
x: 0,
|
||||
y: 0
|
||||
};
|
||||
let offsetIncrement = {
|
||||
x: 0,
|
||||
y: 0
|
||||
}
|
||||
|
||||
let offsetIncrement = {
|
||||
x: 0,
|
||||
y: 0
|
||||
};
|
||||
thisObject.mousePosition = {
|
||||
x: 0,
|
||||
y: 0
|
||||
}
|
||||
|
||||
thisObject.mousePosition = {
|
||||
x: 0,
|
||||
y: 0
|
||||
};
|
||||
thisObject.eventHandler = newEventHandler()
|
||||
|
||||
thisObject.eventHandler = newEventHandler();
|
||||
return thisObject
|
||||
|
||||
return thisObject;
|
||||
function initialize () {
|
||||
thisObject.visibleArea = {
|
||||
topLeft: { x: LEFT_MARGIN, y: TOP_MARGIN },
|
||||
topRight: { x: browserCanvas.width - RIGHT_MARGIN, y: TOP_MARGIN },
|
||||
bottomRight: { x: browserCanvas.width - RIGHT_MARGIN, y: browserCanvas.height - BOTTOM_MARGIN},
|
||||
bottomLeft: { x: LEFT_MARGIN, y: browserCanvas.height - BOTTOM_MARGIN}
|
||||
}
|
||||
}
|
||||
|
||||
function initialize() {
|
||||
function raiseEvents () {
|
||||
let event = {
|
||||
newOffset: offset
|
||||
}
|
||||
|
||||
thisObject.visibleArea = {
|
||||
topLeft: { x: LEFT_MARGIN, y: TOP_MARGIN },
|
||||
topRight: { x: browserCanvas.width - RIGHT_MARGIN , y: TOP_MARGIN },
|
||||
bottomRight: { x: browserCanvas.width - RIGHT_MARGIN, y: browserCanvas.height - BOTTOM_MARGIN},
|
||||
bottomLeft: { x: LEFT_MARGIN, y: browserCanvas.height - BOTTOM_MARGIN}
|
||||
};
|
||||
}
|
||||
thisObject.eventHandler.raiseEvent('Offset Changed', event)
|
||||
}
|
||||
|
||||
function raiseEvents() {
|
||||
function animate () {
|
||||
if (thisObject.zoomLevel < thisObject.zoomTargetLevel) {
|
||||
if (thisObject.zoomTargetLevel - thisObject.zoomLevel < ANIMATION_INCREMENT) {
|
||||
ANIMATION_INCREMENT = Math.abs(thisObject.zoomTargetLevel - thisObject.zoomLevel)
|
||||
}
|
||||
thisObject.zoomLevel = thisObject.zoomLevel + ANIMATION_INCREMENT
|
||||
changeZoom(thisObject.zoomLevel - ANIMATION_INCREMENT, thisObject.zoomLevel)
|
||||
}
|
||||
|
||||
let event = {
|
||||
newOffset: offset
|
||||
};
|
||||
|
||||
thisObject.eventHandler.raiseEvent("Offset Changed", event);
|
||||
|
||||
}
|
||||
|
||||
function animate() {
|
||||
|
||||
if (thisObject.zoomLevel < thisObject.zoomTargetLevel) {
|
||||
if (thisObject.zoomTargetLevel - thisObject.zoomLevel < ANIMATION_INCREMENT) {
|
||||
ANIMATION_INCREMENT = Math.abs(thisObject.zoomTargetLevel - thisObject.zoomLevel);
|
||||
}
|
||||
thisObject.zoomLevel = thisObject.zoomLevel + ANIMATION_INCREMENT;
|
||||
changeZoom(thisObject.zoomLevel - ANIMATION_INCREMENT, thisObject.zoomLevel);
|
||||
}
|
||||
|
||||
if (thisObject.zoomLevel > thisObject.zoomTargetLevel) {
|
||||
if (thisObject.zoomLevel - thisObject.zoomTargetLevel < ANIMATION_INCREMENT) {
|
||||
ANIMATION_INCREMENT = Math.abs(thisObject.zoomTargetLevel - thisObject.zoomLevel);
|
||||
}
|
||||
thisObject.zoomLevel = thisObject.zoomLevel - ANIMATION_INCREMENT;
|
||||
changeZoom(thisObject.zoomLevel + ANIMATION_INCREMENT, thisObject.zoomLevel);
|
||||
}
|
||||
if (thisObject.zoomLevel > thisObject.zoomTargetLevel) {
|
||||
if (thisObject.zoomLevel - thisObject.zoomTargetLevel < ANIMATION_INCREMENT) {
|
||||
ANIMATION_INCREMENT = Math.abs(thisObject.zoomTargetLevel - thisObject.zoomLevel)
|
||||
}
|
||||
thisObject.zoomLevel = thisObject.zoomLevel - ANIMATION_INCREMENT
|
||||
changeZoom(thisObject.zoomLevel + ANIMATION_INCREMENT, thisObject.zoomLevel)
|
||||
}
|
||||
|
||||
/*
|
||||
if (offsetIncrement.x !== 0) {
|
||||
@@ -105,344 +100,290 @@ function newViewPort() {
|
||||
offsetIncrement.x = 0;
|
||||
}
|
||||
}
|
||||
*/
|
||||
*/
|
||||
|
||||
if (offsetIncrement.y !== 0) {
|
||||
if (offsetIncrement.y !== 0) {
|
||||
if (Math.trunc(Math.abs(targetOffset.y - offset.y) * 1000) >= Math.trunc(Math.abs(offsetIncrement.y) * 1000)) {
|
||||
offset.y = offset.y + offsetIncrement.y
|
||||
|
||||
if (Math.trunc(Math.abs(targetOffset.y - offset.y) * 1000) >= Math.trunc(Math.abs(offsetIncrement.y) * 1000)) {
|
||||
offset.y = offset.y + offsetIncrement.y;
|
||||
// console.log("offset.y changed to " + offset.y)
|
||||
} else {
|
||||
offsetIncrement.y = 0
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//console.log("offset.y changed to " + offset.y)
|
||||
function displace (displaceVector) {
|
||||
offset.x = offset.x + displaceVector.x
|
||||
offset.y = offset.y + displaceVector.y
|
||||
|
||||
} else {
|
||||
offsetIncrement.y = 0;
|
||||
}
|
||||
}
|
||||
let event = {
|
||||
newOffset: offset
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
thisObject.eventHandler.raiseEvent('Offset Changed', event)
|
||||
|
||||
function displace(displaceVector) {
|
||||
// console.log("displace produced new Offset x = " + offset.x + " y = " + offset.y);
|
||||
}
|
||||
|
||||
offset.x = offset.x + displaceVector.x;
|
||||
offset.y = offset.y + displaceVector.y;
|
||||
function displaceTarget (displaceVector) {
|
||||
targetOffset.x = targetOffset.x + displaceVector.x
|
||||
targetOffset.y = targetOffset.y + displaceVector.y
|
||||
|
||||
let event = {
|
||||
newOffset: offset
|
||||
};
|
||||
offsetIncrement = {
|
||||
x: (targetOffset.x - offset.x) / 10,
|
||||
y: (targetOffset.y - offset.y) / 10
|
||||
}
|
||||
|
||||
thisObject.eventHandler.raiseEvent("Offset Changed", event);
|
||||
// console.log("displaceTarget x = " + targetOffset.x + " y = " + targetOffset.y);
|
||||
}
|
||||
|
||||
//console.log("displace produced new Offset x = " + offset.x + " y = " + offset.y);
|
||||
function newZoomLevel (level) {
|
||||
thisObject.zoomTargetLevel = level
|
||||
thisObject.zoomLevel = level
|
||||
|
||||
}
|
||||
ANIMATION_INCREMENT = Math.abs(thisObject.zoomTargetLevel - thisObject.zoomLevel) / 3
|
||||
|
||||
function displaceTarget(displaceVector) {
|
||||
let event = {
|
||||
newLevel: thisObject.zoomTargetLevel,
|
||||
newOffset: offset,
|
||||
type: undefined
|
||||
}
|
||||
|
||||
thisObject.eventHandler.raiseEvent('Zoom Changed', event)
|
||||
|
||||
targetOffset.x = targetOffset.x + displaceVector.x;
|
||||
targetOffset.y = targetOffset.y + displaceVector.y;
|
||||
return true
|
||||
}
|
||||
|
||||
|
||||
offsetIncrement = {
|
||||
x: (targetOffset.x - offset.x) / 10,
|
||||
y: (targetOffset.y - offset.y) / 10
|
||||
};
|
||||
|
||||
//console.log("displaceTarget x = " + targetOffset.x + " y = " + targetOffset.y);
|
||||
|
||||
}
|
||||
|
||||
function newZoomLevel(level) {
|
||||
|
||||
thisObject.zoomTargetLevel = level;
|
||||
thisObject.zoomLevel = level;
|
||||
|
||||
ANIMATION_INCREMENT = Math.abs(thisObject.zoomTargetLevel - thisObject.zoomLevel) / 3;
|
||||
|
||||
let event = {
|
||||
newLevel: thisObject.zoomTargetLevel,
|
||||
newOffset: offset,
|
||||
type: undefined
|
||||
};
|
||||
|
||||
thisObject.eventHandler.raiseEvent("Zoom Changed", event);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
function isMinZoom() {
|
||||
function isMinZoom () {
|
||||
/* returns true is we are currently at the min zoom level. */
|
||||
|
||||
if (thisObject.zoomTargetLevel === MIN_ZOOM_LEVEL) { return true; } else { return false;}
|
||||
if (thisObject.zoomTargetLevel === MIN_ZOOM_LEVEL) { return true } else { return false }
|
||||
}
|
||||
|
||||
}
|
||||
function applyZoom (amount) {
|
||||
// console.log("applyZoom amount: " + amount);
|
||||
|
||||
function applyZoom(amount) {
|
||||
if (amount > 0) {
|
||||
if (thisObject.zoomTargetLevel > -5) {
|
||||
amount = amount * 2
|
||||
}
|
||||
|
||||
//console.log("applyZoom amount: " + amount);
|
||||
|
||||
if (amount > 0) {
|
||||
|
||||
|
||||
if (thisObject.zoomTargetLevel > -5) {
|
||||
amount = amount * 2;
|
||||
}
|
||||
|
||||
if (thisObject.zoomTargetLevel > 10) {
|
||||
amount = amount * 3;
|
||||
}
|
||||
|
||||
if (thisObject.zoomTargetLevel > 15) {
|
||||
amount = amount * 4;
|
||||
}
|
||||
}
|
||||
|
||||
if (amount < 0) {
|
||||
|
||||
if (thisObject.zoomTargetLevel > -4) {
|
||||
amount = amount * 2;
|
||||
}
|
||||
|
||||
if (thisObject.zoomTargetLevel > 13) {
|
||||
amount = amount * 3;
|
||||
}
|
||||
|
||||
if (thisObject.zoomTargetLevel > 19) {
|
||||
amount = amount * 4;
|
||||
}
|
||||
}
|
||||
|
||||
if (thisObject.zoomTargetLevel + amount > 1000) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (thisObject.zoomTargetLevel <= -27 && amount < 0) {
|
||||
amount = amount / 4;
|
||||
}
|
||||
|
||||
if (thisObject.zoomTargetLevel < -27 && amount > 0) {
|
||||
amount = amount / 4;
|
||||
}
|
||||
|
||||
if (thisObject.zoomTargetLevel + amount < MIN_ZOOM_LEVEL) {
|
||||
return false;
|
||||
}
|
||||
|
||||
thisObject.zoomTargetLevel = thisObject.zoomTargetLevel + amount;
|
||||
|
||||
ANIMATION_INCREMENT = Math.abs(thisObject.zoomTargetLevel - thisObject.zoomLevel) / 3;
|
||||
|
||||
let event = {
|
||||
newLevel: thisObject.zoomTargetLevel,
|
||||
newOffset: offset,
|
||||
type: undefined
|
||||
};
|
||||
|
||||
if (amount > 0) {
|
||||
event.type = "Zoom In";
|
||||
} else {
|
||||
event.type = "Zoom Out";
|
||||
}
|
||||
|
||||
thisObject.eventHandler.raiseEvent("Zoom Changed", event);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
function changeZoom(oldLevel, newLevel) {
|
||||
|
||||
let mouseNoZoom = unzoomThisPoint(thisObject.mousePosition, oldLevel);
|
||||
let newMouse = zoomThisPoint(mouseNoZoom, newLevel);
|
||||
|
||||
offset.x = offset.x - newMouse.x + thisObject.mousePosition.x;
|
||||
offset.y = offset.y - newMouse.y + thisObject.mousePosition.y;
|
||||
|
||||
targetOffset.x = offset.x
|
||||
targetOffset.y = offset.y ;
|
||||
|
||||
offsetIncrement = {
|
||||
x: 0,
|
||||
y: 0
|
||||
};
|
||||
if (thisObject.zoomTargetLevel > 10) {
|
||||
amount = amount * 3
|
||||
}
|
||||
|
||||
if (thisObject.zoomTargetLevel > 15) {
|
||||
amount = amount * 4
|
||||
}
|
||||
}
|
||||
|
||||
if (amount < 0) {
|
||||
if (thisObject.zoomTargetLevel > -4) {
|
||||
amount = amount * 2
|
||||
}
|
||||
|
||||
function zoomFontSize(baseSize, level) {
|
||||
if (thisObject.zoomTargetLevel > 13) {
|
||||
amount = amount * 3
|
||||
}
|
||||
|
||||
let zoomFactor = increment; // + increment * thisObject.zoomLevel / 100;
|
||||
|
||||
if (level === undefined) {
|
||||
|
||||
baseSize = baseSize * (1 + zoomFactor * thisObject.zoomLevel);
|
||||
|
||||
} else {
|
||||
|
||||
baseSize = baseSize * (1 + zoomFactor * level);
|
||||
|
||||
}
|
||||
|
||||
return baseSize;
|
||||
if (thisObject.zoomTargetLevel > 19) {
|
||||
amount = amount * 4
|
||||
}
|
||||
}
|
||||
|
||||
function fitIntoVisibleArea(point) {
|
||||
if (thisObject.zoomTargetLevel + amount > 1000) {
|
||||
return false
|
||||
}
|
||||
|
||||
if (thisObject.zoomTargetLevel <= -27 && amount < 0) {
|
||||
amount = amount / 4
|
||||
}
|
||||
|
||||
if (thisObject.zoomTargetLevel < -27 && amount > 0) {
|
||||
amount = amount / 4
|
||||
}
|
||||
|
||||
if (thisObject.zoomTargetLevel + amount < MIN_ZOOM_LEVEL) {
|
||||
return false
|
||||
}
|
||||
|
||||
thisObject.zoomTargetLevel = thisObject.zoomTargetLevel + amount
|
||||
|
||||
ANIMATION_INCREMENT = Math.abs(thisObject.zoomTargetLevel - thisObject.zoomLevel) / 3
|
||||
|
||||
let event = {
|
||||
newLevel: thisObject.zoomTargetLevel,
|
||||
newOffset: offset,
|
||||
type: undefined
|
||||
}
|
||||
|
||||
if (amount > 0) {
|
||||
event.type = 'Zoom In'
|
||||
} else {
|
||||
event.type = 'Zoom Out'
|
||||
}
|
||||
|
||||
thisObject.eventHandler.raiseEvent('Zoom Changed', event)
|
||||
|
||||
return true
|
||||
}
|
||||
|
||||
function changeZoom (oldLevel, newLevel) {
|
||||
let mouseNoZoom = unzoomThisPoint(thisObject.mousePosition, oldLevel)
|
||||
let newMouse = zoomThisPoint(mouseNoZoom, newLevel)
|
||||
|
||||
offset.x = offset.x - newMouse.x + thisObject.mousePosition.x
|
||||
offset.y = offset.y - newMouse.y + thisObject.mousePosition.y
|
||||
|
||||
targetOffset.x = offset.x
|
||||
targetOffset.y = offset.y
|
||||
|
||||
offsetIncrement = {
|
||||
x: 0,
|
||||
y: 0
|
||||
}
|
||||
}
|
||||
|
||||
function zoomFontSize (baseSize, level) {
|
||||
let zoomFactor = increment // + increment * thisObject.zoomLevel / 100;
|
||||
|
||||
if (level === undefined) {
|
||||
baseSize = baseSize * (1 + zoomFactor * thisObject.zoomLevel)
|
||||
} else {
|
||||
baseSize = baseSize * (1 + zoomFactor * level)
|
||||
}
|
||||
|
||||
return baseSize
|
||||
}
|
||||
|
||||
function fitIntoVisibleArea (point) {
|
||||
/* Here we check the boundaries of the resulting points, so they dont go out of the visible area. */
|
||||
|
||||
if (point.x > thisObject.visibleArea.bottomRight.x + 1) {
|
||||
point.x = thisObject.visibleArea.bottomRight.x + 1;
|
||||
}
|
||||
|
||||
if (point.x < thisObject.visibleArea.topLeft.x - 1) {
|
||||
point.x = thisObject.visibleArea.topLeft.x - 1;
|
||||
}
|
||||
|
||||
if (point.y > thisObject.visibleArea.bottomRight.y + 1) {
|
||||
point.y = thisObject.visibleArea.bottomRight.y + 1;
|
||||
}
|
||||
|
||||
if (point.y < thisObject.visibleArea.topLeft.y - 1) {
|
||||
point.y = thisObject.visibleArea.topLeft.y - 1;
|
||||
}
|
||||
|
||||
return point;
|
||||
if (point.x > thisObject.visibleArea.bottomRight.x + 1) {
|
||||
point.x = thisObject.visibleArea.bottomRight.x + 1
|
||||
}
|
||||
|
||||
|
||||
function zoomThisPoint(point, level) {
|
||||
|
||||
let zoomFactor = increment; // + increment * thisObject.zoomLevel / 100;
|
||||
|
||||
if (level === undefined) {
|
||||
|
||||
point.x = point.x * (1 + zoomFactor * thisObject.zoomLevel) + offset.x;
|
||||
point.y = point.y * (1 + zoomFactor * thisObject.zoomLevel) + offset.y;
|
||||
|
||||
} else {
|
||||
|
||||
point.x = point.x * (1 + zoomFactor * level) + offset.x;
|
||||
point.y = point.y * (1 + zoomFactor * level) + offset.y;
|
||||
|
||||
}
|
||||
|
||||
return point;
|
||||
if (point.x < thisObject.visibleArea.topLeft.x - 1) {
|
||||
point.x = thisObject.visibleArea.topLeft.x - 1
|
||||
}
|
||||
|
||||
function unzoomThisPoint(pointWithZoom, level) {
|
||||
|
||||
let pointWithoutZoom;
|
||||
let zoomFactor = increment; // + increment * thisObject.zoomLevel / 100;
|
||||
|
||||
if (level === undefined) {
|
||||
|
||||
pointWithoutZoom = {
|
||||
x: (pointWithZoom.x - offset.x) / (1 + zoomFactor * thisObject.zoomLevel),
|
||||
y: (pointWithZoom.y - offset.y) / (1 + zoomFactor * thisObject.zoomLevel)
|
||||
};
|
||||
|
||||
} else {
|
||||
|
||||
pointWithoutZoom = {
|
||||
x: (pointWithZoom.x - offset.x) / (1 + zoomFactor * level),
|
||||
y: (pointWithZoom.y - offset.y) / (1 + zoomFactor * level)
|
||||
};
|
||||
|
||||
}
|
||||
return pointWithoutZoom;
|
||||
|
||||
if (point.y > thisObject.visibleArea.bottomRight.y + 1) {
|
||||
point.y = thisObject.visibleArea.bottomRight.y + 1
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
function isThisPointVisible(point) {
|
||||
|
||||
if (visibleArea === undefined) {
|
||||
|
||||
getVisibleArea();
|
||||
|
||||
}
|
||||
|
||||
if (point.x < visibleArea.topLeft.x || point.x > visibleArea.bottomRight.x || point.y < visibleArea.topLeft.y || point.y > visibleArea.bottomRight.y) {
|
||||
return false;
|
||||
} else {
|
||||
return true;
|
||||
}
|
||||
|
||||
if (point.y < thisObject.visibleArea.topLeft.y - 1) {
|
||||
point.y = thisObject.visibleArea.topLeft.y - 1
|
||||
}
|
||||
|
||||
return point
|
||||
}
|
||||
|
||||
function draw() {
|
||||
function zoomThisPoint (point, level) {
|
||||
let zoomFactor = increment // + increment * thisObject.zoomLevel / 100;
|
||||
|
||||
if (level === undefined) {
|
||||
point.x = point.x * (1 + zoomFactor * thisObject.zoomLevel) + offset.x
|
||||
point.y = point.y * (1 + zoomFactor * thisObject.zoomLevel) + offset.y
|
||||
} else {
|
||||
point.x = point.x * (1 + zoomFactor * level) + offset.x
|
||||
point.y = point.y * (1 + zoomFactor * level) + offset.y
|
||||
}
|
||||
|
||||
return point
|
||||
}
|
||||
|
||||
function unzoomThisPoint (pointWithZoom, level) {
|
||||
let pointWithoutZoom
|
||||
let zoomFactor = increment // + increment * thisObject.zoomLevel / 100;
|
||||
|
||||
if (level === undefined) {
|
||||
pointWithoutZoom = {
|
||||
x: (pointWithZoom.x - offset.x) / (1 + zoomFactor * thisObject.zoomLevel),
|
||||
y: (pointWithZoom.y - offset.y) / (1 + zoomFactor * thisObject.zoomLevel)
|
||||
}
|
||||
} else {
|
||||
pointWithoutZoom = {
|
||||
x: (pointWithZoom.x - offset.x) / (1 + zoomFactor * level),
|
||||
y: (pointWithZoom.y - offset.y) / (1 + zoomFactor * level)
|
||||
}
|
||||
}
|
||||
return pointWithoutZoom
|
||||
}
|
||||
|
||||
function isThisPointVisible (point) {
|
||||
if (visibleArea === undefined) {
|
||||
getVisibleArea()
|
||||
}
|
||||
|
||||
if (point.x < visibleArea.topLeft.x || point.x > visibleArea.bottomRight.x || point.y < visibleArea.topLeft.y || point.y > visibleArea.bottomRight.y) {
|
||||
return false
|
||||
} else {
|
||||
return true
|
||||
}
|
||||
}
|
||||
|
||||
function draw () {
|
||||
/*
|
||||
drawGrid(10);
|
||||
drawGrid(1);
|
||||
drawGrid(0.1);
|
||||
*/
|
||||
}
|
||||
|
||||
function drawGrid (step) {
|
||||
let squareWidth = (thisObject.visibleArea.bottomRight.x - thisObject.visibleArea.bottomLeft.x) / step
|
||||
squareWidth = squareWidth + squareWidth * increment * thisObject.zoomLevel
|
||||
|
||||
let startingX = offset.x - Math.trunc(offset.x / squareWidth) * squareWidth
|
||||
let startingY = offset.y - Math.trunc(offset.y / squareWidth) * squareWidth
|
||||
let lineWidth = 10 / step + 10 / step * increment * thisObject.zoomLevel
|
||||
|
||||
if (lineWidth < 0.5) {
|
||||
return
|
||||
}
|
||||
|
||||
function drawGrid(step) {
|
||||
|
||||
let squareWidth = (thisObject.visibleArea.bottomRight.x - thisObject.visibleArea.bottomLeft.x) / step;
|
||||
squareWidth = squareWidth + squareWidth * increment * thisObject.zoomLevel;
|
||||
|
||||
let startingX = offset.x - Math.trunc(offset.x / squareWidth) * squareWidth;
|
||||
let startingY = offset.y - Math.trunc(offset.y / squareWidth) * squareWidth;
|
||||
let lineWidth = 10 / step + 10 / step * increment * thisObject.zoomLevel;
|
||||
|
||||
if (lineWidth < 0.5) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (lineWidth > 2) {
|
||||
lineWidth = 2;
|
||||
}
|
||||
|
||||
browserCanvasContext.beginPath();
|
||||
|
||||
for (var i = startingX; i < thisObject.visibleArea.bottomRight.x; i = i + squareWidth) {
|
||||
|
||||
for (var j = startingY; j < thisObject.visibleArea.bottomRight.y; j = j + squareWidth) {
|
||||
|
||||
let point1 = {
|
||||
x: thisObject.visibleArea.bottomLeft.x,
|
||||
y: j
|
||||
};
|
||||
|
||||
let point2 = {
|
||||
x: thisObject.visibleArea.bottomRight.x,
|
||||
y: j
|
||||
};
|
||||
|
||||
browserCanvasContext.moveTo(point1.x, point1.y);
|
||||
browserCanvasContext.lineTo(point2.x, point2.y);
|
||||
}
|
||||
|
||||
let point3 = {
|
||||
x: i,
|
||||
y: thisObject.visibleArea.topLeft.y
|
||||
};
|
||||
|
||||
let point4 = {
|
||||
x: i,
|
||||
y: thisObject.visibleArea.bottomLeft.y
|
||||
};
|
||||
|
||||
browserCanvasContext.moveTo(point3.x, point3.y);
|
||||
browserCanvasContext.lineTo(point4.x, point4.y);
|
||||
}
|
||||
browserCanvasContext.closePath();
|
||||
browserCanvasContext.strokeStyle = 'rgba(150, 150, 150, 0.' + Math.trunc(lineWidth + 1) + ')';
|
||||
|
||||
browserCanvasContext.lineWidth = lineWidth;
|
||||
|
||||
browserCanvasContext.stroke();
|
||||
if (lineWidth > 2) {
|
||||
lineWidth = 2
|
||||
}
|
||||
|
||||
browserCanvasContext.beginPath()
|
||||
|
||||
for (var i = startingX; i < thisObject.visibleArea.bottomRight.x; i = i + squareWidth) {
|
||||
for (var j = startingY; j < thisObject.visibleArea.bottomRight.y; j = j + squareWidth) {
|
||||
let point1 = {
|
||||
x: thisObject.visibleArea.bottomLeft.x,
|
||||
y: j
|
||||
}
|
||||
|
||||
let point2 = {
|
||||
x: thisObject.visibleArea.bottomRight.x,
|
||||
y: j
|
||||
}
|
||||
|
||||
browserCanvasContext.moveTo(point1.x, point1.y)
|
||||
browserCanvasContext.lineTo(point2.x, point2.y)
|
||||
}
|
||||
|
||||
let point3 = {
|
||||
x: i,
|
||||
y: thisObject.visibleArea.topLeft.y
|
||||
}
|
||||
|
||||
let point4 = {
|
||||
x: i,
|
||||
y: thisObject.visibleArea.bottomLeft.y
|
||||
}
|
||||
|
||||
browserCanvasContext.moveTo(point3.x, point3.y)
|
||||
browserCanvasContext.lineTo(point4.x, point4.y)
|
||||
}
|
||||
browserCanvasContext.closePath()
|
||||
browserCanvasContext.strokeStyle = 'rgba(150, 150, 150, 0.' + Math.trunc(lineWidth + 1) + ')'
|
||||
|
||||
browserCanvasContext.lineWidth = lineWidth
|
||||
|
||||
browserCanvasContext.stroke()
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
+9
-11
@@ -1,12 +1,10 @@
|
||||
function newVolumeBar() {
|
||||
function newVolumeBar () {
|
||||
var volumeBar = {
|
||||
amountBuy: 0,
|
||||
amountSell: 0,
|
||||
begin: undefined,
|
||||
end: undefined
|
||||
}
|
||||
|
||||
var volumeBar = {
|
||||
amountBuy: 0,
|
||||
amountSell: 0,
|
||||
begin: undefined,
|
||||
end: undefined
|
||||
};
|
||||
|
||||
return volumeBar;
|
||||
|
||||
}
|
||||
return volumeBar
|
||||
}
|
||||
+16
-18
@@ -1,20 +1,18 @@
|
||||
|
||||
function newWebDebugLog() {
|
||||
|
||||
function newWebDebugLog () {
|
||||
let thisObject = {
|
||||
write: write,
|
||||
fileName: undefined
|
||||
}
|
||||
|
||||
let thisObject = {
|
||||
write: write,
|
||||
fileName: undefined
|
||||
return thisObject
|
||||
|
||||
function write (pText) {
|
||||
console.log(spacePad(thisObject.fileName, 50) + ' : ' + pText)
|
||||
|
||||
function spacePad (str, max) {
|
||||
str = str.toString()
|
||||
return str.length < max ? spacePad(' ' + str, max) : str
|
||||
}
|
||||
|
||||
return thisObject;
|
||||
|
||||
function write(pText) {
|
||||
|
||||
console.log(spacePad(thisObject.fileName, 50) + " : " + pText);
|
||||
|
||||
function spacePad(str, max) {
|
||||
str = str.toString();
|
||||
return str.length < max ? spacePad(" " + str, max) : str;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user