d3.js强制有向图的不同节点符号 [英] Different node symbols for d3.js force-directed graph

查看:525
本文介绍了d3.js强制有向图的不同节点符号的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何在d3.js的强制引导库中将节点显示为不同的符号?我想要实现类似于下面写的东西:

How do I display nodes as different symbols in d3.js's force-directed library? I wanted to implement something similar to what I wrote below:

  var node = svg.selectAll(".node") 
      .data(graph.nodes) 
    .enter().append(function(d){return d.shape;}) 
      .attr("class", "node") 
      .attr("r", 5) 
      .style("fill", function(d) { return color(d.group); }) 
      .call(force.drag); 

每个节点都有一个编码形状(rect,circle等)。但是,我得到的错误:

Each node would have an encoded shape ("rect", "circle", etc.). However, I get the error:

Uncaught TypeError: Object function (d){return "circle";} has no method 'indexOf' 

我有关的另一个问题是:我如何在应用不同的属性为每个形状?圈子需要精确的r属性,但是rects需要he​​ight和width。谢谢!

The other question I have related to that is this: how would I toggle between applying different attributes for each shape? Circles need an "r" attribute refined, but rects require "height" and "width". Thanks!

推荐答案

使用 d3.svg.symbol ,如力方向符号示例。

这篇关于d3.js强制有向图的不同节点符号的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆