Published
Edited
Sep 18, 2019
Insert cell
Insert cell
d3 = require("d3")
Insert cell
lirCountsPlz = d3.csv("https://www-static.ripe.net/static/rnd-ui/openipmap/production/maps/lir-postcode.json").then(d => d)
Insert cell
landWithLirs = land.features.map(plz => {
let lirCount = lirCountsPlz.find(lc => lc.postcode.replace("DE-","").replace("D-","").replace(" M","").replace("D ","")===plz.properties.PLZ99);
return { ...plz, properties: { ...plz.properties, lirCount: lirCount && Number(lirCount.count) } }}).filter(l => l.properties.lirCount)
Insert cell
plzWithManyLirs = lirCountsPlz.filter(plz => plz.count > 10)
Insert cell
landWithManyLirs = land.features.map(l => plzWithManyLirs.find(plz => l.properties.PLZ99===plz.postcode.replace("DE-","").replace("D-","").replace(" M","").replace("D ","")) && { name: l.properties.PLZORT99, coords: projection(turf.centroid(l).geometry.coordinates)}).filter(l => l).reduce((set,l) => { if (!set.some(ll => l.name===ll.name)) { set.push(l) } return set }, [])
Insert cell
lirCountsPlz.filter(plz => !land.features.find(l => l.properties.PLZ99===plz.postcode.replace("DE-","").replace("D-","").replace(" M","").replace("D ","")))
Insert cell
totStats = Object.assign({ min: d3.min(landWithLirs, d => d.properties.lirCount), max: d3.max(landWithLirs, d => d.properties.lirCount)})
Insert cell
Insert cell
// html`<svg width="600" height="215">
// <g class="legend">
// ${lirStats.map((lc,i) => `<circle style="fill: ${lc.color}" cy="${i*30 + 20}" r="10" cx="50"/><text style="font: Open Sans, sans-serif" y="${i*30 + 26}" x="70">${lc.name} (${lc.count}) ${lc.min} - ${lc.max} [${lc.median}]</text>`)}
// </g>
// </svg>`
Insert cell
map = html`<svg viewBox="0 0 ${width} ${height}" style="display: block;">
<style>
.kreis { stroke: #eeeeee; stroke-width: 0.5; fill-opacity: 0.2; fill: white;}
.lir-loc { stroke: none; fill-opacity: 1.0; }
.probe-loc { stroke-width: 2; stroke: none; fill: white; fill-opacity: 0.8 }
.l-path { fill: none; stroke-width: 2; stroke: lightBlue; }
.kreis { fill-opacity: 0.8; }
</style>
<defs>
<path id="outline" d="${path(outline)}" />
<clipPath id="clip"><use xlink:href="${new URL("#outline", location)}" /></clipPath>
</defs>
<svg><g class="lir-loc" clip-path="url(${new URL("#clip", location)})">
<use xlink:href="${new URL("#outline", location)}" fill="#fff" />
<g>${kreise.features.map(l => `<path class="kreis" d="${path(l.geometry)}" style="fill: ${popKreisColor(l.properties.pop_density)}"></path>`)}</g>
<g>${landWithLirs.map(l => `<path d="${path(l.geometry)}" style="fill: ${lirCountColor(l.properties.lirCount)}"></path>`)}</g>
</g></svg>
<g>${landWithManyLirs.map(l => `<text x=${l.coords[0]} y=${l.coords[1]}>${l.name}</text>`)}</g>
<use xlink:href="${new URL("#outline", location)}" fill="none" stroke="#000" />
</svg>`
Insert cell
Insert cell
lirCountColor = d3.scaleLinear()
.domain([1, 3, 10])
.range(["yellow", "orange", "red"])
.interpolate(d3.interpolateLab);
Insert cell
popKreisColor = d3.scaleLinear()
.domain([30, 1880])
.range(["#fcfcfc", "#9f9f9f"])
.interpolate(d3.interpolateLab);
Insert cell
path = d3.geoPath(projection.scale(6150).rotate([-10,-53]))
Insert cell
// projection = d3.geoEqualEarth()
projection = d3.geoMercator()
Insert cell
turf = require("https://cdn.jsdelivr.net/npm/turf@3.0.14/turf.min.js")
Insert cell
height = 1200
Insert cell
world = fetch("https://www-static.ripe.net/static/rnd-ui/openipmap/production/maps/country_deu_adm2.topo.json").then(r => r.json())
Insert cell
outline = ({type: "Sphere"})
Insert cell
kreise = topojson.feature(world, world.objects["country_deu_adm2"])
Insert cell
land = fetch("https://www-static.ripe.net/static/rnd-ui/openipmap/production/maps/post_pl_utf8.geo.json").then(r => r.json())
Insert cell
topojson = import("topojson-client@3")
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