diff --git a/static/js/graphing.js b/static/js/graphing.js index c7f059991..4d2c82ba4 100644 --- a/static/js/graphing.js +++ b/static/js/graphing.js @@ -485,6 +485,9 @@ ImageHistoryTree.prototype.buildRoot_ = function() { maxChildHeight = Math.max(maxChildHeight, key); }); + // Recursively prune the nodes that are not referenced by a tag + this.pruneUnreferenced_(root); + // Compact the graph so that any single chain of three (or more) images becomes a collapsed // section. We only do this if the max width is > 1 (since for a single width tree, no long // chain will hide a branch). @@ -505,6 +508,23 @@ ImageHistoryTree.prototype.buildRoot_ = function() { }; +/** + * Prunes images which are not referenced either directly or indireclty by any tag. + */ +ImageHistoryTree.prototype.pruneUnreferenced_ = function(node) { + if (node.children) { + var surviving_children = [] + for (var i = 0; i < node.children.length; ++i) { + if (!this.pruneUnreferenced_(node.children[i])) { + surviving_children.push(node.children[i]); + } + } + node.children = surviving_children; + } + return (node.children.length == 0 && node.tags.length == 0); +}; + + /** * Determines the height of the tree at its longest chain. */