3

Link connects the node from the center of the circle. But I want to to connect the nodes from the circumference of the circle.
I am using following code to create the link and connect it:

 var link = svg.selectAll(".link")
                    .data(links)
                    .enter()
                    .append("g")
                    .attr("class", "link")
                    .append("line")
                    .attr("class", function(d) { return "link " + d.rtype; })
                     .attr("class", "link-line")
                    .style("stroke-width", function(d)
                    {
                        return Math.sqrt(d.rtype);
                    }); 


var path = svg.append("svg:g").selectAll("path")
                    .data(force.links())
                    .enter().append("svg:path")
                    .attr("class", function(d)
                    {
                        return "link " + d.rtype;
                    })
                    .attr("id", function(d, i)
                    {
                        return "linkId_" + i;
                    })
                    .attr("marker-end", function(d)
                    {
                        return "url(#" + d.rtype + ")";
                    });

Inside the tick function, I am using this:

path.attr("d", function(d)
                        {
                            console.log(d.radius);
                            var dx = d.target.x - d.source.x,
                                dy = d.target.y - d.source.y,
                                dr = 75 / d.linknum; //linknum is defined above
                                return "M" + (d.source.x) + "," + (d.source.y) + "A" + dr + "," + dr + " 0 0,1 " + (d.target.x) + "," + d.target.y;
                        });

                        link.attr("d", function(d)
                        {
                            var dx = d.target.x - d.source.x,
                                dy = d.target.y - d.source.y,
                                dr = Math.sqrt(dx * dx + dy * dy);

                            return "M" +
                                (d.source.x ) + "," +
                                d.source.y + "A" +
                                dr + "," + dr + " 0 0,1 " +
                                (d.target.x) + "," +
                                d.target.y;


                            });

Can anybody tell me, what changes I have to make?

Mirza Sisic
  • 2,401
  • 4
  • 24
  • 38
RCS
  • 1,370
  • 11
  • 27
  • See https://stackoverflow.com/questions/16568313/arrows-on-links-in-d3js-force-layout/16568625 and https://stackoverflow.com/questions/16660193/get-arrowheads-to-point-at-outer-edge-of-node-in-d3 – Lars Kotthoff Feb 02 '16 at 17:24

0 Answers0