Published
Edited
Jun 21, 2021
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
chart = {
const svg = d3
.create("svg")
.attr("viewBox", [0, 0, width, height])
.style("font", "10px sans-serif");

const g = svg
.append("g")
.selectAll("g")
.data(
data.series.sort(sortBy.function).map(d =>
Object.assign(
{
clipId: DOM.uid("clip"),
pathId: DOM.uid("path")
},
d
)
)
)
.join("g")
.attr("transform", (d, i) => `translate(0,${i * (step + 1) + margin.top})`);

g.append("clipPath")
.attr("id", d => d.clipId.id)
.append("rect")
.attr("width", width)
.attr("height", step);

g.append("defs")
.append("path")
.attr("id", d => d.pathId.id)
.attr("d", d => area(d.values));

g.append("g")
.attr("clip-path", d => d.clipId)
.selectAll("use")
.data(d => new Array(overlap).fill(d))
.join("use")
.attr("fill", (d, i) => color(i))
.attr("transform", (d, i) => `translate(0,${(i + 1) * step})`)
.attr("xlink:href", d => d.pathId.href);

g.append("text")
.attr("x", 4)
.attr("y", step / 2)
.attr("dy", "0.35em")
.text(d => d.name);

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

return svg.node();
}
Insert cell
// // The different options for sorting that'll be available for the user
// sorts = {
// let sorts = [
// {
// name: "Probe ID",
// ids: ["probeid", "probe", "id"],
// function: (s1, s2) => parseInt(s1.prb_id) - parseInt(s2.prb_id)
// },
// {
// name: "ASN (v4)",
// ids: ["asn4"],
// function: (s1, s2) => s1.asn_v4 - s2.asn_v4
// },
// {
// name: "ASN (v4 preferred)",
// ids: ["asn46"],
// function: (s1, s2) =>
// (s1.asn_v4 ? s1.asn_v4 : s1.asn_v6) -
// (s2.asn_v4 ? s2.asn_v4 : s2.asn_v6)
// },
// {
// name: "ASN (v6 preferred)",
// ids: ["asn64"],
// function: (s1, s2) =>
// (s1.asn_v6 ? s1.asn_v6 : s1.asn_v4) -
// (s2.asn_v6 ? s2.asn_v6 : s2.asn_v4)
// },
// {
// name: "ASN (v6)",
// ids: ["asn6"],
// function: (s1, s2) => s1.asn_v6 - s2.asn_v6
// },
// {
// name: "Country code",
// ids: ["country", "countrycode", "cc"],
// function: (s1, s2) =>
// s1.country_code !== undefined && s2.country_code !== undefined
// ? s1.country_code.localeCompare(s2.country_code)
// : 0
// },
// {
// name: "Prefix size",
// ids: ["pfx_size"],
// function: (s1, s2) => s1.prefix_v4_size - s2.prefix_v4_size
// }
// ];
// //link asn --> asn46
// sorts.push({
// name: "ASN",
// ids: ["asn"],
// function: sorts.filter(s => s.ids.indexOf('asn46') >= 0)[0].function
// });
// return sorts;
// }
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
dataz = {
const data = d3.csvParse(
await FileAttachment("traffic.csv").text(),
d3.autoType
);
const dates = Array.from(d3.group(data, d => +d.date).keys()).sort(
d3.ascending
);
return {
dates: dates.map(d => new Date(d)),
series: d3
.groups(data, d => d.name)
.map(([name, values]) => {
const value = new Map(values.map(d => [+d.date, d.value]));
return { name, values: dates.map(d => value.get(d)) };
})
};
}
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
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