Search code examples
javascriptd3.jsdagre-d3dagre

Specifying style of node through function


In d3 I was able to specify the fill style of an element using a function. For example

color = d3.scale.category10().domain(d3.range(0,10));
...
.style( "fill", function(d) { return color(d); } ) 

Is there a way to do the same thing in dagre-d3?

I have tried

g.setNode( 0, { style: "fill: green; stroke: yellow" } ) (**works fine**)

g.setNode( 0, { style: "fill: function() { return color(2); }" } ) (**Does NOT work**)

g.setNode( 0, { style: "fill: color(2)" } ) (**Does NOT work**)

Solution

  • Just concat the result. Calling a function in a string has no effect here at all.

    g.setNode(0, { style: "fill: " + color(2) }); // **I suppose it works**