handle fixed width formatting

This commit is contained in:
Anantha Kumaran 2022-08-29 20:49:59 +05:30
parent 973e7b09ee
commit 8a38c5050f
2 changed files with 14 additions and 6 deletions

View File

@ -6,6 +6,7 @@ import _ from "lodash";
import {
ajax,
forEachMonth,
formatFixedWidthFloat,
formatCurrency,
formatCurrencyCrude,
Posting,
@ -406,18 +407,18 @@ function renderCurrentExpensesBreakdown(
.attr("class", "is-family-monospace")
.text(
(d) =>
`${formatCurrency(d.total)} ${sprintf(
"%6.2f",
(d.total / total) * 100
`${formatCurrency(d.total)} ${formatFixedWidthFloat(
(d.total / total) * 100,
6
)}%`
),
(update) =>
update
.text(
(d) =>
`${formatCurrency(d.total)} ${sprintf(
"%6.2f",
(d.total / total) * 100
`${formatCurrency(d.total)} ${formatFixedWidthFloat(
(d.total / total) * 100,
6
)}%`
)
.transition(t)

View File

@ -163,6 +163,13 @@ export function formatFloat(value, precision = 2) {
return sprintf(`%.${precision}f`, value);
}
export function formatFixedWidthFloat(value, width, precision = 2) {
if (obscure) {
value = 0;
}
return sprintf(`%${width}.${precision}f`, value);
}
export function forEachMonth(
start: dayjs.Dayjs,
end: dayjs.Dayjs,