I am creating a Sankey Diagram using the D3 Sankey plugin. I have the standard columns: source, target, value plus one additional column called nodeColor. I would like the color of the target node to be dictated by the color noted in the "nodeColorTarget" column. I was able to change the source code for the nodes to be all one color. However, I was unable to develop a function to use the additional column to dictate the color.
Sample Data:
source,target,value,nodeColorTarget
Dist A,Place1,1,red
DistB,Place1,5,red
DistB,Place2,2,grey
DistB,Place2,1,grey
DistB,Place3,2,blue
Existing Code:
// add the rectangles for the nodes
node.append("rect")
.attr("height", function(d) { return d.dy; })
.attr("width", sankey.nodeWidth())
.style("fill", "red")
//.style("fill", function(d) {
//return d.color = color(d.name.replace(/ .*/, "")); })
//.style("stroke", function(d) {
// return d3.rgb(d.color).darker(2); })
//.append("title")
// .text(function(d) {
// return d.name + "\n" + format(d.value); });
My full code is here.