Save fee rates legend preference - Fix xaxis label

This commit is contained in:
nymkappa 2022-04-15 19:39:27 +09:00
parent 31ded69a4c
commit d0b27813b0
No known key found for this signature in database
GPG Key ID: E155910B16E8BD04
5 changed files with 61 additions and 15 deletions

View File

@ -6,7 +6,7 @@ import { ApiService } from 'src/app/services/api.service';
import { SeoService } from 'src/app/services/seo.service'; import { SeoService } from 'src/app/services/seo.service';
import { formatNumber } from '@angular/common'; import { formatNumber } from '@angular/common';
import { FormBuilder, FormGroup } from '@angular/forms'; import { FormBuilder, FormGroup } from '@angular/forms';
import { formatterXAxis } from 'src/app/shared/graphs.utils'; import { formatterXAxis, formatterXAxisLabel, formatterXAxisTimeCategory } from 'src/app/shared/graphs.utils';
import { StorageService } from 'src/app/services/storage.service'; import { StorageService } from 'src/app/services/storage.service';
import { MiningService } from 'src/app/services/mining.service'; import { MiningService } from 'src/app/services/mining.service';
import { selectPowerOfTen } from 'src/app/bitcoin.utils'; import { selectPowerOfTen } from 'src/app/bitcoin.utils';
@ -152,7 +152,7 @@ export class BlockFeeRatesGraphComponent implements OnInit {
grid: { grid: {
right: this.right, right: this.right,
left: this.left, left: this.left,
bottom: 70, bottom: 80,
top: this.isMobile() ? 10 : 50, top: this.isMobile() ? 10 : 50,
}, },
tooltip: { tooltip: {
@ -189,17 +189,28 @@ export class BlockFeeRatesGraphComponent implements OnInit {
return tooltip; return tooltip;
}.bind(this) }.bind(this)
}, },
xAxis: data.series.length === 0 ? undefined : { xAxis: data.series.length === 0 ? undefined :
{
name: formatterXAxisLabel(this.locale, this.timespan),
nameLocation: 'middle',
nameTextStyle: {
padding: [10, 0, 0, 0],
},
type: 'category', type: 'category',
splitNumber: this.isMobile() ? 5 : 10, boundaryGap: false,
axisLine: { onZero: true },
axisLabel: { axisLabel: {
formatter: val => formatterXAxisTimeCategory(this.locale, this.timespan, parseInt(val, 10)),
align: 'center',
fontSize: 11,
lineHeight: 12,
hideOverlap: true, hideOverlap: true,
formatter: val => formatterXAxis(this.locale, this.timespan, parseInt(val, 10)), padding: [0, 5],
}, },
}, },
legend: (data.series.length === 0) ? undefined : { legend: (data.series.length === 0) ? undefined : {
data: data.legends, data: data.legends,
selected: { selected: JSON.parse(this.storageService.getValue('fee_rates_legend')) ?? {
'Min': true, 'Min': true,
'10th': true, '10th': true,
'25th': true, '25th': true,
@ -207,7 +218,8 @@ export class BlockFeeRatesGraphComponent implements OnInit {
'75th': true, '75th': true,
'90th': true, '90th': true,
'Max': false, 'Max': false,
} },
id: 4242,
}, },
yAxis: data.series.length === 0 ? undefined : { yAxis: data.series.length === 0 ? undefined : {
position: 'left', position: 'left',
@ -216,7 +228,7 @@ export class BlockFeeRatesGraphComponent implements OnInit {
formatter: (val) => { formatter: (val) => {
const selectedPowerOfTen: any = selectPowerOfTen(val); const selectedPowerOfTen: any = selectPowerOfTen(val);
const newVal = Math.round(val / selectedPowerOfTen.divider); const newVal = Math.round(val / selectedPowerOfTen.divider);
return `${newVal}${selectedPowerOfTen.unit} sats/vB`; return `${newVal}${selectedPowerOfTen.unit} s/vB`;
}, },
}, },
splitLine: { splitLine: {
@ -227,7 +239,7 @@ export class BlockFeeRatesGraphComponent implements OnInit {
} }
}, },
type: 'value', type: 'value',
max: () => this.timespan === 'all' ? 5000 : undefined, max: (val) => this.timespan === 'all' ? Math.min(val.max, 5000) : undefined,
}, },
series: data.series, series: data.series,
dataZoom: [{ dataZoom: [{
@ -235,7 +247,7 @@ export class BlockFeeRatesGraphComponent implements OnInit {
realtime: true, realtime: true,
zoomLock: true, zoomLock: true,
maxSpan: 100, maxSpan: 100,
minSpan: 10, minSpan: 5,
moveOnMouseMove: false, moveOnMouseMove: false,
}, { }, {
showDetail: false, showDetail: false,
@ -264,6 +276,7 @@ export class BlockFeeRatesGraphComponent implements OnInit {
} }
this.chartInstance = ec; this.chartInstance = ec;
this.chartInstance.on('click', (e) => { this.chartInstance.on('click', (e) => {
if (e.data.data === 9999) { // "Other" if (e.data.data === 9999) { // "Other"
return; return;
@ -275,6 +288,10 @@ export class BlockFeeRatesGraphComponent implements OnInit {
} }
}); });
}); });
this.chartInstance.on('legendselectchanged', (e) => {
this.storageService.setValue('fee_rates_legend', JSON.stringify(e.selected));
});
} }
isMobile() { isMobile() {

View File

@ -175,7 +175,7 @@ export class BlockFeesGraphComponent implements OnInit {
realtime: true, realtime: true,
zoomLock: true, zoomLock: true,
maxSpan: 100, maxSpan: 100,
minSpan: 10, minSpan: 5,
moveOnMouseMove: false, moveOnMouseMove: false,
}, { }, {
showDetail: false, showDetail: false,

View File

@ -175,7 +175,7 @@ export class BlockRewardsGraphComponent implements OnInit {
realtime: true, realtime: true,
zoomLock: true, zoomLock: true,
maxSpan: 100, maxSpan: 100,
minSpan: 10, minSpan: 5,
moveOnMouseMove: false, moveOnMouseMove: false,
}, { }, {
showDetail: false, showDetail: false,

View File

@ -328,7 +328,7 @@ export class HashrateChartComponent implements OnInit {
realtime: true, realtime: true,
zoomLock: true, zoomLock: true,
maxSpan: 100, maxSpan: 100,
minSpan: 10, minSpan: 5,
moveOnMouseMove: false, moveOnMouseMove: false,
}, { }, {
showDetail: false, showDetail: false,

View File

@ -22,8 +22,9 @@ export const formatterXAxis = (
return date.toLocaleTimeString(locale, { month: 'short', day: 'numeric', hour: 'numeric', minute: 'numeric' }); return date.toLocaleTimeString(locale, { month: 'short', day: 'numeric', hour: 'numeric', minute: 'numeric' });
case '2y': case '2y':
case '3y': case '3y':
case 'all':
return date.toLocaleDateString(locale, { year: 'numeric', month: 'short', day: 'numeric' }); return date.toLocaleDateString(locale, { year: 'numeric', month: 'short', day: 'numeric' });
case 'all':
return date.toLocaleDateString(locale, { year: 'numeric', month: 'short' });
} }
}; };
@ -36,6 +37,7 @@ export const formatterXAxisLabel = (
case '2h': case '2h':
case '24h': case '24h':
return date.toLocaleDateString(locale, { year: 'numeric', month: 'short', day: 'numeric' }); return date.toLocaleDateString(locale, { year: 'numeric', month: 'short', day: 'numeric' });
case '3d':
case '1w': case '1w':
return date.toLocaleDateString(locale, { year: 'numeric', month: 'long' }); return date.toLocaleDateString(locale, { year: 'numeric', month: 'long' });
case '1m': case '1m':
@ -48,3 +50,30 @@ export const formatterXAxisLabel = (
return null; return null;
} }
}; };
export const formatterXAxisTimeCategory = (
locale: string,
windowPreference: string,
value: number
) => {
const date = new Date(value);
switch (windowPreference) {
case '2h':
return date.toLocaleTimeString(locale, { hour: 'numeric', minute: 'numeric' });
case '24h':
return date.toLocaleTimeString(locale, { weekday: 'short', hour: 'numeric' });
case '3d':
case '1w':
return date.toLocaleTimeString(locale, { month: 'short', day: 'numeric', hour: 'numeric' });
case '1m':
case '3m':
return date.toLocaleDateString(locale, { month: 'long', day: 'numeric' });
case '6m':
case '1y':
return date.toLocaleDateString(locale, { year: 'numeric', month: 'short', day: 'numeric' });
case '2y':
case '3y':
case 'all':
return date.toLocaleDateString(locale, { year: 'numeric', month: 'long' });
}
};