Skip to content

Instantly share code, notes, and snippets.

@bparaj
Created May 18, 2018 02:46
Show Gist options
  • Save bparaj/fa45f2f80bdf9908ff91cba001218217 to your computer and use it in GitHub Desktop.
Save bparaj/fa45f2f80bdf9908ff91cba001218217 to your computer and use it in GitHub Desktop.
1. When drawing links from source to target, make sure that the link simply touches the target.
This will make the arrow-head at the end of the link visible.
.attr("x1", function(d) { return d.source.x_ * width + nodeW / 2 ; })
.attr("y1", function(d) { return d.source.y_ * height + nodeH / 2 ; })
.attr("x2", function(d) { return d.target.x_ * width + nodeW / 2 + nodeW / 2 * Math.sign(d.source.x_ - d.target.x_); })
.attr("y2", function(d) { return d.target.y_ * height + nodeH / 2 + nodeH / 2 * Math.sign(d.source.y_ - d.target.y_); })
2. If you want to insert text in a rectangle, the text and the rect elements should be siblings. https://stackoverflow.com/a/5450269
To keep the text within the rect, specify the following attributes:
.attr("dominant-baseline", "hanging")
.text(function (d){ return d.id; })
.attr("x", function (d){ return d.x_ * width + rectRound; })
.attr("y", function (d){ return d.y_ * height ; })
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment