fix: 修复在存在异常指针的情况下外部指针的位置错位bug

This commit is contained in:
黎智洲 2021-07-06 00:02:38 +08:00
parent fccd90d176
commit 15c3d0b33a
3 changed files with 24 additions and 9 deletions

2
dist/sv.js vendored

File diff suppressed because one or more lines are too long

View File

@ -169,6 +169,7 @@ export class Element extends Model {
groupName: string;
layouterName: string;
freed: boolean;
pointers: { [key: string]: Pointer };
constructor(id: string, type: string, group: string, layouter: string, sourceElement: SourceElement) {
super(id, type);
@ -189,6 +190,11 @@ export class Element extends Model {
this.sourceId = this.id.split('.')[1];
this.sourceElement = sourceElement;
this.pointers = { };
}
getPointer(pointerType: string): Pointer {
return this.pointers[pointerType] || null;
}
protected defineProps(option: ElementOption): G6NodeModel {
@ -261,6 +267,7 @@ export class Link extends Model {
export class Pointer extends Model {
target: Element;
label: string | string[];
anchor: number;
constructor(id: string, type: string, label: string | string[], target: Element) {
super(id, type);
@ -268,17 +275,24 @@ export class Pointer extends Model {
this.label = label;
this.target.set('externalPointerId', id);
this.target.pointers[type] = this;
}
protected defineProps(option: ElementOption): G6NodeModel {
setAnchor(anchor: number) {
this.anchor = anchor;
};
protected defineProps(option: PointerOption): G6NodeModel {
this.setAnchor(option.anchor);
return {
id: this.id,
x: 0,
y: 0,
rotation: 0,
type: option.type || 'external-pointer',
size: option.size || [8, 45],
anchorPoints: option.anchorPoints,
size: option.size || [8, 50],
anchorPoints: null,
label: typeof this.label === 'string'? this.label: this.label.join(', '),
style: Util.objectClone<Style>(option.style),
labelCfg: Util.objectClone<ElementLabelOption>(option.labelOptions),

View File

@ -39,7 +39,7 @@ export class Layouter {
pointers.forEach(item => {
const options: PointerOption = pointerOptions[item.getType()],
offset = options.offset || 8,
anchor = options.anchor || 0;
anchor = item.anchor || 0;
let target = item.target,
targetBound: BoundingRect = target.getBound(),
@ -102,7 +102,7 @@ export class Layouter {
private layoutModels(layoutGroupTable: LayoutGroupTable): Group[] {
const modelGroupList: Group[] = [];
layoutGroupTable.forEach((group, groupName) => {
layoutGroupTable.forEach(group => {
const options: LayoutOptions = group.options.layout,
modelList: Model[] = group.modelList,
modelGroup: Group = new Group();
@ -111,14 +111,15 @@ export class Layouter {
modelGroup.add(item);
});
this.initLayoutValue(group.element, group.pointer); // 初始化布局参数
group.layouter.layout(group.element, options); // 布局节点
this.layoutPointer(group.pointer, group.options.pointer); // 布局外部指针
modelGroupList.push(modelGroup);
});
layoutGroupTable.forEach(group => {
this.layoutPointer(group.pointer, group.options.pointer); // 布局外部指针
});
return modelGroupList;
}