Skip to content

Instantly share code, notes, and snippets.

@plusjade
Last active August 29, 2015 14:03
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save plusjade/f38ded5d5cda0005bca8 to your computer and use it in GitHub Desktop.
Save plusjade/f38ded5d5cda0005bca8 to your computer and use it in GitHub Desktop.
NOTES: line marker-mid. usage of svg marker to place directional arrows on line (needs to be segmented)
// <marker id="direction-marker" viewBox="0 -5 10 10" markerWidth="6" markerHeight="6" orient="auto"><path d="M0,-5L10,0L0,5"></path></marker>
function updateDirectionMarkers(linkData, namespace) {
var line = d3.svg.line()
.x(function(d) { return d.x; })
.y(function(d) { return d.y; });
var linkData = linkData.map(function(d) {
var midX = (d.source.x + d.target.x)/2;
var midY = (d.source.y + d.target.y)/2;
return [
{
x : d.source.x,
y : d.source.y,
_id : d.source._id + '.' + d.target._id
}
,
{
x : midX,
y : midY
}
];
})
var classname = 'link-' + namespace;
var link = World.container.selectAll("path." + classname)
.data(linkData, function(d) { return namespace + d[0]._id; });
var linkEnter = link.enter().insert("svg:path", "g")
.attr('marker-end', "url(#direction-marker)")
.attr("class", classname)
.attr("d", line);
link.transition()
.duration(World.duration)
.style('stroke-opacity', 1)
.attr("d", line);
link.exit().remove();
return link;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment