diff options
-rw-r--r-- | html/js/git-deps-graph.js | 22 |
1 files changed, 19 insertions, 3 deletions
diff --git a/html/js/git-deps-graph.js b/html/js/git-deps-graph.js index 2561cba..16b6a0f 100644 --- a/html/js/git-deps-graph.js +++ b/html/js/git-deps-graph.js @@ -202,9 +202,7 @@ function draw_graph(commitish) { new_data_notification(new_data); path = fg.selectAll(".link") - .data(links, function (d) { - return d.source + " " + d.target; - }) + .data(links, link_key) .enter().append('svg:path') .attr('class', 'link'); @@ -221,6 +219,24 @@ function draw_graph(commitish) { }); } +// Required for object constancy: http://bost.ocks.org/mike/constancy/ ... +function link_key(link) { + var source = sha1_of_link_pointer(link.source); + var target = sha1_of_link_pointer(link.target); + var key = source + " " + target; + return key; +} + +// ... but even though link sources and targets are initially fed in +// as indices into the nodes array, webcola then replaces the indices +// with references to the node objects. So we have to deal with both +// cases when ensuring we are uniquely identifying each link. +function sha1_of_link_pointer(pointer) { + if (typeof(pointer) == 'object') + return pointer.sha1; + return nodes[pointer].sha1; +} + function new_data_notification(new_data) { var new_nodes = new_data[0]; var new_links = new_data[1]; |