Public
Edited
Aug 28, 2023
Opioid Healthcare Numbers
Modified for Opioid Data
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

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