添加多种数据结构支持

This commit is contained in:
黎智洲
2021-04-24 20:48:54 +08:00
parent 579c72939c
commit 7e6789c8de
13 changed files with 171 additions and 72 deletions
+1 -2
View File
@@ -1,7 +1,6 @@
import { Engine } from "../engine";
import { ConstructedData } from "../Model/modelConstructor";
import { SV } from "../StructV";
import { G6Data, Renderer } from "../View/renderer";
import { G6Data } from "../View/renderer";
/**
+16 -2
View File
@@ -2,6 +2,7 @@ import { Util } from "../Common/util";
import { ElementLabelOption, ElementOption, LinkLabelOption, LinkOption, PointerOption, Style } from "../options";
import { SourceElement } from "../sources";
import { BoundingRect } from "../View/boundingRect";
import { SV } from './../StructV';
export interface G6NodeModel {
@@ -26,6 +27,8 @@ export interface G6EdgeModel {
source: string | number;
target: string | number;
type: string;
controlPoints: { x: number, y: number }[];
curveOffset: number;
sourceAnchor: number | ((index: number) => number);
targetAnchor: number | ((index: number) => number);
label: string;
@@ -105,6 +108,10 @@ export class Model {
return;
}
if(this.props[attr] === value) {
return;
}
if(attr === 'style' || attr === 'labelCfg') {
Object.assign(this.props[attr], value);
}
@@ -143,7 +150,9 @@ export class Model {
*/
getMatrix(): number[] {
if(this.G6Item === null) return null;
return this.G6Item.getContainer().getMatrix();
// return this.G6Item.getContainer().getMatrix();
const Mat3 = SV.G6.Util.mat3;
return Mat3.create();
}
}
@@ -152,6 +161,7 @@ export class Element extends Model {
modelType = 'element';
sourceElement: SourceElement;
sourceId: string;
free: boolean;
constructor(id: string, type: string, sourceElement: SourceElement) {
super(id, type);
@@ -163,6 +173,7 @@ export class Element extends Model {
});
this.sourceId = this.id.split('.')[1];
this.free = false;
}
protected defineProps(option: ElementOption) {
@@ -222,8 +233,11 @@ export class Link extends Model {
label: option.label,
style: Util.objectClone<Style>(option.style),
labelCfg: Util.objectClone<LinkLabelOption>(option.labelOptions),
controlPoints: option.controlPoints,
curveOffset: option.curveOffset,
modelType: this.modelType,
modelName: this.modelName
modelName: this.modelName,
zIndex: 20
};
}
};
+1 -1
View File
@@ -16,7 +16,7 @@ export default G6.registerNode('binary-tree-node', {
height: height,
stroke: cfg.style.stroke,
cursor: cfg.style.cursor,
fill: 'transparent'
fill: '#eee'
},
name: 'wrapper'
});
+1 -1
View File
@@ -15,7 +15,7 @@ export default G6.registerNode('link-list-node', {
width: width,
height: height,
stroke: cfg.style.stroke,
fill: 'transparent'
fill: '#eee'
},
name: 'wrapper'
});
+1 -1
View File
@@ -16,7 +16,7 @@ export default G6.registerNode('two-cell-node', {
width: width,
height: height,
stroke: cfg.style.stroke,
fill: 'transparent'
fill: '#eee'
},
name: 'wrapper'
});
+25 -1
View File
@@ -43,6 +43,7 @@ export class Renderer {
container: DOMContainer,
width: DOMContainer.offsetWidth,
height: DOMContainer.offsetHeight,
groupByTypes: false,
animate: enable,
animateCfg: {
duration: duration,
@@ -133,6 +134,14 @@ export class Renderer {
};
}
/**
* 查找被释放的节点
* @param constructedData
*/
private findFreedItems(constructedData: ConstructedData): G6NodeModel[] {
return Util.converterList(constructedData.element).filter(item => item.free).map(item => item.G6Item);
}
/**
* 处理新增的 G6Item(主要是动画)
* @param appendData
@@ -165,6 +174,12 @@ export class Renderer {
});
}
/**
* 处理被 free 的 G6Item
* @param freedItems
*/
private handleFreedItems(freedItems: G6NodeModel[]) { }
/**
* 构建 G6 元素
* @param constructedData
@@ -197,6 +212,7 @@ export class Renderer {
*/
public render(constructedData: ConstructedData) {
let data: G6Data = Util.convertG6Data(constructedData),
freedItems = this.findFreedItems(constructedData),
renderData: G6Data = null,
appendData: G6Data = null,
removeData: G6Data = null;
@@ -212,7 +228,6 @@ export class Renderer {
if(this.isFirstRender) {
this.graphInstance.read(renderData);
this.isFirstRender = false;
}
else {
this.graphInstance.changeData(renderData);
@@ -229,6 +244,15 @@ export class Renderer {
item.renderG6Item = this.graphInstance.findById(item.id);
item.G6Item = item.renderG6Item;
});
if(this.isFirstRender) {
this.graphInstance.getEdges().forEach(item => item.toFront());
this.graphInstance.paint();
}
if(this.isFirstRender) {
this.isFirstRender = false;
}
}
/**
+2
View File
@@ -46,6 +46,8 @@ export interface LinkOption {
sourceAnchor: number | ((index: number) => number);
targetAnchor: number | ((index: number) => number);
label: string;
controlPoints: { x: number, y: number }[];
curveOffset: number;
labelOptions: LinkLabelOption;
style: Style;
}