ma vbytes
This commit is contained in:
		
							parent
							
								
									5302b27d55
								
							
						
					
					
						commit
						76621464f1
					
				| @ -37,6 +37,7 @@ export class IncomingTransactionsGraphComponent implements OnInit, OnChanges, On | |||||||
|   }; |   }; | ||||||
|   windowPreference: string; |   windowPreference: string; | ||||||
|   chartInstance: any = undefined; |   chartInstance: any = undefined; | ||||||
|  |   MA: number[][] = []; | ||||||
|   weightMode: boolean = false; |   weightMode: boolean = false; | ||||||
|   rateUnitSub: Subscription; |   rateUnitSub: Subscription; | ||||||
| 
 | 
 | ||||||
| @ -62,6 +63,7 @@ export class IncomingTransactionsGraphComponent implements OnInit, OnChanges, On | |||||||
|       return; |       return; | ||||||
|     } |     } | ||||||
|     this.windowPreference = this.windowPreferenceOverride ? this.windowPreferenceOverride : this.storageService.getValue('graphWindowPreference'); |     this.windowPreference = this.windowPreferenceOverride ? this.windowPreferenceOverride : this.storageService.getValue('graphWindowPreference'); | ||||||
|  |     this.MA = this.calculateMA(this.data.series[0]); | ||||||
|     this.mountChart(); |     this.mountChart(); | ||||||
|   } |   } | ||||||
| 
 | 
 | ||||||
| @ -72,7 +74,101 @@ export class IncomingTransactionsGraphComponent implements OnInit, OnChanges, On | |||||||
|     this.isLoading = false; |     this.isLoading = false; | ||||||
|   } |   } | ||||||
| 
 | 
 | ||||||
|  |   /// calculate the moving average of maData
 | ||||||
|  |   calculateMA(maData): number[][] { | ||||||
|  |     //update const variables that are not changed
 | ||||||
|  |     const ma: number[][] = []; | ||||||
|  |     let sum = 0; | ||||||
|  |     let i = 0; | ||||||
|  |     const len = maData.length; | ||||||
|  | 
 | ||||||
|  |     //Adjust window length based on the length of the data
 | ||||||
|  |     //5% appeared as a good amount from tests
 | ||||||
|  |     //TODO: make this a text box in the UI
 | ||||||
|  |     const maWindowLen = Math.ceil(len * 0.05); | ||||||
|  | 
 | ||||||
|  |     //calculate the center of the moving average window
 | ||||||
|  |     const center = Math.floor(maWindowLen / 2); | ||||||
|  | 
 | ||||||
|  |     //calculate the centered moving average
 | ||||||
|  |     for (i = center; i < len - center; i++) { | ||||||
|  |       sum = 0; | ||||||
|  |       //build out ma as we loop through the data
 | ||||||
|  |       ma[i] = []; | ||||||
|  |       ma[i].push(maData[i][0]); | ||||||
|  |       for (let j = i - center; j <= i + center; j++) { | ||||||
|  |         sum += maData[j][1]; | ||||||
|  |       } | ||||||
|  | 
 | ||||||
|  |       ma[i].push(sum / maWindowLen); | ||||||
|  |     } | ||||||
|  | 
 | ||||||
|  |     //return the moving average array
 | ||||||
|  |     return ma; | ||||||
|  |   } | ||||||
|  | 
 | ||||||
|   mountChart(): void { |   mountChart(): void { | ||||||
|  |     //create an array for the echart series
 | ||||||
|  |     //similar to how it is done in mempool-graph.component.ts
 | ||||||
|  |     const seriesGraph = []; | ||||||
|  |     seriesGraph.push({ | ||||||
|  |       zlevel: 0, | ||||||
|  |       name: 'data', | ||||||
|  |       data: this.data.series[0], | ||||||
|  |       type: 'line', | ||||||
|  |       smooth: false, | ||||||
|  |       showSymbol: false, | ||||||
|  |       symbol: 'none', | ||||||
|  |       lineStyle: { | ||||||
|  |         width: 3, | ||||||
|  |       }, | ||||||
|  |       markLine: { | ||||||
|  |         silent: true, | ||||||
|  |         symbol: 'none', | ||||||
|  |         lineStyle: { | ||||||
|  |           color: '#fff', | ||||||
|  |           opacity: 1, | ||||||
|  |           width: 2, | ||||||
|  |         }, | ||||||
|  |         data: [{ | ||||||
|  |           yAxis: 1667, | ||||||
|  |           label: { | ||||||
|  |             show: false, | ||||||
|  |             color: '#ffffff', | ||||||
|  |           } | ||||||
|  |         }], | ||||||
|  |       } | ||||||
|  |     }, | ||||||
|  |     { | ||||||
|  |       zlevel: 0, | ||||||
|  |       name: 'MA', | ||||||
|  |       data: this.MA, | ||||||
|  |       type: 'line', | ||||||
|  |       smooth: false, | ||||||
|  |       showSymbol: false, | ||||||
|  |       symbol: 'none', | ||||||
|  |       lineStyle: { | ||||||
|  |         width: 1, | ||||||
|  |         color: "white", | ||||||
|  |       }, | ||||||
|  |       markLine: { | ||||||
|  |         silent: true, | ||||||
|  |         symbol: 'none', | ||||||
|  |         lineStyle: { | ||||||
|  |           color: '#fff', | ||||||
|  |           opacity: 1, | ||||||
|  |           width: 2, | ||||||
|  |         }, | ||||||
|  |         data: [{ | ||||||
|  |           yAxis: 1667, | ||||||
|  |           label: { | ||||||
|  |             show: false, | ||||||
|  |             color: '#ffffff', | ||||||
|  |           } | ||||||
|  |         }], | ||||||
|  |       } | ||||||
|  |     }); | ||||||
|  | 
 | ||||||
|     this.mempoolStatsChartOption = { |     this.mempoolStatsChartOption = { | ||||||
|       grid: { |       grid: { | ||||||
|         height: this.height, |         height: this.height, | ||||||
| @ -122,16 +218,20 @@ export class IncomingTransactionsGraphComponent implements OnInit, OnChanges, On | |||||||
|           type: 'line', |           type: 'line', | ||||||
|         }, |         }, | ||||||
|         formatter: (params: any) => { |         formatter: (params: any) => { | ||||||
|           const axisValueLabel: string = formatterXAxis(this.locale, this.windowPreference, params[0].axisValue);          |           const axisValueLabel: string = formatterXAxis(this.locale, this.windowPreference, params[0].axisValue); | ||||||
|           const colorSpan = (color: string) => `<span class="indicator" style="background-color: ` + color + `"></span>`; |           const colorSpan = (color: string) => `<span class="indicator" style="background-color: ` + color + `"></span>`; | ||||||
|           let itemFormatted = '<div class="title">' + axisValueLabel + '</div>'; |           let itemFormatted = '<div class="title">' + axisValueLabel + '</div>'; | ||||||
|           params.map((item: any, index: number) => { |           params.map((item: any, index: number) => { | ||||||
|             if (index < 26) { | 
 | ||||||
|               itemFormatted += `<div class="item">
 |             //Do no include MA in tooltip legend!
 | ||||||
|                 <div class="indicator-container">${colorSpan(item.color)}</div> |             if (item.seriesName !== 'MA') { | ||||||
|                 <div class="grow"></div> |               if (index < 26) { | ||||||
|                 <div class="value">${formatNumber(this.weightMode ? item.value[1] * 4 : item.value[1], this.locale, '1.0-0')} <span class="symbol">${this.weightMode ? 'WU' : 'vB'}/s</span></div> |                 itemFormatted += `<div class="item">
 | ||||||
|               </div>`;
 |                   <div class="indicator-container">${colorSpan(item.color)}</div> | ||||||
|  |                   <div class="grow"></div> | ||||||
|  |                   <div class="value">${formatNumber(item.value[1], this.locale, '1.0-0')}<span class="symbol">vB/s</span></div> | ||||||
|  |                 </div>`;
 | ||||||
|  |               } | ||||||
|             } |             } | ||||||
|           }); |           }); | ||||||
|           return `<div class="tx-wrapper-tooltip-chart ${(this.template === 'advanced') ? 'tx-wrapper-tooltip-chart-advanced' : ''}">${itemFormatted}</div>`; |           return `<div class="tx-wrapper-tooltip-chart ${(this.template === 'advanced') ? 'tx-wrapper-tooltip-chart-advanced' : ''}">${itemFormatted}</div>`; | ||||||
| @ -171,35 +271,7 @@ export class IncomingTransactionsGraphComponent implements OnInit, OnChanges, On | |||||||
|           } |           } | ||||||
|         } |         } | ||||||
|       }, |       }, | ||||||
|       series: [ |       series: seriesGraph, | ||||||
|         { |  | ||||||
|           zlevel: 0, |  | ||||||
|           data: this.data.series[0], |  | ||||||
|           type: 'line', |  | ||||||
|           smooth: false, |  | ||||||
|           showSymbol: false, |  | ||||||
|           symbol: 'none', |  | ||||||
|           lineStyle: { |  | ||||||
|             width: 3, |  | ||||||
|           }, |  | ||||||
|           markLine: { |  | ||||||
|             silent: true, |  | ||||||
|             symbol: 'none', |  | ||||||
|             lineStyle: { |  | ||||||
|               color: '#fff', |  | ||||||
|               opacity: 1, |  | ||||||
|               width: 2, |  | ||||||
|             }, |  | ||||||
|             data: [{ |  | ||||||
|               yAxis: 1667, |  | ||||||
|               label: { |  | ||||||
|                 show: false, |  | ||||||
|                 color: '#ffffff', |  | ||||||
|               } |  | ||||||
|             }], |  | ||||||
|           } |  | ||||||
|         }, |  | ||||||
|       ], |  | ||||||
|       visualMap: { |       visualMap: { | ||||||
|         show: false, |         show: false, | ||||||
|         top: 50, |         top: 50, | ||||||
|  | |||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user