chart = {
const svg = d3.create("svg")
.attr("viewBox", [0, 0, width, height]);
const {nodes, links} = sankey({
nodes: graph.nodes.map(d => Object.assign({}, d)),
links: graph.links.map(d => Object.assign({}, d))
});
svg.append("g")
.style("font", `18px ${fontFamily}`)
.style("font-weight", "bold")
.append("text")
.classed('sankey-label',true)
.attr("x", 0)
.attr("y", 28)
.append("tspan")
.text("Point of View");
svg.append("g")
.style("font", `18px ${fontFamily}`)
.style("font-weight", "bold")
.append("text")
.classed('sankey-label',true)
.attr("x", width-margin.left)
.attr("y", 28)
.append("tspan")
.attr("text-anchor", "end")
.text("Chapter");
svg.append("g")
.selectAll("rect")
.data(nodes)
.join("rect")
.attr("x", d => d.x0)
.attr("y", d => d.y0)
.attr("height", d => d.y1 - d.y0)
.attr("width", d => d.x1 - d.x0)
.append("title")
.text(d => d.nameComplete ? d.nameComplete : d.name);
svg.append("g")
.attr("fill", "none")
.selectAll("g")
.data(links)
.join("path")
.attr("d", d3.sankeyLinkHorizontal())
.attr("stroke", d => {
return color(d.names[0])
})
.attr("stroke-width", d => d.width)
.style("mix-blend-mode", "multiply")
.on('mouseover', function(d, i) {
const t = d3.transition('enlarge').duration(500)
tooltipMouseOver(d, i, t)
})
.on('mouseout', function(d, i) {
const t = d3.transition('dwindle').duration(500)
tooltipMouseOut(d, i, t)
})
svg.append("g")
.style("font", `16px ${fontFamily}`)
.selectAll("text")
.data(nodes)
.join("text")
.classed('sankey-text',true)
.attr("x", d => d.x0 < width / 2 ? d.x1 + 6 : d.x0 - 6)
.attr("y", d => (d.y1 + d.y0) / 2)
.attr("dy", "0.35em")
.attr("text-anchor", d => d.x0 < width / 2 ? "start" : "end")
.text(d => d.x0 < width / 2 ? d.name : parseInt(d.name) % 5 == 0 || d.name == "1" ? parseInt(d.name): "")
return svg.node();
}