Merging duplicate mempool graph code.
This commit is contained in:
parent
24c23f1ee8
commit
9814927849
@ -44,6 +44,7 @@ import { MempoolBlockComponent } from './components/mempool-block/mempool-block.
|
|||||||
import { FeeDistributionGraphComponent } from './components/fee-distribution-graph/fee-distribution-graph.component';
|
import { FeeDistributionGraphComponent } from './components/fee-distribution-graph/fee-distribution-graph.component';
|
||||||
import { TimespanComponent } from './components/timespan/timespan.component';
|
import { TimespanComponent } from './components/timespan/timespan.component';
|
||||||
import { SeoService } from './services/seo.service';
|
import { SeoService } from './services/seo.service';
|
||||||
|
import { MempoolGraphComponent } from './components/mempool-graph/mempool-graph.component';
|
||||||
|
|
||||||
@NgModule({
|
@NgModule({
|
||||||
declarations: [
|
declarations: [
|
||||||
@ -78,6 +79,7 @@ import { SeoService } from './services/seo.service';
|
|||||||
FiatComponent,
|
FiatComponent,
|
||||||
MempoolBlockComponent,
|
MempoolBlockComponent,
|
||||||
FeeDistributionGraphComponent,
|
FeeDistributionGraphComponent,
|
||||||
|
MempoolGraphComponent,
|
||||||
],
|
],
|
||||||
imports: [
|
imports: [
|
||||||
BrowserModule,
|
BrowserModule,
|
||||||
|
@ -0,0 +1,6 @@
|
|||||||
|
<app-chartist
|
||||||
|
*ngIf="mempoolVsizeFeesData"
|
||||||
|
[data]="mempoolVsizeFeesData"
|
||||||
|
[type]="'Line'"
|
||||||
|
[options]="mempoolVsizeFeesOptions">
|
||||||
|
</app-chartist>
|
@ -0,0 +1,113 @@
|
|||||||
|
import { Component, OnInit, Input, Inject, LOCALE_ID, ChangeDetectionStrategy, OnChanges } from '@angular/core';
|
||||||
|
import { formatDate } from '@angular/common';
|
||||||
|
import { VbytesPipe } from 'src/app/pipes/bytes-pipe/vbytes.pipe';
|
||||||
|
import * as Chartist from 'chartist';
|
||||||
|
import { environment } from 'src/environments/environment';
|
||||||
|
import { OptimizedMempoolStats } from 'src/app/interfaces/node-api.interface';
|
||||||
|
|
||||||
|
@Component({
|
||||||
|
selector: 'app-mempool-graph',
|
||||||
|
templateUrl: './mempool-graph.component.html',
|
||||||
|
changeDetection: ChangeDetectionStrategy.OnPush,
|
||||||
|
})
|
||||||
|
export class MempoolGraphComponent implements OnInit, OnChanges {
|
||||||
|
@Input() data;
|
||||||
|
|
||||||
|
network = environment.network;
|
||||||
|
mempoolVsizeFeesOptions: any;
|
||||||
|
mempoolVsizeFeesData: any;
|
||||||
|
|
||||||
|
constructor(
|
||||||
|
private vbytesPipe: VbytesPipe,
|
||||||
|
@Inject(LOCALE_ID) private locale: string,
|
||||||
|
) { }
|
||||||
|
|
||||||
|
ngOnInit(): void {
|
||||||
|
const labelInterpolationFnc = (value: any, index: any) => {
|
||||||
|
return index % 6 === 0 ? formatDate(value, 'HH:mm', this.locale) : null;
|
||||||
|
};
|
||||||
|
|
||||||
|
this.mempoolVsizeFeesOptions = {
|
||||||
|
showArea: true,
|
||||||
|
showLine: false,
|
||||||
|
fullWidth: true,
|
||||||
|
showPoint: false,
|
||||||
|
low: 0,
|
||||||
|
axisX: {
|
||||||
|
labelInterpolationFnc: labelInterpolationFnc,
|
||||||
|
offset: 40
|
||||||
|
},
|
||||||
|
axisY: {
|
||||||
|
labelInterpolationFnc: (value: number): any => {
|
||||||
|
return this.vbytesPipe.transform(value, 2);
|
||||||
|
},
|
||||||
|
offset: 160
|
||||||
|
},
|
||||||
|
plugins: [
|
||||||
|
Chartist.plugins.ctTargetLine({
|
||||||
|
value: 1000000
|
||||||
|
}),
|
||||||
|
Chartist.plugins.legend({
|
||||||
|
legendNames: [1, 2, 3, 4, 5, 6, 8, 10, 12, 15, 20, 30, 40, 50, 60, 70, 80, 90, 100, 125, 150, 175, 200,
|
||||||
|
250, 300, 350, 400].map((sats, i, arr) => {
|
||||||
|
if (sats === 400) {
|
||||||
|
return '350+';
|
||||||
|
}
|
||||||
|
if (i === 0) {
|
||||||
|
if (this.network === 'liquid') {
|
||||||
|
return '0 - 1';
|
||||||
|
}
|
||||||
|
return '1 sat/vB';
|
||||||
|
}
|
||||||
|
return arr[i - 1] + ' - ' + sats;
|
||||||
|
})
|
||||||
|
})
|
||||||
|
]
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
ngOnChanges() {
|
||||||
|
this.mempoolVsizeFeesData = this.handleNewMempoolData(this.data.concat([]));
|
||||||
|
}
|
||||||
|
|
||||||
|
handleNewMempoolData(mempoolStats: OptimizedMempoolStats[]) {
|
||||||
|
mempoolStats.reverse();
|
||||||
|
const labels = mempoolStats.map(stats => stats.added);
|
||||||
|
|
||||||
|
const finalArrayVbyte = this.generateArray(mempoolStats);
|
||||||
|
|
||||||
|
// Only Liquid has lower than 1 sat/vb transactions
|
||||||
|
if (this.network !== 'liquid') {
|
||||||
|
finalArrayVbyte.shift();
|
||||||
|
}
|
||||||
|
|
||||||
|
return {
|
||||||
|
labels: labels,
|
||||||
|
series: finalArrayVbyte
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
generateArray(mempoolStats: OptimizedMempoolStats[]) {
|
||||||
|
const finalArray: number[][] = [];
|
||||||
|
let feesArray: number[] = [];
|
||||||
|
|
||||||
|
for (let index = 37; index > -1; index--) {
|
||||||
|
feesArray = [];
|
||||||
|
mempoolStats.forEach((stats) => {
|
||||||
|
const theFee = stats.vsizes[index].toString();
|
||||||
|
if (theFee) {
|
||||||
|
feesArray.push(parseInt(theFee, 10));
|
||||||
|
} else {
|
||||||
|
feesArray.push(0);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
if (finalArray.length) {
|
||||||
|
feesArray = feesArray.map((value, i) => value + finalArray[finalArray.length - 1][i]);
|
||||||
|
}
|
||||||
|
finalArray.push(feesArray);
|
||||||
|
}
|
||||||
|
finalArray.reverse();
|
||||||
|
return finalArray;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@ -1,16 +1,4 @@
|
|||||||
<div class="container-xl" style="max-width: 100%;">
|
<div class="container-xl" style="max-width: 100%;">
|
||||||
<!--
|
|
||||||
<ul class="nav nav-pills" id="myTab" role="tablist">
|
|
||||||
<li class="nav-item">
|
|
||||||
<a class="nav-link" routerLinkActive="active" routerLink="mempool" role="tab">Mempool</a>
|
|
||||||
</li>
|
|
||||||
<li class="nav-item">
|
|
||||||
<a class="nav-link" routerLinkActive="active" routerLink="blocks" role="tab">Blocks</a>
|
|
||||||
</li>
|
|
||||||
</ul>
|
|
||||||
<br/>
|
|
||||||
|
|
||||||
-->
|
|
||||||
|
|
||||||
<div class="row">
|
<div class="row">
|
||||||
<div class="col-lg-12" *ngIf="loading">
|
<div class="col-lg-12" *ngIf="loading">
|
||||||
@ -23,7 +11,7 @@
|
|||||||
|
|
||||||
<div class="col-lg-12">
|
<div class="col-lg-12">
|
||||||
|
|
||||||
<div class="card mb-3" *ngIf="mempoolVsizeFeesData">
|
<div class="card mb-3" *ngIf="mempoolStats.length">
|
||||||
<div class="card-header">
|
<div class="card-header">
|
||||||
<i class="fa fa-area-chart"></i> Mempool by vbytes (satoshis/vbyte)
|
<i class="fa fa-area-chart"></i> Mempool by vbytes (satoshis/vbyte)
|
||||||
|
|
||||||
@ -56,11 +44,7 @@
|
|||||||
</div>
|
</div>
|
||||||
<div class="card-body">
|
<div class="card-body">
|
||||||
<div style="height: 600px;">
|
<div style="height: 600px;">
|
||||||
<app-chartist
|
<app-mempool-graph [data]="mempoolStats"></app-mempool-graph>
|
||||||
[data]="mempoolVsizeFeesData"
|
|
||||||
[type]="'Line'"
|
|
||||||
[options]="mempoolVsizeFeesOptions">
|
|
||||||
</app-chartist>
|
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
@ -3,9 +3,8 @@ import { ActivatedRoute } from '@angular/router';
|
|||||||
import { formatDate } from '@angular/common';
|
import { formatDate } from '@angular/common';
|
||||||
import { FormGroup, FormBuilder } from '@angular/forms';
|
import { FormGroup, FormBuilder } from '@angular/forms';
|
||||||
import { of, merge} from 'rxjs';
|
import { of, merge} from 'rxjs';
|
||||||
import { switchMap, tap } from 'rxjs/operators';
|
import { switchMap } from 'rxjs/operators';
|
||||||
|
|
||||||
import { VbytesPipe } from '../../pipes/bytes-pipe/vbytes.pipe';
|
|
||||||
import { OptimizedMempoolStats } from '../../interfaces/node-api.interface';
|
import { OptimizedMempoolStats } from '../../interfaces/node-api.interface';
|
||||||
import { WebsocketService } from '../../services/websocket.service';
|
import { WebsocketService } from '../../services/websocket.service';
|
||||||
import { ApiService } from '../../services/api.service';
|
import { ApiService } from '../../services/api.service';
|
||||||
@ -39,7 +38,6 @@ export class StatisticsComponent implements OnInit {
|
|||||||
|
|
||||||
constructor(
|
constructor(
|
||||||
@Inject(LOCALE_ID) private locale: string,
|
@Inject(LOCALE_ID) private locale: string,
|
||||||
private vbytesPipe: VbytesPipe,
|
|
||||||
private formBuilder: FormBuilder,
|
private formBuilder: FormBuilder,
|
||||||
private route: ActivatedRoute,
|
private route: ActivatedRoute,
|
||||||
private websocketService: WebsocketService,
|
private websocketService: WebsocketService,
|
||||||
@ -75,44 +73,6 @@ export class StatisticsComponent implements OnInit {
|
|||||||
return index % nr === 0 ? value : null;
|
return index % nr === 0 ? value : null;
|
||||||
};
|
};
|
||||||
|
|
||||||
this.mempoolVsizeFeesOptions = {
|
|
||||||
showArea: true,
|
|
||||||
showLine: false,
|
|
||||||
fullWidth: true,
|
|
||||||
showPoint: false,
|
|
||||||
low: 0,
|
|
||||||
axisX: {
|
|
||||||
labelInterpolationFnc: labelInterpolationFnc,
|
|
||||||
offset: 40
|
|
||||||
},
|
|
||||||
axisY: {
|
|
||||||
labelInterpolationFnc: (value: number): any => {
|
|
||||||
return this.vbytesPipe.transform(value, 2);
|
|
||||||
},
|
|
||||||
offset: 160
|
|
||||||
},
|
|
||||||
plugins: [
|
|
||||||
Chartist.plugins.ctTargetLine({
|
|
||||||
value: 1000000
|
|
||||||
}),
|
|
||||||
Chartist.plugins.legend({
|
|
||||||
legendNames: [1, 2, 3, 4, 5, 6, 8, 10, 12, 15, 20, 30, 40, 50, 60, 70, 80, 90, 100, 125, 150, 175, 200,
|
|
||||||
250, 300, 350, 400, 500, 600].map((sats, i, arr) => {
|
|
||||||
if (sats === 600) {
|
|
||||||
return '500+';
|
|
||||||
}
|
|
||||||
if (i === 0) {
|
|
||||||
if (this.network === 'liquid') {
|
|
||||||
return '0 - 1';
|
|
||||||
}
|
|
||||||
return '1 sat/vB';
|
|
||||||
}
|
|
||||||
return arr[i - 1] + ' - ' + sats;
|
|
||||||
})
|
|
||||||
})
|
|
||||||
]
|
|
||||||
};
|
|
||||||
|
|
||||||
this.transactionsWeightPerSecondOptions = {
|
this.transactionsWeightPerSecondOptions = {
|
||||||
showArea: false,
|
showArea: false,
|
||||||
showLine: true,
|
showLine: true,
|
||||||
@ -142,11 +102,6 @@ export class StatisticsComponent implements OnInit {
|
|||||||
merge(
|
merge(
|
||||||
of(''),
|
of(''),
|
||||||
this.radioGroupForm.controls.dateSpan.valueChanges
|
this.radioGroupForm.controls.dateSpan.valueChanges
|
||||||
.pipe(
|
|
||||||
tap(() => {
|
|
||||||
this.mempoolStats = [];
|
|
||||||
})
|
|
||||||
)
|
|
||||||
)
|
)
|
||||||
.pipe(
|
.pipe(
|
||||||
switchMap(() => {
|
switchMap(() => {
|
||||||
@ -197,40 +152,5 @@ export class StatisticsComponent implements OnInit {
|
|||||||
labels: labels,
|
labels: labels,
|
||||||
series: [mempoolStats.map((stats) => stats.vbytes_per_second)],
|
series: [mempoolStats.map((stats) => stats.vbytes_per_second)],
|
||||||
};
|
};
|
||||||
|
|
||||||
const finalArrayVbyte = this.generateArray(mempoolStats);
|
|
||||||
|
|
||||||
// Only Liquid has lower than 1 sat/vb transactions
|
|
||||||
if (this.network !== 'liquid') {
|
|
||||||
finalArrayVbyte.shift();
|
|
||||||
}
|
|
||||||
|
|
||||||
this.mempoolVsizeFeesData = {
|
|
||||||
labels: labels,
|
|
||||||
series: finalArrayVbyte
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
generateArray(mempoolStats: OptimizedMempoolStats[]) {
|
|
||||||
const finalArray: number[][] = [];
|
|
||||||
let feesArray: number[] = [];
|
|
||||||
|
|
||||||
for (let index = 37; index > -1; index--) {
|
|
||||||
feesArray = [];
|
|
||||||
mempoolStats.forEach((stats) => {
|
|
||||||
const theFee = stats.vsizes[index].toString();
|
|
||||||
if (theFee) {
|
|
||||||
feesArray.push(parseInt(theFee, 10));
|
|
||||||
} else {
|
|
||||||
feesArray.push(0);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
if (finalArray.length) {
|
|
||||||
feesArray = feesArray.map((value, i) => value + finalArray[finalArray.length - 1][i]);
|
|
||||||
}
|
|
||||||
finalArray.push(feesArray);
|
|
||||||
}
|
|
||||||
finalArray.reverse();
|
|
||||||
return finalArray;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -4,12 +4,8 @@
|
|||||||
<div class="spinner-border text-light"></div>
|
<div class="spinner-border text-light"></div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div class="chart-holder" *ngIf="mempoolVsizeFeesData">
|
<div class="chart-holder" *ngIf="mempoolStats.length">
|
||||||
<app-chartist
|
<app-mempool-graph [data]="mempoolStats"></app-mempool-graph>
|
||||||
[data]="mempoolVsizeFeesData"
|
|
||||||
[type]="'Line'"
|
|
||||||
[options]="mempoolVsizeFeesOptions">
|
|
||||||
</app-chartist>
|
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div class="text-center" class="blockchain-wrapper">
|
<div class="text-center" class="blockchain-wrapper">
|
||||||
|
@ -1,8 +1,4 @@
|
|||||||
import { Component, OnInit, LOCALE_ID, Inject, Renderer2 } from '@angular/core';
|
import { Component, OnInit } from '@angular/core';
|
||||||
import { formatDate } from '@angular/common';
|
|
||||||
import { VbytesPipe } from '../../pipes/bytes-pipe/vbytes.pipe';
|
|
||||||
|
|
||||||
import * as Chartist from 'chartist';
|
|
||||||
import { WebsocketService } from 'src/app/services/websocket.service';
|
import { WebsocketService } from 'src/app/services/websocket.service';
|
||||||
import { OptimizedMempoolStats } from '../../interfaces/node-api.interface';
|
import { OptimizedMempoolStats } from '../../interfaces/node-api.interface';
|
||||||
import { StateService } from 'src/app/services/state.service';
|
import { StateService } from 'src/app/services/state.service';
|
||||||
@ -21,12 +17,9 @@ export class TelevisionComponent implements OnInit {
|
|||||||
|
|
||||||
mempoolStats: OptimizedMempoolStats[] = [];
|
mempoolStats: OptimizedMempoolStats[] = [];
|
||||||
mempoolVsizeFeesData: any;
|
mempoolVsizeFeesData: any;
|
||||||
mempoolVsizeFeesOptions: any;
|
|
||||||
|
|
||||||
constructor(
|
constructor(
|
||||||
private websocketService: WebsocketService,
|
private websocketService: WebsocketService,
|
||||||
@Inject(LOCALE_ID) private locale: string,
|
|
||||||
private vbytesPipe: VbytesPipe,
|
|
||||||
private apiService: ApiService,
|
private apiService: ApiService,
|
||||||
private stateService: StateService,
|
private stateService: StateService,
|
||||||
private seoService: SeoService,
|
private seoService: SeoService,
|
||||||
@ -36,52 +29,9 @@ export class TelevisionComponent implements OnInit {
|
|||||||
this.seoService.setTitle('TV view');
|
this.seoService.setTitle('TV view');
|
||||||
this.websocketService.want(['blocks', 'live-2h-chart', 'mempool-blocks']);
|
this.websocketService.want(['blocks', 'live-2h-chart', 'mempool-blocks']);
|
||||||
|
|
||||||
const labelInterpolationFnc = (value: any, index: any) => {
|
|
||||||
return index % 6 === 0 ? formatDate(value, 'HH:mm', this.locale) : null;
|
|
||||||
};
|
|
||||||
|
|
||||||
this.mempoolVsizeFeesOptions = {
|
|
||||||
showArea: true,
|
|
||||||
showLine: false,
|
|
||||||
fullWidth: true,
|
|
||||||
showPoint: false,
|
|
||||||
low: 0,
|
|
||||||
axisX: {
|
|
||||||
labelInterpolationFnc: labelInterpolationFnc,
|
|
||||||
offset: 40
|
|
||||||
},
|
|
||||||
axisY: {
|
|
||||||
labelInterpolationFnc: (value: number): any => {
|
|
||||||
return this.vbytesPipe.transform(value, 2);
|
|
||||||
},
|
|
||||||
offset: 160
|
|
||||||
},
|
|
||||||
plugins: [
|
|
||||||
Chartist.plugins.ctTargetLine({
|
|
||||||
value: 1000000
|
|
||||||
}),
|
|
||||||
Chartist.plugins.legend({
|
|
||||||
legendNames: [1, 2, 3, 4, 5, 6, 8, 10, 12, 15, 20, 30, 40, 50, 60, 70, 80, 90, 100, 125, 150, 175, 200,
|
|
||||||
250, 300, 350, 400].map((sats, i, arr) => {
|
|
||||||
if (sats === 400) {
|
|
||||||
return '350+';
|
|
||||||
}
|
|
||||||
if (i === 0) {
|
|
||||||
if (this.network === 'liquid') {
|
|
||||||
return '0 - 1';
|
|
||||||
}
|
|
||||||
return '1 sat/vB';
|
|
||||||
}
|
|
||||||
return arr[i - 1] + ' - ' + sats;
|
|
||||||
})
|
|
||||||
})
|
|
||||||
]
|
|
||||||
};
|
|
||||||
|
|
||||||
this.apiService.list2HStatistics$()
|
this.apiService.list2HStatistics$()
|
||||||
.subscribe((mempoolStats) => {
|
.subscribe((mempoolStats) => {
|
||||||
this.mempoolStats = mempoolStats;
|
this.mempoolStats = mempoolStats;
|
||||||
this.handleNewMempoolData(this.mempoolStats.concat([]));
|
|
||||||
this.loading = false;
|
this.loading = false;
|
||||||
});
|
});
|
||||||
|
|
||||||
@ -89,48 +39,7 @@ export class TelevisionComponent implements OnInit {
|
|||||||
.subscribe((mempoolStats) => {
|
.subscribe((mempoolStats) => {
|
||||||
this.mempoolStats.unshift(mempoolStats);
|
this.mempoolStats.unshift(mempoolStats);
|
||||||
this.mempoolStats = this.mempoolStats.slice(0, this.mempoolStats.length - 1);
|
this.mempoolStats = this.mempoolStats.slice(0, this.mempoolStats.length - 1);
|
||||||
this.handleNewMempoolData(this.mempoolStats.concat([]));
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
handleNewMempoolData(mempoolStats: OptimizedMempoolStats[]) {
|
|
||||||
mempoolStats.reverse();
|
|
||||||
const labels = mempoolStats.map(stats => stats.added);
|
|
||||||
|
|
||||||
const finalArrayVbyte = this.generateArray(mempoolStats);
|
|
||||||
|
|
||||||
// Only Liquid has lower than 1 sat/vb transactions
|
|
||||||
if (this.network !== 'liquid') {
|
|
||||||
finalArrayVbyte.shift();
|
|
||||||
}
|
|
||||||
|
|
||||||
this.mempoolVsizeFeesData = {
|
|
||||||
labels: labels,
|
|
||||||
series: finalArrayVbyte
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
generateArray(mempoolStats: OptimizedMempoolStats[]) {
|
|
||||||
const finalArray: number[][] = [];
|
|
||||||
let feesArray: number[] = [];
|
|
||||||
|
|
||||||
for (let index = 37; index > -1; index--) {
|
|
||||||
feesArray = [];
|
|
||||||
mempoolStats.forEach((stats) => {
|
|
||||||
const theFee = stats.vsizes[index].toString();
|
|
||||||
if (theFee) {
|
|
||||||
feesArray.push(parseInt(theFee, 10));
|
|
||||||
} else {
|
|
||||||
feesArray.push(0);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
if (finalArray.length) {
|
|
||||||
feesArray = feesArray.map((value, i) => value + finalArray[finalArray.length - 1][i]);
|
|
||||||
}
|
|
||||||
finalArray.push(feesArray);
|
|
||||||
}
|
|
||||||
finalArray.reverse();
|
|
||||||
return finalArray;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user