D3 fisheye on a force graph with markers

ⅰ亾dé卋堺 提交于 2019-12-11 14:36:14

问题


I love the new fisheye plug in (http://bost.ocks.org/mike/fisheye/) but want to get it working on a force graph that uses paths and markers rather than lines. I am new to D3 and so far combining the markers demo, with the fisheye demo has defeated me, I wondered if anyone had been successful and could point me in the right direction.

Cheers Ben


回答1:


vis.on("mousemove", function() { if (rmbMenuHidden) { fisheye.center(d3.mouse(this));

        node
            .each(function(d) { d.display = fisheye(d); })
            .attr("cx", function(d) { return d.display.x; })
            .attr("cy", function(d) { return d.display.y; })
            .attr("r", function(d) {  d.display.r=d.display.z * 10; return d.display.r;});

        path.attr("d", function(d) {

            var dx = d.t.display.x - d.s.display.x;
            var dy = d.t.display.y - d.s.display.y;

            var h= Math.sqrt(dx * dx + dy * dy);
            var htr = h-d.t.display.r-d.edgeWidth-1;
            var cos=dx/h;
            var sin=dy/h;

            var dxt = cos*htr+d.s.display.x;
            var dyt = sin*htr+d.s.display.y;

            //clip source to circle radius too
            var dxs = cos*d.s.display.r+d.s.display.x;
            var dys = sin*d.s.display.r+d.s.display.y;

                var dx = d.t.display.x - d.s.display.x,
                dy = d.t.display.y - d.s.display.y;
                dr = Math.sqrt(dx * dx + dy * dy);
                return "M" + d.s.display.x + "," + d.s.display.y + "A" + dr + "," + dr + " 0 0,1 " + dxt + "," + dyt;
        });
    }
}


来源:https://stackoverflow.com/questions/10327176/d3-fisheye-on-a-force-graph-with-markers

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