Published
Edited
Jul 21, 2020
2 stars
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
data = {
const links = d3.csvParse(await csv, d3.autoType);
const nodes = Array.from(
new Set(links.flatMap(l => [l.source, l.target])),
name => ({name, category: name}));
return {nodes, links, units: "things"};
}
Insert cell
sankey = {
const sankey = d3.sankey()
.nodeId(d => d.name)
.nodeAlign(d3[`sankeyLeft`])
.nodeWidth(12)
.nodePadding(48)
.extent([[1, 5], [params.svg.width - 1, params.plot.height - 5]]);
return ({nodes, links}) => sankey({
nodes: nodes.map(d => Object.assign({}, d)),
links: links.map(d => Object.assign({}, d))
});
}
Insert cell
color = {
const color = d3.scaleOrdinal().range(["#DD6876", "#6E8FEA", "#BD74CB", "#5396CF", "#9885D5", "#4EA376"]);
return d => color(d.category === undefined ? d.name : d.category);
}
Insert cell
height = 600
Insert cell
mutable params = {
let output = {};
output["svg"] = {
"width": 954,
"height": 600
};
output["margin"] = {
"top": 72,
"right": 0,
"bottom": 72,
"left": 0
};
output["plot"] = {
"x": output["margin"]["left"],
"y": output["margin"]["top"],
"width": output["svg"]["width"] - output["margin"]["left"] - output["margin"]["right"],
"height": output["svg"]["height"] - output["margin"]["top"] - output["margin"]["bottom"]
};

return output;
}
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