Skip to content

Commit

Permalink
Remove SI symbol suffix for <1 values WIP Applied the new formattings…
Browse files Browse the repository at this point in the history
… to legens only
  • Loading branch information
BielStela committed Jan 18, 2024
1 parent 1e82be1 commit 897bd0f
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { useCallback, useMemo } from 'react';

import { useAppDispatch } from 'store/hooks';
import { setLayer } from 'store/features/analysis/map';
import { NUMBER_FORMAT } from 'utils/number-format';
import {NUMBER_FORMAT, SMALL_NUMBER_FORMAT} from 'utils/number-format';
import LegendItem from 'components/legend/item';
import LegendTypeBasic from 'components/legend/types/basic';
import LegendTypeCategorical from 'components/legend/types/categorical';
Expand Down Expand Up @@ -38,7 +38,9 @@ const ContextualLegendItem = ({ layer }: ContextualLegendItemProps) => {
...item,
label:
item.label ||
`${!Number.isNaN(item.value) ? NUMBER_FORMAT(item.value as number) : item.value}`,
`${Number.isNaN(item.value) ? item.value :
item.value > 1 ? NUMBER_FORMAT(item.value as number) : SMALL_NUMBER_FORMAT(item.value as number)
}`,
})),
};
switch (layer.metadata.legend.type) {
Expand Down
6 changes: 5 additions & 1 deletion client/src/utils/number-format.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
import { format } from 'd3-format';

export const NUMBER_FORMAT = format(',.3~s');
// for numbers bigger than 1
export const NUMBER_FORMAT = format('.3~s');

// for numbers smaller than 1
export const SMALL_NUMBER_FORMAT = format('.3~g');

export const PRECISE_NUMBER_FORMAT = format(',.3~r');

Expand Down

0 comments on commit 897bd0f

Please sign in to comment.