Initial commit
This commit is contained in:
30
node_modules/d3-hierarchy/src/hierarchy/path.js
generated
vendored
Normal file
30
node_modules/d3-hierarchy/src/hierarchy/path.js
generated
vendored
Normal file
@@ -0,0 +1,30 @@
|
||||
export default function(end) {
|
||||
var start = this,
|
||||
ancestor = leastCommonAncestor(start, end),
|
||||
nodes = [start];
|
||||
while (start !== ancestor) {
|
||||
start = start.parent;
|
||||
nodes.push(start);
|
||||
}
|
||||
var k = nodes.length;
|
||||
while (end !== ancestor) {
|
||||
nodes.splice(k, 0, end);
|
||||
end = end.parent;
|
||||
}
|
||||
return nodes;
|
||||
}
|
||||
|
||||
function leastCommonAncestor(a, b) {
|
||||
if (a === b) return a;
|
||||
var aNodes = a.ancestors(),
|
||||
bNodes = b.ancestors(),
|
||||
c = null;
|
||||
a = aNodes.pop();
|
||||
b = bNodes.pop();
|
||||
while (a === b) {
|
||||
c = a;
|
||||
a = aNodes.pop();
|
||||
b = bNodes.pop();
|
||||
}
|
||||
return c;
|
||||
}
|
||||
Reference in New Issue
Block a user