chart = {
const root = tree(bilink(d3.hierarchy(data)
.sort((a, b) => d3.ascending(a.height, b.height) || d3.ascending(a.data.name, b.data.name))));
const svg = d3.create("svg")
.attr("viewBox", [-width / 2, -width / 2, width, width]);
const typeColors = {
'member': '#000',
'chapter': '#8c1d40',
'product': '#78BE20',
'guild': '#FF7F32'
}
const node = svg.append("g")
.attr("font-family", "sans-serif")
.attr("font-size", 22)
.selectAll("g")
.data(root.leaves())
.join("g")
.attr("transform", d => `rotate(${d.x * 180 / Math.PI - 90}) translate(${d.y},0)`)
.append("text")
.attr("dy", "0.31em")
.attr("x", d => d.x < Math.PI ? 6 : -6)
.attr("text-anchor", d => d.x < Math.PI ? "start" : "end")
.attr("transform", d => d.x >= Math.PI ? "rotate(180)" : null)
.attr('fill', d => typeColors[d.data.type])
.text(d => d.data.name)
.each(function(d) { d.text = this; })
.on("mouseover", overed)
.on("mouseout", outed)
.call(text => text.append("title").text(d => `${id(d)}
${d.outgoing.length} outgoing
${d.incoming.length} incoming`));
const link = svg.append("g")
.attr("stroke", colornone)
.attr("fill", "none")
.selectAll("path")
.data(root.leaves().flatMap(leaf => leaf.outgoing))
.join("path")
.style("mix-blend-mode", "multiply")
.attr("d", ([i, o]) => line(i.path(o)))
.each(function(d) { d.path = this; });
function overed(d) {
// console.log('d',d);
// console.log('d.data',d.data);
// console.log('d.data.type',d.data.type);
link.style("mix-blend-mode", null);
let mycolor = typeColors[d.data.type];
// console.log('mycolor', mycolor);
d3.select(this).attr("font-weight", "bold");
d3.selectAll(d.incoming.map(d => d.path))
.attr("stroke", (d,i) => typeColors[d[1].data.type])
.attr("stroke-width", 4)
.raise();
d3.selectAll(d.incoming.map(([d]) => d.text))
.attr("font-weight", "bold")
.attr("text-decoration", "underline");
d3.selectAll(d.outgoing.map(d => d.path)).attr("stroke", (d,i) => typeColors[d[1].data.type])
.attr("stroke-width", 4)
.raise();
d3.selectAll(d.outgoing.map(([, d]) => d.text))
.attr("font-weight", "bold")
.attr("text-decoration", "underline");
// d3.selectAll(d.incoming.map(d => d.path)).attr("stroke", colorin).raise();
// d3.selectAll(d.incoming.map(([d]) => d.text)).attr("fill", colorin).attr("font-weight", "bold");
// d3.selectAll(d.outgoing.map(d => d.path)).attr("stroke", colorout).raise();
// d3.selectAll(d.outgoing.map(([, d]) => d.text)).attr("fill", colorout).attr("font-weight", "bold");
}
function outed(d) {
link.style("mix-blend-mode", "multiply");
d3.select(this).attr("font-weight", null).attr('fill', typeColors[d.data.type]);
d3.selectAll(d.incoming.map(d => d.path)).attr("stroke", null).attr("stroke-width", null);
d3.selectAll(d.incoming.map(([d]) => d.text)).attr("font-weight", null).attr("text-decoration", null);
d3.selectAll(d.outgoing.map(d => d.path)).attr("stroke", null).attr("stroke-width", null);
d3.selectAll(d.outgoing.map(([, d]) => d.text)).attr("font-weight", null).attr("text-decoration", null);
// d3.selectAll(d.incoming.map(d => d.path)).attr("stroke", null);
// d3.selectAll(d.incoming.map(([d]) => d.text)).attr("fill", null).attr("font-weight", null);
// d3.selectAll(d.outgoing.map(d => d.path)).attr("stroke", null);
// d3.selectAll(d.outgoing.map(([, d]) => d.text)).attr("fill", null).attr("font-weight", null);
}
return svg.node();
}