diff --git a/static/js/graphing.js b/static/js/graphing.js index 65a11a265..c65af00b5 100644 --- a/static/js/graphing.js +++ b/static/js/graphing.js @@ -340,6 +340,23 @@ ImageHistoryTree.prototype.changeImage_ = function(imageId) { }; +/** + * Expands the given collapsed node in the tree. + */ +ImageHistoryTree.prototype.expandCollapsed_ = function(imageNode) { + var index = imageNode.parent.children.indexOf(imageNode); + if (index < 0 || imageNode.encountered.length < 2) { + return; + } + + // Note: we start at 1 since the 0th encountered node is the parent. + imageNode.parent.children.splice(index, 1, imageNode.encountered[1]); + this.maxHeight_ = this.determineMaximumHeight_(this.root_); + this.update_(this.root_); + this.updateDimensions_(); +}; + + /** * Builds the root node for the tree. */ @@ -642,7 +659,10 @@ ImageHistoryTree.prototype.update_ = function(source) { .attr("dy", ".35em") .attr("text-anchor", function(d) { return d.children || d._children ? "end" : "start"; }) .text(function(d) { return d.name; }) - .on("click", function(d) { if (d.image) { that.changeImage_(d.image.id); } }) + .on("click", function(d) { + if (d.image) { that.changeImage_(d.image.id); } + if (d.collapsed) { that.expandCollapsed_(d); } + }) .on('mouseover', tip.show) .on('mouseout', tip.hide); @@ -695,9 +715,9 @@ ImageHistoryTree.prototype.update_ = function(source) { if (d.virtual) { return 'virtual'; } - if (!currentImage) { - return ''; - } + if (!currentImage) { + return ''; + } return d.image.id == currentImage.id ? 'current' : ''; });