Public
Edited
Feb 6, 2024
Insert cell
Insert cell
Insert cell
Insert cell
data.map((d) => {
let coordinates = updatedLocations.find((f) => d.id === d.location?.[0]);
return {
...d,
lat: coordinates ? coordinates.coordinates.lat : "",
lon: coordinates ? coordinates.coordinates.lon : ""
};
})
Insert cell
updatedLocations = locations.map((d) => {
const coordinates = findCoordinatesForCity(d.name);
return { ...d, coordinates };
})
Insert cell
groupedData = data
.reduce((acc, item) => {
const location = updatedLocations.find(
(loc) => item.location[0] === loc.id
);
const label = location ? location.name : "Unknown";

const existingGroup = acc.find((group) => group.location === label);

if (!existingGroup) {
acc.push({
location: label,
values: [item],
lat: location?.coordinates?.Latitude,
lon: location?.coordinates?.Longitude
});
} else {
existingGroup.values.push(item);
}

return acc;
}, [])
.filter((d) => d.lat != undefined)
Insert cell
function findCoordinatesForCity(city) {
return geo.find(
(d) => d.City == city || d.District == city || d.Country == city
);
}
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell

Purpose-built for displays of data

Observable is your go-to platform for exploring data and creating expressive data visualizations. Use reactive JavaScript notebooks for prototyping and a collaborative canvas for visual data exploration and dashboard creation.
Learn more