Calculating after cursor fully loaded

This commit is contained in:
Luis Fernando Molina committed 2018-03-03 18:29:39 +01:00
1 parent 976393bb94
commit 27628c93a0
3 files changed
+58 -100

No files matched your search

Binary file not shown.
+31 -52
View File
@@ -11,6 +11,10 @@
setDatetime: setDatetime,
draw: draw,
/* Events declared outside the plotter. */
onDailyFileLoaded: onDailyFileLoaded,
// Secondary functions and properties.
currentCandle: undefined,
@@ -95,64 +99,37 @@
function setTimePeriod(pTimePeriod) {
timePeriod = pTimePeriod;
if (timePeriod !== pTimePeriod) {
if (timePeriod >= _1_HOUR_IN_MILISECONDS) {
timePeriod = pTimePeriod;
let newMarketFile = fileCache.getFile(pTimePeriod);
if (timePeriod >= _1_HOUR_IN_MILISECONDS) {
if (newMarketFile !== undefined) {
let newMarketFile = fileCache.getFile(pTimePeriod);
marketFile = newMarketFile;
if (newMarketFile !== undefined) {
recalculate();
marketFile = newMarketFile;
recalculate();
}
}
} else {
} else {
let newFileCursor = fileCursorCache.getFileCursor(pTimePeriod);
fileCursorCache.setTimePeriod(pTimePeriod);
fileCursorCache.setDatetime(datetime);
let newFileCursor = fileCursorCache.getFileCursor(pTimePeriod);
if (newFileCursor !== undefined) {
fileCursor = newFileCursor;
recalculate();
if (newFileCursor !== undefined) {
fileCursor = newFileCursor;
recalculate();
}
}
}
if (timePeriod === _1_HOUR_IN_MILISECONDS) {
fileCursorCache.setTimePeriod(pTimePeriod);
fileCursorCache.setDatetime(datetime);
}
}
function setDatetime(newDatetime) {
function setDatetime(pDatetime) {
/* If there is a change in the day, then we take some actions, otherwise, we dont. */
datetime = pDatetime;
let currentDate = Math.trunc(datetime.valueOf() / ONE_DAY_IN_MILISECONDS);
let newDate = Math.trunc(newDatetime.valueOf() / ONE_DAY_IN_MILISECONDS);
datetime = newDatetime;
if (currentDate !== newDate) {
if (timePeriod <= _1_HOUR_IN_MILISECONDS) {
fileCursorCache.setDatetime(newDatetime);
}
}
}
function positionAtDatetime(newDatetime) {
@@ -217,19 +194,21 @@
}
}
function onDailyFileLoaded(event) {
if (event.currentValue === event.totalValue) {
/* This happens only when all of the files in the cursor have been loaded. */
recalculate()
}
}
function draw() {
this.container.frame.draw();
if (timePeriod < _1_HOUR_IN_MILISECONDS) {
if (Math.random() * 1000 > 995) {
recalculate();
}
}
plotChart();
}
+27 -48
View File
@@ -2,6 +2,10 @@
let thisObject = {
/* Events declared outside the plotter. */
onDailyFileLoaded: onDailyFileLoaded,
// Main functions and properties.
initialize: initialize,
@@ -93,63 +97,49 @@
function setTimePeriod(pTimePeriod) {
timePeriod = pTimePeriod;
if (timePeriod !== pTimePeriod) {
if (timePeriod >= _1_HOUR_IN_MILISECONDS) {
timePeriod = pTimePeriod;
let newMarketFile = fileCache.getFile(pTimePeriod);
if (timePeriod >= _1_HOUR_IN_MILISECONDS) {
if (newMarketFile !== undefined) {
let newMarketFile = fileCache.getFile(pTimePeriod);
marketFile = newMarketFile;
if (newMarketFile !== undefined) {
recalculate();
marketFile = newMarketFile;
recalculate();
}
}
} else {
} else {
let newFileCursor = fileCursorCache.getFileCursor(pTimePeriod);
fileCursorCache.setTimePeriod(pTimePeriod);
fileCursorCache.setDatetime(datetime);
let newFileCursor = fileCursorCache.getFileCursor(pTimePeriod);
if (newFileCursor !== undefined) {
fileCursor = newFileCursor;
recalculate();
if (newFileCursor !== undefined) {
fileCursor = newFileCursor;
recalculate();
}
}
}
}
if (timePeriod === _1_HOUR_IN_MILISECONDS) {
function setDatetime(pDatetime) {
fileCursorCache.setTimePeriod(pTimePeriod);
fileCursorCache.setDatetime(datetime);
}
datetime = pDatetime;
}
function setDatetime(newDatetime) {
function onDailyFileLoaded(event) {
/* If there is a change in the day, then we take some actions, otherwise, we dont. */
if (event.currentValue === event.totalValue) {
let currentDate = Math.trunc(datetime.valueOf() / ONE_DAY_IN_MILISECONDS);
let newDate = Math.trunc(newDatetime.valueOf() / ONE_DAY_IN_MILISECONDS);
/* This happens only when all of the files in the cursor have been loaded. */
datetime = newDatetime;
recalculateScaleX();
recalculate();
recalculateScaleY();
if (currentDate !== newDate) {
if (timePeriod <= _1_HOUR_IN_MILISECONDS) {
fileCursorCache.setDatetime(newDatetime);
}
}
}
@@ -157,17 +147,6 @@
this.container.frame.draw();
if (timePeriod < _1_HOUR_IN_MILISECONDS) {
if (Math.random() * 1000 > 995) {
recalculateScaleX();
recalculate();
recalculateScaleY();
}
}
plotChart();
}