feat: 重构
This commit is contained in:
+36
-10
@@ -1,6 +1,7 @@
|
||||
import { Util } from "./util";
|
||||
import { BoundingRect, Bound } from "./boundingRect";
|
||||
import { Element, Model } from "../Model/modelData";
|
||||
import { SVModel } from "../Model/SVModel";
|
||||
import { ext } from '@antv/matrix-util';
|
||||
|
||||
|
||||
|
||||
@@ -9,12 +10,12 @@ import { Element, Model } from "../Model/modelData";
|
||||
*/
|
||||
export class Group {
|
||||
id: string;
|
||||
private models: Array<Model | Group> = [];
|
||||
private models: Array<SVModel | Group> = [];
|
||||
|
||||
constructor(...arg: Array<Model | Group>) {
|
||||
constructor(...arg: Array<SVModel | Group>) {
|
||||
this.id = Util.generateId();
|
||||
|
||||
if(arg) {
|
||||
if (arg) {
|
||||
this.add(...arg);
|
||||
}
|
||||
}
|
||||
@@ -23,7 +24,7 @@ export class Group {
|
||||
* 添加element
|
||||
* @param arg
|
||||
*/
|
||||
add(...arg: Array<Model | Group>) {
|
||||
add(...arg: Array<SVModel | Group>) {
|
||||
arg.map(ele => {
|
||||
this.models.push(ele);
|
||||
});
|
||||
@@ -33,7 +34,7 @@ export class Group {
|
||||
* 移除 model
|
||||
* @param element
|
||||
*/
|
||||
remove(model: Model | Group) {
|
||||
remove(model: SVModel | Group) {
|
||||
Util.removeFromList(this.models, item => item.id === model.id);
|
||||
}
|
||||
|
||||
@@ -41,9 +42,9 @@ export class Group {
|
||||
* 获取group的包围盒
|
||||
*/
|
||||
getBound(): BoundingRect {
|
||||
return this.models.length?
|
||||
Bound.union(...this.models.map(item => item.getBound())):
|
||||
{ x: 0, y: 0, width: 0, height: 0 };
|
||||
return this.models.length ?
|
||||
Bound.union(...this.models.map(item => item.getBound())) :
|
||||
{ x: 0, y: 0, width: 0, height: 0 };
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -62,6 +63,10 @@ export class Group {
|
||||
return bound;
|
||||
}
|
||||
|
||||
getModels(): Array<SVModel | Group> {
|
||||
return this.models;
|
||||
}
|
||||
|
||||
/**
|
||||
* 位移group
|
||||
* @param dx
|
||||
@@ -69,7 +74,7 @@ export class Group {
|
||||
*/
|
||||
translate(dx: number, dy: number) {
|
||||
this.models.map(item => {
|
||||
if(item instanceof Group) {
|
||||
if (item instanceof Group) {
|
||||
item.translate(dx, dy);
|
||||
}
|
||||
else {
|
||||
@@ -79,6 +84,27 @@ export class Group {
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* 缩放group
|
||||
* @param center
|
||||
* @param ratio
|
||||
*/
|
||||
scale(center: [number, number], ratio: number) {
|
||||
this.models.map(item => {
|
||||
if (item instanceof Group) {
|
||||
item.scale(center, ratio);
|
||||
}
|
||||
else {
|
||||
const matrix = ext.transform(item.getMatrix(), [
|
||||
['t', -center[0], -center[1]],
|
||||
['s', ratio, ratio],
|
||||
['t', center[0], center[1]],
|
||||
]);
|
||||
item.setMatrix(matrix);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* 清空group
|
||||
*/
|
||||
|
||||
+13
-11
@@ -1,7 +1,8 @@
|
||||
import { EdgeConfig, GraphData, NodeConfig } from "@antv/g6-core";
|
||||
import { LayoutGroup, LayoutGroupTable } from "../Model/modelConstructor";
|
||||
import { G6EdgeModel, G6NodeModel, Link, Model } from "../Model/modelData";
|
||||
import { SVLink } from "../Model/SVLink";
|
||||
import { SVModel } from "../Model/SVModel";
|
||||
import { SV } from "../StructV";
|
||||
import { G6Data } from "../View/renderer";
|
||||
|
||||
|
||||
/**
|
||||
@@ -89,8 +90,8 @@ export const Util = {
|
||||
* @param groupTable
|
||||
* @returns
|
||||
*/
|
||||
convertGroupTable2ModelList(groupTable: LayoutGroupTable): Model[] {
|
||||
const list: Model[] = [];
|
||||
convertGroupTable2ModelList(groupTable: LayoutGroupTable): SVModel[] {
|
||||
const list: SVModel[] = [];
|
||||
|
||||
groupTable.forEach(item => {
|
||||
list.push(...item.modelList);
|
||||
@@ -104,13 +105,13 @@ export const Util = {
|
||||
* @param layoutGroup
|
||||
* @returns
|
||||
*/
|
||||
convertG6Data(layoutGroup: LayoutGroup): G6Data {
|
||||
let nodes = [...layoutGroup.element, ...layoutGroup.marker],
|
||||
convertG6Data(layoutGroup: LayoutGroup): GraphData {
|
||||
let nodes = [...layoutGroup.node, ...layoutGroup.marker],
|
||||
edges = layoutGroup.link;
|
||||
|
||||
return {
|
||||
nodes: nodes.map(item => item.cloneProps()) as G6NodeModel[],
|
||||
edges: edges.map(item => item.cloneProps()) as G6EdgeModel[]
|
||||
nodes: nodes.map(item => item.getG6ModelProps()) as NodeConfig[],
|
||||
edges: edges.map(item => item.getG6ModelProps()) as EdgeConfig[]
|
||||
};
|
||||
},
|
||||
|
||||
@@ -118,10 +119,10 @@ export const Util = {
|
||||
* 将 modelList 转换到 G6Data
|
||||
* @param modelList
|
||||
*/
|
||||
convertModelList2G6Data(modelList: Model[]): G6Data {
|
||||
convertModelList2G6Data(modelList: SVModel[]): GraphData {
|
||||
return {
|
||||
nodes: <G6NodeModel[]>(modelList.filter(item => !(item instanceof Link)).map(item => item.cloneProps())),
|
||||
edges: <G6EdgeModel[]>(modelList.filter(item => item instanceof Link).map(item => item.cloneProps()))
|
||||
nodes: <NodeConfig[]>(modelList.filter(item => !(item instanceof SVLink)).map(item => item.getG6ModelProps())),
|
||||
edges: <EdgeConfig[]>(modelList.filter(item => item instanceof SVLink).map(item => item.getG6ModelProps()))
|
||||
}
|
||||
},
|
||||
|
||||
@@ -137,3 +138,4 @@ export const Util = {
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user