mempool/frontend/src/app/components/fee-distribution-graph/fee-distribution-graph.component.ts

70 lines
1.7 KiB
TypeScript
Raw Normal View History

import { Component, Input, OnChanges } from '@angular/core';
import { VbytesPipe } from 'src/app/pipes/bytes-pipe/vbytes.pipe';
import * as Chartist from 'chartist';
@Component({
selector: 'app-fee-distribution-graph',
templateUrl: './fee-distribution-graph.component.html',
styleUrls: ['./fee-distribution-graph.component.scss']
})
export class FeeDistributionGraphComponent implements OnChanges {
@Input() feeRange;
mempoolVsizeFeesData: any;
mempoolVsizeFeesOptions: any;
feeLevels = [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];
constructor(
) { }
ngOnChanges() {
this.mempoolVsizeFeesOptions = {
showArea: true,
showLine: true,
fullWidth: true,
showPoint: true,
low: 0,
axisY: {
showLabel: false,
},
axisX: {
showGrid: true,
showLabel: false,
offset: 0
},
plugins: [
Chartist.plugins.ctPointLabels({
textAnchor: 'middle',
labelInterpolationFnc: (value) => Math.round(value)
})
]
};
const fees = this.feeRange;
const series = [];
for (let i = 0; i < this.feeLevels.length; i++) {
let total = 0;
// for (let j = 0; j < fees.length; j++) {
for (const fee of fees) {
if (i === this.feeLevels.length - 1) {
if (fee >= this.feeLevels[i]) {
total += 1;
}
} else if (fee >= this.feeLevels[i] && fee < this.feeLevels[i + 1]) {
total += 1;
}
}
series.push(total);
}
this.mempoolVsizeFeesData = {
series: [fees],
labels: fees.map((d, i) => i)
};
}
}