From fe3cb743238fa2854fe49002531411e97c13eb6b Mon Sep 17 00:00:00 2001 From: Luis Fernando Molina Date: Fri, 2 Mar 2018 21:47:28 +0100 Subject: [PATCH] All progress bars working --- .vs/AAWebPlatform/v15/.suo | Bin 75776 -> 75776 bytes ProductCard.js | 229 ++++++++++++++++++++++++++++++++----- Storage.js | 18 +-- TimelineChart.js | 33 +++++- 4 files changed, 240 insertions(+), 40 deletions(-) diff --git a/.vs/AAWebPlatform/v15/.suo b/.vs/AAWebPlatform/v15/.suo index 03b4c7d61ac132e5b98770119a74dabbc4ef2477..c9f151a87a432e48b9ba45fe31e38554cd89c162 100644 GIT binary patch delta 1178 zcmb`FT}YEr7{_h-Il^l3nxxsf89>%t#5EbR~76 zJ{J+0!W$?EgWRD&=psr%>>>p%iHH#?louj+p+v6d>?4c}y6B7_&&PSr^Zd`dFFj4*b+QB2AvC!n_rxq###h0v_ZK9h}}0pYa{v_H^tWvW=thV}r$m2nLv2(RT@ zvXCOgj#MJWNG-C}f62-=RP`zq@6M}XuEh*K{XF#CEoMIPE!9TSnr++6mwKNLG~Oac z*45}HT9S;LTyy-qq8bAVoBFzFmvn*h+RPIKCY5%!zDJ{yj8w81f_4*Sriu`ejtEi} zg@&+`Igjh8mhe{m-;1|ozS<$e#A89C(PEn4CBCIFW6;YsPbw3FO(KmJalPA%G?5}q z@-^Ug{W$@A?z(7p`&HPwTSJ29Oo_~NB}9U)T<>LcPI1RaDVPnJtg_>?l9_IX^3_KC z@F_S!Et8<(@inNQ(ZTAPg$zZa^Uo5&_DKZ$q5;MRM_}x|0ZfBu;o?v!j4uU1%(a1M z^eFVQedH0I@Up=03z|e^GJ-_b)vDhctHC=}Ds@xv441*j5gl`lOc3cdh5k`1D;Qgl zOMXFUadqAZ23O?z9_+!NY0VQ-Q*Otf^jrsCsWqbD;p7|BgkM~c<%ckX40^#ZMkT$h^Q=kI8w5REME$Hu&nH6Sz{+Q-r*wU$R@%Wg6CKgw_bdccBj9o7LReL$ zwqYO-TtW_UL5pB3sE8#PVwM%Lf=aacF`vDc!-SAyF2hJFl7OTj+mTYbA{-+`72Ut- z;^GSKAJ8k!-|)>_FHNHJ~l(_t@x1u}Ks+W{Vz1m*JtvPLq|h0PQl) z^E#4*A$Gt&!sb3+k$Atc{-^Y<0#8izT>5UJWy!kDMd1vss5p26`a~XP-1}+3eUSLwH8H=FP-Ek&+MjxsZJg>Rx~R-J zEZdL^;fx|G?Rgi?B*9iGfl9}hN${w|Q|SmgzZ0O23ZUz4`6880@;uExvy`VX;o&A@ zYYle=9*nfX>eB?UFBzeF+yafm*B~@<3hcMyVd|<3V~;H$4ef)ZdwMuMD?_K!4t;Zp z5EzxoAXayPZQMqC1N}Tqu1x3&#}OpDPE`NWUeIv03RaaX-8@(WE?8DdsW&u0lpY?) za2nhUs%h@n6P5psp!ftB9x0(^!8pS>F>UL3QN3#e z|9?8@4ahJ#ngVHa)AafKbOLujXyDnH8|)KXf+LoHn!GJGa=*%dU4TPFsUW?uz;v(% zyvthfz4XD2g?PwZl)I5*GQIKKf-;HH=W diff --git a/ProductCard.js b/ProductCard.js index 2b6c5a439..b15de8e22 100644 --- a/ProductCard.js +++ b/ProductCard.js @@ -1,5 +1,7 @@ function newProductCard() { + const CONSOLE_LOG = true; + var thisObject = { container: undefined, draw: draw, @@ -8,15 +10,37 @@ bot: undefined, product: undefined, code: undefined, - onFileLoaded: onFileLoaded, + onMarketFileLoaded: onMarketFileLoaded, + onDailyFileLoaded: onDailyFileLoaded, + onSingleFileLoaded: onSingleFileLoaded, getContainer: getContainer, // returns the inner most container that holds the point received by parameter. initialize: initialize }; - let progressBar = { + let LOADING_FILL_STYLE = 'rgba(234, 143, 23, 0.5)'; + let LOADED_FILL_STYLE = 'rgba(45, 232, 28, 0.5)'; + let UNLOADED_FILL_STYLE = 'rgba(226, 226, 226, 0.5)'; + + let LOADING_STROKE_STYLE = 'rgba(234, 143, 23, 0.5)'; + let LOADED_STROKE_STYLE = 'rgba(150, 150, 150, 0.5)'; + let UNLOADED_STROKE_STYLE = 'rgba(226, 226, 226, 0.5)'; + + let marketFileProgressBar = { value: 100, - fillStyle: 'rgba(226, 226, 226, 1)', - strokeStyle: 'rgba(86, 86, 86, 1)' + fillStyle: UNLOADED_FILL_STYLE, + strokeStyle: UNLOADED_STROKE_STYLE + }; + + let dailyFileProgressBar = { + value: 100, + fillStyle: UNLOADED_FILL_STYLE, + strokeStyle: UNLOADED_STROKE_STYLE + }; + + let singleFileProgressBar = { + value: 100, + fillStyle: UNLOADED_FILL_STYLE, + strokeStyle: UNLOADED_STROKE_STYLE }; return thisObject; @@ -42,7 +66,7 @@ this.container.frame.position = position; this.container.frame.width = 280; - this.container.frame.height = 45; + this.container.frame.height = 60; /* We retrieve the locally stored status of the Product */ @@ -87,26 +111,85 @@ } - function onFileLoaded(event) { + function onMarketFileLoaded(event) { - if (event.totalValue === event.totalValue) { + if (event.currentValue === event.totalValue) { - progressBar = { + marketFileProgressBar = { value: 100, - fillStyle: 'rgba((56, 209, 6, 1)', - strokeStyle: 'rgba(40, 99, 21, 1)' + fillStyle: LOADED_FILL_STYLE, + strokeStyle: LOADED_STROKE_STYLE }; } else { - progressBar = { - value: event.totalValue * 100 / event.totalValue, - fillStyle: 'rgba(234, 143, 23, 1)', - strokeStyle: 'rgba(122, 79, 23, 1)' + marketFileProgressBar = { + value: Math.trunc(event.currentValue * 100 / event.totalValue), + fillStyle: LOADING_FILL_STYLE, + strokeStyle: LOADING_STROKE_STYLE }; } + if (CONSOLE_LOG === true) { + + console.log("ProductCard onMarketFileLoaded Value = " + marketFileProgressBar.value + "% for " + thisObject.code); + + } + } + + function onDailyFileLoaded(event) { + + if (event.currentValue === event.totalValue) { + + dailyFileProgressBar = { + value: 100, + fillStyle: LOADED_FILL_STYLE, + strokeStyle: LOADED_STROKE_STYLE + }; + + } else { + + dailyFileProgressBar = { + value: Math.trunc(event.currentValue * 100 / event.totalValue), + fillStyle: LOADING_FILL_STYLE, + strokeStyle: LOADING_STROKE_STYLE + }; + + } + + if (CONSOLE_LOG === true) { + + console.log("ProductCard onDailyFileLoaded Value = " + dailyFileProgressBar.value + "% for " + thisObject.code); + + } + } + + function onSingleFileLoaded(event) { + + if (event.currentValue === event.totalValue) { + + singleFileProgressBar = { + value: 100, + fillStyle: LOADED_FILL_STYLE, + strokeStyle: LOADED_STROKE_STYLE + }; + + } else { + + singleFileProgressBar = { + value: Math.trunc(event.currentValue * 100 / event.totalValue), + fillStyle: LOADING_FILL_STYLE, + strokeStyle: LOADING_STROKE_STYLE + }; + + } + + if (CONSOLE_LOG === true) { + + console.log("ProductCard onSingleFileLoaded Value = " + singleFileProgressBar.value + "% for " + thisObject.code); + + } } function buttonPressed(event) { @@ -198,7 +281,7 @@ labelPoint = { x: 20, - y: thisObject.container.frame.height - 35 + y: thisObject.container.frame.height - 45 }; labelPoint = thisObject.container.frame.frameThisPoint(labelPoint); @@ -212,7 +295,7 @@ labelPoint = { x: 20, - y: thisObject.container.frame.height - 20 + y: thisObject.container.frame.height - 30 }; labelPoint = thisObject.container.frame.frameThisPoint(labelPoint); @@ -226,7 +309,7 @@ labelPoint = { x: 20, - y: thisObject.container.frame.height - 5 + y: thisObject.container.frame.height - 15 }; labelPoint = thisObject.container.frame.frameThisPoint(labelPoint); @@ -234,7 +317,12 @@ browserCanvasContext.fillStyle = 'rgba(60, 60, 60, 0.50)'; browserCanvasContext.fillText(label, labelPoint.x, labelPoint.y); - /* We draw here the progress bar. */ + let point1; + let point2; + let point3; + let point4; + + /* We draw here the Market Progress Bar. */ point1 = { x: 0, @@ -242,18 +330,18 @@ }; point2 = { - x: thisObject.container.frame.width * progressBar.value / 100, + x: thisObject.container.frame.width * marketFileProgressBar.value / 100, y: thisObject.container.frame.height - 1 }; point3 = { - x: thisObject.container.frame.width * progressBar.value / 100, - y: thisObject.container.frame.height - 5 + x: thisObject.container.frame.width * marketFileProgressBar.value / 100, + y: thisObject.container.frame.height - 3 }; point4 = { x: 0, - y: thisObject.container.frame.height - 5 + y: thisObject.container.frame.height - 3 }; /* Now the transformations. */ @@ -265,17 +353,102 @@ browserCanvasContext.beginPath(); browserCanvasContext.moveTo(point1.x, point1.y); - browserCanvasContext.moveTo(point2.x, point2.y); - browserCanvasContext.moveTo(point3.x, point3.y); - browserCanvasContext.moveTo(point4.x, point4.y); + browserCanvasContext.lineTo(point2.x, point2.y); + browserCanvasContext.lineTo(point3.x, point3.y); + browserCanvasContext.lineTo(point4.x, point4.y); browserCanvasContext.closePath(); - browserCanvasContext.fillStyle = progressBar.fillStyle; - browserCanvasContext.strokeStyle = progressBar.strokeStyle; + browserCanvasContext.fillStyle = marketFileProgressBar.fillStyle; + browserCanvasContext.strokeStyle = marketFileProgressBar.strokeStyle; browserCanvasContext.fill(); - browserCanvasContext.lineWidth = 1; + browserCanvasContext.lineWidth = 0.1; browserCanvasContext.stroke(); + /* We draw here the Daily Progress Bar. */ + + point1 = { + x: 0, + y: thisObject.container.frame.height - 4 + }; + + point2 = { + x: thisObject.container.frame.width * dailyFileProgressBar.value / 100, + y: thisObject.container.frame.height - 4 + }; + + point3 = { + x: thisObject.container.frame.width * dailyFileProgressBar.value / 100, + y: thisObject.container.frame.height - 6 + }; + + point4 = { + x: 0, + y: thisObject.container.frame.height - 6 + }; + + /* Now the transformations. */ + + point1 = thisObject.container.frame.frameThisPoint(point1); + point2 = thisObject.container.frame.frameThisPoint(point2); + point3 = thisObject.container.frame.frameThisPoint(point3); + point4 = thisObject.container.frame.frameThisPoint(point4); + + browserCanvasContext.beginPath(); + browserCanvasContext.moveTo(point1.x, point1.y); + browserCanvasContext.lineTo(point2.x, point2.y); + browserCanvasContext.lineTo(point3.x, point3.y); + browserCanvasContext.lineTo(point4.x, point4.y); + browserCanvasContext.closePath(); + + browserCanvasContext.fillStyle = dailyFileProgressBar.fillStyle; + browserCanvasContext.strokeStyle = dailyFileProgressBar.strokeStyle; + + browserCanvasContext.fill(); + browserCanvasContext.lineWidth = 0.1; + browserCanvasContext.stroke(); + + /* We draw here the Single File Progress Bar. */ + + point1 = { + x: 0, + y: thisObject.container.frame.height - 7 + }; + + point2 = { + x: thisObject.container.frame.width * singleFileProgressBar.value / 100, + y: thisObject.container.frame.height - 7 + }; + + point3 = { + x: thisObject.container.frame.width * singleFileProgressBar.value / 100, + y: thisObject.container.frame.height - 9 + }; + + point4 = { + x: 0, + y: thisObject.container.frame.height - 9 + }; + + /* Now the transformations. */ + + point1 = thisObject.container.frame.frameThisPoint(point1); + point2 = thisObject.container.frame.frameThisPoint(point2); + point3 = thisObject.container.frame.frameThisPoint(point3); + point4 = thisObject.container.frame.frameThisPoint(point4); + + browserCanvasContext.beginPath(); + browserCanvasContext.moveTo(point1.x, point1.y); + browserCanvasContext.lineTo(point2.x, point2.y); + browserCanvasContext.lineTo(point3.x, point3.y); + browserCanvasContext.lineTo(point4.x, point4.y); + browserCanvasContext.closePath(); + + browserCanvasContext.fillStyle = singleFileProgressBar.fillStyle; + browserCanvasContext.strokeStyle = singleFileProgressBar.strokeStyle; + + browserCanvasContext.fill(); + browserCanvasContext.lineWidth = 0.1; + browserCanvasContext.stroke(); } } \ No newline at end of file diff --git a/Storage.js b/Storage.js index 38e7ba693..bbfa0244f 100644 --- a/Storage.js +++ b/Storage.js @@ -1,5 +1,5 @@  -function newStorage() { +function newStorage(pName) { const CONSOLE_LOG = false; @@ -24,15 +24,15 @@ function newStorage() { } thisObject.eventHandler = newEventHandler(); - + + /* We name the event Handler to easy debugging. */ + + thisObject.eventHandler.name = "Storage-" + pName; + return thisObject; function initialize(pDevTeam, pBot, pProduct, pExchange, pMarket, pDatetime, pTimePeriod, callBackFunction) { - /* We name the event Handler to easy debugging. */ - - thisObject.eventHandler.name = "Storage-" + pDevTeam.codeName + "-" + pBot.codeName + "-" + pProduct.codeName - if (CONSOLE_LOG === true) { console.log("Storage initialize for " + pDevTeam.codeName + "-" + pBot.codeName + "-" + pProduct.codeName); @@ -104,7 +104,7 @@ function newStorage() { currentValue: thisObject.fileCache.getFilesLoaded() } - thisObject.eventHandler.raiseEvent('Storage File Loaded', event); + thisObject.eventHandler.raiseEvent('Market File Loaded', event); if (event.currentValue === event.totalValue) { @@ -127,7 +127,7 @@ function newStorage() { currentValue: thisObject.fileCursorCache.getFilesLoaded() } - thisObject.eventHandler.raiseEvent('Storage File Loaded', event); + thisObject.eventHandler.raiseEvent('Daily File Loaded', event); if (event.currentValue === event.totalValue) { @@ -150,7 +150,7 @@ function newStorage() { currentValue: 1 } - thisObject.eventHandler.raiseEvent('Storage File Loaded', event); + thisObject.eventHandler.raiseEvent('Single File Loaded', event); if (event.currentValue === event.totalValue) { diff --git a/TimelineChart.js b/TimelineChart.js index 5511171f2..8fd398b44 100644 --- a/TimelineChart.js +++ b/TimelineChart.js @@ -118,16 +118,43 @@ function newTimelineChart() { /* Before Initializing a Plotter, we need the Storage it will use, loaded with the files it will initially need. */ - let storage = newStorage(); + let objName = pProductCard.devTeam.codeName + "-" + pProductCard.bot.codeName + "-" + pProductCard.product.codeName; + let storage = newStorage(objName); /* Before Initializing the Storage, we will put put the Product Card to listen to the events the storage will raise every time a file is loaded, - so that the UI can somehow show this. + so that the UI can somehow show this. There are different types of events. */ - storage.eventHandler.listenToEvent('Storage File Loaded', pProductCard.onFileLoaded); + for (let i = 0; i < pProductCard.product.sets.length; i++) { + + let thisSet = pProductCard.product.sets[i]; + + switch (thisSet.type) { + case 'Market Files': { + + storage.eventHandler.listenToEvent('Market File Loaded', pProductCard.onMarketFileLoaded); + + } + break; + + case 'Daily Files': { + + storage.eventHandler.listenToEvent('Daily File Loaded', pProductCard.onDailyFileLoaded); + + } + break; + + case 'Single File': { + + storage.eventHandler.listenToEvent('Single File Loaded', pProductCard.onSingleFileLoaded);; + + } + break; + } + } storage.initialize(pProductCard.devTeam, pProductCard.bot, pProductCard.product, DEFAULT_EXCHANGE, DEFAULT_MARKET, datetime, timePeriod, onStorageInitialized) ;