Skip to content

Commit b3dbc00

Browse files
committed
added and implemented iso3 code crosswalk
1 parent 4c6ca04 commit b3dbc00

4 files changed

Lines changed: 206 additions & 12 deletions

File tree

public/data/iso3_names.json

Lines changed: 174 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,174 @@
1+
{
2+
"AFG": "Afghanistan",
3+
"AGO": "Angola",
4+
"ALB": "Albania",
5+
"ARE": "United Arab Emirates",
6+
"ARG": "Argentina",
7+
"ARM": "Armenia",
8+
"ATA": "Antarctica",
9+
"ATF": "Fr. S. Antarctic Lands",
10+
"AUS": "Australia",
11+
"AUT": "Austria",
12+
"AZE": "Azerbaijan",
13+
"BDI": "Burundi",
14+
"BEL": "Belgium",
15+
"BEN": "Benin",
16+
"BFA": "Burkina Faso",
17+
"BGD": "Bangladesh",
18+
"BGR": "Bulgaria",
19+
"BHS": "Bahamas",
20+
"BIH": "Bosnia and Herz.",
21+
"BLR": "Belarus",
22+
"BLZ": "Belize",
23+
"BOL": "Bolivia",
24+
"BRA": "Brazil",
25+
"BRN": "Brunei",
26+
"BTN": "Bhutan",
27+
"BWA": "Botswana",
28+
"CAF": "Central African Rep.",
29+
"CAN": "Canada",
30+
"CHE": "Switzerland",
31+
"CHL": "Chile",
32+
"CHN": "China",
33+
"CIV": "Côte d'Ivoire",
34+
"CMR": "Cameroon",
35+
"COD": "Dem. Rep. Congo",
36+
"COG": "Congo",
37+
"COL": "Colombia",
38+
"CRI": "Costa Rica",
39+
"CUB": "Cuba",
40+
"CYP": "Cyprus",
41+
"CZE": "Czechia",
42+
"DEU": "Germany",
43+
"DJI": "Djibouti",
44+
"DNK": "Denmark",
45+
"DOM": "Dominican Rep.",
46+
"DZA": "Algeria",
47+
"ECU": "Ecuador",
48+
"EGY": "Egypt",
49+
"ERI": "Eritrea",
50+
"ESH": "W. Sahara",
51+
"ESP": "Spain",
52+
"EST": "Estonia",
53+
"ETH": "Ethiopia",
54+
"FIN": "Finland",
55+
"FJI": "Fiji",
56+
"FLK": "Falkland Is.",
57+
"GAB": "Gabon",
58+
"GBR": "United Kingdom",
59+
"GEO": "Georgia",
60+
"GHA": "Ghana",
61+
"GIN": "Guinea",
62+
"GMB": "Gambia",
63+
"GNB": "Guinea-Bissau",
64+
"GNQ": "Eq. Guinea",
65+
"GRC": "Greece",
66+
"GRL": "Greenland",
67+
"GTM": "Guatemala",
68+
"GUY": "Guyana",
69+
"HND": "Honduras",
70+
"HRV": "Croatia",
71+
"HTI": "Haiti",
72+
"HUN": "Hungary",
73+
"IDN": "Indonesia",
74+
"IND": "India",
75+
"IRL": "Ireland",
76+
"IRN": "Iran",
77+
"IRQ": "Iraq",
78+
"ISL": "Iceland",
79+
"ISR": "Israel",
80+
"ITA": "Italy",
81+
"JAM": "Jamaica",
82+
"JOR": "Jordan",
83+
"JPN": "Japan",
84+
"KAZ": "Kazakhstan",
85+
"KEN": "Kenya",
86+
"KGZ": "Kyrgyzstan",
87+
"KHM": "Cambodia",
88+
"KOR": "South Korea",
89+
"KWT": "Kuwait",
90+
"LAO": "Laos",
91+
"LBN": "Lebanon",
92+
"LBR": "Liberia",
93+
"LBY": "Libya",
94+
"LKA": "Sri Lanka",
95+
"LSO": "Lesotho",
96+
"LTU": "Lithuania",
97+
"LUX": "Luxembourg",
98+
"LVA": "Latvia",
99+
"MAR": "Morocco",
100+
"MDA": "Moldova",
101+
"MDG": "Madagascar",
102+
"MEX": "Mexico",
103+
"MKD": "North Macedonia",
104+
"MLI": "Mali",
105+
"MMR": "Myanmar",
106+
"MNE": "Montenegro",
107+
"MNG": "Mongolia",
108+
"MOZ": "Mozambique",
109+
"MRT": "Mauritania",
110+
"MWI": "Malawi",
111+
"MYS": "Malaysia",
112+
"NAM": "Namibia",
113+
"NCL": "New Caledonia",
114+
"NER": "Niger",
115+
"NGA": "Nigeria",
116+
"NIC": "Nicaragua",
117+
"NLD": "Netherlands",
118+
"NPL": "Nepal",
119+
"NZL": "New Zealand",
120+
"OMN": "Oman",
121+
"PAK": "Pakistan",
122+
"PAN": "Panama",
123+
"PER": "Peru",
124+
"PHL": "Philippines",
125+
"PNG": "Papua New Guinea",
126+
"POL": "Poland",
127+
"PRI": "Puerto Rico",
128+
"PRK": "North Korea",
129+
"PRT": "Portugal",
130+
"PRY": "Paraguay",
131+
"PSE": "Palestine",
132+
"QAT": "Qatar",
133+
"ROU": "Romania",
134+
"RUS": "Russia",
135+
"RWA": "Rwanda",
136+
"SAU": "Saudi Arabia",
137+
"SDN": "Sudan",
138+
"SEN": "Senegal",
139+
"SLB": "Solomon Is.",
140+
"SLE": "Sierra Leone",
141+
"SLV": "El Salvador",
142+
"SOM": "Somalia",
143+
"SRB": "Serbia",
144+
"SSD": "S. Sudan",
145+
"SUR": "Suriname",
146+
"SVK": "Slovakia",
147+
"SVN": "Slovenia",
148+
"SWE": "Sweden",
149+
"SWZ": "eSwatini",
150+
"SYR": "Syria",
151+
"TCD": "Chad",
152+
"TGO": "Togo",
153+
"THA": "Thailand",
154+
"TJK": "Tajikistan",
155+
"TKM": "Turkmenistan",
156+
"TLS": "Timor-Leste",
157+
"TTO": "Trinidad and Tobago",
158+
"TUN": "Tunisia",
159+
"TUR": "Turkey",
160+
"TWN": "Taiwan",
161+
"TZA": "Tanzania",
162+
"UGA": "Uganda",
163+
"UKR": "Ukraine",
164+
"URY": "Uruguay",
165+
"USA": "United States of America",
166+
"UZB": "Uzbekistan",
167+
"VEN": "Venezuela",
168+
"VNM": "Vietnam",
169+
"VUT": "Vanuatu",
170+
"YEM": "Yemen",
171+
"ZAF": "South Africa",
172+
"ZMB": "Zambia",
173+
"ZWE": "Zimbabwe"
174+
}

src/anthromes/lib/MapCanvas.svelte

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@
5454
let cellHistoryLoading = $state(false);
5555
let countryData = $state(null);
5656
let countryDataLoading = $state(false);
57+
let iso3ToName = $state(new Map());
5758
const cache = new Map();
5859
const inFlight = new Map();
5960
let draggingHandle = $state(false);
@@ -300,14 +301,19 @@
300301
countryDataLoading = true;
301302
try {
302303
const base = import.meta.env.BASE_URL;
303-
const url = `${base}data/country_index.json`;
304304
const isDev = import.meta.env.DEV;
305-
const res = await fetch(url, { cache: isDev ? 'no-store' : 'force-cache' });
306-
if (!res.ok) {
307-
throw new Error(`Failed to load country data (${res.status})`);
305+
306+
const [countryRes, namesRes] = await Promise.all([
307+
fetch(`${base}data/country_index.json`, { cache: isDev ? 'no-store' : 'force-cache' }),
308+
fetch(`${base}data/iso3_names.json`, { cache: isDev ? 'no-store' : 'force-cache' }),
309+
]);
310+
311+
if (!countryRes.ok) throw new Error(`Failed to load country data (${countryRes.status})`);
312+
countryData = new Map(Object.entries(await countryRes.json()));
313+
314+
if (namesRes.ok) {
315+
iso3ToName = new Map(Object.entries(await namesRes.json()));
308316
}
309-
const data = await res.json();
310-
countryData = new Map(Object.entries(data));
311317
} catch (err) {
312318
console.error('MapCanvas: Failed to load country data', err);
313319
} finally {
@@ -753,7 +759,7 @@
753759
<div class="kv">
754760
<div class="k">${label} total in ${yearLabel}</div><div>${globalAreaDisplay}</div>
755761
<div class="k">${label} share in ${yearLabel}</div><div>${percentDisplay}</div>
756-
${countryISO3 ? `<div class="k">Present Day Country</div><div>${crosswalk?.country || countryISO3}</div>` : ''}
762+
${countryISO3 ? `<div class="k">Present Day Country</div><div>${iso3ToName.get(countryISO3) || crosswalk?.country || countryISO3}</div>` : ''}
757763
${crosswalk ? `<div class="k">Number of samples from this country</div><div>${crosswalk.samples_total || 0}</div>` : ''}
758764
${crosswalk ? `<div class="k">Percent of "Western" lifestyles in sampled persons</div><div>${westPercent}%</div>` : ''}
759765
</div>

src/biomes/lib/BiomesChart.svelte

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,9 @@
5050
let highlightedSGBs = $state(new Set());
5151
let crossHighlightActive = $state(false);
5252
53+
// Country name lookup (ISO3 → display name)
54+
let iso3ToName = $state(new Map());
55+
5356
// Constants
5457
const fullSize = 6400; // base SVG dimension for full view
5558
const previewSize = 1200; // smaller preview mode
@@ -576,7 +579,7 @@
576579
const glyphPath = glyphLine(chain);
577580
578581
// Summary text
579-
const loc = locationsFromMeta(meta);
582+
const loc = locationsFromMeta(meta, iso3ToName);
580583
const sgb = sgbLabel(d);
581584
const summary = `<b>${sgb}</b> includes <b>${rec.toLocaleString()}</b> genomes within the <b>${phylum.replace(/_/g, ' ')}</b> phylum, identified from <b>${loc}</b>.`;
582585
@@ -931,6 +934,16 @@
931934
})
932935
.catch(() => {});
933936
937+
// Load ISO3 → country name lookup
938+
const base = import.meta.env.BASE_URL;
939+
fetch(`${base}data/iso3_names.json`)
940+
.then(res => res.ok ? res.json() : null)
941+
.then(json => {
942+
if (!json) return;
943+
iso3ToName = new Map(Object.entries(json));
944+
})
945+
.catch(() => {});
946+
934947
const svg = d3.select(svgElement);
935948
936949
// Ensure zoom container exists

src/biomes/lib/dataAdapter.js

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -133,7 +133,7 @@ export function parseWestern(meta) {
133133
* @param {Object} meta - Metadata object
134134
* @returns {string} Human-readable location string
135135
*/
136-
export function locationsFromMeta(meta) {
136+
export function locationsFromMeta(meta, nameMap) {
137137
if (!meta) return '—';
138138

139139
let v = meta["Country_List"];
@@ -165,10 +165,11 @@ export function locationsFromMeta(meta) {
165165
if (!arr.length) return 'various global sites';
166166

167167
const uniq = Array.from(new Set(arr.map(s => s.trim())));
168+
const named = nameMap ? uniq.map(code => nameMap.get(code) || code) : uniq;
168169

169-
const shown = uniq.slice(0, 5).join(', ');
170-
if (uniq.length > 5) {
171-
const remaining = uniq.length - 5;
170+
const shown = named.slice(0, 5).join(', ');
171+
if (named.length > 5) {
172+
const remaining = named.length - 5;
172173
return `${shown}, and ${remaining} other global site${remaining > 1 ? 's' : ''}`;
173174
}
174175
return shown;

0 commit comments

Comments
 (0)