2022-02-16 22:56:06 +09:00
|
|
|
import { Component, Inject, LOCALE_ID, OnInit } from '@angular/core';
|
2022-02-16 21:20:28 +09:00
|
|
|
import { EChartsOption } from 'echarts';
|
|
|
|
import { Observable } from 'rxjs';
|
2022-02-16 22:56:06 +09:00
|
|
|
import { map, share, tap } from 'rxjs/operators';
|
2022-02-16 21:20:28 +09:00
|
|
|
import { ApiService } from 'src/app/services/api.service';
|
|
|
|
import { SeoService } from 'src/app/services/seo.service';
|
2022-02-16 22:56:06 +09:00
|
|
|
import { formatNumber } from "@angular/common";
|
2022-02-16 21:20:28 +09:00
|
|
|
|
|
|
|
@Component({
|
|
|
|
selector: 'app-difficulty-chart',
|
|
|
|
templateUrl: './difficulty-chart.component.html',
|
|
|
|
styleUrls: ['./difficulty-chart.component.scss'],
|
|
|
|
styles: [`
|
|
|
|
.loadingGraphs {
|
|
|
|
position: absolute;
|
|
|
|
top: 38%;
|
|
|
|
left: calc(50% - 15px);
|
|
|
|
z-index: 100;
|
|
|
|
}
|
|
|
|
`],
|
|
|
|
})
|
|
|
|
export class DifficultyChartComponent implements OnInit {
|
|
|
|
chartOptions: EChartsOption = {};
|
|
|
|
chartInitOptions = {
|
|
|
|
renderer: 'svg'
|
|
|
|
};
|
|
|
|
|
|
|
|
difficultyObservable$: Observable<any>;
|
|
|
|
isLoading = true;
|
2022-02-16 22:56:06 +09:00
|
|
|
formatNumber = formatNumber;
|
2022-02-16 21:20:28 +09:00
|
|
|
|
|
|
|
constructor(
|
2022-02-16 22:56:06 +09:00
|
|
|
@Inject(LOCALE_ID) public locale: string,
|
2022-02-16 21:20:28 +09:00
|
|
|
private seoService: SeoService,
|
|
|
|
private apiService: ApiService,
|
|
|
|
) {
|
|
|
|
this.seoService.setTitle($localize`:@@mining.difficulty:Difficulty`);
|
|
|
|
}
|
|
|
|
|
|
|
|
ngOnInit(): void {
|
|
|
|
this.difficultyObservable$ = this.apiService.getHistoricalDifficulty$(undefined)
|
|
|
|
.pipe(
|
|
|
|
map(data => {
|
2022-02-16 22:56:06 +09:00
|
|
|
let formatted = [];
|
|
|
|
for (let i = 0; i < data.length - 1; ++i) {
|
|
|
|
const change = (data[i].difficulty / data[i + 1].difficulty - 1) * 100;
|
|
|
|
formatted.push([
|
|
|
|
data[i].timestamp,
|
|
|
|
data[i].difficulty,
|
|
|
|
data[i].height,
|
|
|
|
formatNumber(change, this.locale, '1.2-2'),
|
|
|
|
change,
|
|
|
|
formatNumber(data[i].difficulty, this.locale, '1.2-2'),
|
|
|
|
]);
|
|
|
|
}
|
|
|
|
return formatted;
|
2022-02-16 21:20:28 +09:00
|
|
|
}),
|
|
|
|
tap(data => {
|
|
|
|
this.prepareChartOptions(data);
|
|
|
|
this.isLoading = false;
|
2022-02-16 22:56:06 +09:00
|
|
|
}),
|
|
|
|
share()
|
2022-02-16 21:20:28 +09:00
|
|
|
)
|
|
|
|
}
|
|
|
|
|
|
|
|
prepareChartOptions(data) {
|
|
|
|
this.chartOptions = {
|
|
|
|
title: {
|
|
|
|
text: $localize`:@@mining.difficulty:Difficulty`,
|
|
|
|
left: 'center',
|
|
|
|
textStyle: {
|
|
|
|
color: '#FFF',
|
|
|
|
},
|
|
|
|
},
|
|
|
|
tooltip: {
|
|
|
|
show: true,
|
|
|
|
trigger: 'axis',
|
|
|
|
},
|
|
|
|
axisPointer: {
|
|
|
|
type: 'line',
|
|
|
|
},
|
|
|
|
xAxis: [
|
|
|
|
{
|
|
|
|
type: 'time',
|
|
|
|
}
|
|
|
|
],
|
|
|
|
yAxis: {
|
|
|
|
type: 'value',
|
|
|
|
axisLabel: {
|
|
|
|
fontSize: 11,
|
|
|
|
formatter: function(val) {
|
|
|
|
const diff = val / Math.pow(10, 12); // terra
|
|
|
|
return diff.toString() + 'T';
|
|
|
|
}
|
|
|
|
},
|
|
|
|
splitLine: {
|
|
|
|
lineStyle: {
|
|
|
|
type: 'dotted',
|
|
|
|
color: '#ffffff66',
|
|
|
|
opacity: 0.25,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
},
|
|
|
|
series: [
|
|
|
|
{
|
|
|
|
data: data,
|
|
|
|
type: 'line',
|
|
|
|
smooth: false,
|
|
|
|
lineStyle: {
|
|
|
|
width: 3,
|
|
|
|
},
|
|
|
|
areaStyle: {}
|
|
|
|
},
|
|
|
|
],
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|