Ok - I have modified the downloaded source for Tidy Tree and placed that source in my own html file. I’m successfully loading the data from the flare-2.json data file. I get no errors, and I’ve verified proper loading of the data from flare-2.json.
However - I cannot get the tree to render in the browser (I’m using chrome). There must be some really simple step I’m missing. Here’s the modified source that’s no longer dependent on Observable:
<head>
<script src="https://d3js.org/d3.v6.min.js"></script>
<link rel="stylesheet" type="text/css" href="./inspector.css">
<style>
</style>
</head>
<body>
<script>
var data = d3.json(“http://localhost:8000/flare-2.json”);
var width = 954;
var tree = data => {
const root = d3.hierarchy(data);
root.dx = 10;
root.dy = width / (root.height + 1);
return d3.tree().nodeSize([root.dx, root.dy])(root);
};
chart(tree,data,width);
function chart(tree,data,width)
{
const root = tree(data);
//console.log(root);
let x0 = Infinity;
let x1 = -x0;
root.each(d => {
if (d.x > x1) x1 = d.x;
if (d.x < x0) x0 = d.x;
});
const svg = d3.create(“svg”)
.attr("viewBox", [0, 0, width, x1 - x0 + root.dx * 2]);
const g = svg.append(“g”)
.attr("font-family", "sans-serif")
.attr("font-size", 10)
.attr("transform", `translate(${root.dy / 3},${root.dx - x0})`);
const link = g.append(“g”)
.attr("fill", "none")
.attr("stroke", "#555")
.attr("stroke-opacity", 0.4)
.attr("stroke-width", 1.5)
.selectAll(“path”)
.data(root.links())
.join("path")
.attr("d", d3.linkHorizontal()
.x(d => d.y)
.y(d => d.x));
const node = g.append(“g”)
.attr("stroke-linejoin", "round")
.attr("stroke-width", 3)
.selectAll("g")
.data(root.descendants())
.join("g")
.attr("transform", d => `translate(${d.y},${d.x})`);
node.append(“circle”)
.attr("fill", d => d.children ? "#555" : "#999")
.attr("r", 2.5);
node.append(“text”)
.attr("dy", "0.31em")
.attr("x", d => d.children ? -6 : 6)
.attr("text-anchor", d => d.children ? "end" : "start")
.text(d => d.data.name)
.clone(true).lower()
.attr("stroke", "white");
return svg.node();
};
</body>