Public
Edited
Jun 4, 2023
2 forks
Importers
32 stars
Also listed in…
d3-shape
Insert cell
Insert cell
<svg viewBox="0 0 ${width} ${height}" fill="none">
<path stroke="red" stroke-width="0.5" d="${d3.geoPath()(object)}"></path>
<path stroke="black" d="${geoCurvePath(d3.curveCatmullRomClosed)(object)}"></path>
</svg>
Insert cell
Insert cell
{
const context = DOM.context2d(width, height);
context.beginPath();
d3.geoPath(null, context)(object);
context.lineWidth = 0.5;
context.strokeStyle = "red";
context.stroke();
context.beginPath();
geoCurvePath(d3.curveCatmullRomClosed, null, context)(object);
context.lineWidth = 1.0;
context.strokeStyle = "black";
context.stroke();
context.canvas.style.display = "block";
context.canvas.style.margin = "auto";
return context.canvas;
}
Insert cell
function geoCurvePath(curve, projection, context) {
return object => {
const pathContext = context === undefined ? d3.path() : context;
d3.geoPath(projection, curveContext(curve(pathContext)))(object);
return context === undefined ? pathContext + "" : undefined;
};
}
Insert cell
function curveContext(curve) {
return {
moveTo(x, y) {
curve.lineStart();
curve.point(x, y);
},
lineTo(x, y) {
curve.point(x, y);
},
closePath() {
curve.lineEnd();
}
};
}
Insert cell
Insert cell
topology = FileAttachment("nation-albers.json").json()
Insert cell
object = topojson.feature(topology, topology.objects.nation)
Insert cell
width = 975
Insert cell
height = 610
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