Skip to content

Commit a8057e1

Browse files
fix(highcharts): address review feedback for choropleth-basic
Attempt 1/4 - fixes based on AI review
1 parent 4b68e0a commit a8057e1

1 file changed

Lines changed: 18 additions & 14 deletions

File tree

plots/choropleth-basic/implementations/javascript/highcharts.js

Lines changed: 18 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,13 @@ const MARGIN_BOTTOM = 140;
2525
const PLOT_WIDTH = MOUNT_WIDTH - MARGIN_LEFT - MARGIN_RIGHT;
2626
const PLOT_HEIGHT = MOUNT_HEIGHT - MARGIN_TOP - MARGIN_BOTTOM;
2727

28+
// LON_MIN/LON_MAX are asymmetric on purpose: the visible region mass (North
29+
// America through Oceania) spans roughly lon -170..153, not a symmetric
30+
// -170..170 — Antarctica's single eastward vertex at lon 170 is a thin sliver
31+
// that barely registers visually. Padding both edges by the same 25° keeps
32+
// the *content* horizontally centered instead of the raw coordinate extremes.
2833
const LON_MIN = -195;
29-
const LON_MAX = 195;
34+
const LON_MAX = 178;
3035
const LAT_MIN = -85;
3136
const LAT_MAX = 80;
3237
const PX_PER_LON = PLOT_WIDTH / (LON_MAX - LON_MIN);
@@ -81,17 +86,17 @@ const REGIONS = [
8186
{
8287
name: "Central Asia",
8388
value: 12,
84-
poly: [[46, 55], [70, 55], [88, 50], [80, 38], [60, 38], [46, 42]],
89+
poly: [[46, 55], [66, 56], [76, 48], [70, 38], [58, 37], [46, 41]],
8590
},
8691
{
8792
name: "South Asia",
8893
value: 18,
89-
poly: [[60, 37], [78, 34], [88, 28], [92, 22], [80, 8], [68, 8], [60, 24]],
94+
poly: [[60, 36], [76, 33], [86, 27], [90, 21], [79, 8], [68, 8], [60, 23]],
9095
},
9196
{
9297
name: "East Asia",
9398
value: 29,
94-
poly: [[73, 40], [90, 53], [120, 53], [135, 45], [130, 32], [122, 25], [108, 18], [95, 22], [80, 30]],
99+
poly: [[84, 39], [92, 52], [120, 53], [135, 45], [130, 32], [122, 25], [108, 18], [96, 21], [86, 27]],
95100
},
96101
{
97102
name: "Southeast Asia",
@@ -128,20 +133,19 @@ function colorForValue(value) {
128133
const frac = Math.min(1, Math.max(0, (value - VALUE_MIN) / (VALUE_MAX - VALUE_MIN)));
129134
return lerpColor(t.seq[0], t.seq[1], frac);
130135
}
131-
function bounds(poly) {
132-
const lons = poly.map((p) => p[0]);
133-
const lats = poly.map((p) => p[1]);
134-
return { minLon: Math.min(...lons), maxLon: Math.max(...lons), minLat: Math.min(...lats), maxLat: Math.max(...lats) };
135-
}
136-
137136
// Precompute centroid + a hover hit-radius (px) sized to fit inside each
138137
// region's bounding box, so the invisible tooltip marker (below) never spills
139138
// past its own polygon into a neighbor.
140139
REGIONS.forEach((region) => {
141-
const b = bounds(region.poly);
142-
region.centroidLon = (b.minLon + b.maxLon) / 2;
143-
region.centroidLat = (b.minLat + b.maxLat) / 2;
144-
region.hitRadius = 0.42 * Math.min((b.maxLon - b.minLon) * PX_PER_LON, (b.maxLat - b.minLat) * PX_PER_LAT);
140+
const lons = region.poly.map((p) => p[0]);
141+
const lats = region.poly.map((p) => p[1]);
142+
const minLon = Math.min(...lons);
143+
const maxLon = Math.max(...lons);
144+
const minLat = Math.min(...lats);
145+
const maxLat = Math.max(...lats);
146+
region.centroidLon = (minLon + maxLon) / 2;
147+
region.centroidLat = (minLat + maxLat) / 2;
148+
region.hitRadius = 0.42 * Math.min((maxLon - minLon) * PX_PER_LON, (maxLat - minLat) * PX_PER_LAT);
145149
region.fill = region.value === null ? MUTED : colorForValue(region.value);
146150
});
147151

0 commit comments

Comments
 (0)