Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Improvement] Improved radius legend number formatting #2726

Merged
merged 1 commit into from
Nov 1, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading