Public
Edited
Mar 22, 2023
4 forks
4 stars
Insert cell
Insert cell
Insert cell
chart = {
const svg = d3.create("svg").attr("viewBox", [0, 0, width, height]);
svg
.selectAll(".mcpio")
.data(features.features)
.join("path")
.attr("class", "mcpio")
.style("stroke", "#ddd")
.style("stroke-width", 0.5)
.style("fill", "none")
.attr("d", d => path(d));

svg
.selectAll(".depto")
.data(geoJSON.features)
.join("path")
.attr("class", "depto")
.style("fill", "none")
.style("stroke", "#aaa")
.style("stroke-width", 0.5)
.attr("d", d => path(d));

svg
.selectAll(".mountain")
.data(features.features)
.join("path")
.attr("transform", d => `translate(${projection(d3.geoCentroid(d))})`)
.attr("class", "mountain")
.style("fill", "#eee")
.style("fill-opacity", 0.9)
.style("stroke", "steelblue")
.style("stroke-width", 1)
.attr("d", d => mountain(d.properties[spikeBy]));

svg
.selectAll(".legend")
.data(d3.range(0, h.domain()[1] + 1, h.domain()[1] / 6))
.join("g")
.attr(
"transform",
(d, i) =>
`translate(${width -
margin.left -
margin.right -
200 +
i * 30},${height - margin.bottom - margin.top - 20})`
)
.call(legend =>
legend
.append("path")
.attr("class", "legend mountain")
.style("fill", "#eee")
.style("fill-opacity", 0.9)
.style("stroke", "steelblue")
.style("stroke-width", 0.7)
.attr("d", d => mountain(d))
)
.call(legend =>
legend
.append("text")
.style("font-size", "6pt")
.style("text-anchor", "middle")
.style("font-family", "sans-serif")
.attr("y", 10)
.text(d => fmt(d))
);

return svg.node();
}
Insert cell
geoJSON = topojson.feature(mapData, mapData.objects.MGN_AMN_DPTOS)
Insert cell
fmt = d3.format(".2s")
Insert cell
spikeBy = "STP27_PERS"
Insert cell
h = d3
.scaleLinear()
.domain([0, d3.max(features.features, d => d.properties[spikeBy])])
.range([0, 350])
.nice()
Insert cell
mountain = (d, mx = 5) => {
return `M${-mx / 2} 0 Q0 ${-h(d)} ${mx / 2} 0`;
}
Insert cell
path = d3.geoPath().projection(projection)
Insert cell
projection = d3
.geoAzimuthalEqualArea()
.rotate([74 + 30 / 60, -38 - 50 / 60])
.fitExtent(
[[margin.left, margin.top], [width - margin.right, height - margin.bottom]],
features
)
Insert cell
margin = ({ left: 20, right: 20, top: 20, bottom: 20 })
Insert cell
height = 600
Insert cell
line(features.features[0].geometry.coordinates[0][0])
Insert cell
path(features.features[0])
Insert cell
line = d3.line()
Insert cell
features = {
const features = topojson.feature(mapData, mapData.objects.MGN_AMN_MPIOS);
features.features = features.features.sort(
(a, b) => a.properties[spikeBy] - b.properties[spikeBy]
);
return features;
}
Insert cell
mapData = FileAttachment(
"Colombia_departamentos_municipios_poblacion-topo@1.json"
).json()
Insert cell
d3 = require("d3@6")
Insert cell
topojson = require("topojson@3")
Insert cell
import { createJsonDownloadButton } from "@trebor/download-json"
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