Published
Edited
Sep 18, 2019
Insert cell
Insert cell
rttFile = d3.text("https://sg-pub.ripe.net/emile/tmp/minexternalrtts.2019-09-01.txt").then(d => d.split("\n"))
Insert cell
rttArr = rttFile.map(e => { let a = e.split(" "); return { prb_id: Number(a[0]), af: Number(a[1]), rtt: Number(a[2]) }})
Insert cell
de_prbs = fetch("https://atlas.ripe.net/api/v2/probes/archive?status=1,2").then(d => d.json())
Insert cell
probes_kreis = d3.text("https://sg-pub.ripe.net/emile/tmp/probes_kreis.csv").then(text => d3.dsvFormat("\t").parseRows(text))
Insert cell
data2 = de_prbs.results.filter(p => p.country_code==="DE").filter(p => p.id < 6000 || p.id > 7000).map(p => {
let pR = rttArr.find(p2 => p2.prb_id===p.id);
let pK = probes_kreis.find(pk => Number(pk[0])===p.id);
return {
prb_id: p.id,
rtt: pR && pR.rtt,
pop_density: pK && Number(pK[2]),
kreis: pK && Number(pK[1])
}
}).filter(p => p.rtt).reduce((kreis, p) => { if (kreis[p.kreis]) { kreis[p.kreis].rtts.push(p.rtt) } else { kreis[p.kreis]={ rtts: [p.rtt], pop_density: p.pop_density} }; return kreis },{})
Insert cell
data = Object.entries(data2).map(p => ({ name: p[0], y1: d3.quantile(p[1].rtts, 0.95), x: p[1].pop_density}))
Insert cell
Type JavaScript, then Shift-Enter. Ctrl-space for more options. Arrow ↑/↓ to switch modes.

Insert cell
// data = de_prbs.results.filter(p => p.country_code==="DE").filter(p => p.id < 6000 || p.id > 10000).map(p => {
// let pR = rttArr.find(p2 => p2.prb_id===p.id);
// let pK = probes_kreis.find(pk => Number(pk[0])===p.id);
// return {
// name: p.id,
// y1: pR && pR.rtt,
// x: pK && Number(pK[2])
// //kreis: pK && Number(pK[1])
// }
// }).filter(p => p.y1)
Insert cell
chart = {
const svg = d3.create("svg")
.attr("viewBox", [0, 0, width, height]);

svg.append("g")
.call(xAxis);

svg.append("g")
.call(yAxis);

svg.append("g")
.attr("stroke-width", 1.5)
.attr("font-family", "sans-serif")
.attr("font-size", 10)
.selectAll("g")
.data(data)
.join("g")
.attr("transform", d => `translate(${x(d.x)},${y(d.y1)})`)
.call(g => g.append("circle")
.attr("stroke", "steelblue")
.attr("fill", "none")
// .attr("cx", d => d.x)
// .attr("cy", d => -d.y1 + 570)
.attr("r", 3))
.call(g => g.append("text")
.attr("dy", "0.35em")
.attr("x", 7)
.text(d => d.name))
// .append("g").attr("transform", d => `translate(0,${-d.y1})`)
// .call(g => g.append("circle")
// .attr("stroke", "red")
// .attr("fill", "none")
// // .attr("cx", d => d.x)
// // .attr("cy", d => -d.y0)
// .attr("r", 3))
// .call(g => g.append("text")
// .attr("dy", "0.35em")
// .attr("x", 7)
// .text(d => d.name))
// .call(g => g.append("line")
// .attr("x1", 0)
// .attr("y1", 0)
// .attr("x2", 0)
// .attr("y2", d => +d.y0)
// .attr("stroke", "black"))
// .call(g => g.append("line")
// .attr("fill", "none")
// .attr("x1", -5)
// .attr("y1", d => d.y1-d.median)
// .attr("x2", 5)
// .attr("y2", d => d.y1-d.median)
// .attr("stroke", "black"))
return svg.node();
}
Insert cell
height = 600
Insert cell
margin = ({top: 20, right: 30, bottom: 30, left: 40})
Insert cell
x = d3.scaleLinear()
.domain(d3.extent(data, d => d.x)).nice()
.range([margin.left, width - margin.right])
Insert cell
y = d3.scaleLinear()
.domain(d3.extent(data, d => d.y1)).nice()
.range([height - margin.bottom, margin.top])
Insert cell
xAxis = g => g
.attr("transform", `translate(0,${height - margin.bottom})`)
.call(d3.axisBottom(x))
.call(g => g.select(".domain").remove())
.call(g => g.append("text")
.attr("x", width - margin.right)
.attr("y", -4)
.attr("fill", "#000")
.attr("font-weight", "bold")
.attr("text-anchor", "end")
.text(data.x))
Insert cell
yAxis = g => g
.attr("transform", `translate(${margin.left},0)`)
.call(d3.axisLeft(y))
.call(g => g.select(".domain").remove())
.call(g => g.select(".tick:last-of-type text").clone()
.attr("x", 4)
.attr("text-anchor", "start")
.attr("font-weight", "bold")
.text(data.y1))
Insert cell
// data = Object.assign(await d3.csv("https://gist.githubusercontent.com/mbostock/77a98cd519be20ea1f8e33bbd3617ac2/raw/574433e95e983b288a54f4d2217cb39d1557cd8d/mtcars.csv", ({name, mpg: x, hp: y}) => ({name, x: +x, y: +y})), {x: "Miles per gallon", y: "Horsepower"})
Insert cell
d3 = require("d3@5")
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