D3.js Edge Bundling without Hierachy

无人久伴 提交于 2019-12-12 03:14:11

问题


Holten's hierarchical edge bundling algorithm in D3 depends on hierarchical data.

Example: http://bl.ocks.org/mbostock/7607999

Is there a way to implement a similar circular edge bundling graph with those nice splines for non-hierarchical data?

Example: http://bl.ocks.org/sjengle/5432087 (Like this, but with splines...)


回答1:


If your data really is non-hierarchical, you could change the drawCurves function of your example into something like this:

function drawCurves(links) {

  d3.select("#plot").selectAll(".link")
    .data(links)
    .enter()
    .append("path")
    .attr("class", "link")
    .attr("d", function(d){
      var lineData = [
      {
        x: Math.round(d.target.x),
        y: Math.round(d.target.y)
      }, {
      x: Math.round(d.target.x) - Math.round(d.target.x)/3,
        y: Math.round(d.target.y) - Math.round(d.target.y)/3
      }, 
      {
      x: Math.round(d.source.x) - Math.round(d.source.x)/3,
        y: Math.round(d.source.y) - Math.round(d.source.y)/3
      },{
        x: Math.round(d.source.x),
        y: Math.round(d.source.y)
      }];
      return `M${lineData[0].x},${lineData[0].y}C${lineData[1].x},${lineData[1].y},${lineData[2].x},${lineData[2].y},${lineData[3].x},${lineData[3].y} `;
    });
}

To draw the lines with the d attribute the SVG specification provides. Consult https://developer.mozilla.org/en-US/docs/Web/SVG/Attribute/d for further reference.



来源:https://stackoverflow.com/questions/34263110/d3-js-edge-bundling-without-hierachy

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!