Public
Edited
Aug 28, 2023
Insert cell
Insert cell
Insert cell
data = parseGraph(`
Direct Healthcare,ED Visits,35368489
Direct Healthcare,Hospitalizations,203024598
Direct Healthcare,Ambulance and Nalaxone Use,16091701
Indirect Healthcare,"HIV, HBV, HCV, TB, & NAS Conditions",812584286
`)
Insert cell
function parseGraph(source) {
const links = d3.csvParseRows(source, ([source, target, value, linkColor = color]) => (source && target ? {source, target, value: !value || isNaN(value = +value) ? 1 : value, color: linkColor} : null));
const nodeByName = new Map;
for (const link of links) {
if (!nodeByName.has(link.source)) nodeByName.set(link.source, {name: link.source});
if (!nodeByName.has(link.target)) nodeByName.set(link.target, {name: link.target});
}
return {nodes: Array.from(nodeByName.values()), links};
}
Insert cell
sankey = d3.sankey()
.nodeId(d => d.name)
.nodeAlign(d3.sankeyCenter)
.nodeSort(null)
.nodeWidth(15)
.nodePadding(padding)
.extent([[0, 5], [width, height - 5]])
Insert cell
width = 975
Insert cell
height = 440
Insert cell
padding = 24
Insert cell
color = "#dddddd"
Insert cell
d3 = require("d3@6", "d3-sankey@0.12")
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