Note that there are some explanatory texts on larger screens.

plurals
  1. POScaling an arrowhead on a D3 force layout link marker
    primarykey
    data
    text
    <p>I have the following code in a d3 force directed graph where I'm trying to vary the size of the links and their associated arrowheads based on a value (from 1-3). The stroke weight does change with the value but the arrowheads does not stay in the correct position. It tends to shift back from the end when the stroke weight changes from say 1 to a 3. Any ideas on how to keep the arrowheads (markers) properly aligned when changing the stroke value? Many thanks!</p> <pre><code> var link = vis.selectAll("line.link") .data(json.links) .enter().append("svg:line") .attr("class", "link") .style("stroke-width", function(d) { return Math.sqrt(d.value); }) .attr("x1", function(d) { return d.source.x; }) .attr("y1", function(d) { return d.source.y; }) .attr("x2", function(d) { return d.target.x; }) .attr("y2", function(d) { return d.target.y; }) .attr("marker-end", "url(#arrowGray)") .on("click", function(d) { link.style("stroke","#dddddd"); node.style("stroke","#FFFFFF"); d3.select(this).style("stroke","red"); link.attr("marker-end", null); link.attr("marker-end", "url(#arrowGray)"); d3.select(this).attr("marker-end", null); d3.select(this).attr("marker-end", "url(#arrowRed)"); clickLink(d); }); defs.append("svg:marker") .attr("id", "arrowGray") .attr("viewBox","0 0 10 10") .attr("refX","20") .attr("refY","5") .attr("markerUnits","strokeWidth") .attr("markerWidth","9") .attr("markerHeight","5") .attr("orient","auto") .append("svg:path") .attr("d","M 0 0 L 10 5 L 0 10 z") .attr("fill", "#BBBBBB"); </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload