2020-03-29 18:59:04 +02:00
|
|
|
import { Component, OnInit, Input, Inject, LOCALE_ID, ChangeDetectionStrategy, OnChanges } from '@angular/core';
|
|
|
|
import { formatDate } from '@angular/common';
|
2020-07-03 18:45:19 +02:00
|
|
|
import { VbytesPipe } from 'src/app/shared/pipes/bytes-pipe/vbytes.pipe';
|
2020-03-29 18:59:04 +02:00
|
|
|
import { OptimizedMempoolStats } from 'src/app/interfaces/node-api.interface';
|
2020-05-09 15:37:50 +02:00
|
|
|
import { StateService } from 'src/app/services/state.service';
|
2020-11-16 13:27:06 +01:00
|
|
|
import { StorageService } from 'src/app/services/storage.service';
|
2021-08-21 06:46:28 +02:00
|
|
|
import { EChartsOption } from 'echarts';
|
|
|
|
import { feeLevels, chartColors } from 'src/app/app.constants';
|
|
|
|
|
|
|
|
interface AxisObject {
|
|
|
|
axisDimension: string;
|
|
|
|
axisIndex: number;
|
|
|
|
seriesData: any;
|
|
|
|
value: string;
|
|
|
|
}
|
2020-03-29 18:59:04 +02:00
|
|
|
|
|
|
|
@Component({
|
|
|
|
selector: 'app-mempool-graph',
|
|
|
|
templateUrl: './mempool-graph.component.html',
|
|
|
|
changeDetection: ChangeDetectionStrategy.OnPush,
|
|
|
|
})
|
|
|
|
export class MempoolGraphComponent implements OnInit, OnChanges {
|
2021-08-21 06:46:28 +02:00
|
|
|
@Input() data: any[];
|
|
|
|
@Input() limitFee = 300;
|
|
|
|
@Input() height: number | string = 200;
|
|
|
|
@Input() top: number | string = 20;
|
|
|
|
@Input() right: number | string = 10;
|
|
|
|
@Input() left: number | string = 75;
|
2020-05-10 12:44:19 +02:00
|
|
|
@Input() dateSpan = '2h';
|
2020-09-26 17:46:26 +02:00
|
|
|
@Input() showLegend = true;
|
2020-09-27 21:51:01 +02:00
|
|
|
@Input() small = false;
|
2020-03-29 18:59:04 +02:00
|
|
|
|
|
|
|
mempoolVsizeFeesData: any;
|
2021-08-21 06:46:28 +02:00
|
|
|
mempoolVsizeFeesOptions: EChartsOption;
|
2020-03-29 18:59:04 +02:00
|
|
|
|
2020-11-16 13:27:06 +01:00
|
|
|
inverted: boolean;
|
2020-09-23 10:49:07 +02:00
|
|
|
|
2020-03-29 18:59:04 +02:00
|
|
|
constructor(
|
|
|
|
private vbytesPipe: VbytesPipe,
|
2020-05-09 15:37:50 +02:00
|
|
|
private stateService: StateService,
|
2020-03-29 18:59:04 +02:00
|
|
|
@Inject(LOCALE_ID) private locale: string,
|
|
|
|
) { }
|
|
|
|
|
|
|
|
ngOnInit(): void {
|
2021-08-21 06:46:28 +02:00
|
|
|
this.mountFeeChart();
|
2020-03-29 18:59:04 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
ngOnChanges() {
|
2021-08-21 06:46:28 +02:00
|
|
|
// this.inverted = this.storageService.getValue('inverted-graph') === 'true';
|
2020-03-29 18:59:04 +02:00
|
|
|
this.mempoolVsizeFeesData = this.handleNewMempoolData(this.data.concat([]));
|
2021-08-21 06:46:28 +02:00
|
|
|
this.mountFeeChart();
|
2020-03-29 18:59:04 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
handleNewMempoolData(mempoolStats: OptimizedMempoolStats[]) {
|
|
|
|
mempoolStats.reverse();
|
|
|
|
const labels = mempoolStats.map(stats => stats.added);
|
2021-08-21 06:46:28 +02:00
|
|
|
const finalArrayVByte = this.generateArray(mempoolStats);
|
2020-03-29 18:59:04 +02:00
|
|
|
|
|
|
|
// Only Liquid has lower than 1 sat/vb transactions
|
2020-05-17 12:06:09 +02:00
|
|
|
if (this.stateService.network !== 'liquid') {
|
2021-08-21 06:46:28 +02:00
|
|
|
finalArrayVByte.shift();
|
2020-03-29 18:59:04 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
return {
|
|
|
|
labels: labels,
|
2021-08-21 06:46:28 +02:00
|
|
|
series: finalArrayVByte
|
2020-03-29 18:59:04 +02:00
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
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);
|
|
|
|
}
|
|
|
|
});
|
2021-08-21 06:46:28 +02:00
|
|
|
// if (this.inverted && finalArray.length) {
|
|
|
|
// feesArray = feesArray.map((value, i) => value + finalArray[finalArray.length - 1][i]);
|
|
|
|
// }
|
2020-03-29 18:59:04 +02:00
|
|
|
finalArray.push(feesArray);
|
|
|
|
}
|
|
|
|
finalArray.reverse();
|
|
|
|
return finalArray;
|
|
|
|
}
|
2021-08-21 06:46:28 +02:00
|
|
|
|
|
|
|
mountFeeChart(){
|
|
|
|
const { labels, series } = this.mempoolVsizeFeesData;
|
|
|
|
|
|
|
|
const legendNames: string[] = feeLevels.map((sat, i, arr) => {
|
|
|
|
if (sat > this.limitFee) { return `${this.limitFee}+`; }
|
|
|
|
if (i === 0) { return '0 - 1'; }
|
|
|
|
return arr[i - 1] + ' - ' + sat;
|
|
|
|
});
|
|
|
|
|
|
|
|
const yAxisSeries = series.map((value: Array<number>, index: number) => {
|
|
|
|
return {
|
|
|
|
name: labels[index].name,
|
|
|
|
type: 'line',
|
|
|
|
stack: 'total',
|
|
|
|
smooth: false,
|
|
|
|
lineStyle: {
|
|
|
|
width: 0,
|
|
|
|
opacity: 0,
|
|
|
|
},
|
|
|
|
showSymbol: false,
|
|
|
|
areaStyle: {
|
|
|
|
opacity: 1,
|
|
|
|
color: chartColors[index],
|
|
|
|
},
|
|
|
|
emphasis: {
|
|
|
|
focus: 'series'
|
|
|
|
},
|
|
|
|
markLine: {
|
|
|
|
symbol: 'none',
|
|
|
|
itemStyle: {
|
|
|
|
borderWidth: 0,
|
|
|
|
borderColor: 'none',
|
|
|
|
color: '#fff',
|
|
|
|
},
|
|
|
|
lineStyle: {
|
|
|
|
color: '#fff',
|
|
|
|
opacity: 0.75,
|
|
|
|
width: 2,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
data: this.vbytesPipe.transform(value, 2, 'vB', 'MvB', true)
|
|
|
|
};
|
|
|
|
});
|
|
|
|
|
|
|
|
this.mempoolVsizeFeesOptions = {
|
|
|
|
color: chartColors,
|
|
|
|
tooltip: {
|
|
|
|
trigger: 'axis',
|
|
|
|
position: (pos, params, el, elRect, size) => {
|
|
|
|
const positions = { top: -20 };
|
|
|
|
positions[['left', 'right'][+(pos[0] < size.viewSize[0] / 2)]] = 80;
|
|
|
|
return positions;
|
|
|
|
},
|
|
|
|
extraCssText: `width: 150px;
|
|
|
|
background: transparent;
|
|
|
|
border: none;
|
|
|
|
box-shadow: none;`,
|
|
|
|
axisPointer: {
|
|
|
|
type: 'cross',
|
|
|
|
label: {
|
|
|
|
formatter: (axis: AxisObject) => {
|
|
|
|
if (axis.axisDimension === 'y') {
|
|
|
|
return `${this.vbytesPipe.transform(axis.value, 2, 'vB', 'MvB', true)}`;
|
|
|
|
}
|
|
|
|
if (axis.axisDimension === 'x') {
|
|
|
|
return axis.value;
|
|
|
|
}
|
|
|
|
},
|
|
|
|
}
|
|
|
|
},
|
|
|
|
formatter: (params: any) => {
|
|
|
|
const colorSpan = (index: number) => `<div class="indicator" style="background-color: ` + chartColors[index] + `"></div>`;
|
|
|
|
const legendName = (index: number) => legendNames[index];
|
|
|
|
let itemFormatted = '<div>' + params[0].axisValue + '</div>';
|
|
|
|
params.map((item: any, index: number) => {
|
|
|
|
if (feeLevels[index - 1] < this.limitFee) {
|
|
|
|
itemFormatted += `<div class="item">
|
|
|
|
${colorSpan(index - 1)} ${legendName(index)}
|
|
|
|
<div class="grow"></div>
|
|
|
|
<div class="value">${this.vbytesPipe.transform(item.value, 2, 'vB', 'MvB', true)}</div>
|
|
|
|
</div>`;
|
|
|
|
}
|
|
|
|
});
|
|
|
|
return `<div class="fees-wrapper-tooltip-chart">${itemFormatted}</div>`;
|
|
|
|
}
|
|
|
|
},
|
|
|
|
grid: {
|
|
|
|
height: this.height,
|
|
|
|
right: this.right,
|
|
|
|
top: this.top,
|
|
|
|
left: this.left,
|
|
|
|
},
|
|
|
|
xAxis: [
|
|
|
|
{
|
|
|
|
type: 'category',
|
|
|
|
boundaryGap: false,
|
|
|
|
data: labels.map((value: any) => formatDate(value, 'HH:mm', this.locale)),
|
|
|
|
}
|
|
|
|
],
|
|
|
|
yAxis: {
|
|
|
|
type: 'value',
|
|
|
|
axisLabel: {
|
|
|
|
formatter: (value: number) => (`${this.vbytesPipe.transform(value, 2, 'vB', 'MvB', true)}`),
|
|
|
|
},
|
|
|
|
splitLine: {
|
|
|
|
lineStyle: {
|
|
|
|
type: 'dotted',
|
|
|
|
color: '#ffffff66',
|
|
|
|
opacity: 0.25,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
},
|
|
|
|
series: yAxisSeries
|
|
|
|
};
|
|
|
|
}
|
2020-03-29 18:59:04 +02:00
|
|
|
}
|