Public
Edited
Sep 29, 2022
2 stars
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
chart = {
// Create the svg
const svg = d3
.create("svg")
.attr("width", svgWidth)
.attr("height", svgHeight)
// Add a g for each projection
const gs = svg
.selectAll("path")
.data(nodes, d => d.name)
.join("g")
.attr(
"transform",
(d, i) =>
`translate(${(i % n_col) * width}, ${Math.floor(i / n_col) *
width})`
);

// Define a projection
const projection = mapProjection
.fitExtent(
[[5, 5], [width, height]],
topojson.feature(world, world.objects.land)
);

gs.append("path")
.attr("d", d => {
// Set the projection and apply it to the data
const path_d = d3.geoPath().projection(projection)(path_data);
return path_d;
})
// To fix stroke issues
.attr("fill", colorschemes[activeColorScheme]["land"])
.attr("stroke", colorschemes[activeColorScheme]["land"])

gs.append('text')
.text((d, i) => aggregationType === "Cities" ? (i+1) + '. ' + d.city :(i+1) + '. ' + d.name)
.attr("transform", `translate(${width/2}, ${height*1.1})`)
.style("text-anchor", "middle")
.style("font-size", "0.5em")
.style("font-family", "Akkurat Ll");

gs.append("g").attr("class", "paths")
.each(function (node, i) {
let chart = d3.select(this);
let edges = node["edges"];

chart.append("g")
.attr("id", "connections")
.selectAll("paths")
.data(edges)
.enter()
.append("path")
.attr("d", (d) => {
let source = d["sourceCoords"];
let target = d["targetCoords"];
let toDraw = {type: "LineString", coordinates: [source, target]};
let fullPath = mapPath(toDraw);
return fullPath;
})
.attr("stroke", d => sectorColor(d["distanceType"]))
.attr("stroke-linecap", "round")
.attr("fill", "none")
.attr("stroke-width", d => linkWidthFxn(d[d["distanceType"]]))
.attr("stroke-opacity", linkOpacity);
});
return svg.node();
}
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
land, world
Insert cell
Insert cell
Insert cell
Insert cell

One platform to build and deploy the best data apps

Experiment and prototype by building visualizations in live JavaScript notebooks. Collaborate with your team and decide which concepts to build out.
Use Observable Framework to build data apps locally. Use data loaders to build in any language or library, including Python, SQL, and R.
Seamlessly deploy to Observable. Test before you ship, use automatic deploy-on-commit, and ensure your projects are always up-to-date.
Learn more