An interactive map of my research, grouped by JEL classification. The treemap below shows how papers are distributed across categories; the network shows how individual papers relate to one another by topical similarity. Click any category swatch to highlight it in both charts; click any paper to open its page.
papers = papersRaw.map(p => {
const catEntry = categoriesRaw[p.id];
const cats = (catEntry && catEntry.categories && catEntry.categories.length) ? catEntry.categories : ["Uncategorized"];
const rawPath = (pathsRaw[p.id] && pathsRaw[p.id][0]) ? pathsRaw[p.id][0] : null;
const path = rawPath ? rawPath.replace(/^research\//, "") : null;
const gs = (p.google_scholar && p.google_scholar[0]) ? p.google_scholar[0] : null;
return {
id: p.id,
title: p.title,
year: (p.issued && p.issued["date-parts"] && p.issued["date-parts"][0]) ? p.issued["date-parts"][0][0] : null,
categories: cats,
citations: gs ? (gs.gs_cites || 0) : 0,
path: path,
neighbors: p.neighbors || []
};
})categoryList = Array.from(new Set(papers.flatMap(d => d.categories))).sort()
// A paper's categories aren't ranked (the classifier just records set membership),
// so for the network's single-color-per-node display we pick each paper's rarest
// category — its least common label — as the most distinctive/representative one.
categoryCounts = d3.rollup(papers.flatMap(d => d.categories), v => v.length, c => c)
colorCategoryOf = (p) => p.categories.slice()
.sort((a, b) => (categoryCounts.get(a) - categoryCounts.get(b)) || a.localeCompare(b))[0]
colorPalette = d3.schemeTableau10.concat(d3.schemeDark2)
colorScale = d3.scaleOrdinal(categoryList, colorPalette.slice(0, categoryList.length))
// A Set so one or several categories can be highlighted at once.
mutable selected = new Set()
setSelected = (cat) => {
const next = new Set(selected);
next.has(cat) ? next.delete(cat) : next.add(cat);
mutable selected = next;
}
clearSelected = () => { mutable selected = new Set(); }legend = {
const container = document.createElement("div");
container.className = "viz-legend";
for (const cat of categoryList) {
const item = document.createElement("div");
item.className = "viz-legend-item" + (selected.has(cat) ? " active" : "");
item.style.cursor = "pointer";
item.title = "Click to toggle — select several to highlight multiple categories";
item.onclick = () => setSelected(cat);
const swatch = document.createElement("span");
swatch.className = "viz-swatch";
swatch.style.backgroundColor = colorScale(cat);
const label = document.createElement("span");
label.className = "viz-legend-label";
label.textContent = cat;
item.appendChild(swatch);
item.appendChild(label);
container.appendChild(item);
}
if (selected.size > 0) {
const clear = document.createElement("div");
clear.className = "viz-legend-item viz-legend-clear";
clear.style.cursor = "pointer";
clear.textContent = "Clear selection ×";
clear.onclick = () => clearSelected();
container.appendChild(clear);
}
return container;
}tooltip = {
const div = html`<div class="viz-tooltip" style="opacity:0;"></div>`;
document.body.appendChild(div);
invalidation.then(() => div.remove());
return div;
}
showTooltip = (event, text) => {
tooltip.innerHTML = text;
tooltip.style.left = `${event.pageX + 12}px`;
tooltip.style.top = `${event.pageY + 12}px`;
tooltip.style.opacity = 1;
}
hideTooltip = () => { tooltip.style.opacity = 0; }Categories
treemapWidth = 928
treemapHeight = 520
treemapRoot = {
// Papers can belong to several categories, so a paper appears as a leaf under
// every category it's tagged with — cell sizes reflect true membership counts
// rather than forcing each paper into a single category.
const root = {
name: "root",
children: categoryList
.map(cat => ({
name: cat,
children: papers.filter(p => p.categories.includes(cat)).map(p => ({ name: p.title, value: 1, paper: p }))
}))
.filter(cat => cat.children.length > 0)
};
return d3.treemap()
.size([treemapWidth, treemapHeight])
.paddingOuter(3)
.paddingTop(18)
.paddingInner(1)
(d3.hierarchy(root).sum(d => d.value));
}
treemapChart = {
const svg = d3.create("svg")
.attr("class", "viz-svg treemap-svg")
.attr("viewBox", [0, 0, treemapWidth, treemapHeight])
.attr("width", treemapWidth)
.attr("height", treemapHeight)
.attr("style", "max-width: 100%; height: auto; font-family: sans-serif;");
const categoryNodes = treemapRoot.children;
const catGroup = svg.append("g")
.selectAll("g")
.data(categoryNodes)
.join("g")
.attr("class", "treemap-category")
.style("cursor", "pointer")
.style("opacity", d => (selected.size > 0 && !selected.has(d.data.name)) ? 0.3 : 1)
.on("click", (event, d) => setSelected(d.data.name));
catGroup.append("rect")
.attr("x", d => d.x0)
.attr("y", d => d.y0)
.attr("width", d => d.x1 - d.x0)
.attr("height", d => d.y1 - d.y0)
.attr("fill", "none")
.attr("stroke", d => colorScale(d.data.name))
.attr("stroke-width", 1.5);
catGroup.append("text")
.attr("x", d => d.x0 + 4)
.attr("y", d => d.y0 + 13)
.attr("font-size", 11)
.attr("font-weight", 600)
.attr("fill", d => colorScale(d.data.name))
.text(d => `${d.data.name} (${d.children ? d.children.length : 0})`);
const leaf = svg.append("g")
.selectAll("g")
.data(treemapRoot.leaves())
.join("g")
.attr("transform", d => `translate(${d.x0},${d.y0})`)
.style("cursor", "pointer")
.style("opacity", d => (selected.size > 0 && !selected.has(d.parent.data.name)) ? 0.25 : 1)
.on("click", (event, d) => { if (d.data.paper.path) window.location.href = d.data.paper.path; })
.on("mousemove", (event, d) => showTooltip(event, `<strong>${d.data.paper.title}</strong><br>${d.data.paper.categories.join(", ")}${d.data.paper.year ? " · " + d.data.paper.year : ""}${d.data.paper.citations >= 20 ? " · " + d.data.paper.citations + " Google Scholar citations" : ""}`))
.on("mouseleave", hideTooltip);
leaf.append("rect")
.attr("width", d => Math.max(0, d.x1 - d.x0))
.attr("height", d => Math.max(0, d.y1 - d.y0))
.attr("fill", d => colorScale(d.parent.data.name))
.attr("fill-opacity", 0.55)
.attr("stroke", "white")
.attr("stroke-width", 0.5);
return svg.node();
}
Paper Similarity Network
Many papers span several categories, so each node is colored by its rarest category — the least common of its labels — since that’s the most distinctive one.
networkWidth = 928
networkHeight = 620
networkData = {
const nodes = papers.map(p => ({ ...p }));
const seen = new Set();
const links = [];
for (const p of papers) {
for (const n of p.neighbors) {
if (n.similarity < threshold) continue;
const key = [p.id, n.id].sort().join("|");
if (seen.has(key)) continue;
seen.add(key);
links.push({ source: p.id, target: n.id, value: n.similarity });
}
}
return { nodes, links };
}
// Survives re-evaluation of networkChart (legend clicks, threshold changes),
// so the entrance plays once per page view.
networkIntro = ({ played: false })
citationRadius = d3.scaleSqrt()
.domain([0, d3.max(papers, d => d.citations) || 1])
.range([4, 16])
networkChart = {
const nodes = networkData.nodes.map(d => ({ ...d }));
const links = networkData.links.map(d => ({ ...d }));
const wrapper = document.createElement("div");
wrapper.className = "viz-chart-wrapper";
const svg = d3.create("svg")
.attr("class", "viz-svg network-svg")
.attr("viewBox", [0, 0, networkWidth, networkHeight])
.attr("width", networkWidth)
.attr("height", networkHeight)
.attr("style", "max-width: 100%; height: auto;");
// Everything pannable/zoomable lives in this group; the svg element itself
// keeps the card background so it stays put while the contents transform.
const zoomLayer = svg.append("g").attr("class", "zoom-layer");
const simulation = d3.forceSimulation(nodes)
.force("link", d3.forceLink(links).id(d => d.id).distance(55).strength(0.25))
.force("charge", d3.forceManyBody().strength(-85).distanceMax(320))
.force("center", d3.forceCenter(networkWidth / 2, networkHeight / 2))
// Weak pull toward the center so nodes that lose all their links at a
// high similarity threshold don't drift away unopposed by charge alone.
.force("x", d3.forceX(networkWidth / 2).strength(0.03))
.force("y", d3.forceY(networkHeight / 2).strength(0.03))
.force("collide", d3.forceCollide(d => citationRadius(d.citations) + 2));
const LINK_STROKE = "#8f949a", LINK_OPACITY = 0.4;
const link = zoomLayer.append("g")
.selectAll("line")
.data(links)
.join("line")
.attr("stroke", LINK_STROKE)
.attr("stroke-opacity", LINK_OPACITY)
.attr("stroke-width", d => Math.max(0.5, d.value * 3));
const reduceMotion = window.matchMedia("(prefers-reduced-motion: reduce)").matches;
const baseOpacity = d => (selected.size > 0 && !d.categories.some(c => selected.has(c))) ? 0.2 : 1;
const pulseLayer = zoomLayer.append("g").attr("class", "pulse-layer").style("pointer-events", "none");
let pulseTimer = null;
// Hover: light a paper's similarity links in its colour, dim the rest, and
// send signals along each link toward its neighbours. Stronger similarity,
// faster signal; each pulse eases out and back in so it reads as a wave.
function focusNode(d) {
const mine = new Set(links.filter(l => l.source === d || l.target === d));
const near = new Set([d]);
for (const l of mine) near.add(l.source === d ? l.target : l.source);
const col = colorScale(colorCategoryOf(d));
link.attr("stroke", l => mine.has(l) ? col : LINK_STROKE)
.attr("stroke-opacity", l => mine.has(l) ? 0.8 : 0.1);
node.style("opacity", n => near.has(n) ? 1 : 0.15);
if (reduceMotion || mine.size === 0) return;
const pulses = [...mine].flatMap(l => [0, 1 / 3, 2 / 3].map(phase =>
({ l, phase, from: d, to: l.source === d ? l.target : l.source })));
const dots = pulseLayer.selectAll("circle").data(pulses).join("circle")
.attr("r", 2.4).attr("fill", col).attr("stroke", "#f9f8f4").attr("stroke-width", 0.6);
pulseTimer = d3.timer(elapsed => {
dots.each(function (p) {
const speed = 0.45 + 0.9 * p.l.value;
const t = (elapsed / 2200 * speed + p.phase) % 1;
const e = d3.easeSinInOut(t);
this.setAttribute("cx", p.from.x + (p.to.x - p.from.x) * e);
this.setAttribute("cy", p.from.y + (p.to.y - p.from.y) * e);
this.setAttribute("opacity", Math.sin(Math.PI * t).toFixed(3));
});
});
}
function blurNode() {
if (pulseTimer) { pulseTimer.stop(); pulseTimer = null; }
pulseLayer.selectAll("circle").remove();
link.attr("stroke", LINK_STROKE).attr("stroke-opacity", LINK_OPACITY);
node.style("opacity", baseOpacity);
}
invalidation.then(blurNode); // stop pulses if the chart is rebuilt mid-hover
const node = zoomLayer.append("g")
.selectAll("circle")
.data(nodes)
.join("circle")
.attr("r", d => citationRadius(d.citations))
.attr("fill", d => colorScale(colorCategoryOf(d)))
.attr("stroke", "white")
.attr("stroke-width", 0.8)
.style("cursor", "pointer")
.style("opacity", baseOpacity)
.on("mouseenter", (event, d) => focusNode(d))
.on("mousemove", (event, d) => showTooltip(event, `<strong>${d.title}</strong><br>${d.categories.join(", ")}${d.year ? " · " + d.year : ""}${d.citations >= 20 ? " · " + d.citations + " Google Scholar citations" : ""}`))
.on("mouseleave", () => { hideTooltip(); blurNode(); })
.call(d3.drag()
.on("start", (event, d) => {
// Keep the pan/zoom behavior on the svg from also panning
// when a drag starts on a node.
event.sourceEvent.stopPropagation();
if (!event.active) simulation.alphaTarget(0.3).restart();
d.fx = d.x; d.fy = d.y;
d._dragOrigin = [event.x, event.y];
})
.on("drag", (event, d) => { d.fx = event.x; d.fy = event.y; })
.on("end", (event, d) => {
if (!event.active) simulation.alphaTarget(0);
d.fx = null; d.fy = null;
const moved = Math.hypot(event.x - d._dragOrigin[0], event.y - d._dragOrigin[1]);
if (moved < 3 && d.path) window.location.href = d.path;
}));
const radiusOf = d => citationRadius(d.citations);
// Entrance, once per page view, when the network first scrolls into view:
// papers appear in publication order, so the record accumulates year by
// year, then the similarity links draw in.
if (!reduceMotion && !networkIntro.played) {
const years = nodes.map(n => +n.year).filter(Boolean);
const when = d3.scaleLinear().domain(d3.extent(years)).range([0, 1600]).clamp(true);
const midYear = d3.median(years);
node.attr("r", 0);
link.attr("stroke-opacity", 0);
const play = () => {
networkIntro.played = true;
node.transition()
.delay(n => 100 + when(+n.year || midYear))
.duration(520)
.ease(d3.easeBackOut.overshoot(1.7))
.attr("r", radiusOf);
link.transition().delay(1500).duration(900).attr("stroke-opacity", LINK_OPACITY);
};
const io = new IntersectionObserver(entries => {
if (entries.some(e => e.isIntersecting)) { io.disconnect(); play(); }
}, { threshold: 0.25 });
io.observe(svg.node());
invalidation.then(() => io.disconnect());
}
simulation.on("tick", () => {
// Hard-clamp positions so nodes can never drift outside the visible
// frame, regardless of how sparse the graph gets at high thresholds.
for (const d of nodes) {
const r = radiusOf(d);
d.x = Math.max(r, Math.min(networkWidth - r, d.x));
d.y = Math.max(r, Math.min(networkHeight - r, d.y));
}
link
.attr("x1", d => d.source.x)
.attr("y1", d => d.source.y)
.attr("x2", d => d.target.x)
.attr("y2", d => d.target.y);
node
.attr("cx", d => d.x)
.attr("cy", d => d.y);
});
const zoomBehavior = d3.zoom()
.scaleExtent([0.5, 8])
.on("zoom", (event) => zoomLayer.attr("transform", event.transform));
svg.call(zoomBehavior);
const controls = document.createElement("div");
controls.className = "viz-zoom-controls";
const makeButton = (label, title, onClick) => {
const btn = document.createElement("button");
btn.type = "button";
btn.className = "viz-zoom-btn";
btn.textContent = label;
btn.title = title;
btn.onclick = onClick;
return btn;
};
controls.appendChild(makeButton("+", "Zoom in", () =>
svg.transition().duration(200).call(zoomBehavior.scaleBy, 1.4)));
controls.appendChild(makeButton("−", "Zoom out", () =>
svg.transition().duration(200).call(zoomBehavior.scaleBy, 1 / 1.4)));
controls.appendChild(makeButton("Reset", "Reset zoom and pan", () =>
svg.transition().duration(300).call(zoomBehavior.transform, d3.zoomIdentity)));
invalidation.then(() => simulation.stop());
wrapper.appendChild(controls);
wrapper.appendChild(svg.node());
return wrapper;
}