Autoformatter applied on all js files
This commit is contained in:
1 parent
72c1017b20
commit
c627aedcf6
59 files changed
+9087
-10892
No files matched your search
+113
-127
@@ -1,180 +1,166 @@
|
||||
/*
|
||||
/*
|
||||
|
||||
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,
|
||||
draw: draw,
|
||||
charts: [],
|
||||
getContainer: getContainer, // returns the inner most container that holds the point received by parameter.
|
||||
initialize: initialize
|
||||
}
|
||||
|
||||
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...
|
||||
let productsPanelHandle // ... also to request a reference to the object for the cases we need it.
|
||||
|
||||
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 initialize(callBackFunction) {
|
||||
|
||||
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);
|
||||
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);
|
||||
productsPanelHandle = canvas.panelsSpace.createNewPanel('Products Panel')
|
||||
let productsPanel = canvas.panelsSpace.getPanel(productsPanelHandle)
|
||||
|
||||
let iteration = 0;
|
||||
let iteration = 0
|
||||
|
||||
/* 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 timelineChart = newTimelineChart()
|
||||
|
||||
timelineChart.container.displacement.parentDisplacement = thisObject.container.displacement;
|
||||
timelineChart.container.frame.parentFrame = thisObject.container.frame;
|
||||
timelineChart.container.displacement.parentDisplacement = thisObject.container.displacement
|
||||
timelineChart.container.frame.parentFrame = thisObject.container.frame
|
||||
|
||||
timelineChart.container.parentContainer = thisObject.container;
|
||||
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.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.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, onDefaultMarketInitialized);
|
||||
timelineChart.initialize(productsPanel, onDefaultMarketInitialized)
|
||||
|
||||
iteration++;
|
||||
iteration++
|
||||
|
||||
function onDefaultMarketInitialized(err) {
|
||||
function onDefaultMarketInitialized (err) {
|
||||
if (INFO_LOG === true) { logger.write('[INFO] initialize -> onDefaultMarketInitialized -> Entering function.') }
|
||||
|
||||
if (INFO_LOG === true) { logger.write("[INFO] initialize -> onDefaultMarketInitialized -> Entering function."); }
|
||||
if (err.result !== GLOBAL.DEFAULT_OK_RESPONSE.result) {
|
||||
if (INFO_LOG === true) { logger.write('[INFO] initialize -> onDefaultMarketInitialized -> Initialization of the only market failed.') }
|
||||
|
||||
if (err.result !== GLOBAL.DEFAULT_OK_RESPONSE.result) {
|
||||
callBackFunction(err)
|
||||
return
|
||||
}
|
||||
|
||||
if (INFO_LOG === true) { logger.write("[INFO] initialize -> onDefaultMarketInitialized -> Initialization of the only market failed."); }
|
||||
thisObject.charts.push(timelineChart)
|
||||
|
||||
callBackFunction(err);
|
||||
return;
|
||||
}
|
||||
controlPanel.container.eventHandler.listenToEvent('Datetime Changed', timelineChart.setDatetime, undefined)
|
||||
timelineChart.container.eventHandler.listenToEvent('Datetime Changed', controlPanel.setDatetime)
|
||||
|
||||
thisObject.charts.push(timelineChart);
|
||||
callBackFunction(GLOBAL.DEFAULT_OK_RESPONSE)
|
||||
|
||||
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);
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
// initializeTheRestOfTheMarkets();
|
||||
}
|
||||
|
||||
function draw() {
|
||||
function initializeTheRestOfTheMarkets () {
|
||||
if (INFO_LOG === true) { logger.write('[INFO] initialize -> initializeTheRestOfTheMarkets -> Entering function.') }
|
||||
|
||||
this.container.frame.draw(false, false);
|
||||
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)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function draw () {
|
||||
this.container.frame.draw(false, false)
|
||||
|
||||
/* When we draw a time machine, that means also to draw all the charts in it. */
|
||||
|
||||
for (let i = 0; i < this.charts.length; i++) {
|
||||
|
||||
let chart = this.charts[i];
|
||||
chart.draw();
|
||||
|
||||
}
|
||||
for (let i = 0; i < this.charts.length; i++) {
|
||||
let chart = this.charts[i]
|
||||
chart.draw()
|
||||
}
|
||||
}
|
||||
|
||||
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
|
||||
|
||||
/* 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
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user