Last active
February 16, 2019 08:39
-
-
Save LironHazan/ad9de7f7eed1534ba3ed30a85e070a73 to your computer and use it in GitHub Desktop.
for d3-force medium post
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
export const ticked = (link, node, edgepaths, edgelabels) => { | |
link | |
.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;}); | |
node.attr("transform", | |
function (d) {return "translate(" + d.x + ", " + d.y + ")";}); | |
edgepaths.attr('d', function (d) { | |
return 'M ' + d.source.x + ' ' + d.source.y + ' L ' + d.target.x + ' ' + d.target.y; | |
}); | |
edgelabels.attr('transform', function (d) { | |
if (d.target.x < d.source.x) { | |
let bbox = this.getBBox(); | |
let rx = bbox.x + bbox.width / 2; | |
let ry = bbox.y + bbox.height / 2; | |
return 'rotate(180 ' + rx + ' ' + ry + ')'; | |
} | |
else { | |
return 'rotate(0)'; | |
} | |
}); | |
} | |
// used as: | |
simulation | |
.nodes(nodes) | |
.on("tick", () => { ticked(link, node, edgepaths, edgelabels)}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment