fix: resolve miniapp errors

This commit is contained in:
openwayne 2021-05-09 17:14:22 +08:00 committed by Yanyan Wang
parent 2c0eb297fb
commit afc11e125b
3 changed files with 32 additions and 23 deletions

View File

@ -125,7 +125,7 @@ const singleEdge: ShapeOptions = {
stroke: cfg.color,
};
const shape =
group.find(element => element.get('className') === 'edge-shape') || item.getKeyShape();
group.find((element) => element.get('className') === 'edge-shape') || item.getKeyShape();
const { size } = cfg;
cfg = this.getPathPoints!(cfg);
@ -178,7 +178,7 @@ const singleEdge: ShapeOptions = {
const labelPosition = labelCfg.position || this.labelPosition; // 文本的位置用户可以传入
const style: LabelStyle = {};
const pathShape = group && group.find(element => element.get('className') === CLS_SHAPE);
const pathShape = group && group.find((element) => element.get('className') === CLS_SHAPE);
// 不对 pathShape 进行判空,如果线不存在,说明有问题了
let pointPercent;
@ -247,7 +247,7 @@ const singleEdge: ShapeOptions = {
if (isNil(labelCfg.autoRotate)) autoRotate = this.labelAutoRotate;
else autoRotate = labelCfg.autoRotate;
const pathShape = group && group.find(element => element.get('className') === CLS_SHAPE);
const pathShape = group && group.find((element) => element.get('className') === CLS_SHAPE);
// 不对 pathShape 进行判空,如果线不存在,说明有问题了
let pointPercent;
@ -349,7 +349,7 @@ const singleEdge: ShapeOptions = {
drawLabel(cfg: EdgeConfig, group: IGroup): IShape {
const { labelCfg: defaultLabelCfg } = this.options as ModelConfig;
let defaultFontFamily;
if (typeof window !== 'undefined' && window.getComputedStyle)
if (typeof window !== 'undefined' && typeof window.getComputedStyle !== 'undefined')
defaultFontFamily =
window.getComputedStyle(document.body, null).getPropertyValue('font-family') ||
'Arial, sans-serif';

View File

@ -327,10 +327,10 @@ export default class ItemController {
const keyShape = (combo as ICombo).getKeyShape();
if (!keyShape || keyShape.destroyed) return;
(combo as ICombo).getShapeCfg(model); // 更新 combo 缓存的 size
this.updateComboEdges(combo as ICombo)
this.updateComboEdges(combo as ICombo);
}, 201);
} else {
this.updateComboEdges(combo as ICombo)
this.updateComboEdges(combo as ICombo);
}
}
@ -636,7 +636,6 @@ export default class ItemController {
item.changeVisibility(visible);
if (item.getType && item.getType() === NODE) {
const edges = (item as INode).getEdges();
each(edges, (edge: IEdge) => {
// 若隐藏节点,则将与之关联的边也隐藏

View File

@ -42,7 +42,7 @@ export default abstract class LayoutController {
const pipes = layoutCfg.pipes;
if (Array.isArray(pipes)) {
return pipes.map((pipe) => pipe?.type || "");
return pipes.map((pipe) => pipe?.type || '');
}
return null;
@ -52,7 +52,7 @@ export default abstract class LayoutController {
const current = this.getLayoutCfgType(cfg);
// already has pipes
if (Array.isArray(this.layoutType)) {
return this.layoutType.every((type, index) => type === current[index])
return this.layoutType.every((type, index) => type === current[index]);
}
return cfg?.type === this.layoutType;
@ -159,7 +159,15 @@ export default abstract class LayoutController {
}
combos.push(model);
}
return { nodes, hiddenNodes, edges, hiddenEdges, combos, hiddenCombos, comboEdges } as GraphData;
return {
nodes,
hiddenNodes,
edges,
hiddenEdges,
combos,
hiddenCombos,
comboEdges,
} as GraphData;
}
protected reLayoutMethod(layoutMethod, layoutCfg): Promise<void> {
@ -171,7 +179,7 @@ export default abstract class LayoutController {
layoutCfg.onLayoutEnd = () => {
graph.emit('aftersublayout', { type: layoutType });
reslove();
}
};
layoutMethod.init(this.data);
if (layoutType === 'force') {
@ -206,9 +214,11 @@ export default abstract class LayoutController {
start = start.then(() => this.reLayoutMethod(layoutMethod, currentCfg));
});
start.then(() => {
start
.then(() => {
if (layoutCfg.onAllLayoutEnd) layoutCfg.onAllLayoutEnd();
}).catch((error) => {
})
.catch((error) => {
console.warn('relayout failed', error);
});
}
@ -237,14 +247,14 @@ export default abstract class LayoutController {
}, {});
edegsFilter = (edge) => {
return nodesMap[edge.source] && nodesMap[edge.target];
}
};
}
return {
nodes: nodes.filter(nodesFilter),
edges: edges.filter(edegsFilter),
...rest
}
...rest,
};
}
protected getLayoutBBox(nodes) {
@ -261,8 +271,8 @@ export default abstract class LayoutController {
const groupNodes = Object.values(groupBy(nodes, 'layoutOrder'));
return {
groupNodes,
layoutNodes
}
layoutNodes,
};
}
// 控制布局动画