From b261a34d47c8e036cbb6bd97f04ffdbb1f9934e1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=BB=8E=E6=99=BA=E6=B4=B2?= <1543046129@qq.com> Date: Fri, 11 Mar 2022 15:22:30 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20bug=E4=BF=AE=E5=A4=8D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/Model/SVLink.ts | 5 +++++ src/View/reconcile.ts | 17 ++++++++++++++++- 2 files changed, 21 insertions(+), 1 deletion(-) diff --git a/src/Model/SVLink.ts b/src/Model/SVLink.ts index 741d5c3..9ec6fa0 100644 --- a/src/Model/SVLink.ts +++ b/src/Model/SVLink.ts @@ -12,6 +12,9 @@ export class SVLink extends SVModel { public shadowG6Item: IEdge; public G6Item: IEdge; + public nodeId: string; + public targetId: string; + constructor( id: string, type: string, @@ -26,6 +29,8 @@ export class SVLink extends SVModel { this.node = node; this.target = target; + this.nodeId = node.id; + this.targetId = target.id; this.linkIndex = index; node.links.outDegree.push(this); diff --git a/src/View/reconcile.ts b/src/View/reconcile.ts index cfb05b9..0a4a8a0 100644 --- a/src/View/reconcile.ts +++ b/src/View/reconcile.ts @@ -378,6 +378,21 @@ export class Reconcile { }); } + /** + * 过滤新增model中那些不需要高亮的model(比如target和node都一样的link) + * @param appendModels + */ + private filterUnChangeModelsOfAppend(appendModels: SVModel[], prevModelList: SVModel[]): SVModel[] { + const links: SVLink[] = appendModels.filter(item => item instanceof SVLink) as SVLink[], + prevLinks: SVLink[] = prevModelList.filter(item => item instanceof SVLink) as SVLink[], + models = appendModels.filter(item => item instanceof SVLink === false), + changeLinks: SVLink[] = links.filter( + item => !prevLinks.some(prev => prev.targetId === item.targetId && prev.nodeId === item.nodeId) + ); + + return [...models, ...changeLinks]; + } + /** * 进行diff * @param layoutGroupTable @@ -402,7 +417,7 @@ export class Reconcile { const updateModels: SVModel[] = [ ...this.getReTargetMarkers(prevModelList, modelList), ...this.getLabelChangeModels(prevModelList, modelList), - ...appendModels, + ...this.filterUnChangeModelsOfAppend(appendModels, prevModelList), ...leakModels, ]; const freedModels: SVNode[] = this.getFreedModels(prevModelList, modelList);