fix: 修正freed节点被restore样式的问题

This commit is contained in:
黎智洲 2022-03-10 15:29:33 +08:00
parent e238087f3f
commit 4bb64214e7
4 changed files with 29 additions and 28 deletions

View File

@ -6,6 +6,7 @@ import { SVLink } from '../Model/SVLink';
import { SVModel } from '../Model/SVModel'; import { SVModel } from '../Model/SVModel';
import { SVNode } from '../Model/SVNode'; import { SVNode } from '../Model/SVNode';
import { SVAddressLabel, SVMarker, SVNodeAppendage } from '../Model/SVNodeAppendage'; import { SVAddressLabel, SVMarker, SVNodeAppendage } from '../Model/SVNodeAppendage';
import { handleUpdate } from '../sources';
import { Animations } from './animation'; import { Animations } from './animation';
import { Renderer } from './renderer'; import { Renderer } from './renderer';
@ -272,7 +273,7 @@ export class Reconcile {
Animations.APPEND(item.G6Item, { Animations.APPEND(item.G6Item, {
duration, duration,
timingFunction, timingFunction,
callback: () => item.afterRender() callback: () => item.afterRender(),
}); });
} }
}); });
@ -422,13 +423,13 @@ export class Reconcile {
* @param diffResult * @param diffResult
* @param isFirstRender * @param isFirstRender
*/ */
public patch(diffResult: DiffResult,handleUpdata: any) { public patch(diffResult: DiffResult, handleUpdate: handleUpdate) {
const { APPEND, REMOVE, FREED, LEAKED, UPDATE, CONTINUOUS, ACCUMULATE_LEAK } = diffResult; const { APPEND, REMOVE, FREED, LEAKED, UPDATE, CONTINUOUS, ACCUMULATE_LEAK } = diffResult;
this.handleAccumulateLeakModels(ACCUMULATE_LEAK); this.handleAccumulateLeakModels(ACCUMULATE_LEAK);
// 第一次渲染和进入函数的时候不高亮变化的元素 // 第一次渲染和进入函数的时候不高亮变化的元素
if (this.isFirstPatch === false && !handleUpdata.isEnterFunction && !handleUpdata.isFirstDebug) { if (this.isFirstPatch === false && !handleUpdate?.isEnterFunction && !handleUpdate?.isFirstDebug) {
this.handleChangeModels(UPDATE); this.handleChangeModels(UPDATE);
} }

View File

@ -16,6 +16,7 @@ import {
SolveNodeAppendagesDrag, SolveNodeAppendagesDrag,
SolveZoomCanvasWithLeak, SolveZoomCanvasWithLeak,
} from '../BehaviorHelper/behaviorIssueHelper'; } from '../BehaviorHelper/behaviorIssueHelper';
import { handleUpdate } from '../sources';
export class ViewContainer { export class ViewContainer {
private engine: Engine; private engine: Engine;
@ -140,13 +141,18 @@ export class ViewContainer {
* @param models * @param models
* @param layoutFn * @param layoutFn
*/ */
render(layoutGroupTable: LayoutGroupTable, isSameSources: boolean, handleUpdata: any) { render(layoutGroupTable: LayoutGroupTable, isSameSources: boolean, handleUpdate: handleUpdate) {
const modelList = Util.convertGroupTable2ModelList(layoutGroupTable); const modelList = Util.convertGroupTable2ModelList(layoutGroupTable);
// 如果数据没变的话 // 如果数据没变的话
if (isSameSources) { if (isSameSources) {
modelList.forEach(item => item.restoreHighlight()); modelList.forEach(item => {
return; // 不是free节点才进行还原
if(!item.freed) {
item.restoreHighlight()
}
});
return;
} }
const diffResult = this.reconcile.diff( const diffResult = this.reconcile.diff(
@ -154,7 +160,7 @@ export class ViewContainer {
this.prevModelList, this.prevModelList,
modelList, modelList,
this.accumulateLeakModels, this.accumulateLeakModels,
handleUpdata.isEnterFunction handleUpdate?.isEnterFunction
), ),
renderModelList = [...modelList, ...diffResult.REMOVE, ...diffResult.LEAKED, ...diffResult.ACCUMULATE_LEAK]; renderModelList = [...modelList, ...diffResult.REMOVE, ...diffResult.LEAKED, ...diffResult.ACCUMULATE_LEAK];
@ -182,7 +188,7 @@ export class ViewContainer {
this.beforeRender(); this.beforeRender();
this.renderer.render(renderModelList); // 渲染视图 this.renderer.render(renderModelList); // 渲染视图
this.reconcile.patch(diffResult,handleUpdata); // 对视图上的某些变化进行对应的动作,比如:节点创建动画,节点消失动画等 this.reconcile.patch(diffResult, handleUpdate); // 对视图上的某些变化进行对应的动作,比如:节点创建动画,节点消失动画等
this.afterRender(); this.afterRender();
this.layoutGroupTable = layoutGroupTable; this.layoutGroupTable = layoutGroupTable;

View File

@ -1,4 +1,4 @@
import { Sources } from "./sources"; import { handleUpdate, Sources } from "./sources";
import { LayoutGroupTable, ModelConstructor } from "./Model/modelConstructor"; import { LayoutGroupTable, ModelConstructor } from "./Model/modelConstructor";
import { AnimationOptions, BehaviorOptions, EngineOptions, LayoutGroupOptions, ViewOptions } from "./options"; import { AnimationOptions, BehaviorOptions, EngineOptions, LayoutGroupOptions, ViewOptions } from "./options";
import { EventBus } from "./Common/eventBus"; import { EventBus } from "./Common/eventBus";
@ -59,7 +59,7 @@ export class Engine {
return; return;
} }
let handleUpdate = source.handleUpdate, let handleUpdate: handleUpdate = source.handleUpdate,
stringSource = JSON.stringify(source); stringSource = JSON.stringify(source);
if (this.prevStringSource === stringSource) { if (this.prevStringSource === stringSource) {

View File

@ -1,4 +1,3 @@
// 连接目标信息 // 连接目标信息
export type LinkTarget = number | string; export type LinkTarget = number | string;
@ -10,24 +9,19 @@ export type sourceMarkerData = string | string[];
// 源数据单元 // 源数据单元
export interface SourceNode { export interface SourceNode {
id: string | number; id: string | number;
[key: string]: any | sourceLinkData | sourceMarkerData; [key: string]: any | sourceLinkData | sourceMarkerData;
} }
export interface handleUpdata { export interface handleUpdate {
isEnterFunction: boolean, isEnterFunction: boolean;
isFirstDebug: boolean isFirstDebug: boolean;
} }
export type Sources = { export type Sources = {
[key: string]: {
[key: string]: { data: SourceNode[];
data: SourceNode[]; layouter: string;
layouter: string; };
}; handleUpdate?: handleUpdate | any;
handleUpdata?:any
}; };