Tweak drawing.js to have a better default margin that never truncates image ids on the left in small widths. Tweak the screenshot generator to use the smallest possible width. Remove tabs from several files. Add the browser-chrome plugin to wrap phantomjs screenshots with browser chrome. Add some repository descriptions to the dataset generator. Switch to using our own screenshots vs those hosted on blogger.
This commit is contained in:
parent
04b8a009da
commit
4040bb37c6
15 changed files with 391 additions and 155 deletions
|
@ -65,12 +65,7 @@ ImageHistoryTree.prototype.draw = function(container) {
|
|||
var boundingBox = document.getElementById(container).getBoundingClientRect();
|
||||
document.getElementById(container).style.maxHeight = (viewportHeight - boundingBox.top) + 'px';
|
||||
|
||||
var leftMargin = 20;
|
||||
if (width > document.getElementById(container).clientWidth) {
|
||||
leftMargin = 120;
|
||||
}
|
||||
|
||||
var margin = { top: 40, right: 20, bottom: 20, left: leftMargin };
|
||||
var margin = { top: 40, right: 20, bottom: 20, left: 40 };
|
||||
var m = [margin.top, margin.right, margin.bottom, margin.left];
|
||||
var w = width - m[1] - m[3];
|
||||
var h = height - m[0] - m[2];
|
||||
|
@ -98,13 +93,13 @@ ImageHistoryTree.prototype.draw = function(container) {
|
|||
.direction('e')
|
||||
.html(function(d) {
|
||||
var html = '';
|
||||
if (d.collapsed) {
|
||||
for (var i = 1; i < d.encountered.length; ++i) {
|
||||
html += '<span>' + d.encountered[i].image.id.substr(0, 12) + '</span>';
|
||||
html += '<span class="created">' + formatTime(d.encountered[i].image.created) + '</span>';
|
||||
}
|
||||
return html;
|
||||
}
|
||||
if (d.collapsed) {
|
||||
for (var i = 1; i < d.encountered.length; ++i) {
|
||||
html += '<span>' + d.encountered[i].image.id.substr(0, 12) + '</span>';
|
||||
html += '<span class="created">' + formatTime(d.encountered[i].image.created) + '</span>';
|
||||
}
|
||||
return html;
|
||||
}
|
||||
|
||||
if (d.image.comment) {
|
||||
html += '<span class="comment">' + formatComment(d.image.comment) + '</span>';
|
||||
|
@ -228,9 +223,9 @@ ImageHistoryTree.prototype.buildRoot_ = function() {
|
|||
var immediateParent = ancestors[ancestors.length - 1] * 1;
|
||||
var parent = imageByDBID[immediateParent];
|
||||
if (parent) {
|
||||
// Add a reference to the parent. This makes walking the tree later easier.
|
||||
imageNode.parent = parent;
|
||||
parent.children.push(imageNode);
|
||||
// Add a reference to the parent. This makes walking the tree later easier.
|
||||
imageNode.parent = parent;
|
||||
parent.children.push(imageNode);
|
||||
} else {
|
||||
formatted = imageNode;
|
||||
}
|
||||
|
@ -240,16 +235,16 @@ ImageHistoryTree.prototype.buildRoot_ = function() {
|
|||
// the width of the tree properly.
|
||||
var maxChildCount = 0;
|
||||
for (var i = 0; i < this.images_.length; ++i) {
|
||||
var image = this.images_[i];
|
||||
var image = this.images_[i];
|
||||
var imageNode = imageByDBID[image.dbid];
|
||||
maxChildCount = Math.max(maxChildCount, this.determineMaximumChildCount_(imageNode));
|
||||
maxChildCount = Math.max(maxChildCount, this.determineMaximumChildCount_(imageNode));
|
||||
}
|
||||
|
||||
// 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).
|
||||
if (maxChildCount > 1) {
|
||||
this.collapseNodes_(formatted);
|
||||
this.collapseNodes_(formatted);
|
||||
}
|
||||
|
||||
// Determine the maximum height of the tree.
|
||||
|
@ -259,8 +254,8 @@ ImageHistoryTree.prototype.buildRoot_ = function() {
|
|||
this.root_ = formatted;
|
||||
|
||||
return {
|
||||
'maxWidth': maxChildCount + 1,
|
||||
'maxHeight': maxHeight
|
||||
'maxWidth': maxChildCount + 1,
|
||||
'maxHeight': maxHeight
|
||||
};
|
||||
};
|
||||
|
||||
|
@ -284,35 +279,35 @@ ImageHistoryTree.prototype.determineMaximumHeight_ = function(node) {
|
|||
*/
|
||||
ImageHistoryTree.prototype.collapseNodes_ = function(node) {
|
||||
if (node.children.length == 1) {
|
||||
// Keep searching downward until we find a node with more than a single child.
|
||||
var current = node;
|
||||
var previous = node;
|
||||
var encountered = [];
|
||||
while (current.children.length == 1) {
|
||||
encountered.push(current);
|
||||
previous = current;
|
||||
current = current.children[0];
|
||||
}
|
||||
// Keep searching downward until we find a node with more than a single child.
|
||||
var current = node;
|
||||
var previous = node;
|
||||
var encountered = [];
|
||||
while (current.children.length == 1) {
|
||||
encountered.push(current);
|
||||
previous = current;
|
||||
current = current.children[0];
|
||||
}
|
||||
|
||||
if (encountered.length >= 3) {
|
||||
// Collapse the node.
|
||||
var collapsed = {
|
||||
"name": '(' + encountered.length + ' images)',
|
||||
"children": [current],
|
||||
"collapsed": true,
|
||||
"encountered": encountered
|
||||
};
|
||||
node.children = [collapsed];
|
||||
if (encountered.length >= 3) {
|
||||
// Collapse the node.
|
||||
var collapsed = {
|
||||
"name": '(' + encountered.length + ' images)',
|
||||
"children": [current],
|
||||
"collapsed": true,
|
||||
"encountered": encountered
|
||||
};
|
||||
node.children = [collapsed];
|
||||
|
||||
// Update the parent relationships.
|
||||
collapsed.parent = node;
|
||||
current.parent = collapsed;
|
||||
return;
|
||||
}
|
||||
// Update the parent relationships.
|
||||
collapsed.parent = node;
|
||||
current.parent = collapsed;
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
for (var i = 0; i < node.children.length; ++i) {
|
||||
this.collapseNodes_(node.children[i]);
|
||||
this.collapseNodes_(node.children[i]);
|
||||
}
|
||||
};
|
||||
|
||||
|
@ -326,7 +321,7 @@ ImageHistoryTree.prototype.determineMaximumChildCount_ = function(node) {
|
|||
var nestedCount = 0;
|
||||
|
||||
for (var i = 0; i < children.length; ++i) {
|
||||
nestedCount += children[i].children.length;
|
||||
nestedCount += children[i].children.length;
|
||||
}
|
||||
|
||||
return Math.max(myLevelCount, nestedCount);
|
||||
|
@ -339,10 +334,10 @@ ImageHistoryTree.prototype.determineMaximumChildCount_ = function(node) {
|
|||
*/
|
||||
ImageHistoryTree.prototype.findImage_ = function(checker) {
|
||||
for (var i = 0; i < this.images_.length; ++i) {
|
||||
var image = this.images_[i];
|
||||
if (checker(image)) {
|
||||
return image;
|
||||
}
|
||||
var image = this.images_[i];
|
||||
if (checker(image)) {
|
||||
return image;
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
|
@ -356,8 +351,8 @@ ImageHistoryTree.prototype.markPath_ = function(startingNode, isHighlighted) {
|
|||
var currentNode = startingNode;
|
||||
currentNode.current = isHighlighted;
|
||||
while (currentNode != null) {
|
||||
currentNode.highlighted = isHighlighted;
|
||||
currentNode = currentNode.parent;
|
||||
currentNode.highlighted = isHighlighted;
|
||||
currentNode = currentNode.parent;
|
||||
}
|
||||
};
|
||||
|
||||
|
@ -384,25 +379,25 @@ ImageHistoryTree.prototype.setTag_ = function(tagName) {
|
|||
|
||||
// Ensure that the children are in the correct order.
|
||||
for (var i = 0; i < this.images_.length; ++i) {
|
||||
var image = this.images_[i];
|
||||
var imageNode = this.imageByDBID_[image.dbid];
|
||||
var ancestors = this.getAncestors_(image);
|
||||
var image = this.images_[i];
|
||||
var imageNode = this.imageByDBID_[image.dbid];
|
||||
var ancestors = this.getAncestors_(image);
|
||||
var immediateParent = ancestors[ancestors.length - 1] * 1;
|
||||
var parent = imageByDBID[immediateParent];
|
||||
if (parent && imageNode.highlighted) {
|
||||
var arr = parent.children;
|
||||
if (parent._children) {
|
||||
arr = parent._children;
|
||||
}
|
||||
if (parent && imageNode.highlighted) {
|
||||
var arr = parent.children;
|
||||
if (parent._children) {
|
||||
arr = parent._children;
|
||||
}
|
||||
|
||||
if (arr[0] != imageNode) {
|
||||
var index = arr.indexOf(imageNode);
|
||||
if (index > 0) {
|
||||
arr.splice(index, 1);
|
||||
arr.splice(0, 0, imageNode);
|
||||
}
|
||||
}
|
||||
}
|
||||
if (arr[0] != imageNode) {
|
||||
var index = arr.indexOf(imageNode);
|
||||
if (index > 0) {
|
||||
arr.splice(index, 1);
|
||||
arr.splice(0, 0, imageNode);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Update the tree.
|
||||
|
@ -416,11 +411,11 @@ ImageHistoryTree.prototype.setTag_ = function(tagName) {
|
|||
ImageHistoryTree.prototype.setImage_ = function(imageId) {
|
||||
// Find the new current image.
|
||||
var newImage = this.findImage_(function(image) {
|
||||
return image.id == imageId;
|
||||
return image.id == imageId;
|
||||
});
|
||||
|
||||
if (newImage == this.currentImage_) {
|
||||
return;
|
||||
return;
|
||||
}
|
||||
|
||||
this.currentImage_ = newImage;
|
||||
|
@ -510,7 +505,7 @@ ImageHistoryTree.prototype.update_ = function(source) {
|
|||
nodeUpdate.select("circle")
|
||||
.attr("r", 4.5)
|
||||
.attr("class", function(d) {
|
||||
return (d._children ? "closed " : "open ") + (d.current ? "current " : "") + (d.highlighted ? "highlighted " : "");
|
||||
return (d._children ? "closed " : "open ") + (d.current ? "current " : "") + (d.highlighted ? "highlighted " : "");
|
||||
})
|
||||
.style("fill", function(d) {
|
||||
if (d.current) {
|
||||
|
@ -522,10 +517,10 @@ ImageHistoryTree.prototype.update_ = function(source) {
|
|||
// Update the repo text.
|
||||
nodeUpdate.select("text")
|
||||
.attr("class", function(d) {
|
||||
if (d.collapsed) {
|
||||
return 'collapsed';
|
||||
}
|
||||
return d.image.id == that.currentImage_.id ? 'current' : '';
|
||||
if (d.collapsed) {
|
||||
return 'collapsed';
|
||||
}
|
||||
return d.image.id == that.currentImage_.id ? 'current' : '';
|
||||
});
|
||||
|
||||
// Ensure that the node is visible.
|
||||
|
@ -535,9 +530,9 @@ ImageHistoryTree.prototype.update_ = function(source) {
|
|||
// Update the tags.
|
||||
node.select(".tags")
|
||||
.html(function(d) {
|
||||
if (!d.tags) {
|
||||
return '';
|
||||
}
|
||||
if (!d.tags) {
|
||||
return '';
|
||||
}
|
||||
|
||||
var html = '';
|
||||
for (var i = 0; i < d.tags.length; ++i) {
|
||||
|
@ -554,10 +549,10 @@ ImageHistoryTree.prototype.update_ = function(source) {
|
|||
// Listen for click events on the labels.
|
||||
node.selectAll(".tag")
|
||||
.on("click", function(d, e) {
|
||||
var tag = this.getAttribute('data-tag');
|
||||
if (tag) {
|
||||
that.changeTag_(tag);
|
||||
}
|
||||
var tag = this.getAttribute('data-tag');
|
||||
if (tag) {
|
||||
that.changeTag_(tag);
|
||||
}
|
||||
});
|
||||
|
||||
// Ensure the tags are visible.
|
||||
|
@ -568,7 +563,7 @@ ImageHistoryTree.prototype.update_ = function(source) {
|
|||
// we force a redraw by adjusting the height of the object ever so slightly.
|
||||
nodeUpdate.select(".fo")
|
||||
.attr('height', function(d) {
|
||||
return DEPTH_HEIGHT - 20 + Math.random() / 10;
|
||||
return DEPTH_HEIGHT - 20 + Math.random() / 10;
|
||||
});
|
||||
|
||||
// Transition exiting nodes to the parent's new position.
|
||||
|
|
Reference in a new issue