fitfuction and refactoring
This commit is contained in:
1 parent
3f86b9d7db
commit
f26c20423c
2 files changed
+57
-33
No files matched your search
+31
-19
@@ -13,6 +13,7 @@
|
||||
initialize: initialize,
|
||||
finalize: finalize,
|
||||
container: undefined,
|
||||
fitFunction: undefined,
|
||||
getContainer: getContainer,
|
||||
setTimeFrame: setTimeFrame,
|
||||
setDatetime: setDatetime,
|
||||
@@ -34,7 +35,7 @@
|
||||
thisObject.container = newContainer()
|
||||
thisObject.container.initialize(MODULE_NAME)
|
||||
|
||||
let timeLineCoordinateSystem = newTimeLineCoordinateSystem(); // Needed to be able to plot on the timeline, otherwise not.
|
||||
let coordinateSystem = newCoordinateSystem(); // Needed to be able to plot on the timeline, otherwise not.
|
||||
|
||||
let timeFrame; // This will hold the current Time Frame the user is at.
|
||||
let datetime; // This will hold the current Datetime the user is at.
|
||||
@@ -81,6 +82,7 @@
|
||||
marketFile = undefined;
|
||||
fileCursor = undefined;
|
||||
|
||||
thisObject.fitFunction = undefined
|
||||
} catch (err) {
|
||||
|
||||
if (ERROR_LOG === true) { logger.write("[ERROR] finalize -> err = " + err.stack); }
|
||||
@@ -242,7 +244,7 @@
|
||||
y: candles[i].open
|
||||
};
|
||||
|
||||
targetPoint = timeLineCoordinateSystem.transformThisPoint(targetPoint);
|
||||
targetPoint = coordinateSystem.transformThisPoint(targetPoint);
|
||||
targetPoint = transformThisPoint(targetPoint, thisObject.container);
|
||||
|
||||
let targetMax = {
|
||||
@@ -250,7 +252,7 @@
|
||||
y: candles[i].max
|
||||
};
|
||||
|
||||
targetMax = timeLineCoordinateSystem.transformThisPoint(targetMax);
|
||||
targetMax = coordinateSystem.transformThisPoint(targetMax);
|
||||
targetMax = transformThisPoint(targetMax, thisObject.container);
|
||||
|
||||
let targetMin = {
|
||||
@@ -258,7 +260,7 @@
|
||||
y: candles[i].min
|
||||
};
|
||||
|
||||
targetMin = timeLineCoordinateSystem.transformThisPoint(targetMin);
|
||||
targetMin = coordinateSystem.transformThisPoint(targetMin);
|
||||
targetMin = transformThisPoint(targetMin, thisObject.container);
|
||||
|
||||
let center = {
|
||||
@@ -295,7 +297,7 @@
|
||||
y: lastClose
|
||||
};
|
||||
|
||||
targetPoint = timeLineCoordinateSystem.transformThisPoint(targetPoint);
|
||||
targetPoint = coordinateSystem.transformThisPoint(targetPoint);
|
||||
targetPoint = transformThisPoint(targetPoint, thisObject.container);
|
||||
|
||||
let center = {
|
||||
@@ -385,8 +387,8 @@
|
||||
|
||||
let daysOnSides = getSideDays(timeFrame);
|
||||
|
||||
let leftDate = getDateFromPoint(viewPort.visibleArea.topLeft, thisObject.container, timeLineCoordinateSystem);
|
||||
let rightDate = getDateFromPoint(viewPort.visibleArea.topRight, thisObject.container, timeLineCoordinateSystem);
|
||||
let leftDate = getDateFromPoint(viewPort.visibleArea.topLeft, thisObject.container, coordinateSystem);
|
||||
let rightDate = getDateFromPoint(viewPort.visibleArea.topRight, thisObject.container, coordinateSystem);
|
||||
|
||||
let dateDiff = rightDate.valueOf() - leftDate.valueOf();
|
||||
|
||||
@@ -471,8 +473,8 @@
|
||||
|
||||
let daysOnSides = getSideDays(timeFrame);
|
||||
|
||||
let leftDate = getDateFromPoint(viewPort.visibleArea.topLeft, thisObject.container, timeLineCoordinateSystem);
|
||||
let rightDate = getDateFromPoint(viewPort.visibleArea.topRight, thisObject.container, timeLineCoordinateSystem);
|
||||
let leftDate = getDateFromPoint(viewPort.visibleArea.topLeft, thisObject.container, coordinateSystem);
|
||||
let rightDate = getDateFromPoint(viewPort.visibleArea.topRight, thisObject.container, coordinateSystem);
|
||||
|
||||
let dateDiff = rightDate.valueOf() - leftDate.valueOf();
|
||||
|
||||
@@ -529,7 +531,7 @@
|
||||
|
||||
try {
|
||||
|
||||
if (timeLineCoordinateSystem.maxValue > 0) { return; } // Already calculated.
|
||||
if (coordinateSystem.maxValue > 0) { return; } // Already calculated.
|
||||
|
||||
let minValue = {
|
||||
x: MIN_PLOTABLE_DATE.valueOf(),
|
||||
@@ -542,7 +544,7 @@
|
||||
};
|
||||
|
||||
|
||||
timeLineCoordinateSystem.initialize(
|
||||
coordinateSystem.initialize(
|
||||
minValue,
|
||||
maxValue,
|
||||
thisObject.container.frame.width,
|
||||
@@ -589,10 +591,10 @@
|
||||
y: candle.close
|
||||
};
|
||||
|
||||
candle.candlePoint1 = timeLineCoordinateSystem.transformThisPoint(candle.candlePoint1);
|
||||
candle.candlePoint2 = timeLineCoordinateSystem.transformThisPoint(candle.candlePoint2);
|
||||
candle.candlePoint3 = timeLineCoordinateSystem.transformThisPoint(candle.candlePoint3);
|
||||
candle.candlePoint4 = timeLineCoordinateSystem.transformThisPoint(candle.candlePoint4);
|
||||
candle.candlePoint1 = coordinateSystem.transformThisPoint(candle.candlePoint1);
|
||||
candle.candlePoint2 = coordinateSystem.transformThisPoint(candle.candlePoint2);
|
||||
candle.candlePoint3 = coordinateSystem.transformThisPoint(candle.candlePoint3);
|
||||
candle.candlePoint4 = coordinateSystem.transformThisPoint(candle.candlePoint4);
|
||||
|
||||
candle.candlePoint1 = transformThisPoint(candle.candlePoint1, thisObject.container);
|
||||
candle.candlePoint2 = transformThisPoint(candle.candlePoint2, thisObject.container);
|
||||
@@ -604,6 +606,11 @@
|
||||
candle.candlePoint3 = viewPort.fitIntoVisibleArea(candle.candlePoint3);
|
||||
candle.candlePoint4 = viewPort.fitIntoVisibleArea(candle.candlePoint4);
|
||||
|
||||
candle.candlePoint1 = thisObject.fitFunction(candle.candlePoint1);
|
||||
candle.candlePoint2 = thisObject.fitFunction(candle.candlePoint2);
|
||||
candle.candlePoint3 = thisObject.fitFunction(candle.candlePoint3);
|
||||
candle.candlePoint4 = thisObject.fitFunction(candle.candlePoint4);
|
||||
|
||||
candle.stickPoint1 = {
|
||||
x: candle.begin + timeFrame / 7 * 3.2,
|
||||
y: candle.max
|
||||
@@ -624,10 +631,10 @@
|
||||
y: candle.min
|
||||
};
|
||||
|
||||
candle.stickPoint1 = timeLineCoordinateSystem.transformThisPoint(candle.stickPoint1);
|
||||
candle.stickPoint2 = timeLineCoordinateSystem.transformThisPoint(candle.stickPoint2);
|
||||
candle.stickPoint3 = timeLineCoordinateSystem.transformThisPoint(candle.stickPoint3);
|
||||
candle.stickPoint4 = timeLineCoordinateSystem.transformThisPoint(candle.stickPoint4);
|
||||
candle.stickPoint1 = coordinateSystem.transformThisPoint(candle.stickPoint1);
|
||||
candle.stickPoint2 = coordinateSystem.transformThisPoint(candle.stickPoint2);
|
||||
candle.stickPoint3 = coordinateSystem.transformThisPoint(candle.stickPoint3);
|
||||
candle.stickPoint4 = coordinateSystem.transformThisPoint(candle.stickPoint4);
|
||||
|
||||
candle.stickPoint1 = transformThisPoint(candle.stickPoint1, thisObject.container);
|
||||
candle.stickPoint2 = transformThisPoint(candle.stickPoint2, thisObject.container);
|
||||
@@ -639,6 +646,11 @@
|
||||
candle.stickPoint3 = viewPort.fitIntoVisibleArea(candle.stickPoint3);
|
||||
candle.stickPoint4 = viewPort.fitIntoVisibleArea(candle.stickPoint4);
|
||||
|
||||
candle.stickPoint1 = thisObject.fitFunction(candle.stickPoint1);
|
||||
candle.stickPoint2 = thisObject.fitFunction(candle.stickPoint2);
|
||||
candle.stickPoint3 = thisObject.fitFunction(candle.stickPoint3);
|
||||
candle.stickPoint4 = thisObject.fitFunction(candle.stickPoint4);
|
||||
|
||||
}
|
||||
|
||||
/* On screen candles */
|
||||
|
||||
+26
-14
@@ -17,6 +17,7 @@
|
||||
initialize: initialize,
|
||||
finalize: finalize,
|
||||
container: undefined,
|
||||
fitFunction: undefined,
|
||||
getContainer: getContainer,
|
||||
setTimeFrame: setTimeFrame,
|
||||
setDatetime: setDatetime,
|
||||
@@ -29,8 +30,8 @@
|
||||
thisObject.container = newContainer()
|
||||
thisObject.container.initialize(MODULE_NAME)
|
||||
|
||||
let timeLineCoordinateSystem = newTimeLineCoordinateSystem(); // Needed to be able to plot on the timeline, otherwise not.
|
||||
let plotAreaFrame = newTimeLineCoordinateSystem(); // This chart uses this extra object.
|
||||
let coordinateSystem = newCoordinateSystem(); // Needed to be able to plot on the timeline, otherwise not.
|
||||
let plotAreaFrame = newCoordinateSystem(); // This chart uses this extra object.
|
||||
|
||||
let timeFrame; // This will hold the current Time Frame the user is at.
|
||||
let datetime; // This will hold the current Datetime the user is at.
|
||||
@@ -79,6 +80,7 @@
|
||||
marketFile = undefined;
|
||||
fileCursor = undefined;
|
||||
|
||||
thisObject.fitFunction = undefined
|
||||
} catch (err) {
|
||||
|
||||
if (ERROR_LOG === true) { logger.write("[ERROR] finalize -> err = " + err.stack); }
|
||||
@@ -303,8 +305,8 @@
|
||||
|
||||
if (fileCursor.files.size === 0) { return; } // We need to wait until there are files in the cursor
|
||||
|
||||
let leftDate = getDateFromPoint(viewPort.visibleArea.topLeft, thisObject.container, timeLineCoordinateSystem);
|
||||
let rightDate = getDateFromPoint(viewPort.visibleArea.topRight, thisObject.container, timeLineCoordinateSystem);
|
||||
let leftDate = getDateFromPoint(viewPort.visibleArea.topLeft, thisObject.container, coordinateSystem);
|
||||
let rightDate = getDateFromPoint(viewPort.visibleArea.topRight, thisObject.container, coordinateSystem);
|
||||
|
||||
let dateDiff = rightDate.valueOf() - leftDate.valueOf();
|
||||
|
||||
@@ -384,8 +386,8 @@
|
||||
|
||||
if (marketFile === undefined) { return; } // Initialization not complete yet.
|
||||
|
||||
let leftDate = getDateFromPoint(viewPort.visibleArea.topLeft, thisObject.container, timeLineCoordinateSystem);
|
||||
let rightDate = getDateFromPoint(viewPort.visibleArea.topRight, thisObject.container, timeLineCoordinateSystem);
|
||||
let leftDate = getDateFromPoint(viewPort.visibleArea.topLeft, thisObject.container, coordinateSystem);
|
||||
let rightDate = getDateFromPoint(viewPort.visibleArea.topRight, thisObject.container, coordinateSystem);
|
||||
|
||||
let dateDiff = rightDate.valueOf() - leftDate.valueOf();
|
||||
|
||||
@@ -441,7 +443,7 @@
|
||||
x: MAX_PLOTABLE_DATE.valueOf()
|
||||
};
|
||||
|
||||
timeLineCoordinateSystem.initializeX(
|
||||
coordinateSystem.initializeX(
|
||||
minValue,
|
||||
maxValue,
|
||||
thisObject.container.frame.width
|
||||
@@ -475,7 +477,7 @@
|
||||
|
||||
maxValue.y = getMaxVolume() / (timeFrameRatio / 2.5);
|
||||
|
||||
timeLineCoordinateSystem.initializeY(
|
||||
coordinateSystem.initializeY(
|
||||
minValue,
|
||||
maxValue,
|
||||
viewPort.visibleArea.bottomRight.y - viewPort.visibleArea.topLeft.y
|
||||
@@ -601,13 +603,13 @@
|
||||
|
||||
if (volumePointA1.y > viewPort.visibleArea.bottomLeft.y && frameHeightInViewPort > visibleHeight * 2 / 3) {
|
||||
|
||||
if (calculateBuys(timeLineCoordinateSystem, visibleHeight) === false) { continue; } // We snap t to the view port.
|
||||
if (calculateBuys(coordinateSystem, visibleHeight) === false) { continue; } // We snap t to the view port.
|
||||
|
||||
/* Now we set the real value of y. */
|
||||
|
||||
volumePointA1.y = viewPort.visibleArea.bottomRight.y;
|
||||
volumePointA2.y = viewPort.visibleArea.bottomRight.y - volume.amountBuy * timeLineCoordinateSystem.scale.y;
|
||||
volumePointA3.y = viewPort.visibleArea.bottomRight.y - volume.amountBuy * timeLineCoordinateSystem.scale.y;
|
||||
volumePointA2.y = viewPort.visibleArea.bottomRight.y - volume.amountBuy * coordinateSystem.scale.y;
|
||||
volumePointA3.y = viewPort.visibleArea.bottomRight.y - volume.amountBuy * coordinateSystem.scale.y;
|
||||
volumePointA4.y = viewPort.visibleArea.bottomRight.y;
|
||||
|
||||
}
|
||||
@@ -655,13 +657,13 @@
|
||||
|
||||
if (volumePointB1.y < viewPort.visibleArea.topLeft.y && frameHeightInViewPort > visibleHeight * 2 / 3) {
|
||||
|
||||
calculateSells(timeLineCoordinateSystem, visibleHeight); // We snap it to the view port.
|
||||
calculateSells(coordinateSystem, visibleHeight); // We snap it to the view port.
|
||||
|
||||
/* Now we set the real value of y. */
|
||||
|
||||
volumePointB1.y = viewPort.visibleArea.topLeft.y;
|
||||
volumePointB2.y = viewPort.visibleArea.topLeft.y + volume.amountSell * timeLineCoordinateSystem.scale.y;
|
||||
volumePointB3.y = viewPort.visibleArea.topLeft.y + volume.amountSell * timeLineCoordinateSystem.scale.y;
|
||||
volumePointB2.y = viewPort.visibleArea.topLeft.y + volume.amountSell * coordinateSystem.scale.y;
|
||||
volumePointB3.y = viewPort.visibleArea.topLeft.y + volume.amountSell * coordinateSystem.scale.y;
|
||||
volumePointB4.y = viewPort.visibleArea.topLeft.y;
|
||||
|
||||
}
|
||||
@@ -696,6 +698,16 @@
|
||||
volumePointB3 = viewPort.fitIntoVisibleArea(volumePointB3);
|
||||
volumePointB4 = viewPort.fitIntoVisibleArea(volumePointB4);
|
||||
|
||||
volumePointA1 = thisObject.fitFunction(volumePointA1);
|
||||
volumePointA2 = thisObject.fitFunction(volumePointA2);
|
||||
volumePointA3 = thisObject.fitFunction(volumePointA3);
|
||||
volumePointA4 = thisObject.fitFunction(volumePointA4);
|
||||
|
||||
volumePointB1 = thisObject.fitFunction(volumePointB1);
|
||||
volumePointB2 = thisObject.fitFunction(volumePointB2);
|
||||
volumePointB3 = thisObject.fitFunction(volumePointB3);
|
||||
volumePointB4 = thisObject.fitFunction(volumePointB4);
|
||||
|
||||
/* Everything must fit within the Frame. We know that that is equivalent to say that each bar con not be higher than the base of the opposite . */
|
||||
|
||||
if (volumePointA2.y < volumePointB1.y) {
|
||||
|
||||
Reference in new issue
Block a user