From 5b2ecac1f6a202456ff68032fd85741f3e575a1d Mon Sep 17 00:00:00 2001 From: Mononaut Date: Thu, 9 May 2024 18:00:09 +0000 Subject: [PATCH] Fix statistics graphs --- .../incoming-transactions-graph.component.ts | 23 ++++++++----------- .../mempool-graph/mempool-graph.component.ts | 18 ++++++++++----- .../src/app/dashboard/dashboard.component.ts | 4 +++- 3 files changed, 25 insertions(+), 20 deletions(-) diff --git a/frontend/src/app/components/incoming-transactions-graph/incoming-transactions-graph.component.ts b/frontend/src/app/components/incoming-transactions-graph/incoming-transactions-graph.component.ts index c456053ea..a63c166d9 100644 --- a/frontend/src/app/components/incoming-transactions-graph/incoming-transactions-graph.component.ts +++ b/frontend/src/app/components/incoming-transactions-graph/incoming-transactions-graph.component.ts @@ -66,7 +66,7 @@ export class IncomingTransactionsGraphComponent implements OnInit, OnChanges, On if (!this.data) { return; } - this.windowPreference = this.windowPreferenceOverride ? this.windowPreferenceOverride : this.storageService.getValue('graphWindowPreference'); + this.windowPreference = (this.windowPreferenceOverride ? this.windowPreferenceOverride : this.storageService.getValue('graphWindowPreference')) || '2h'; const windowSize = Math.max(10, Math.floor(this.data.series[0].length / 8)); this.MA = this.calculateMA(this.data.series[0], windowSize); if (this.outlierCappingEnabled === true) { @@ -216,22 +216,19 @@ export class IncomingTransactionsGraphComponent implements OnInit, OnChanges, On type: 'line', }, formatter: (params: any) => { - const axisValueLabel: string = formatterXAxis(this.locale, this.windowPreference, params[0].axisValue); + const bestItem = params.reduce((best, item) => { + return (item.seriesName === 'data' && (!best || best.value[1] < item.value[1])) ? item : best; + }, null); + const axisValueLabel: string = formatterXAxis(this.locale, this.windowPreference, bestItem.axisValue); const colorSpan = (color: string) => ``; let itemFormatted = '
' + axisValueLabel + '
'; - params.map((item: any, index: number) => { - - //Do no include MA in tooltip legend! - if (item.seriesName !== 'MA') { - if (index < 26) { - itemFormatted += `
-
${colorSpan(item.color)}
+ if (bestItem) { + itemFormatted += `
+
${colorSpan(bestItem.color)}
-
${formatNumber(item.value[1], this.locale, '1.0-0')}vB/s
+
${formatNumber(bestItem.value[1], this.locale, '1.0-0')}vB/s
`; - } - } - }); + } return `
${itemFormatted}
`; } diff --git a/frontend/src/app/components/mempool-graph/mempool-graph.component.ts b/frontend/src/app/components/mempool-graph/mempool-graph.component.ts index 4700332a3..1f1a0b739 100644 --- a/frontend/src/app/components/mempool-graph/mempool-graph.component.ts +++ b/frontend/src/app/components/mempool-graph/mempool-graph.component.ts @@ -77,7 +77,7 @@ export class MempoolGraphComponent implements OnInit, OnChanges { } this.isWidget = this.template === 'widget'; this.showCount = !this.isWidget && !this.hideCount; - this.windowPreference = this.windowPreferenceOverride ? this.windowPreferenceOverride : this.storageService.getValue('graphWindowPreference'); + this.windowPreference = (this.windowPreferenceOverride ? this.windowPreferenceOverride : this.storageService.getValue('graphWindowPreference')) || '2h'; this.mempoolVsizeFeesData = this.handleNewMempoolData(this.data.concat([])); this.mountFeeChart(); } @@ -256,11 +256,17 @@ export class MempoolGraphComponent implements OnInit, OnChanges { const itemFormatted = []; let sum = 0; let progressPercentageText = ''; - let countItem; - let items = this.inverted ? [...params].reverse() : params; - if (items[items.length - 1].seriesName === 'count') { - countItem = items.pop(); - } + const unfilteredItems = this.inverted ? [...params].reverse() : params; + const countItem = unfilteredItems.find(p => p.seriesName === 'count'); + const usedSeries = {}; + const items = unfilteredItems.filter(p => { + if (usedSeries[p.seriesName] || p.seriesName === 'count') { + return false; + } + usedSeries[p.seriesName] = true; + return true; + }); + items.map((item: any, index: number) => { sum += item.value[1]; const progressPercentage = (item.value[1] / totalValue) * 100; diff --git a/frontend/src/app/dashboard/dashboard.component.ts b/frontend/src/app/dashboard/dashboard.component.ts index 1660e7310..6bedaafb0 100644 --- a/frontend/src/app/dashboard/dashboard.component.ts +++ b/frontend/src/app/dashboard/dashboard.component.ts @@ -231,8 +231,10 @@ export class DashboardComponent implements OnInit, OnDestroy, AfterViewInit { this.stateService.live2Chart$ .pipe( scan((acc, stats) => { + const now = Date.now() / 1000; + const start = now - (2 * 60 * 60); acc.unshift(stats); - acc = acc.slice(0, 120); + acc = acc.filter(p => p.added >= start); return acc; }, (mempoolStats || [])) ),