feat:添加多种数据结构同时渲染的支持

This commit is contained in:
黎智洲
2021-05-25 16:05:10 +08:00
parent 4c1510da1f
commit efdb325adc
24 changed files with 815 additions and 611 deletions
+11
View File
@@ -106,6 +106,17 @@ export const Bound = {
};
},
/**
* 位移包围盒
* @param bound
* @param dx
* @param dy
*/
translate(bound: BoundingRect, dx: number, dy: number) {
bound.x += dx;
bound.y += dy;
},
/**
* 求包围盒旋转后新形成的包围盒
* @param bound
+30 -43
View File
@@ -1,18 +1,17 @@
import { Util } from "./util";
import { BoundingRect, Bound } from "./boundingRect";
import { Vector } from "./vector";
import { Element } from "../Model/modelData";
import { Element, Model } from "../Model/modelData";
/**
* element
* model 集合
*/
export class Group {
id: string;
private elements: Array<Element | Group> = [];
private models: Array<Model | Group> = [];
constructor(...arg: Array<Element | Group>) {
constructor(...arg: Array<Model | Group>) {
this.id = Util.generateId();
if(arg) {
@@ -24,25 +23,43 @@ export class Group {
* 添加element
* @param arg
*/
add(...arg: Array<Element | Group>) {
add(...arg: Array<Model | Group>) {
arg.map(ele => {
this.elements.push(ele);
this.models.push(ele);
});
}
/**
* 移除element
* 移除 model
* @param element
*/
remove(element: Element | Group) {
Util.removeFromList(this.elements, item => item.id === element.id);
remove(model: Model | Group) {
Util.removeFromList(this.models, item => item.id === model.id);
}
/**
* 获取group的包围盒
*/
getBound(): BoundingRect {
return Bound.union(...this.elements.map(item => item.getBound()));
return this.models.length?
Bound.union(...this.models.map(item => item.getBound())):
{ x: 0, y: 0, width: 0, height: 0 };
}
/**
* 获取具有一定内边距的包围盒
* @param padding
* @returns
*/
getPaddingBound(padding: number = 0): BoundingRect {
const bound = this.getBound();
bound.x -= padding;
bound.y -= padding;
bound.width += padding * 2;
bound.height += padding * 2;
return bound;
}
/**
@@ -51,7 +68,7 @@ export class Group {
* @param dy
*/
translate(dx: number, dy: number) {
this.elements.map(item => {
this.models.map(item => {
if(item instanceof Group) {
item.translate(dx, dy);
}
@@ -62,40 +79,10 @@ export class Group {
});
}
/**
* 旋转group
* @param rotation
* @param center
*/
rotate(rotation: number, center?: [number, number]) {
// if(rotation === 0) return;
// let {x, y, width, height} = this.getBound(),
// cx = x + width / 2,
// cy = y + height / 2;
// if(center) {
// cx = center[0];
// cy = center[1];
// }
// this.elements.map(item => {
// if(item instanceof Group) {
// item.rotate(rotation, [cx, cy]);
// }
// else {
// let d = Vector.rotation(rotation, [item.x, item.y], [cx, cy]);
// item.x = d[0];
// item.y = d[1];
// item.set('rotation', rotation);
// }
// });
}
/**
* 清空group
*/
clear() {
this.elements.length = 0;
this.models.length = 0;
}
}
+14 -8
View File
@@ -1,4 +1,4 @@
import { ConstructList } from "../Model/modelConstructor";
import { LayoutGroup, LayoutGroupTable } from "../Model/modelConstructor";
import { G6EdgeModel, G6NodeModel, Link, Model } from "../Model/modelData";
import { SV } from "../StructV";
import { G6Data } from "../View/renderer";
@@ -78,21 +78,27 @@ export const Util = {
/**
*
* @param constructListType
* @param groupTable
* @returns
*/
converterList(modelContainer: { [key: string]: ConstructList[keyof ConstructList]}) {
return [].concat(...Object.keys(modelContainer).map(item => modelContainer[item]));
convertGroupTable2ModelList(groupTable: LayoutGroupTable): Model[] {
const list: Model[] = [];
groupTable.forEach(item => {
list.push(...item.modelList);
});
return list;
},
/**
* G6 data 转换器
* @param constructList
* @param layoutGroup
* @returns
*/
convertG6Data(constructList: ConstructList): G6Data {
let nodes = [...constructList.element, ...constructList.pointer],
edges = constructList.link;
convertG6Data(layoutGroup: LayoutGroup): G6Data {
let nodes = [...layoutGroup.element, ...layoutGroup.pointer],
edges = layoutGroup.link;
return {
nodes: nodes.map(item => item.cloneProps()) as G6NodeModel[],