admin管理员组文章数量:1399901
I have built a d3
force directed graph with grouped nodes. I want to enclose the groups inside cloud like structure. How can I do this?
Js Fiddle link for the graph: /
My result should look similar to this image:
I have built a d3
force directed graph with grouped nodes. I want to enclose the groups inside cloud like structure. How can I do this?
Js Fiddle link for the graph: http://jsfiddle/Cfq9J/5/
My result should look similar to this image:
Share Improve this question edited Oct 10, 2017 at 17:21 Cœur 38.8k25 gold badges205 silver badges277 bronze badges asked Oct 15, 2012 at 4:21 Sunil RajSunil Raj 4605 silver badges20 bronze badges 1- Your data only shows one group - are there supposed to be more? – nrabinowitz Commented Oct 15, 2012 at 17:27
1 Answer
Reset to default 12This is a tricky problem, and I'm not wholly sure you can do it in a performative way. You can see my static implementation here: http://jsfiddle/nrabinowitz/yPfJH/
and the dynamic implementation here, though it's quite slow and jittery: http://jsfiddle/nrabinowitz/9a7yy/
Notes on the implementation:
This works by masking each circle with all of the other circles in its group. You might be able to speed this up with collision detection.
Because each circle is both rendered and used as a mask, there's heavy use of
use
elements to reference the circle for each node. The actual circle is defined in adef
element, a non-rendered definition for reuse. When this is run, each node will be rendered like this:<g class="node"> <defs> <circle id="circlelanguages" r="46" transform="translate(388,458)" /> </defs> <mask id="masklanguages"> <!-- show the circle itself, as a base --> <use xlink:href="#circlelanguages" fill="white" stroke-width="2" stroke="white"></use> <!-- now hide all the other circles in the group --> <use class="other" xlink:href="#circleenglish" fill="black"></use> <use class="other" xlink:href="#circlereligion" fill="black"> <!-- ... --> </mask> <!-- now render the circle, with its custom mask --> <use xlink:href="#circlelanguages" mask="url(#masklanguages)" style="fill: #ffffff; stroke: #1f77b4; " /> </g>
I put node circles, links, and text each in a different
g
container, to layer them appropriately.You'd be better off including a data variable in your node data, rather than font size - I had to convert the
fontSize
property to an integer to use it for the circle radius. Even then, because the width of the text isn't tied to the data value, you'll get some text that's bigger than the circle beneath it.Not sure why the circle for the first node isn't placed correctly in the static version - it works in the dynamic one. Mystery.
本文标签:
版权声明:本文标题:javascript - enclosing the nodes of a d3 force directed graph in a circle or a polygon or a cloud - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1744190712a2594504.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论