Published
Edited
Jan 9, 2021
1 star
Insert cell
md`# Austria's border lenghts by neighbour`
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', '#FFF8E7');

let zupanije = svg
.selectAll('path')
.data(geojson.features)
.enter()
.append("path")
.attr("fill", "lightsteelblue")
.attr("stroke", "steelblue")
.attr("stroke-width", 1.4)
.attr("stroke-linejoin", "round")
.attr("d", d => {
return path(d);
});

let title = svg
.append('text')
.attr('x', centroid[0])
.attr('y', centroid[1])
.attr('text-anchor', 'middle')
.style('opacity', 0)
.text('Total border length:');

let subtitle = svg
.append('text')
.attr('x', centroid[0])
.attr('y', centroid[1] + 30)
.attr('text-anchor', 'middle')
.style('opacity', 0)
.text(`${d3.format(',')(totalLenth)} km`);

let credit = svg
.append('text')
.attr('x', width - 20)
.attr('y', height - 20)
.attr('fill', '#546767')
.attr('text-anchor', 'end')
.attr('font-size', 12)
.style('opacity', 1)
.text(`@velimirgasp`);

//🇦🇹
let majorTitle = svg
.append('text')
.attr('x', 20)
.attr('y', 50)
.attr('fill', '#546767')
.attr('text-anchor', 'start')
.attr('font-size', 24)
.style('opacity', 1)
.text(`🇦🇹 Austrian Borders 🇦🇹`);

let transitions = [];

transitions.push(
svg
.selectAll('path')
.transition()
.delay(duration)
.duration(duration)
.attrTween('d', function(d, i) {
return flubber.toCircle(path(d), centroid[0], centroid[1], radius, {
maxSegmentLength: 0.2
});
})
.transition()
.duration(duration)
.attr('stroke-width', 40)
.transition()
.duration(duration)
// .attr('fill', 'white')
.attr('fill', '#FFF8E7')
.end()
);

title
.transition()
.duration(duration)
.delay(2 * duration)
.style('opacity', 1);

subtitle
.transition()
.duration(duration)
.delay(3 * duration)
.style('opacity', 1);

Promise.all(transitions).then(() => {
let pieChart = svg
.selectAll(".arc")
.data(arcs)
.join("path")
.attr("fill", d => color(d.data.name))
.attr("class", "arc")
.style('opacity', 0)
.attr("transform", d => `translate(${centroid[0]},${centroid[1]})`)
.attr("d", arc);

pieChart
.append("title")
.text(d => `${d.data.name}: ${d.data.value.toLocaleString()}`);

pieChart
.transition()
.duration(duration)
.style('opacity', 1)
.end('sad je');

let texts = svg
.append("g")
.attr("font-family", "sans-serif")
.attr("font-size", 16)
.attr("text-anchor", "middle")
.selectAll("text")
.data(arcs)
.join("text")
.style('opacity', 0)
.attr(
"transform",
d =>
`translate(${arc.centroid(d)[0] + centroid[0]}, ${arc.centroid(d)[1] +
centroid[1]})`
)
.call(text =>
text
.append("tspan")
.attr("y", "-0.4em")
.attr("font-weight", "bold")
.text(d => d.data.name)
)
.call(text =>
text
.append("tspan")
.attr("x", 0)
.attr("y", "0.7em")
.attr("fill-opacity", 0.7)
.text(d => `${d3.format(".0%")(d.data.value / totalLenth)}`)
)
.transition()
.duration(duration)
.style('opacity', 1);
});

return svg.node();
}
Insert cell
arc = {
// const radius = Math.min(width, height) / 2;
return d3
.arc()
.innerRadius(radius * 0.85)
.outerRadius(radius * 1.15);
}
Insert cell
duration = 2000
Insert cell
pie = d3
.pie()
//.padAngle(0.005)
.padAngle(0.000)
.sort(null)
.value(d => d.value)
Insert cell
radius = 150
Insert cell
Insert cell
arcs = pie(data)
Insert cell
color = d3
.scaleOrdinal()
.domain(data.map(d => d.name))
.range(
d3
.quantize(t => d3.interpolateSpectral(t * 0.8 + 0.1), data.length)
.reverse()
)
Insert cell
data = neighbours.map(d => {
return { name: d[0], value: d[1] };
})
Insert cell
totalLenth = neighbours.reduce((a, b) => a + (b[1] || 0), 0)
Insert cell
neighbours = [
["🇨🇿", 402],
["🇸🇰", 105],
["🇭🇺", 331],
["🇸🇮", 299],
["🇮🇹", 404],
["🇨🇭", 158],
["🇱🇮", 34],
["🇩🇪", 801]
]
Insert cell
path = d3.geoPath().projection(projection)
Insert cell
projection = d3
.geoAlbers()
.rotate([-15, 0])
.fitExtent([[20, 20], [width * 0.9, height * 0.9]], geojson)
Insert cell
height = 600
Insert cell
geojson = {
//let retval = topojson.feature(topoHrv, topoHrv.objects['gadm36_HRV_0']);
let retval = topojson.feature(topo, topo.objects.subunits);

//topojson.feature(topo, topo.objects.states)

// let retval = await FileAttachment('hrv.geojson').json();
// let geojson = topojson.mesh(topoHrv);
return retval;
}
Insert cell
topo = {
//let retval = await FileAttachment("gadm36_HRV_0.json").json();
let retval = await FileAttachment('aut.topo.json').json();
retval.arcs.reverse();
let simplified = topojson.presimplify(retval);
//let min_weight = topojson.quantile(simplified, 0.35);
let min_weight = topojson.quantile(simplified, 0.25);
return (simplified = topojson.simplify(simplified, min_weight));
}
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