fix: 高亮问题修复
This commit is contained in:
parent
76ee9b1968
commit
7e3378bb82
@ -1,6 +1,6 @@
|
|||||||
const fs = require('fs');
|
const fs = require('fs');
|
||||||
const sourcePath = 'D:\\个人项目\\v\\StructV2\\dist\\sv.js';
|
const sourcePath = 'D:\\个人项目\\v\\StructV2\\dist\\sv.js';
|
||||||
const targetPath = 'D:\\个人项目\\anyview项目\\froend_student\\src\\pages\\student\\assets\\js\\sv.js'
|
const targetPath = 'D:\\个人项目\\froend_student\\src\\pages\\student\\assets\\js\\sv.js'
|
||||||
|
|
||||||
|
|
||||||
function COPY(from, to) {
|
function COPY(from, to) {
|
||||||
|
4203
package-lock.json
generated
4203
package-lock.json
generated
File diff suppressed because it is too large
Load Diff
@ -1,8 +1,4 @@
|
|||||||
{
|
{
|
||||||
"dependencies": {
|
|
||||||
"@antv/g6": "^4.4.1",
|
|
||||||
"merge": "^2.1.1"
|
|
||||||
},
|
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"merge": "^2.1.1",
|
"merge": "^2.1.1",
|
||||||
"ts-loader": "^5.2.1",
|
"ts-loader": "^5.2.1",
|
||||||
@ -15,5 +11,9 @@
|
|||||||
"dep": "webpack --config webpack.config.product.js && node copyDist2Anyview.js",
|
"dep": "webpack --config webpack.config.product.js && node copyDist2Anyview.js",
|
||||||
"dev": "webpack --w --config webpack.config.develop.js",
|
"dev": "webpack --w --config webpack.config.develop.js",
|
||||||
"copy": "node copyDist2Anyview.js"
|
"copy": "node copyDist2Anyview.js"
|
||||||
|
},
|
||||||
|
"dependencies": {
|
||||||
|
"@antv/g6": "^4.6.1",
|
||||||
|
"merge": "^2.1.1"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -12,8 +12,8 @@ export class SVLink extends SVModel {
|
|||||||
public shadowG6Item: IEdge;
|
public shadowG6Item: IEdge;
|
||||||
public G6Item: IEdge;
|
public G6Item: IEdge;
|
||||||
|
|
||||||
public nodeId: string;
|
public nodeId: string;
|
||||||
public targetId: string;
|
public targetId: string;
|
||||||
|
|
||||||
constructor(
|
constructor(
|
||||||
id: string,
|
id: string,
|
||||||
@ -29,8 +29,8 @@ export class SVLink extends SVModel {
|
|||||||
|
|
||||||
this.node = node;
|
this.node = node;
|
||||||
this.target = target;
|
this.target = target;
|
||||||
this.nodeId = node.id;
|
this.nodeId = node.id;
|
||||||
this.targetId = target.id;
|
this.targetId = target.id;
|
||||||
this.linkIndex = index;
|
this.linkIndex = index;
|
||||||
|
|
||||||
node.links.outDegree.push(this);
|
node.links.outDegree.push(this);
|
||||||
@ -53,7 +53,7 @@ export class SVLink extends SVModel {
|
|||||||
let label = this.target.sourceNode.freed ? 'freed' : '',
|
let label = this.target.sourceNode.freed ? 'freed' : '',
|
||||||
labelCfg = this.target.sourceNode.freed
|
labelCfg = this.target.sourceNode.freed
|
||||||
? { position: 'start', autoRotate: true, refY: 7, style: { fontSize: 11, opacity: 0.8 } }
|
? { position: 'start', autoRotate: true, refY: 7, style: { fontSize: 11, opacity: 0.8 } }
|
||||||
: Util.objectClone<LinkLabelOption>(options.labelOptions || {} as LinkLabelOption);
|
: Util.objectClone<LinkLabelOption>(options.labelOptions || ({} as LinkLabelOption));
|
||||||
|
|
||||||
return {
|
return {
|
||||||
id: this.id,
|
id: this.id,
|
||||||
@ -76,6 +76,10 @@ export class SVLink extends SVModel {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
isEqual(link: SVLink): boolean {
|
||||||
|
return link.targetId === this.targetId && link.nodeId === this.nodeId && link.linkIndex === this.linkIndex;
|
||||||
|
}
|
||||||
|
|
||||||
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);
|
||||||
|
@ -207,9 +207,11 @@ export class SVModel {
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
beforeRender () {
|
isEqual(model: SVModel): boolean {
|
||||||
this.restoreHighlight();
|
return this.id === model.id;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
beforeRender () {}
|
||||||
afterRender() {}
|
afterRender() {}
|
||||||
|
|
||||||
beforeDestroy () {}
|
beforeDestroy () {}
|
||||||
|
@ -6,12 +6,16 @@ import { SVModel } from './SVModel';
|
|||||||
import { SVNode } from './SVNode';
|
import { SVNode } from './SVNode';
|
||||||
|
|
||||||
export class SVNodeAppendage extends SVModel {
|
export class SVNodeAppendage extends SVModel {
|
||||||
|
public targetId: string;
|
||||||
public target: SVNode;
|
public target: SVNode;
|
||||||
|
public label: string;
|
||||||
|
|
||||||
constructor(id: string, type: string, group: string, layout: string, modelType: string, target: SVNode) {
|
constructor(id: string, type: string, group: string, layout: string, modelType: string, target: SVNode, label: string | string[]) {
|
||||||
super(id, type, group, layout, modelType);
|
super(id, type, group, layout, modelType);
|
||||||
|
|
||||||
this.target = target;
|
this.target = target;
|
||||||
|
this.targetId = target.id;
|
||||||
|
this.label = typeof label === 'string' ? label : label.join(', ');
|
||||||
|
|
||||||
if (this.target.appendages[modelType] === undefined) {
|
if (this.target.appendages[modelType] === undefined) {
|
||||||
this.target.appendages[modelType] = [];
|
this.target.appendages[modelType] = [];
|
||||||
@ -29,6 +33,10 @@ export class SVNodeAppendage extends SVModel {
|
|||||||
|
|
||||||
this.target = null;
|
this.target = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
isEqual(appendage: SVNodeAppendage): boolean {
|
||||||
|
return appendage.targetId === this.targetId && appendage.label === this.label;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -36,7 +44,7 @@ export class SVNodeAppendage extends SVModel {
|
|||||||
*/
|
*/
|
||||||
export class SVFreedLabel extends SVNodeAppendage {
|
export class SVFreedLabel extends SVNodeAppendage {
|
||||||
constructor(id: string, type: string, group: string, layout: string, target: SVNode) {
|
constructor(id: string, type: string, group: string, layout: string, target: SVNode) {
|
||||||
super(id, type, group, layout, 'freedLabel', target);
|
super(id, type, group, layout, 'freedLabel', target, '已释放');
|
||||||
this.G6ModelProps = this.generateG6ModelProps();
|
this.G6ModelProps = this.generateG6ModelProps();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -46,7 +54,7 @@ export class SVFreedLabel extends SVNodeAppendage {
|
|||||||
x: 0,
|
x: 0,
|
||||||
y: 0,
|
y: 0,
|
||||||
type: 'rect',
|
type: 'rect',
|
||||||
label: '已释放',
|
label: this.label,
|
||||||
labelCfg: {
|
labelCfg: {
|
||||||
style: {
|
style: {
|
||||||
fill: '#b83b5e',
|
fill: '#b83b5e',
|
||||||
@ -67,12 +75,8 @@ export class SVFreedLabel extends SVNodeAppendage {
|
|||||||
* 被移动到泄漏区的节点上面显示的地址
|
* 被移动到泄漏区的节点上面显示的地址
|
||||||
*/
|
*/
|
||||||
export class SVAddressLabel extends SVNodeAppendage {
|
export class SVAddressLabel extends SVNodeAppendage {
|
||||||
private sourceId: string;
|
|
||||||
|
|
||||||
constructor(id: string, type: string, group: string, layout: string, target: SVNode, options: AddressLabelOption) {
|
constructor(id: string, type: string, group: string, layout: string, target: SVNode, options: AddressLabelOption) {
|
||||||
super(id, type, group, layout, 'addressLabel', target);
|
super(id, type, group, layout, 'addressLabel', target, target.sourceId);
|
||||||
|
|
||||||
this.sourceId = target.sourceId;
|
|
||||||
this.G6ModelProps = this.generateG6ModelProps(options);
|
this.G6ModelProps = this.generateG6ModelProps(options);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -93,7 +97,7 @@ export class SVAddressLabel extends SVNodeAppendage {
|
|||||||
x: 0,
|
x: 0,
|
||||||
y: 0,
|
y: 0,
|
||||||
type: 'rect',
|
type: 'rect',
|
||||||
label: this.sourceId,
|
label: this.label,
|
||||||
labelCfg: {
|
labelCfg: {
|
||||||
style: {
|
style: {
|
||||||
fill: '#666',
|
fill: '#666',
|
||||||
@ -114,8 +118,6 @@ export class SVAddressLabel extends SVNodeAppendage {
|
|||||||
* 节点的下标文字
|
* 节点的下标文字
|
||||||
*/
|
*/
|
||||||
export class SVIndexLabel extends SVNodeAppendage {
|
export class SVIndexLabel extends SVNodeAppendage {
|
||||||
private value: string;
|
|
||||||
|
|
||||||
constructor(
|
constructor(
|
||||||
id: string,
|
id: string,
|
||||||
indexName: string,
|
indexName: string,
|
||||||
@ -125,8 +127,7 @@ export class SVIndexLabel extends SVNodeAppendage {
|
|||||||
target: SVNode,
|
target: SVNode,
|
||||||
options: IndexLabelOption
|
options: IndexLabelOption
|
||||||
) {
|
) {
|
||||||
super(id, indexName, group, layout, 'indexLabel', target);
|
super(id, indexName, group, layout, 'indexLabel', target, value);
|
||||||
this.value = value;
|
|
||||||
this.G6ModelProps = this.generateG6ModelProps(options) as NodeConfig;
|
this.G6ModelProps = this.generateG6ModelProps(options) as NodeConfig;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -136,7 +137,7 @@ export class SVIndexLabel extends SVNodeAppendage {
|
|||||||
x: 0,
|
x: 0,
|
||||||
y: 0,
|
y: 0,
|
||||||
type: 'rect',
|
type: 'rect',
|
||||||
label: this.value,
|
label: this.label,
|
||||||
labelCfg: {
|
labelCfg: {
|
||||||
style: {
|
style: {
|
||||||
fill: '#bbb',
|
fill: '#bbb',
|
||||||
@ -160,7 +161,6 @@ export class SVIndexLabel extends SVNodeAppendage {
|
|||||||
* 外部指针
|
* 外部指针
|
||||||
*/
|
*/
|
||||||
export class SVMarker extends SVNodeAppendage {
|
export class SVMarker extends SVNodeAppendage {
|
||||||
public label: string | string[];
|
|
||||||
public anchor: number;
|
public anchor: number;
|
||||||
|
|
||||||
public shadowG6Item: INode;
|
public shadowG6Item: INode;
|
||||||
@ -175,9 +175,7 @@ export class SVMarker extends SVNodeAppendage {
|
|||||||
target: SVNode,
|
target: SVNode,
|
||||||
options: MarkerOption
|
options: MarkerOption
|
||||||
) {
|
) {
|
||||||
super(id, type, group, layout, 'marker', target);
|
super(id, type, group, layout, 'marker', target, label);
|
||||||
|
|
||||||
this.label = label;
|
|
||||||
this.G6ModelProps = this.generateG6ModelProps(options);
|
this.G6ModelProps = this.generateG6ModelProps(options);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -195,7 +193,7 @@ export class SVMarker extends SVNodeAppendage {
|
|||||||
type: options.type || 'marker',
|
type: options.type || 'marker',
|
||||||
size: options.size || defaultSize,
|
size: options.size || defaultSize,
|
||||||
anchorPoints: null,
|
anchorPoints: null,
|
||||||
label: typeof this.label === 'string' ? this.label : this.label.join(', '),
|
label: this.label,
|
||||||
style: Util.objectClone<Style>(options.style),
|
style: Util.objectClone<Style>(options.style),
|
||||||
labelCfg: Util.objectClone<NodeLabelOption>(options.labelOptions),
|
labelCfg: Util.objectClone<NodeLabelOption>(options.labelOptions),
|
||||||
};
|
};
|
||||||
|
@ -195,7 +195,7 @@ export class ModelConstructor {
|
|||||||
let isGeneralLink = ModelConstructor.isGeneralLink(sourceLinkData.toString());
|
let isGeneralLink = ModelConstructor.isGeneralLink(sourceLinkData.toString());
|
||||||
|
|
||||||
if (targetNode) {
|
if (targetNode) {
|
||||||
link = this.createLink(name, group, layout, node, targetNode, null, linkOptions[name]);
|
link = this.createLink(name, group, layout, node, targetNode, 0, linkOptions[name]);
|
||||||
linkList.push(link);
|
linkList.push(link);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -17,7 +17,6 @@ export interface DiffResult {
|
|||||||
FREED: SVNode[];
|
FREED: SVNode[];
|
||||||
LEAKED: SVModel[];
|
LEAKED: SVModel[];
|
||||||
UPDATE: SVModel[];
|
UPDATE: SVModel[];
|
||||||
ACCUMULATE_LEAK: SVModel[];
|
|
||||||
}
|
}
|
||||||
|
|
||||||
export class Reconcile {
|
export class Reconcile {
|
||||||
@ -319,16 +318,6 @@ export class Reconcile {
|
|||||||
EventBus.emit('onLeak', leakModels);
|
EventBus.emit('onLeak', leakModels);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* 处理已经堆积的泄漏区 models
|
|
||||||
* @param accumulateModels
|
|
||||||
*/
|
|
||||||
private handleAccumulateLeakModels(accumulateModels: SVModel[]) {
|
|
||||||
accumulateModels.forEach(item => {
|
|
||||||
item.restoreHighlight();
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 处理被释放的节点 models
|
* 处理被释放的节点 models
|
||||||
* @param freedModes
|
* @param freedModes
|
||||||
@ -379,18 +368,11 @@ export class Reconcile {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 过滤新增model中那些不需要高亮的model(比如target和node都一样的link)
|
* 过滤新增model中那些不需要高亮的model(比如target和node都一样的link,marker等)
|
||||||
* @param appendModels
|
* @param appendModels
|
||||||
*/
|
*/
|
||||||
private filterUnChangeModelsOfAppend(appendModels: SVModel[], prevModelList: SVModel[]): SVModel[] {
|
private filterUnChangeModelsOfAppend(appendModels: SVModel[], prevModelList: SVModel[]): SVModel[] {
|
||||||
const links: SVLink[] = appendModels.filter(item => item instanceof SVLink) as SVLink[],
|
return appendModels.filter(item => !prevModelList.some(prev => item.isEqual(prev)));
|
||||||
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];
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -429,7 +411,6 @@ export class Reconcile {
|
|||||||
FREED: freedModels,
|
FREED: freedModels,
|
||||||
LEAKED: leakModels,
|
LEAKED: leakModels,
|
||||||
UPDATE: updateModels,
|
UPDATE: updateModels,
|
||||||
ACCUMULATE_LEAK: [...accumulateLeakModels],
|
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -439,9 +420,7 @@ export class Reconcile {
|
|||||||
* @param isFirstRender
|
* @param isFirstRender
|
||||||
*/
|
*/
|
||||||
public patch(diffResult: DiffResult, handleUpdate: handleUpdate) {
|
public patch(diffResult: DiffResult, handleUpdate: handleUpdate) {
|
||||||
const { APPEND, REMOVE, FREED, LEAKED, UPDATE, CONTINUOUS, ACCUMULATE_LEAK } = diffResult;
|
const { APPEND, REMOVE, FREED, LEAKED, UPDATE, CONTINUOUS } = diffResult;
|
||||||
|
|
||||||
this.handleAccumulateLeakModels(ACCUMULATE_LEAK);
|
|
||||||
|
|
||||||
// 第一次渲染和进入函数的时候不高亮变化的元素
|
// 第一次渲染和进入函数的时候不高亮变化的元素
|
||||||
if (this.isFirstPatch === false && !handleUpdate?.isEnterFunction && !handleUpdate?.isFirstDebug) {
|
if (this.isFirstPatch === false && !handleUpdate?.isEnterFunction && !handleUpdate?.isFirstDebug) {
|
||||||
|
@ -136,6 +136,19 @@ export class ViewContainer {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* @param models
|
||||||
|
*/
|
||||||
|
private restoreHighlight(models: SVModel[]) {
|
||||||
|
models.forEach(item => {
|
||||||
|
// 不是free节点才进行还原
|
||||||
|
if(!item.freed) {
|
||||||
|
item.restoreHighlight()
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 渲染所有视图
|
* 渲染所有视图
|
||||||
* @param models
|
* @param models
|
||||||
@ -144,14 +157,10 @@ export class ViewContainer {
|
|||||||
render(layoutGroupTable: LayoutGroupTable, isSameSources: boolean, handleUpdate: handleUpdate) {
|
render(layoutGroupTable: LayoutGroupTable, isSameSources: boolean, handleUpdate: handleUpdate) {
|
||||||
const modelList = Util.convertGroupTable2ModelList(layoutGroupTable);
|
const modelList = Util.convertGroupTable2ModelList(layoutGroupTable);
|
||||||
|
|
||||||
// 如果数据没变的话
|
this.restoreHighlight([...modelList, ...this.accumulateLeakModels]);
|
||||||
|
|
||||||
|
// 如果数据没变的话,直接退出
|
||||||
if (isSameSources) {
|
if (isSameSources) {
|
||||||
modelList.forEach(item => {
|
|
||||||
// 不是free节点才进行还原
|
|
||||||
if(!item.freed) {
|
|
||||||
item.restoreHighlight()
|
|
||||||
}
|
|
||||||
});
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -162,7 +171,7 @@ export class ViewContainer {
|
|||||||
this.accumulateLeakModels,
|
this.accumulateLeakModels,
|
||||||
handleUpdate?.isEnterFunction
|
handleUpdate?.isEnterFunction
|
||||||
),
|
),
|
||||||
renderModelList = [...modelList, ...diffResult.REMOVE, ...diffResult.LEAKED, ...diffResult.ACCUMULATE_LEAK];
|
renderModelList = [...modelList, ...diffResult.REMOVE, ...diffResult.LEAKED, ...this.accumulateLeakModels];
|
||||||
|
|
||||||
// 从有泄漏区变成无泄漏区
|
// 从有泄漏区变成无泄漏区
|
||||||
if (this.hasLeak === true && this.accumulateLeakModels.length === 0) {
|
if (this.hasLeak === true && this.accumulateLeakModels.length === 0) {
|
||||||
|
Loading…
Reference in New Issue
Block a user