【问题标题】:Specifying style of node through function通过函数指定节点的样式
【发布时间】:2015-01-09 14:30:57
【问题描述】:

在 d3 中,我能够使用函数指定元素的填充样式。例如

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

有没有办法在 dagre-d3 中做同样的事情?

我试过了

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**)

【问题讨论】:

    标签: javascript d3.js dagre-d3 dagre


    【解决方案1】:

    只需连接结果。在字符串中调用函数在这里根本没有任何作用。

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

    【讨论】:

    • @gaitat 很高兴能帮上忙 :)
    猜你喜欢
    • 1970-01-01
    • 2013-08-22
    • 1970-01-01
    • 2019-07-14
    • 2023-03-16
    • 1970-01-01
    • 2023-03-09
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多