08-27-周三_17-09-29
This commit is contained in:
53
node_modules/dagre-layout/lib/order/add-subgraph-constraints.js
generated
vendored
Normal file
53
node_modules/dagre-layout/lib/order/add-subgraph-constraints.js
generated
vendored
Normal file
@@ -0,0 +1,53 @@
|
||||
import _ from 'lodash'
|
||||
|
||||
function addSubgraphConstraints (g, cg, vs) {
|
||||
const prev = {}
|
||||
let rootPrev
|
||||
|
||||
_.forEach(vs, function (v) {
|
||||
let child = g.parent(v)
|
||||
let parent
|
||||
let prevChild
|
||||
while (child) {
|
||||
parent = g.parent(child)
|
||||
if (parent) {
|
||||
prevChild = prev[parent]
|
||||
prev[parent] = child
|
||||
} else {
|
||||
prevChild = rootPrev
|
||||
rootPrev = child
|
||||
}
|
||||
if (prevChild && prevChild !== child) {
|
||||
cg.setEdge(prevChild, child)
|
||||
return
|
||||
}
|
||||
child = parent
|
||||
}
|
||||
})
|
||||
|
||||
/*
|
||||
function dfs(v) {
|
||||
const children = v ? g.children(v) : g.children();
|
||||
if (children.length) {
|
||||
const min = Number.POSITIVE_INFINITY,
|
||||
subgraphs = [];
|
||||
_.forEach(children, function(child) {
|
||||
const childMin = dfs(child);
|
||||
if (g.children(child).length) {
|
||||
subgraphs.push({ v: child, order: childMin });
|
||||
}
|
||||
min = Math.min(min, childMin);
|
||||
});
|
||||
_.reduce(_.sortBy(subgraphs, "order"), function(prev, curr) {
|
||||
cg.setEdge(prev.v, curr.v);
|
||||
return curr;
|
||||
});
|
||||
return min;
|
||||
}
|
||||
return g.node(v).order;
|
||||
}
|
||||
dfs(undefined);
|
||||
*/
|
||||
}
|
||||
|
||||
export default addSubgraphConstraints
|
Reference in New Issue
Block a user