Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
return;
} else if (nodes.length === 1) {
nodes[0].x = center[0];
nodes[0].y = center[1];
return;
}
const linkDistance = self.get('linkDistance');
const unitRadius = self.get('unitRadius');
// 如果正在布局,忽略布局请求
if (self.isTicking()) {
return;
}
// layout
let focusNode = self.get('focusNode');
if (Util.isString(focusNode)) {
let found = false;
for (let i = 0; i < nodes.length; i++) {
if (nodes[i].id === focusNode) {
focusNode = nodes[i];
self.set('focusNode', focusNode);
found = true;
i = nodes.length;
}
}
if (!found) focusNode = null;
}
// default focus node
if (!focusNode) {
focusNode = nodes[0];
if (!focusNode) return;
self.set('focusNode', focusNode);
const center = self.get('center');
const nodes = data.nodes;
if (nodes.length === 0) return;
else if (nodes.length === 1) {
nodes[0].x = center[0];
nodes[0].y = center[1];
}
const linkDistance = self.get('linkDistance');
// 如果正在布局,忽略布局请求
if (self.isTicking()) {
return;
}
// layout
let focusNode = self.get('focusNode');
if (Util.isString(focusNode)) {
let found = false;
for (let i = 0; i < nodes.length; i++) {
if (nodes[i].id === focusNode) {
focusNode = nodes[i];
self.set('focusNode', focusNode);
found = true;
i = nodes.length;
}
}
if (!found) focusNode = null;
}
// default focus node
if (!focusNode) {
focusNode = nodes[0];
if (!focusNode) return;
self.set('focusNode', focusNode);
cfg.content.edges.forEach(edgeCfg => {
let source = edgeCfg.source;
let target = edgeCfg.target;
if (source && Util.isString(source)) {
source = group.findById(source);
source = source.get('item');
}
if (target && Util.isString(target)) {
target = group.findById(target);
target = target.get('item');
}
const edgeContainer = group.addGroup();
const edge = new Edge({
group: edgeContainer,
capture: false,
source,
target,
id: edgeCfg.id,
model: {
...edgeCfg,
cfg.content.edges.forEach(edgeCfg => {
let source = edgeCfg.source;
let target = edgeCfg.target;
if (source && Util.isString(source)) {
source = group.findById(source);
source = source.get('item');
}
if (target && Util.isString(target)) {
target = group.findById(target);
target = target.get('item');
}
const edgeContainer = group.addGroup();
const edge = new Edge({
group: edgeContainer,
capture: false,
source,
target,
id: edgeCfg.id,
model: {
...edgeCfg,
shape: 'flow-polyline-round',
},
});
edge.toFront();