Skip to content
Snippets Groups Projects
Unverified Commit d032fce7 authored by Sreetam Das's avatar Sreetam Das Committed by GitHub
Browse files

fix: number format config not being respected for graphs (#2832)

* Add computed padding for handling clipped Net worth amounts

* Add comment, early handle 5 character case

* Add release note

* Use currency decimal preference for Net Worth graph Y-axis ticks

* use number format preference for `BarLineGraph` ticks

* use number format preference for checking `NetWorthGraph` tick overflow

* prevent `numberFormatConfig` overwrite

`getNumberFormat` uses `numberFormatConfig` as the default argument;
passing just `{ hideFraction: true }` caused `numberFormatConfig.format`
to be ignored

* add release note

* use `amountToCurrencyNoDecimal` instead for `{BarLine,NetWorth}Graph` ticks
parent 2fdc7fef
No related branches found
No related tags found
No related merge requests found
...@@ -13,6 +13,8 @@ import { ...@@ -13,6 +13,8 @@ import {
ResponsiveContainer, ResponsiveContainer,
} from 'recharts'; } from 'recharts';
import { amountToCurrencyNoDecimal } from 'loot-core/shared/util';
import { theme } from '../../../style'; import { theme } from '../../../style';
import { type CSSProperties } from '../../../style'; import { type CSSProperties } from '../../../style';
import { AlignedText } from '../../common/AlignedText'; import { AlignedText } from '../../common/AlignedText';
...@@ -77,7 +79,7 @@ type BarLineGraphProps = { ...@@ -77,7 +79,7 @@ type BarLineGraphProps = {
export function BarLineGraph({ style, data, compact }: BarLineGraphProps) { export function BarLineGraph({ style, data, compact }: BarLineGraphProps) {
const tickFormatter = tick => { const tickFormatter = tick => {
return `${Math.round(tick).toLocaleString()}`; // Formats the tick values as strings with commas return `${amountToCurrencyNoDecimal(Math.round(tick))}`; // Formats the tick values as strings with commas
}; };
return ( return (
......
...@@ -12,6 +12,8 @@ import { ...@@ -12,6 +12,8 @@ import {
ResponsiveContainer, ResponsiveContainer,
} from 'recharts'; } from 'recharts';
import { amountToCurrencyNoDecimal } from 'loot-core/shared/util';
import { usePrivacyMode } from '../../../hooks/usePrivacyMode'; import { usePrivacyMode } from '../../../hooks/usePrivacyMode';
import { useResponsive } from '../../../ResponsiveProvider'; import { useResponsive } from '../../../ResponsiveProvider';
import { theme } from '../../../style'; import { theme } from '../../../style';
...@@ -35,7 +37,11 @@ export function NetWorthGraph({ ...@@ -35,7 +37,11 @@ export function NetWorthGraph({
const { isNarrowWidth } = useResponsive(); const { isNarrowWidth } = useResponsive();
const tickFormatter = tick => { const tickFormatter = tick => {
return privacyMode ? '...' : `${Math.round(tick).toLocaleString()}`; // Formats the tick values as strings with commas const res = privacyMode
? '...'
: `${amountToCurrencyNoDecimal(Math.round(tick))}`; // Formats the tick values as strings with commas
return res;
}; };
const gradientOffset = () => { const gradientOffset = () => {
...@@ -197,7 +203,7 @@ function computePadding(netWorthData: Array<{ y: number }>) { ...@@ -197,7 +203,7 @@ function computePadding(netWorthData: Array<{ y: number }>) {
*/ */
const maxLength = Math.max( const maxLength = Math.max(
...netWorthData.map(({ y }) => { ...netWorthData.map(({ y }) => {
return Math.round(y).toLocaleString().length; return amountToCurrencyNoDecimal(Math.round(y)).length;
}), }),
); );
......
...@@ -341,7 +341,10 @@ export function amountToCurrency(n) { ...@@ -341,7 +341,10 @@ export function amountToCurrency(n) {
} }
export function amountToCurrencyNoDecimal(n) { export function amountToCurrencyNoDecimal(n) {
return getNumberFormat({ hideFraction: true }).formatter.format(n); return getNumberFormat({
...numberFormatConfig,
hideFraction: true,
}).formatter.format(n);
} }
export function currencyToAmount(str: string) { export function currencyToAmount(str: string) {
......
---
category: Bugfix
authors: [sreetamdas]
---
Fix number format preference not being used for graphs
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment