Published
Edited
Jul 13, 2022
Fork of D3 world map
1 fork
Importers
Insert cell
Insert cell
Insert cell
projection = d3.geoEqualEarth()
Insert cell
Insert cell
cobalt_p_all = FileAttachment("cobalt_p_all.csv").csv()
Insert cell
Insert cell
Insert cell
sample = cobalt_report_exports[0].values
Insert cell
cobalt_partner_exports = d3
.nest()
.key(function (d) {
return d.yr;
})
.key(function (d) {
return d.source;
})
.entries(
cobalt_p_all
.filter((f) => f.rgDesc == "Import")
.filter((f) => f.ptTitle != "World")
.filter((f) => f.cmdCode != "2605")
.map((m) => {
let newobj = {};
newobj.source = m.ptTitle;
newobj.target = m.rtTitle;
newobj.value = m.NetWeight;
newobj.yr = m.yr;
return newobj;
})
)
Insert cell
cobalt_report_exports = d3
.nest()
.key(function (d) {
return d.yr;
})
.key(function (d) {
return d.source;
})
.entries(
cobalt_r_all
.filter((f) => f.rgDesc == "Export")
.filter((f) => f.ptTitle != "World")
.filter((f) => f.cmdCode != "2605")
.map((m) => {
let newobj = {};
newobj.source = m.rtTitle;
newobj.target = m.ptTitle;
newobj.value = m.NetWeight;
newobj.yr = m.yr;
return newobj;
})
)
// .map((m) => {
// m.key = parseInt(m.key);
// return m;
// })
Insert cell
comtradeChanges = Array.from(comtrade_countries).filter(
(f) => !countries.has(f)
)
Insert cell
Insert cell
countries = new Set(
world.objects.countries.geometries.map((w) => w.properties.name)
)
Insert cell
function changeCountryValue(obj, val1, val2) {
if (obj.target == val1) {
obj.target = val2;
}
return obj;
}
Insert cell
sample[5].values.map((m) =>
changeCountryValue(m, "Dem. Rep. of the Congo", "DRC")
)
Insert cell
sample
Insert cell
pt_comtrade = Array.from(
new Set(
cobalt_r_all
.filter((f) => f.rgDesc == "Export")
.filter((f) => f.ptTitle != "World")
.map((m) => m.ptTitle)
)
)
Insert cell
rt_comtrade = Array.from(
new Set(
cobalt_r_all
.filter((f) => f.rgDesc == "Export")
.filter((f) => f.ptTitle != "World")
.map((m) => m.rtTitle)
)
)
Insert cell
comtrade_countries = new Set([...rt_comtrade, ...pt_comtrade])
Insert cell
Insert cell
cobalt_report[19].values
Insert cell
Insert cell
Insert cell
path = d3.geoPath(projection)
Insert cell
height = {
const [[x0, y0], [x1, y1]] = d3.geoPath(projection.fitWidth(width, outline)).bounds(outline);
const dy = Math.ceil(y1 - y0), l = Math.min(Math.ceil(x1 - x0), dy);
projection.scale(projection.scale() * (l - 1) / l).precision(0.2);
return dy;
}
Insert cell
outline = ({type: "Sphere"})
Insert cell
graticule = d3.geoGraticule10()
Insert cell
land = topojson.feature(world, world.objects.land)
Insert cell
borders = topojson.mesh(world, world.objects.countries, (a, b) => a !== b)
Insert cell
world = FileAttachment("countries-50m.json").json()
Insert cell
d3 = require("d3-collection@latest", "d3@5.9")
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