Fix fiat tick precision on address balance chart

This commit is contained in:
Mononaut 2024-12-07 20:31:57 +00:00
parent a0596cd366
commit 526625fc56
No known key found for this signature in database
GPG Key ID: A3F058E41374C04E
2 changed files with 18 additions and 9 deletions

View File

@ -116,7 +116,7 @@ export class AddressGraphComponent implements OnChanges, OnDestroy {
} else if (this.conversions && this.conversions['USD']) {
price = this.conversions['USD'];
}
return { ...item, price: price }
return { ...item, price: price };
});
}
}),
@ -338,7 +338,7 @@ export class AddressGraphComponent implements OnChanges, OnDestroy {
axisLabel: {
color: 'rgb(110, 112, 121)',
formatter: function(val) {
return `$${this.amountShortenerPipe.transform(val, 0, undefined, true)}`;
return `$${this.amountShortenerPipe.transform(val, 3, undefined, true, true)}`;
}.bind(this)
},
splitLine: {

View File

@ -8,8 +8,12 @@ export class AmountShortenerPipe implements PipeTransform {
const digits = args[0] ?? 1;
const unit = args[1] || undefined;
const isMoney = args[2] || false;
const sigfigs = args[3] || false; // if true, "digits" is the number of significant digits, not the number of decimal places
if (num < 1000) {
if (sigfigs) {
return Number(num.toPrecision(digits));
}
return num.toFixed(digits);
}
@ -25,10 +29,15 @@ export class AmountShortenerPipe implements PipeTransform {
const rx = /\.0+$|(\.[0-9]*[1-9])0+$/;
const item = lookup.slice().reverse().find((item) => num >= item.value);
if (unit !== undefined) {
return item ? (num / item.value).toFixed(digits).replace(rx, '$1') + ' ' + item.symbol + unit : '0';
} else {
return item ? (num / item.value).toFixed(digits).replace(rx, '$1') + item.symbol : '0';
}
if (!item) {
return '0';
}
const scaledNum = num / item.value;
const formattedNum = Number(sigfigs ? scaledNum.toPrecision(digits) : scaledNum.toFixed(digits)).toString();
return unit !== undefined
? formattedNum + ' ' + item.symbol + unit
: formattedNum + item.symbol;
}
}