Published
Edited
Dec 3, 2020
Insert cell
md`# Vascular chart of Vienna

Different levels of road infrastructure portrayed as the vascular system.

Data: Open Street Map`
Insert cell
chart = {
const svg = d3.create("svg").attr("viewBox", [0, 0, width, height]);

svg
.append('rect')
.attr('width', width)
.attr('height', height)
.attr('fill', 'black');
svg
.append('g')
.selectAll('path')
.data(aggDataGeoJSON.features)
.enter()
.append("path")
.attr("fill", 'none')
.attr("stroke", "red")
.attr("stroke-linejoin", "round")
.attr('class', d => d.properties.highway)
.attr('opacity', d => {
if (
d.properties.highway == 'motorway' ||
d.properties.highway == 'trunk'
) {
return 0.95;
} else if (d.properties.highway == 'primary') {
return 0.9;
} else if (d.properties.highway == 'secondary') {
return 0.8;
} else if (d.properties.highway == 'tertiary') {
return 0.7;
} else if (d.properties.highway == 'residential') {
return 0.6;
} else {
return 0.4;
}
})
.attr('stroke-width', d => {
if (
d.properties.highway == 'motorway' ||
d.properties.highway == 'trunk'
) {
return 3;
} else if (d.properties.highway == 'primary') {
return 1.5;
} else if (d.properties.highway == 'secondary') {
return 0.6;
} else if (d.properties.highway == 'tertiary') {
return 0.4;
} else if (d.properties.highway == 'residential') {
return 0.3;
} else {
return 0.2;
}
})
.attr("d", path);

return svg.node();
}
Insert cell
[...new Set(d3.map(aggDataGeoJSON.features, d => d.properties.highway))]
Insert cell
aggDataGeoJSON = topojson.feature(aggData, aggData.objects.vienna2)
// aggDataGeoJSON = topojson.mesh(aggData, aggData.objects.sf2)
Insert cell
aggData = JSON.parse(await FileAttachment('vienna.all.trimmed.topojson').text())
Insert cell
// canvas = {
// const context = DOM.context2d(width, height * 1.1);
// const path = d3.geoPath(null, context);
// context.canvas.style.maxWidth = "100%";
// context.lineJoin = "round";
// context.lineCap = "round";
// context.fillStyle = "black";
// context.fillRect(0, 0, width, height * 1.1);
// var geoGenerator = d3
// .geoPath()
// .pointRadius(5)
// .projection(projection)
// .context(context);
// context.strokeStyle = "red";
// context.beginPath();
// context.lineWidth = 3;
// geoGenerator({ type: 'FeatureCollection', features: data.features });
// context.stroke();
// context.beginPath();
// context.lineWidth = 3;
// geoGenerator({ type: 'FeatureCollection', features: trunk.features });
// context.stroke();
// context.beginPath();
// context.lineWidth = 1;
// geoGenerator({
// type: 'FeatureCollection',
// features: primary.features
// });
// context.stroke();
// context.beginPath();
// context.lineWidth = 0.6;
// geoGenerator({
// type: 'FeatureCollection',
// features: secondary.features
// });
// context.stroke();
// context.beginPath();
// context.lineWidth = 0.4;
// geoGenerator({
// type: 'FeatureCollection',
// features: tertiary.features
// });
// context.stroke();
// context.beginPath();
// context.lineWidth = 0.3;
// geoGenerator({
// type: 'FeatureCollection',
// features: residential.features
// });
// context.stroke();
// return context.canvas;
// }
Insert cell
Insert cell
height = 600
Insert cell
Insert cell
data = JSON.parse(await FileAttachment('vienna.motorway.geojson').text())
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