我正在研究D3中的力导向图.我想通过将所有其他节点和链接设置为较低的不透明度来突出显示鼠标悬停节点,其链接及其子节点.
在这个例子中,http://jsfiddle.net/xReHA/,我能够淡出所有的链接和节点然后淡化连接的链接,但是,到目前为止,我还没有能够优雅地淡化连接的节点,它们是当前鼠标悬停节点的子节点.
这是代码中的关键功能:
function fade(opacity) {
    return function(d, i) {
        //fade all elements
        svg.selectAll("circle, line").style("opacity", opacity);
        var associated_links = svg.selectAll("line").filter(function(d) {
            return d.source.index == i || d.target.index == i;
        }).each(function(dLink, iLink) {
            //unfade links and nodes connected to the current node
            d3.select(this).style("opacity", 1);
            //THE FOLLOWING CAUSES: Uncaught TypeError: Cannot call method 'setProperty' of undefined
            d3.select(dLink.source).style("opacity", 1);
            d3.select(dLink.target).style("opacity", 1);
        });
    };
}
Run Code Online (Sandbox Code Playgroud)
Uncaught TypeError: Cannot call method 'setProperty' of undefined当我尝试在从source.target加载的元素上设置不透明度时,我收到错误.我怀疑这不是将该节点作为d3对象加载的正确方法,但我找不到另一种方法来加载它而不再遍历所有节点以找到与链接的目标或源匹配的节点.为了保持性能合理,我不希望迭代超过所有节点.
我以http://mbostock.github.com/d3/ex/chord.html上的链接淡化为例:

但是,这并未显示如何更改已连接的子节点.
任何有关如何解决或改善这一点的好建议都将被激烈地推崇:)
您将如何使用data.table有效地获取数据框中每个组内的行样本?
DT = data.table(a = sample(1:2), b = sample(1:1000,20))
DT
    a   b
 1: 2 562
 2: 1 183
 3: 2 180
 4: 1 874
 5: 2 533
 6: 1  21
 7: 2  57
 8: 1  20
 9: 2  39
10: 1 948
11: 2 799
12: 1 893
13: 2 993
14: 1  69
15: 2 906
16: 1 347
17: 2 969
18: 1 130
19: 2 118
20: 1 732
Run Code Online (Sandbox Code Playgroud)
我想的是:DT[ , sample(??, 3), by = a] …
我正在批量导入记录,并且不希望每次都更新计数器.我想在批量upsert期间跳过counter_cache sql更新,然后在循环结束时调用reset_counters.
我试过了:
my_model = MyModel.find_or_initialize_by_slug row[:slug]
my_model.association(:my_association).reflection.options[:counter_cache] = false
my_model.attributes = {:name => "Christopher"}
my_model.save!
Run Code Online (Sandbox Code Playgroud)
但我可以在sql输出中看到它仍在更新counter_cache.
注意:我不能使用activerecord-import,因为我想执行upserts并且我正在使用postgresql
activerecord ×1
chord ×1
d3.js ×1
data.table ×1
force-layout ×1
highlight ×1
javascript ×1
postgresql ×1
r ×1