aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAdam Spiers <git@adamspiers.org>2015-01-08 19:22:00 +0000
committerAdam Spiers <git@adamspiers.org>2015-01-08 19:22:00 +0000
commit94a9f191635b7dc31e380531b9b5c671a63b0b9a (patch)
treec3424547836ee234f7bbfd323547db339c2123bb
parentac3982353bbdf9fddf92e4677ee2b9003de4b27d (diff)
downloadgit-deps-94a9f191635b7dc31e380531b9b5c671a63b0b9a.tar.gz
fix object constancy for links
-rw-r--r--html/js/git-deps-graph.js22
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];