fix: 修复多个free节点显示的bug

This commit is contained in:
黎智洲 2021-08-24 23:53:43 +08:00
parent 324a085867
commit 80e761a57e
6 changed files with 42 additions and 43 deletions

View File

@ -58,7 +58,7 @@ SV.registerLayouter('LinkList', {
},
marker: {
rootExternal: {
type: 'cursor',
type: 'pointer',
anchor: 6,
offset: 8,
style: {
@ -66,7 +66,7 @@ SV.registerLayouter('LinkList', {
}
},
external: {
type: 'cursor',
type: 'pointer',
anchor: 0,
offset: 8,
style: {

View File

@ -20,7 +20,7 @@
element: {
default: {
type: 'link-list-node',
label: '[data]',
label: '[id]',
size: [60, 30],
style: {
stroke: '#333',

View File

@ -88,22 +88,31 @@
let data = [{
"LinkStack0": {
"LinkStack1": {
"data": [
{ id: 6, next: 7 },
{ id: 7, next: 8, freed: true },
{ id: 8, external: 'h', data: '66' }
{
"id": 0,
external: 'gg'
}
],
"layouter": "LinkList"
"layouter": "LinkStack"
}
}, {
"LinkStack0": {
"LinkStack1": {
"data": [
{ id: 6, next: 7 },
{ id: 7, next: 8, freed: true },
{ id: 8, freed: true, external: 'h' }
{
"id": 0
},
{
"id": 1,
"freed": true,
},
{
"freed": true,
"id": 2
}
],
"layouter": "LinkList"
"layouter": "LinkStack"
}
}];

2
dist/sv.js vendored

File diff suppressed because one or more lines are too long

View File

@ -20,7 +20,7 @@ export default G6.registerNode('pointer', {
x: 0,
y: 0,
text: cfg.label,
fill: style.fill || '#fafafa',
fill: null,
radius: 2
},
name: 'bgRect'

View File

@ -89,41 +89,31 @@ export class ViewManager {
private getFreedModelList(prevLayoutGroupTable: LayoutGroupTable, layoutGroupTable: LayoutGroupTable): Model[] {
let freedElements: Element[] = [],
freedMarkers: Marker[] = [],
freedGroup: LayoutGroup = null,
freedGroupName: string = null,
removeModels: Model[] = [];
removeModels: Model[] = [],
freedGroupName: string;
layoutGroupTable.forEach((group, key) => {
let targetElements: Element[] = group.element.filter(item => item.freed),
newFreedNode = null;
let targetElements: Element[] = group.element.filter(item => item.freed);
targetElements.forEach(fItem => {
removeModels.push(
...Util.removeFromList(group.element, item => item.id === fItem.id),
...Util.removeFromList(group.link, item => item.element.id === fItem.id || item.target.id === fItem.id),
...Util.removeFromList(group.marker, item => item.target.id === fItem.id),
);
});
removeModels.map(model => {
Util.removeFromList(group.modelList, item => item.id === model.id);
});
// 找出最新的freed节点防止上一次的freed节点被遗留在该次渲染此时会出现大于一个freed节点
targetElements.forEach(item => {
if (this.prevFreedElements.find(prevEle => prevEle.id === item.id) === undefined) {
newFreedNode = item;
freedGroupName = key;
freedElements.push(item);
}
});
if (targetElements.length) {
freedGroupName = key;
freedElements = [newFreedNode];
}
});
freedGroup = layoutGroupTable.get(freedGroupName);
freedElements.forEach(fItem => {
removeModels.push(
...Util.removeFromList(freedGroup.element, item => item.id === fItem.id),
...Util.removeFromList(freedGroup.link, item => item.element.id === fItem.id || item.target.id === fItem.id),
...Util.removeFromList(freedGroup.marker, item => item.target.id === fItem.id),
);
});
removeModels.map(model => {
Util.removeFromList(freedGroup.modelList, item => item.id === model.id);
});
freedElements.map(item => {
@ -253,7 +243,7 @@ export class ViewManager {
if (this.freedContainer && freedModelList.length) {
this.freedContainer.fitCenter(freedModelList);
this.freedContainer.render(freedModelList);
this.freedContainer.render(freedModelList);
EventBus.emit('onFreed', freedModelList);
}