chart = {
const articles = {
"Black Holes": ["RA1", "RA3", "RA6"],
"Supernovae": ["RA3"],
"Dark Matter": ["RA6"],
"Galaxies": ["RA1", "RA3", "RA6"],
"Gravitational Waves": ["RA3"],
"Stars": ["RA2", "RA3", "RA5"],
"Constellations": ["RA3"],
"Star Maps": ["RA5"],
"Solar Path Analysis": ["RA2", "RA3"],
"The Moon": ["RA2", "RA8"],
"Planets": ["RA3", "RA4", "RA7", "RA9", "RA10"],
"Mars": ["RA4", "RA10"],
"Solar System": ["RA7"],
"Celestial Objects": ["RA3"],
"Celestial Object Movements": ["RA5"],
"Planetarium": ["RA9"],
"Astronomical Software": ["RA9"],
"Satellites": ["RA1", "RA6"],
"Space Exploration": ["RA1", "RA6"],
"Space Technology": ["RA1", "RA6"],
"Conditions for Life": ["RA10"],
"Chemical Changes": ["RA10"],
"Historical Development of Astrophysics": ["RA6"],
"General Science Inquiries": ["RA7"],
"General Physics": ["RA4", "RA6", "RA10"],
"Forces": ["RA4", "RA6", "RA10"],
"Newtonian Physics": ["RA4", "RA6", "RA10"],
"Earth's Celestial South Pole": ["RA5"],
"Earth's Motion": ["RA5"],
"Earth's Angular Velocity": ["RA5"]
};
const width = 928;
const marginTop = 10;
const marginRight = 10;
const marginBottom = 10;
const marginLeft = 40;
const root = d3.hierarchy(data);
const dx = 10;
const dy = (width - marginRight - marginLeft) / (1 + root.height);
const tree = d3.tree().nodeSize([dx, dy]);
const diagonal = d3.linkHorizontal().x(d => d.y).y(d => d.x);
const style = document.createElement("style");
style.innerHTML = `
@import url('https://fonts.googleapis.com/css2?family=Latin+Modern+Roman:wght@400&display=swap');
svg {
font-family: 'Latin Modern Roman', serif;
}
`;
document.head.appendChild(style);
const color = d3.scaleOrdinal(d3.schemeCategory10);
root.descendants().forEach(d => {
if (d.depth === 1) {
d.color = color(d.data.name);
} else if (d.depth > 1) {
d.color = d.parent.color;
}
});
const svg = d3.create("svg")
.attr("width", width)
.attr("height", dx)
.attr("viewBox", [-marginLeft, -marginTop, width, dx])
.attr("style", "max-width: 100%; height: auto; font: 10px 'Latin Modern Roman', serif; user-select: none;");
const gLink = svg.append("g")
.attr("fill", "none")
.attr("stroke", "#555")
.attr("stroke-opacity", 0.4)
.attr("stroke-width", 1.5);
const gNode = svg.append("g")
.attr("cursor", "pointer")
.attr("pointer-events", "all");
function update(event, source) {
const duration = event?.altKey ? 2500 : 250;
const nodes = root.descendants().reverse();
const links = root.links();
tree(root);
let left = root;
let right = root;
root.eachBefore(node => {
if (node.x < left.x) left = node;
if (node.x > right.x) right = node;
});
const height = right.x - left.x + marginTop + marginBottom;
const transition = svg.transition()
.duration(duration)
.attr("height", height)
.attr("viewBox", [-marginLeft, left.x - marginTop, width, height])
.tween("resize", window.ResizeObserver ? null : () => () => svg.dispatch("toggle"));
const node = gNode.selectAll("g")
.data(nodes, d => d.id);
const nodeEnter = node.enter().append("g")
.attr("transform", d => `translate(${source.y0},${source.x0})`)
.attr("fill-opacity", 0)
.attr("stroke-opacity", 0)
.on("click", (event, d) => {
d.children = d.children ? null : d._children;
update(event, d);
});
nodeEnter.append("circle")
.attr("r", 2.5)
.attr("fill", d => d._children ? "#555" : "#999")
.attr("stroke-width", 10);
nodeEnter.append("text")
.attr("dy", "0.31em")
.attr("x", d => d._children ? -6 : 6)
.attr("text-anchor", d => d._children ? "end" : "start")
.attr("fill", d => d.color)
.text(d => d.data.name)
.clone(true).lower()
.attr("stroke-linejoin", "round")
.attr("stroke-width", 3)
.attr("stroke", "white");
const nodeUpdate = node.merge(nodeEnter).transition(transition)
.attr("transform", d => `translate(${d.y},${d.x})`)
.attr("fill-opacity", 1)
.attr("stroke-opacity", 1);
const nodeExit = node.exit().transition(transition).remove()
.attr("transform", d => `translate(${source.y},${source.x})`)
.attr("fill-opacity", 0)
.attr("stroke-opacity", 0);
const link = gLink.selectAll("path")
.data(links, d => d.target.id);
const linkEnter = link.enter().append("path")
.attr("d", d => {
const o = {x: source.x0, y: source.y0};
return diagonal({source: o, target: o});
});
link.merge(linkEnter).transition(transition)
.attr("d", diagonal);
link.exit().transition(transition).remove()
.attr("d", d => {
const o = {x: source.x, y: source.y};
return diagonal({source: o, target: o});
});
root.eachBefore(d => {
d.x0 = d.x;
d.y0 = d.y;
});
}
root.x0 = dy / 2;
root.y0 = 0;
root.descendants().forEach((d, i) => {
d.id = i;
d._children = d.children;
if (d.depth && d.data.name.length !== 7) d.children = null;
});
update(null, root);
return svg.node();
}