Skip to content
Open
Show file tree
Hide file tree
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
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,11 @@ function WorldMap(element: HTMLElement, props: WorldMapProps): void {
fillColor: colorFn(d.name, sliceId),
}));
} else {
const rawExtents = d3Extent(filteredData, d => d.m1);
// Exclude null/zero so they render as "no data" instead of getting a scale color.
const colorableData = filteredData.filter(
d => d.m1 != null && d.m1 !== 0,
);
const rawExtents = d3Extent(colorableData, d => d.m1);
const extents: [number, number] =
rawExtents[0] != null && rawExtents[1] != null
? [rawExtents[0], rawExtents[1]]
Expand All @@ -160,7 +164,7 @@ function WorldMap(element: HTMLElement, props: WorldMapProps): void {
? colorSchemeObj.createLinearScale(extents)
: () => theme.colorBorder;

processedData = filteredData.map(d => ({
processedData = colorableData.map(d => ({
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Bubble rendering inconsistency

The diff incorrectly filters processedData to only include colorableData (where m1 is not null and not zero), which excludes countries from bubble rendering even when they have valid m2 values for bubble size. Bubbles should render for all countries in filteredData. Additionally, fillColor should use theme.colorBorder for null/zero m1 to prevent scale colors, rather than relying on the nullish coalescing operator.

Code suggestion
Check the AI-generated fix before applying
 -    processedData = colorableData.map(d => ({
 -      ...d,
 -      radius: radiusScale(Math.sqrt(d.m2)),
 -      fillColor: colorFn(d.m1) ?? theme.colorBorder,
 -    }));
 +    processedData = filteredData.map(d => ({
 +      ...d,
 +      radius: radiusScale(Math.sqrt(d.m2)),
 +      fillColor: (d.m1 != null && d.m1 !== 0) ? colorFn(d.m1) : theme.colorBorder,
 +    }));

Code Review Run #74c8a4


Should Bito avoid suggestions like this for future reviews? (Manage Rules)

  • Yes, avoid them

...d,
radius: radiusScale(Math.sqrt(d.m2)),
fillColor: colorFn(d.m1) ?? theme.colorBorder,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -511,25 +511,66 @@ test('assigns fill colors from sequential scheme when colorBy is metric', () =>
expect(data.CAN.fillColor).toMatch(/^(#|rgb)/);
});

test('falls back to theme.colorBorder when metric values are null', () => {
test('excludes countries with null metric value from data when colorBy is metric', () => {
WorldMap(container, {
...baseProps,
colorBy: ColorBy.Metric,
data: [
{
country: 'USA',
name: 'United States',
m1: 100,
m2: 200,
code: 'US',
latitude: 37.0902,
longitude: -95.7129,
},
{
country: 'CAN',
name: 'Canada',
m1: null as unknown as number,
m2: 100,
code: 'CA',
latitude: 56.1304,
longitude: -106.3468,
},
],
});

const data = lastDatamapConfig?.data as Record<string, unknown>;
expect(data).toHaveProperty('USA');
expect(data).not.toHaveProperty('CAN');
});

test('excludes countries with zero metric value from data when colorBy is metric', () => {
WorldMap(container, {
...baseProps,
colorBy: ColorBy.Metric,
data: [
{
country: 'USA',
name: 'United States',
m1: 100,
m2: 200,
code: 'US',
latitude: 37.0902,
longitude: -95.7129,
},
{
country: 'MEX',
name: 'Mexico',
m1: 0,
m2: 50,
code: 'MX',
latitude: 23.6345,
longitude: -102.5528,
},
],
} as any);
});

const data = lastDatamapConfig?.data as Record<string, { fillColor: string }>;
expect(data.USA.fillColor).toBe('#e0e0e0');
const data = lastDatamapConfig?.data as Record<string, unknown>;
expect(data).toHaveProperty('USA');
expect(data).not.toHaveProperty('MEX');
});

test('does not throw with empty data and metric coloring', () => {
Expand Down
Loading