Skip to content

Commit

Permalink
[Improvement] Improved radius legend number formatting
Browse files Browse the repository at this point in the history
Signed-off-by: Ihor Dykhta <[email protected]>
  • Loading branch information
igorDykhta committed Oct 31, 2024
1 parent 934f8e8 commit 8d8aa65
Showing 1 changed file with 3 additions and 5 deletions.
8 changes: 3 additions & 5 deletions src/components/src/common/radius-legend.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ import React, {useMemo, FC} from 'react';
import styled from 'styled-components';
import {scaleSqrt} from 'd3-scale';
import {SCALE_TYPES} from '@kepler.gl/constants';
import {formatNumber} from '@kepler.gl/utils';
import {max} from 'd3-array';
import {format} from 'd3-format';
import {console as Console} from 'global/window';

const StyledLegend = styled.div<{width: number; height: number}>`
Expand Down Expand Up @@ -48,8 +48,6 @@ const ValueLabel = styled.div`
border-radius: 2px;
`;

const formatValue = format('.2~f');

const margin = {left: 1, top: 5, right: 2, bottom: 5};

type Props = {
Expand All @@ -60,7 +58,7 @@ type Props = {
range: [number, number];
};

const RadiusLegend: FC<Props> = ({scaleType, width, domain, range}) => {
const RadiusLegend: FC<Props> = ({scaleType, width, domain, range, fieldType}) => {
const radiusScale = useMemo(() => {
if (scaleType !== SCALE_TYPES.sqrt) {
Console.warn(`Unsupported radius scale type: ${scaleType}`);
Expand Down Expand Up @@ -141,7 +139,7 @@ const RadiusLegend: FC<Props> = ({scaleType, width, domain, range}) => {
top: margin.top + h - radiusScale(v) * 2
}}
>
{formatValue(v)}
{formatNumber(v, fieldType)}
</ValueLabel>
))}
</LabelsOuter>
Expand Down

0 comments on commit 8d8aa65

Please sign in to comment.