fix: 修复高亮问题

This commit is contained in:
黎智洲 2022-03-05 00:58:24 +08:00
parent 3170bd77ec
commit b3060b0e27
23 changed files with 72 additions and 39 deletions

View File

@ -50,6 +50,13 @@ export class SVLink extends SVModel {
}; };
} }
triggerHighlight(changeHighlightColor: string) {
this.originStyle = Util.objectClone(this.G6ModelProps.style);
this.set('style', {
stroke: changeHighlightColor,
});
}
beforeDestroy(): void { beforeDestroy(): void {
Util.removeFromList(this.target.links.inDegree, item => item.id === this.id); Util.removeFromList(this.target.links.inDegree, item => item.id === this.id);
Util.removeFromList(this.node.links.outDegree, item => item.id === this.id); Util.removeFromList(this.node.links.outDegree, item => item.id === this.id);

View File

@ -21,7 +21,7 @@ export class SVModel {
public discarded: boolean; public discarded: boolean;
public freed: boolean; public freed: boolean;
public leaked: boolean; public leaked: boolean;
public generalStyle: Partial<Style>; public originStyle: Partial<Style>; // 用作保存修改前的样式
private transformMatrix: number[]; private transformMatrix: number[];
private modelType: string; private modelType: string;
@ -187,6 +187,19 @@ export class SVModel {
return this.modelType; return this.modelType;
} }
triggerHighlight(changeHighlightColor: string) {
this.originStyle = Util.objectClone(this.G6ModelProps.style);
this.set('style', {
fill: changeHighlightColor,
});
}
restoreHighlight() {
if (this.originStyle) {
this.set('style', { ...this.originStyle });
}
}
/** /**
* modelSVNode * modelSVNode
*/ */
@ -194,9 +207,13 @@ export class SVModel {
return false; return false;
} }
beforeDestroy () {} beforeRender () {
this.restoreHighlight();
}
afterRender() {}
destroy() { beforeDestroy () {}
afterDestroy() {
this.G6Item = null; this.G6Item = null;
this.shadowG6Instance = null; this.shadowG6Instance = null;
this.shadowG6Item = null; this.shadowG6Item = null;

View File

@ -50,8 +50,7 @@ export class Reconcile {
private getAppendModels( private getAppendModels(
prevModelList: SVModel[], prevModelList: SVModel[],
modelList: SVModel[], modelList: SVModel[],
accumulateLeakModels: SVModel[], accumulateLeakModels: SVModel[]
prevStep: boolean
): SVModel[] { ): SVModel[] {
const appendModels = modelList.filter(item => !prevModelList.find(model => model.id === item.id)); const appendModels = modelList.filter(item => !prevModelList.find(model => model.id === item.id));
@ -273,6 +272,7 @@ export class Reconcile {
Animations.APPEND(item.G6Item, { Animations.APPEND(item.G6Item, {
duration, duration,
timingFunction, timingFunction,
callback: () => item.afterRender()
}); });
} }
}); });
@ -291,6 +291,7 @@ export class Reconcile {
timingFunction, timingFunction,
callback: () => { callback: () => {
this.renderer.removeModel(item); this.renderer.removeModel(item);
item.afterDestroy();
}, },
}); });
}); });
@ -323,9 +324,7 @@ export class Reconcile {
*/ */
private handleAccumulateLeakModels(accumulateModels: SVModel[]) { private handleAccumulateLeakModels(accumulateModels: SVModel[]) {
accumulateModels.forEach(item => { accumulateModels.forEach(item => {
if (item.generalStyle) { item.restoreHighlight();
item.set('style', { ...item.generalStyle });
}
}); });
} }
@ -374,19 +373,7 @@ export class Reconcile {
} }
models.forEach(item => { models.forEach(item => {
if (item.generalStyle === undefined) { item.triggerHighlight(changeHighlightColor);
item.generalStyle = Util.objectClone(item.G6ModelProps.style);
}
if (item instanceof SVLink) {
item.set('style', {
stroke: changeHighlightColor,
});
} else {
item.set('style', {
fill: changeHighlightColor,
});
}
}); });
} }
@ -403,14 +390,13 @@ export class Reconcile {
prevModelList: SVModel[], prevModelList: SVModel[],
modelList: SVModel[], modelList: SVModel[],
accumulateLeakModels: SVModel[], accumulateLeakModels: SVModel[],
isEnterFunction: boolean, isEnterFunction: boolean
prevStep: boolean
): DiffResult { ): DiffResult {
const continuousModels: SVModel[] = this.getContinuousModels(prevModelList, modelList); const continuousModels: SVModel[] = this.getContinuousModels(prevModelList, modelList);
const leakModels: SVModel[] = isEnterFunction const leakModels: SVModel[] = isEnterFunction
? [] ? []
: this.getLeakModels(layoutGroupTable, prevModelList, modelList); : this.getLeakModels(layoutGroupTable, prevModelList, modelList);
const appendModels: SVModel[] = this.getAppendModels(prevModelList, modelList, accumulateLeakModels, prevStep); const appendModels: SVModel[] = this.getAppendModels(prevModelList, modelList, accumulateLeakModels);
const removeModels: SVModel[] = this.getRemoveModels(prevModelList, modelList, accumulateLeakModels); const removeModels: SVModel[] = this.getRemoveModels(prevModelList, modelList, accumulateLeakModels);
const updateModels: SVModel[] = [ const updateModels: SVModel[] = [
...this.getReTargetMarkers(prevModelList, modelList), ...this.getReTargetMarkers(prevModelList, modelList),

View File

@ -106,11 +106,15 @@ export class Renderer {
/** /**
* *
* @param renderModelList * @param renderModelList
* @param isFirstRender * @param isSameSources
*/ */
public render(renderModelList: SVModel[]) { public render(renderModelList: SVModel[]) {
const renderData: GraphData = Util.convertModelList2G6Data(renderModelList); const renderData: GraphData = Util.convertModelList2G6Data(renderModelList);
renderModelList.forEach(item => {
item.beforeRender();
});
this.g6Instance.changeData(renderData); this.g6Instance.changeData(renderData);
renderModelList.forEach(item => { renderModelList.forEach(item => {

View File

@ -140,18 +140,25 @@ export class ViewContainer {
* @param models * @param models
* @param layoutFn * @param layoutFn
*/ */
render(layoutGroupTable: LayoutGroupTable, isEnterFunction: boolean, prevStep: boolean) { render(layoutGroupTable: LayoutGroupTable, isSameSources: boolean, isEnterFunction: boolean) {
const modelList = Util.convertGroupTable2ModelList(layoutGroupTable), const modelList = Util.convertGroupTable2ModelList(layoutGroupTable);
diffResult = this.reconcile.diff(
// 如果数据没变的话
if (isSameSources) {
modelList.forEach(item => item.restoreHighlight());
return;
}
const diffResult = this.reconcile.diff(
this.layoutGroupTable, this.layoutGroupTable,
this.prevModelList, this.prevModelList,
modelList, modelList,
this.accumulateLeakModels, this.accumulateLeakModels,
isEnterFunction, isEnterFunction
prevStep
), ),
renderModelList = [...modelList, ...diffResult.REMOVE, ...diffResult.LEAKED, ...diffResult.ACCUMULATE_LEAK]; renderModelList = [...modelList, ...diffResult.REMOVE, ...diffResult.LEAKED, ...diffResult.ACCUMULATE_LEAK];
// 从有泄漏区变成无泄漏区
if (this.hasLeak === true && this.accumulateLeakModels.length === 0) { if (this.hasLeak === true && this.accumulateLeakModels.length === 0) {
this.hasLeak = false; this.hasLeak = false;
EventBus.emit('onLeakAreaUpdate', { EventBus.emit('onLeakAreaUpdate', {
@ -160,6 +167,7 @@ export class ViewContainer {
}); });
} }
// 从无泄漏区变成有泄漏区
if (diffResult.LEAKED.length) { if (diffResult.LEAKED.length) {
this.hasLeak = true; this.hasLeak = true;
EventBus.emit('onLeakAreaUpdate', { EventBus.emit('onLeakAreaUpdate', {

View File

@ -51,23 +51,34 @@ export class Engine {
* @param sources * @param sources
* @param prevStep * @param prevStep
*/ */
public render(source: Sources, prevStep: boolean = false) { public render(source: Sources) {
let isSameSources: boolean = false,
layoutGroupTable: LayoutGroupTable,
isEnterFunction = source.isEnterFunction;
if (source === undefined || source === null) { if (source === undefined || source === null) {
return; return;
} }
``
let stringSource = JSON.stringify(source); let stringSource = JSON.stringify(source);
if (this.prevStringSource === stringSource) { if (this.prevStringSource === stringSource) {
return; isSameSources = true;
} }
this.prevStringSource = stringSource; this.prevStringSource = stringSource;
if(isSameSources) {
// 若源数据两次一样的用回上一次的layoutGroupTable
layoutGroupTable = this.modelConstructor.getLayoutGroupTable();
}
else {
// 1 转换模型data => model // 1 转换模型data => model
const layoutGroupTable = this.modelConstructor.construct(source); layoutGroupTable = this.modelConstructor.construct(source);
}
// 2 渲染使用g6进行渲染 // 2 渲染使用g6进行渲染
this.viewContainer.render(layoutGroupTable, source.isEnterFunction as boolean, prevStep); this.viewContainer.render(layoutGroupTable, isSameSources, isEnterFunction);
} }