Here's the part of code written in Javascript that creates the rectangle node in the sankey diagram.
Code :
node.append("rect")
.attr("height", function(d) { return d.dy; })
.attr("width", sankey.nodeWidth())
.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); });
each node contain a name as "location|month". so here randomly colours are assigned from the d3.scale.category20();
So i want to assign same colour to all node whose location is same. Eg loc3|May
so all the nodes having location as loc3 must be of same colour.