From e54b4186f0e1568fa2dd491a974aacfa9d9bbc30 Mon Sep 17 00:00:00 2001 From: Luis Fernando Molina Date: Sat, 3 Mar 2018 12:09:56 +0100 Subject: [PATCH] plotArea refactored Part 1 --- .vs/Plotters-Candles-Volumes/v15/.suo | Bin 22528 -> 20480 bytes Candles.js | 41 ++++++++++++++------------ Volumes.js | 38 +++++++++++++----------- 3 files changed, 42 insertions(+), 37 deletions(-) diff --git a/.vs/Plotters-Candles-Volumes/v15/.suo b/.vs/Plotters-Candles-Volumes/v15/.suo index 51998f4f15d066eb9f0b3c58ff9272314e3c522a..e5084fecadc0b623c010c5c4a17aacc6c30883d9 100644 GIT binary patch delta 232 zcmZqJz}T>Wae{#Y69W_oFfgzHnT$aE@Bjb*AW>!@-Wa%^aq@r0T-FE2S}xw(T*&mB znN?s@o3)zAgCm&`r-28<-gq1@9s1~U0|71Z0mB}T%7dE?SG%#*H!r#Ee0}=)q z1(V)fB6Nk3gAGMQM1j>!Su XMw6>tKMBI*K(r(fD{QWHYvu$10q;oT delta 324 zcmZozz}T>Xae{#Y0}Kc-FmM6cj6nSF|Ns9WVGw&`;CjZ%{~2>xKkP1#b=q9W^qZNL z!Q4YxW^*B15F;-mQ0adKpgIseSx`Y`^B49I)=7#wlS_CnurLE9fb7jBd>5E`*nk`k zWR)dCR~R{XP((y7Nb`V9;zSWOxFaw*!G&w`WM_@ZO^$7o100PeTRBaEiEVOT%P1@h z)Byuafex2oV3^G4+yPcw<@!mG6XY2vPyw+w*Sa-xPI6f*tO^qb(rOSkicTH4yw(AG M5F4bEd66Fz06Ozq!2kdN diff --git a/Candles.js b/Candles.js index 5e8cb0d86..8c03872e7 100644 --- a/Candles.js +++ b/Candles.js @@ -23,7 +23,7 @@ container.initialize(); thisObject.container = container; - let plotArea = newPlotArea(); // Needed to be able to plot on the timeline, otherwise not. + let timeLineCoordinateSystem = newTimeLineCoordinateSystem(); // Needed to be able to plot on the timeline, otherwise not. let timePeriod; // This will hold the current Time Period the user is at. let datetime; // This will hold the current Datetime the user is at. @@ -55,7 +55,6 @@ marketFile = fileCache.getFile(ONE_DAY_IN_MILISECONDS); // This file is the one processed faster. recalculateScale(); - recalculate(); /* Now we set the right files according to current Period. */ @@ -67,6 +66,10 @@ viewPort.eventHandler.listenToEvent("Zoom Changed", onZoomChanged); canvas.eventHandler.listenToEvent("Drag Finished", onDragFinished); + /* Get ready for plotting. */ + + recalculate(); + callBackFunction(); } @@ -167,7 +170,7 @@ y: candles[i].open }; - targetPoint = plotArea.inverseTransform(targetPoint, thisObject.container.frame.height); + targetPoint = timeLineCoordinateSystem.inverseTransform(targetPoint, thisObject.container.frame.height); targetPoint = transformThisPoint(targetPoint, thisObject.container); let targetMax = { @@ -175,7 +178,7 @@ y: candles[i].max }; - targetMax = plotArea.inverseTransform(targetMax, thisObject.container.frame.height); + targetMax = timeLineCoordinateSystem.inverseTransform(targetMax, thisObject.container.frame.height); targetMax = transformThisPoint(targetMax, thisObject.container); let targetMin = { @@ -183,7 +186,7 @@ y: candles[i].min }; - targetMin = plotArea.inverseTransform(targetMin, thisObject.container.frame.height); + targetMin = timeLineCoordinateSystem.inverseTransform(targetMin, thisObject.container.frame.height); targetMin = transformThisPoint(targetMin, thisObject.container); let center = { @@ -254,8 +257,8 @@ let daysOnSides = getSideDays(timePeriod); - let leftDate = getDateFromPoint(viewPort.visibleArea.topLeft, thisObject.container, plotArea); - let rightDate = getDateFromPoint(viewPort.visibleArea.topRight, thisObject.container, plotArea); + let leftDate = getDateFromPoint(viewPort.visibleArea.topLeft, thisObject.container, timeLineCoordinateSystem); + let rightDate = getDateFromPoint(viewPort.visibleArea.topRight, thisObject.container, timeLineCoordinateSystem); let dateDiff = rightDate.valueOf() - leftDate.valueOf(); @@ -342,8 +345,8 @@ let daysOnSides = getSideDays(timePeriod); - let leftDate = getDateFromPoint(viewPort.visibleArea.topLeft, thisObject.container, plotArea); - let rightDate = getDateFromPoint(viewPort.visibleArea.topRight, thisObject.container, plotArea); + let leftDate = getDateFromPoint(viewPort.visibleArea.topLeft, thisObject.container, timeLineCoordinateSystem); + let rightDate = getDateFromPoint(viewPort.visibleArea.topRight, thisObject.container, timeLineCoordinateSystem); let dateDiff = rightDate.valueOf() - leftDate.valueOf(); @@ -397,7 +400,7 @@ if (marketFile === undefined) { return; } // We need the market file to be loaded to make the calculation. - if (plotArea.maxValue > 0) { return; } // Already calculated. + if (timeLineCoordinateSystem.maxValue > 0) { return; } // Already calculated. let minValue = { x: EARLIEST_DATE.valueOf(), @@ -410,7 +413,7 @@ }; - plotArea.initialize( + timeLineCoordinateSystem.initialize( minValue, maxValue, thisObject.container.frame.width, @@ -466,10 +469,10 @@ y: candle.close }; - candlePoint1 = plotArea.inverseTransform(candlePoint1, thisObject.container.frame.height); - candlePoint2 = plotArea.inverseTransform(candlePoint2, thisObject.container.frame.height); - candlePoint3 = plotArea.inverseTransform(candlePoint3, thisObject.container.frame.height); - candlePoint4 = plotArea.inverseTransform(candlePoint4, thisObject.container.frame.height); + candlePoint1 = timeLineCoordinateSystem.inverseTransform(candlePoint1, thisObject.container.frame.height); + candlePoint2 = timeLineCoordinateSystem.inverseTransform(candlePoint2, thisObject.container.frame.height); + candlePoint3 = timeLineCoordinateSystem.inverseTransform(candlePoint3, thisObject.container.frame.height); + candlePoint4 = timeLineCoordinateSystem.inverseTransform(candlePoint4, thisObject.container.frame.height); candlePoint1 = transformThisPoint(candlePoint1, thisObject.container); candlePoint2 = transformThisPoint(candlePoint2, thisObject.container); @@ -505,10 +508,10 @@ y: candle.min }; - stickPoint1 = plotArea.inverseTransform(stickPoint1, thisObject.container.frame.height); - stickPoint2 = plotArea.inverseTransform(stickPoint2, thisObject.container.frame.height); - stickPoint3 = plotArea.inverseTransform(stickPoint3, thisObject.container.frame.height); - stickPoint4 = plotArea.inverseTransform(stickPoint4, thisObject.container.frame.height); + stickPoint1 = timeLineCoordinateSystem.inverseTransform(stickPoint1, thisObject.container.frame.height); + stickPoint2 = timeLineCoordinateSystem.inverseTransform(stickPoint2, thisObject.container.frame.height); + stickPoint3 = timeLineCoordinateSystem.inverseTransform(stickPoint3, thisObject.container.frame.height); + stickPoint4 = timeLineCoordinateSystem.inverseTransform(stickPoint4, thisObject.container.frame.height); stickPoint1 = transformThisPoint(stickPoint1, thisObject.container); stickPoint2 = transformThisPoint(stickPoint2, thisObject.container); diff --git a/Volumes.js b/Volumes.js index ad1520b2c..4561bcda1 100644 --- a/Volumes.js +++ b/Volumes.js @@ -18,8 +18,8 @@ container.initialize(); thisObject.container = container; - let plotArea = newPlotArea(); // Needed to be able to plot on the timeline, otherwise not. - let plotAreaFrame = newPlotArea(); // This chart uses this extra object. + let timeLineCoordinateSystem = newTimeLineCoordinateSystem(); // Needed to be able to plot on the timeline, otherwise not. + let plotAreaFrame = newTimeLineCoordinateSystem(); // This chart uses this extra object. let timePeriod; // This will hold the current Time Period the user is at. let datetime; // This will hold the current Datetime the user is at. @@ -52,10 +52,6 @@ scaleFile = fileCache.getFile(ONE_DAY_IN_MILISECONDS); // This file is the one processed faster. - recalculateScaleX(); - recalculate(); - recalculateScaleY(); - /* Now we set the right files according to current Period. */ marketFile = fileCache.getFile(pTimePeriod); @@ -66,6 +62,12 @@ viewPort.eventHandler.listenToEvent("Zoom Changed", onZoomChanged); canvas.eventHandler.listenToEvent("Drag Finished", onDragFinished); + /* Get ready for plotting. */ + + recalculateScaleX(); + recalculate(); + recalculateScaleY(); + callBackFunction(); } @@ -193,8 +195,8 @@ let daysOnSides = getSideDays(timePeriod); - let leftDate = getDateFromPoint(viewPort.visibleArea.topLeft, thisObject.container, plotArea); - let rightDate = getDateFromPoint(viewPort.visibleArea.topRight, thisObject.container, plotArea); + let leftDate = getDateFromPoint(viewPort.visibleArea.topLeft, thisObject.container, timeLineCoordinateSystem); + let rightDate = getDateFromPoint(viewPort.visibleArea.topRight, thisObject.container, timeLineCoordinateSystem); let dateDiff = rightDate.valueOf() - leftDate.valueOf(); @@ -270,8 +272,8 @@ let daysOnSides = getSideDays(timePeriod); - let leftDate = getDateFromPoint(viewPort.visibleArea.topLeft, thisObject.container, plotArea); - let rightDate = getDateFromPoint(viewPort.visibleArea.topRight, thisObject.container, plotArea); + let leftDate = getDateFromPoint(viewPort.visibleArea.topLeft, thisObject.container, timeLineCoordinateSystem); + let rightDate = getDateFromPoint(viewPort.visibleArea.topRight, thisObject.container, timeLineCoordinateSystem); let dateDiff = rightDate.valueOf() - leftDate.valueOf(); @@ -321,7 +323,7 @@ x: MAX_PLOTABLE_DATE.valueOf() }; - plotArea.initializeX( + timeLineCoordinateSystem.initializeX( minValue, maxValue, thisObject.container.frame.width @@ -349,7 +351,7 @@ maxValue.y = getMaxVolume() / (timePeriodRatio / 10); - plotArea.initializeY( + timeLineCoordinateSystem.initializeY( minValue, maxValue, viewPort.visibleArea.bottomRight.y - viewPort.visibleArea.topLeft.y @@ -466,13 +468,13 @@ if (volumePointA1.y > viewPort.visibleArea.bottomLeft.y && frameHeightInViewPort > visibleHeight * 2 / 3) { - if (calculateBuys(plotArea, visibleHeight) === false) { continue; } // We snap t to the view port. + if (calculateBuys(timeLineCoordinateSystem, visibleHeight) === false) { continue; } // We snap t to the view port. /* Now we set the real value of y. */ volumePointA1.y = viewPort.visibleArea.bottomRight.y; - volumePointA2.y = viewPort.visibleArea.bottomRight.y - volume.amountBuy * plotArea.scale.y; - volumePointA3.y = viewPort.visibleArea.bottomRight.y - volume.amountBuy * plotArea.scale.y; + volumePointA2.y = viewPort.visibleArea.bottomRight.y - volume.amountBuy * timeLineCoordinateSystem.scale.y; + volumePointA3.y = viewPort.visibleArea.bottomRight.y - volume.amountBuy * timeLineCoordinateSystem.scale.y; volumePointA4.y = viewPort.visibleArea.bottomRight.y; } @@ -520,13 +522,13 @@ if (volumePointB1.y < viewPort.visibleArea.topLeft.y && frameHeightInViewPort > visibleHeight * 2 / 3) { - calculateSells(plotArea, visibleHeight); // We snap it to the view port. + calculateSells(timeLineCoordinateSystem, visibleHeight); // We snap it to the view port. /* Now we set the real value of y. */ volumePointB1.y = viewPort.visibleArea.topLeft.y; - volumePointB2.y = viewPort.visibleArea.topLeft.y + volume.amountSell * plotArea.scale.y; - volumePointB3.y = viewPort.visibleArea.topLeft.y + volume.amountSell * plotArea.scale.y; + volumePointB2.y = viewPort.visibleArea.topLeft.y + volume.amountSell * timeLineCoordinateSystem.scale.y; + volumePointB3.y = viewPort.visibleArea.topLeft.y + volume.amountSell * timeLineCoordinateSystem.scale.y; volumePointB4.y = viewPort.visibleArea.topLeft.y; }