chartInternal = {
const svg = d3.select(DOM.svg(width, height))
.style("background", "#fff")
.style("width", "100%")
.style("height", "auto");
const {nodes, links} = sankey({
nodes: traffickingSankeyInternal.nodes,
links: traffickingSankeyInternal.links
});
tooltip
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)
.style("fill", "#cccccc")
.append("title")
.text(d => `${d.name}\n${d.value.toLocaleString()}`);
svg.append("g")
.attr("fill", "none")
.selectAll("g")
.data(links)
.join("path")
.attr("d", d3.sankeyLinkHorizontal())
.attr("stroke", d => color(d.names[0]))
.attr("stroke-width", d => d.width)
.style("opacity", .7)
.on("mouseover", d => tooltip.style("visibility", "visible").text(d.names[0] + " to " + d.names[1] + ":" + d.value.toLocaleString() + " persons trafficked.\n" + d.names[0] + " Global GDP Ranking: " + d.gdpRanking), function() {
d3.select(this)
.transition()
.style("opacity", 1.0) // HELP NEEDED HERE - CAN'T GET OPACITY TO TRANSITION
})
.on("mousemove", d => tooltip.style("top", (d3.event.pageY-10)+"px").style("left",(d3.event.pageX+10)+"px").text(d.names[0] + " to " + d.names[1] + ":" + d.value.toLocaleString() + " persons trafficked.\n" + d.names[0] + " Global GDP Ranking: " + d.gdpRanking), function() {
d3.select(this)
.transition()
.style("opacity", 1.0) // HELP NEEDED HERE - CAN'T GET OPACITY TO TRANSITION
})
.on("mouseout", d => tooltip.style("visibility", "hidden"), function() {
d3.select(this)
.transition()
.style("opacity", 0.7) // HELP NEEDED HERE - CAN'T GET OPACITY TO TRANSITION
})
.style("mix-blend-mode", "multiply")
// .append("title")
// .text(d => `${d.names.join(" to ")}\n${d.value.toLocaleString()}`)
// .attr("font", "20px sans-serif")
// svg.append("g")
// .selectAll("text")
// .data(nodes)
// .join("text")
// .attr("x", d => d.x0 < width / 2 ? d.x1 + 6 : d.x0 - 6) // define position of text
// .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.name)
// .style("font", "10px sans-serif") // define text for paths
// .style("font-size", fontScale(d => d.value)) // HELP NEEDED HERE - CAN'T GET FONT TO SCALE PROPERLY
// .append("tspan")
// .attr("fill-opacity", 0.7)
// .text(d => ` ${d.value.toLocaleString()}`);
return svg.node();
}