From 105768ba176aecb47c4162702bda5808b74318e8 Mon Sep 17 00:00:00 2001 From: Luis Fernando Molina Date: Thu, 1 Mar 2018 17:17:42 +0100 Subject: [PATCH] Timeline chart re implemented --- .vs/AAWebPlatform/v15/.suo | Bin 57856 -> 69632 bytes Dashboard.js | 5 +- Panels/ProductsPanel.js | 19 ++--- TimelineChart.js | 171 ++++++++++++++++++++++--------------- 4 files changed, 112 insertions(+), 83 deletions(-) diff --git a/.vs/AAWebPlatform/v15/.suo b/.vs/AAWebPlatform/v15/.suo index b1f087a1c425a90196ea0b0f448a34a49bfc7f6a..a0cd512c9a6a75028dc9cc99c7d4f15a3824e1d9 100644 GIT binary patch delta 2116 zcmds%ZA_C_6vumSTcGu6eV~HKTVJfa*bT~SAOb5dF^El}BFZvgVko=!rd|(HcU& z39Slw2}wl6d>vW|k>QFeH@O(S#~8JTW_O~EN6Ha1sMW?DHK7@iD@Ix9c@LDRPm!n~U~aXNK3I)RQ}4%6HJGEabjQ#uMXC@d zG)39WyU+`tNOWVphPAae^u>uDO|%%`YLrB3C)~E^IE;uBgjXG!a3>bILxB>sCPa;h zLx@I*g%-3q$U)=)BHAH_3trab#va)a5mC{oc$m`UYI@Oo7ion>%^OlQQ7B@NBm|sV zYf>^gDTomnhtzSq}BSd0j_Dg%P+eTq$3%NW}Y!%;mgg;wv;s z+|;;4SONt%&*%A7UnyAJL4Kx!?WlLAv>+LP?w1PZrgAPwEd~Zu(rzzBqZHJm$ zozO9w%B7(d0!`xvD7lbMB0wIrc+dEuWytkZdImVo`sK3sq$hi39_`A9pGPuun<5($ z-6MPBnu2Fr|2c|Ae0nMw7G5LDf$8Ccur`v2Ru9YfWbgTepld#Bgirbm?!oepV|0IEdHY7u279A6XajMtMl$ z!qQOsx(wLIlzl|mMFO4Qmcwh~GPb4yJmYrg7~kV-u&B7@^ZRNxNm(OhtrTXv<6+>w z7Lto(o-;j1pu>lC`&P(iVE_t)U8XERS+5XCxk-E)!{fgY3$R5iT&hdpr8lk-Xg*WO z3vb^f&ybLvLQHigv=3Q=0%CI%`~f}J-~Hw9#I!&mtpxAZcgyPkfvOh%NlH*`)q?io tug_8j3IgnZAq6E1sKU)xhWn}vwXQS*K5X9&lkKK|g`Gxumt4=A`Uiix1kYz3+JGXyGx5bpo&%+QnI6a}U!vrDoJqXl2Vg8~fLT7bsyttL<`F`FS zxj5`miCx896?ZWqi!4$31cjDrGaS8dU{!X976MzJfWQ7~wAc^+3r#eJaW1??3JFh0 zl^00E3quist-BReev!%_(8SAGeS~LmiYCq+Ah1+h0JSkAD>*k!<Z38d+5xm{3l&I#ZA_M?fvm&_zt`Jx zQvZ72vEi}dk^aHD!?|rgt;TyEdu^vMeFv=1YQ+6NXaxbphV8U}5LV}lSu%$I!537% zNTOp-Sc#a6(qWv&TcPI z*p`W&d*q%X?^4l@3sdZIM*)?;qVktiexJ(U(Zr&SW@>y%1vdsQ5Kd{q>NT>4#2q3Z zr115?1e+K*P2@k7iNg;ylpw^A3|EdRIJ^8dA2YpmMwOdC8^CeHW>T%K=)=6NUK zozek+OjV>S6$p=}_1-x>^iJL4NJs#_v_6UB#|H HNRWR3Yi{@S diff --git a/Dashboard.js b/Dashboard.js index 9ebc5bb3a..09dc0897a 100644 --- a/Dashboard.js +++ b/Dashboard.js @@ -104,7 +104,10 @@ var viewPort = newViewPort(); - +const PRODUCT_CARD_STATUS = { + ON: 'on', + OFF: 'off' +}; /* Here we list the valid Time Periods: */ diff --git a/Panels/ProductsPanel.js b/Panels/ProductsPanel.js index 8ee72b81e..2e50326d7 100644 --- a/Panels/ProductsPanel.js +++ b/Panels/ProductsPanel.js @@ -3,11 +3,6 @@ function newProductsPanel() { - const PRODUCT_STATUS = { - ON: 'on', - OFF: 'off' - }; - var thisObject = { container: undefined, getOnProductCards: getOnProductCards, @@ -107,7 +102,7 @@ function newProductsPanel() { } else { - productCard.status = PRODUCT_STATUS.ON; + productCard.status = PRODUCT_CARD_STATUS.ON; } @@ -131,7 +126,7 @@ function newProductsPanel() { for (let i = 0; i < productCards.length; i++) { - if (productCards[i].status = PRODUCT_STATUS.ON) { + if (productCards[i].status = PRODUCT_CARD_STATUS.ON) { onProducts.push(productCards[i]); } @@ -154,7 +149,7 @@ function newProductsPanel() { } - return PRODUCT_STATUS.OFF; + return PRODUCT_CARD_STATUS.OFF; } function getContainer(point) { @@ -197,12 +192,12 @@ function newProductsPanel() { switch (productCards[index].status) { - case PRODUCT_STATUS.ON: - productCards[index].status = PRODUCT_STATUS.OFF; + case PRODUCT_CARD_STATUS.ON: + productCards[index].status = PRODUCT_CARD_STATUS.OFF; break; - case PRODUCT_STATUS.OFF: - productCards[index].status = PRODUCT_STATUS.ON; + case PRODUCT_CARD_STATUS.OFF: + productCards[index].status = PRODUCT_CARD_STATUS.ON; break; } diff --git a/TimelineChart.js b/TimelineChart.js index 5434ffd2d..40edf74af 100644 --- a/TimelineChart.js +++ b/TimelineChart.js @@ -1,15 +1,14 @@  function newTimelineChart() { - let layers = []; + let activePlotters = []; let plotArea = newPlotArea(); - let timePeriod = INITIAL_TIME_PERIOD; - var datetime; + let timePeriod = INITIAL_TIME_PERIOD; + let datetime = INITIAL_DATE; var timelineChart = { - layers: layers, setDatetime: setDatetime, container: undefined, draw: draw, @@ -34,10 +33,6 @@ function newTimelineChart() { let chartGrid; - let targetLabelFontSize = 150; - let fontSizeIncrement = 12.5; - let currentFontSize = 150; - let initializationReady = false; let currentCandlePanel; @@ -53,10 +48,9 @@ function newTimelineChart() { currentVolumePanel = currentVolumePanelToUse; orderBookPanel = orderBookPanelToUse; - productsPanel = pProductsPanel; - productsPanel.eventHandler.listenToEvent("Product Card Status Changed", onProductStatusChanged); + productsPanel.eventHandler.listenToEvent("Product Card Status Changed", onProductCardStatusChanged); marketId = market; exchangeId = exchange; @@ -70,22 +64,21 @@ function newTimelineChart() { recalculateScale(); - /* Event Subscriptions - we need this events to be fired first here and then in layers. */ + /* 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); canvas.eventHandler.listenToEvent("Drag Finished", onDragFinished); - initializeLayers(); + initializePlotters(); callBackFunction(); initializationReady = true; - } } - function initializeLayers() { + function initializePlotters() { /* Here we need to move the viewPort to the default date. */ @@ -100,8 +93,6 @@ function newTimelineChart() { viewPort.displace(displaceVector); - let layerStatus; - /* Lets get all the cards that are turned on. */ let onProductCards = productsPanel.getOnProductCards(); @@ -110,49 +101,86 @@ function newTimelineChart() { /* For each one, we will initialize the associated plotter. */ - let onProductCard = onProductCards[i]; + initializePlotter(onProductCards[i]); - let plotter = getNewPlotter(onProductCard.product.plotter.devTeam, onProductCard.product.plotter.repo, onProductCard.product.plotter.moduleName); - - plotter.container.displacement.parentDisplacement = timelineChart.container.displacement; - plotter.container.zoom.parentZoom = timelineChart.container.zoom; - plotter.container.frame.parentFrame = timelineChart.container.frame; - - plotter.container.parentContainer = timelineChart.container; - - plotter.container.frame.width = timelineChart.container.frame.width * 1; - plotter.container.frame.height = timelineChart.container.frame.height * 1; - - plotter.container.frame.position.x = timelineChart.container.frame.width / 2 - plotter.container.frame.width / 2; - plotter.container.frame.position.y = timelineChart.container.frame.height / 2 - plotter.container.frame.height / 2; - - plotter.initialize(DEFAULT_EXCHANGE, DEFAULT_MARKET, INITIAL_DATE, INITIAL_TIME_PERIOD, onInizialized); - - function onInizialized() { - - console.log(onProductCard.product.plotter.devTeam + '->' + onProductCard.product.plotter.repo + '->' + onProductCard.product.plotter.moduleName + " Initialized. "); - - try { - plotter.positionAtDatetime(INITIAL_DATE); - } catch (err) { - // If the plotter does not implement this function its ok. - } - - let layer = { - onProductCard: onProductCard, - plotter: plotter - }; - - timelineChart.layers.push(layer); - - } } } - function onProductStatusChanged(pProductCard) { + function initializePlotter(pProductCard) { + let plotter = getNewPlotter(pProductCard.product.plotter.devTeam, pProductCard.product.plotter.repo, pProductCard.product.plotter.moduleName); + plotter.container.displacement.parentDisplacement = timelineChart.container.displacement; + plotter.container.zoom.parentZoom = timelineChart.container.zoom; + plotter.container.frame.parentFrame = timelineChart.container.frame; + plotter.container.parentContainer = timelineChart.container; + + plotter.container.frame.width = timelineChart.container.frame.width * 1; + plotter.container.frame.height = timelineChart.container.frame.height * 1; + + plotter.container.frame.position.x = timelineChart.container.frame.width / 2 - plotter.container.frame.width / 2; + plotter.container.frame.position.y = timelineChart.container.frame.height / 2 - plotter.container.frame.height / 2; + + plotter.initialize(DEFAULT_EXCHANGE, DEFAULT_MARKET, datetime, timePeriod, onInizialized); + + function onInizialized() { + + console.log(pProductCard.product.plotter.devTeam + '->' + pProductCard.product.plotter.repo + '->' + pProductCard.product.plotter.moduleName + " Initialized. "); + + try { + plotter.positionAtDatetime(INITIAL_DATE); + } catch (err) { + // If the plotter does not implement this function its ok. + } + + let activePlotter = { + productCard: pProductCard, + plotter: plotter + }; + + activePlotters.push(activePlotter); + + } + } + + function onProductCardStatusChanged(pProductCard) { + + if (pProductCard.status === PRODUCT_CARD_STATUS.ON) { + + /* Lets see if we can find the Plotter of this card on our Active Plotters list, other wise we will initialize it */ + + let found = false; + + for (let i = 0; i < activePlotters.length; i++) { + + if (activePlotters[i].productCard.code === pProductCard.code) { + + found = true; + + } + + } + + if (found === false) { + + initializePlotter(pProductCard); + + } + + } else { + + /* If the plotter of this card is on our Active Plotters list, then we remove it. */ + + for (let i = 0; i < activePlotters.length; i++) { + + if (activePlotters[i].productCard.code === pProductCard.code) { + + activePlotters.splice(i, 1); // Delete item from array. + + } + } + } } function onZoomChanged(event) { @@ -167,10 +195,10 @@ function newTimelineChart() { if (timePeriod !== currentTimePeriod) { - for (var i = 0; i < timelineChart.layers.length; i++) { + for (var i = 0; i < activePlotters.length; i++) { - let layer = timelineChart.layers[i]; - layer.plotter.setTimePeriod(timePeriod); + let activePlotter = activePlotters[i]; + activePlotter.plotter.setTimePeriod(timePeriod); } } @@ -226,10 +254,10 @@ function newTimelineChart() { datetime = newDate; - for (var i = 0; i < timelineChart.layers.length; i++) { + for (var i = 0; i < activePlotters.length; i++) { - let layer = timelineChart.layers[i]; - layer.plotter.setDatetime(datetime); + let activePlotter = activePlotters[i]; + activePlotter.plotter.setDatetime(datetime); } @@ -256,17 +284,19 @@ function newTimelineChart() { } - function setDatetime(newDatetime) { + function setDatetime(pDatetime) { + + datetime = pDatetime; if (timelineChart.container.frame.isInViewPort()) { - for (var i = 0; i < timelineChart.layers.length; i++) { + for (var i = 0; i < activePlotters.length; i++) { - let layer = timelineChart.layers[i]; - layer.plotter.setDatetime(newDatetime); + let activePlotter = activePlotters[i]; + activePlotter.plotter.setDatetime(pDatetime); - if (layer.plotter.positionAtDatetime !== undefined) { - layer.plotter.positionAtDatetime(newDatetime); + if (activePlotter.plotter.positionAtDatetime !== undefined) { + activePlotter.plotter.positionAtDatetime(pDatetime); } } @@ -283,15 +313,12 @@ function newTimelineChart() { chartGrid.draw(timelineChart.container, plotArea); - for (var i = 0; i < this.layers.length; i++) { + for (var i = 0; i < this.activePlotters.length; i++) { - let layer = this.layers[i]; - layer.plotter.draw(); + let activePlotter = this.activePlotters[i]; + activePlotter.plotter.draw(); } - - - } } @@ -339,6 +366,10 @@ function newTimelineChart() { function drawBackground() { + let targetLabelFontSize = 150; + let fontSizeIncrement = 12.5; + let currentFontSize = 150; + var market = markets.get(marketId); var label = market.assetA + " " + market.assetB;