Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Auto-expand tree nodes in "Data" pane #83

Merged
merged 5 commits into from
Jul 31, 2017
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
127 changes: 68 additions & 59 deletions inst/htmlwidgets/lib/profvis/profvis.js
Original file line number Diff line number Diff line change
Expand Up @@ -1408,74 +1408,77 @@ profvis = (function() {
return collapsed ? "none" : "";
}

function updateLabelCells(labelCell) {
labelCell
.attr("nowrap", "true")
.style("padding-left", function(d) {
return (8 + 15 * (d.visualDepth - 1)) + "px";
})
.on("click", function(d) {
if (!d.canExpand)
return;
function toggleTreeNode(d) {
if (!d.canExpand)
return;

var collapsed = d.collapsed;
if (collapsed === undefined) {
// Create a copy since we might insert the same node twice: once
// for the normal leaf the other one for a collapsed node.
var sumChildren = d.sumChildren.map(function(x) {
return jQuery.extend({}, x);
});
var collapsed = d.collapsed;
if (collapsed === undefined) {
// Create a copy since we might insert the same node twice: once
// for the normal leaf the other one for a collapsed node.
var sumChildren = d.sumChildren.map(function(x) {
return jQuery.extend({}, x);
});

var childNodes = sumChildren.filter(function(x) {
return x.depthCollapsed !== null;
});
var childNodes = sumChildren.filter(function(x) {
return x.depthCollapsed !== null;
});

childNodes.forEach(function(x) {
x.isInternal = d.isInternal ? d.isInternal : false;
x.isDescendant = d.isDescendant ? d.isDescendant : false;
});
childNodes.forEach(function(x) {
x.isInternal = d.isInternal ? d.isInternal : false;
x.isDescendant = d.isDescendant ? d.isDescendant : false;
});

var internalChildNodes = sumChildren.filter(function(x) {
return x.depthCollapsed === null;
});
var internalChildNodes = sumChildren.filter(function(x) {
return x.depthCollapsed === null;
});

internalChildNodes.forEach(function(x) {
x.isInternal = true;
x.isDescendant = false;
});
internalChildNodes.forEach(function(x) {
x.isInternal = true;
x.isDescendant = false;
});

var notInternalDescendantNodes = [];
if (!d.isInternal) {
notInternalDescendantNodes = allTopNodes(internalChildNodes, function(x) {
return x.depthCollapsed !== null && d.depth < x.depth;
});
}
var notInternalDescendantNodes = [];
if (!d.isInternal) {
notInternalDescendantNodes = allTopNodes(internalChildNodes, function(x) {
return x.depthCollapsed !== null && d.depth < x.depth;
});
}

notInternalDescendantNodes.forEach(function(x) {
x.isInternal = false;
x.isDescendant = true;
});
notInternalDescendantNodes.forEach(function(x) {
x.isInternal = false;
x.isDescendant = true;
});

childNodes = childNodes.concat(internalChildNodes);
childNodes = childNodes.concat(notInternalDescendantNodes);
childNodes = childNodes.concat(internalChildNodes);
childNodes = childNodes.concat(notInternalDescendantNodes);

childNodes.forEach(function(n) {
n.visualDepth = d.visualDepth + 1;
n.parent = d;
});
childNodes.forEach(function(n) {
n.visualDepth = d.visualDepth + 1;
n.parent = d;
});

vis.profTable = vis.profTable.concat(childNodes);
d.collapsed = false;
}
else if (collapsed) {
d.collapsed = false;
}
else {
d.collapsed = true;
}
vis.profTable = vis.profTable.concat(childNodes);
d.collapsed = false;

updateRows();

// Nodes are sorted "heaviest first"
if (childNodes.length == 1) toggleTreeNode(childNodes[0]);
}
else {
d.collapsed = !collapsed;
updateRows();
}
}

updateRows();
function updateLabelCells(labelCell) {
labelCell
.attr("nowrap", "true")
.style("padding-left", function(d) {
return (8 + 15 * (d.visualDepth - 1)) + "px";
})
.on("click", toggleTreeNode)
.attr("class", function(d) {
d.canExpand = false;
if (d.sumChildren) {
Expand Down Expand Up @@ -1647,9 +1650,15 @@ profvis = (function() {
childrenSum.push(nameMap[label]);
}

// Sort by time descending
childrenSum.sort(function(a, b) { return b.sumTime - a.sumTime });
return childrenSum;
};

function addToNodesAt(c, i) {
nodes.splice(i, 0, c);
}

var id = 0;
while (nodes.length > 0) {
var node = nodes.shift();
Expand All @@ -1658,9 +1667,9 @@ profvis = (function() {
id = id + 1;

node.sumChildren = aggregateChildren(node);
node.sumChildren.forEach(function(c) {
nodes.unshift(c);
});

// Processing in order is important to preserve order of IDs!
node.sumChildren.forEach(addToNodesAt);
}

return head.sumChildren;
Expand Down