【问题标题】:d3 js highlight nodes containing given stringd3 js突出显示包含给定字符串的节点
【发布时间】:2017-02-21 18:19:51
【问题描述】:

我愿意搜索并突出显示包含给定字符串的节点。 sample

为此,我正在调用 set_focus 方法

function set_focus(d)
{   
    text.style("opacity", function(o) {
        return isConnected(d.id, o.id) ? 1 : null;
    });

    img.style("opacity", function(o) {
        return isConnected(d.id, o.id) ? 1 : null;
    });

    link.style("opacity", function(o) {
        return o.source.index == d.index || o.target.index == d.index ? 1 : null;
    }); 

}

上面的函数是有条件地设置元素的不透明度。我想设置相互连接的节点的不透明度。但我不想打扰那些未连接的节点的不透明度。

更多说明:

return isConnected(d.id, o.id) ? 1 : null;

如果isConnected == false,我不想返回不透明度

必填: return isConnected(d.id, o.id) ? 1 : "here return the current opacity value";

正在发生的事情: return isConnected(d.id, o.id) ? 1 : "returning zero or null";

【问题讨论】:

    标签: javascript jquery asp.net d3.js


    【解决方案1】:

    可以通过getter获取当前元素的不透明度值:

    d3.select(this).style("opacity");
    

    然后,您可以在三元运算符中使用它:

    text.style("opacity", function(o) {
        var current =  d3.select(this).style("opacity");
        return isConnected(d.id, o.id) ? 1 : current;
    });
    

    【讨论】:

    • 谢谢 Gerardo,我已经尝试过你所说的...但是 var current = d3.select(this).attr("opacity");正在返回 null。我需要在创建文本时设置文本的不透明度吗?
    • 好的,var current = d3.select(this).style("opacity");用样式替换 attr .... 谢谢!
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-01-28
    • 2021-06-14
    • 2011-09-04
    • 1970-01-01
    • 2014-04-19
    相关资源
    最近更新 更多