首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >更改protovis节点链接树中的颜色

更改protovis节点链接树中的颜色
EN

Stack Overflow用户
提问于 2017-02-16 04:52:26
回答 1查看 47关注 0票数 0

虽然Protovis不再处于开发阶段,而且D3是较新的软件,但我对它还是个新手。然而,由于各种原因,我使用Protovis的节点链接树来显示我的数据,所以我更喜欢使用Protovis,但是如果有人在脑海中有我还没有遇到的R包(除了dendextend,ggplot2,d3network等),让我使用R而不是Protovis,请让我知道。无论如何,我的Protovis数据片段如下所示:

代码语言:javascript
复制
var PB = {
    PBC03013: {
"103937011_PbUn_2838": 3013,
"103934808_PbUn_26206": 3013,
"103930675_PbUn_35145": 3013,
"103941984_PbUn_52102": 3013,
"103935933_PbUn_63128": 3013,
"103966210_PbUn_64271": 3013
},
PBC03018: {
"103935981_PbUn_53113": 3018,
"103934997_PbUn_59093": 3018,
"103936640_PbUn_65330": 3018,
"103955166_PbUn_112582": 3018
},
...
}
}
I'm trying to change the node colors such that the dots for the elements in PB03013 and PB03018 are different, say "green" and "red", respectively. So all of the PB03013 element dots are green and all of the PB03018 element dots are red. There are 10 nodes in total. I've done a lot of research on this but I'm having such a hard time setting different dot colors I decided to post for help.  

This is the body of my html code:
var tree = vis.add(pv.Layout.Tree)
    .nodes(pv.dom(PB).root("PB").nodes())
    .depth(127)
    .breadth(7.25)
    .orient("radial");

tree.link.add(pv.Line);

tree.node.add(pv.Dot)
    .fillStyle(function(n) n.firstChild ? "#a1d99b" : "#de2d26");

tree.label.add(pv.Label);

So far, I've been using pv.Color pallets or n.key n.parentNode, etc code alterations to no success. I also set a new variable to force different colors like:
var re = "",
    color = pv.Colors.category19().by(function(d) d.parentNode.nodeName)
    nodes = pv.dom(PB).root("PB").nodes();

Then:

treemap.leaf.add(pv.Panel)
    .fillStyle(function(d) color(d).alpha(title(d).match(re) ? 1 : .2))

The node-link tree code can also be found here: 
http://mbostock.github.io/protovis/ex/tree.html  

Any help is greatly appreciated.
EN

回答 1

Stack Overflow用户

发布于 2017-09-06 20:52:33

networkD3d3Network的继任者,功能更强大,可能会满足您的需求。特别是,当前的开发版本(截至2017.09.06的v0.4.9000)具有一个新的treeNetwork功能,该功能非常强大,包括显式设置每个单独节点和链接的颜色的能力。我们很高兴得到feedback,因为它还在开发中。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/42259827

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档