File tree Expand file tree Collapse file tree 6 files changed +187
-21
lines changed Expand file tree Collapse file tree 6 files changed +187
-21
lines changed Original file line number Diff line number Diff line change 28
28
"@typescript-eslint/eslint-plugin" : " ^3.6.1" ,
29
29
"@typescript-eslint/parser" : " ^3.2.0" ,
30
30
"@vuepress-reco/vuepress-plugin-back-to-top" : " ^1.6.0" ,
31
+ "commitizen" : " ^4.2.4" ,
31
32
"cz-lerna-changelog" : " ^2.0.3" ,
32
33
"eslint" : " ^7.0.0" ,
33
34
"eslint-config-airbnb-typescript" : " ^9.0.0" ,
Original file line number Diff line number Diff line change @@ -37,6 +37,7 @@ class GraphModel {
37
37
topElement : BaseNodeModel | BaseEdgeModel ; // 当前位于顶部的元素
38
38
selectElement : BaseNodeModel | BaseEdgeModel ; // 当前位于顶部的元素
39
39
selectElements = new Map < string , BaseElementModel > ( ) ; // 多选
40
+ idGenerator : ( ) => number | string ;
40
41
@observable selectElementSize = 0 ;
41
42
@observable edgeType : string ;
42
43
@observable nodes : BaseNodeModel [ ] = [ ] ;
@@ -61,6 +62,7 @@ class GraphModel {
61
62
grid : { size = 1 } = { } ,
62
63
isSilentMode = false ,
63
64
eventCenter,
65
+ idGenerator,
64
66
} = config ;
65
67
this . background = background ;
66
68
this . isSlient = isSilentMode ;
@@ -73,6 +75,7 @@ class GraphModel {
73
75
this . width = config . width ;
74
76
this . height = config . height ;
75
77
this . partial = config . partial ;
78
+ this . idGenerator = idGenerator ;
76
79
}
77
80
@computed get nodesMap ( ) : { [ key : string ] : { index : number , model : BaseNodeModel } } {
78
81
return this . nodes . reduce ( ( nMap , model , index ) => {
Original file line number Diff line number Diff line change @@ -90,9 +90,22 @@ class BaseEdgeModel implements IBaseModel {
90
90
if ( ! data . properties ) {
91
91
data . properties = { } ;
92
92
}
93
+
94
+ if ( ! data . id ) {
95
+ const { idGenerator } = this . graphModel ;
96
+ const globalId = idGenerator && idGenerator ( ) ;
97
+ if ( globalId ) data . id = globalId ;
98
+ const nodeId = this . createId ( ) ;
99
+ if ( nodeId ) data . id = nodeId ;
100
+ }
101
+
93
102
assign ( this , pickEdgeConfig ( data ) ) ;
94
103
}
95
104
105
+ createId ( ) {
106
+ return null ;
107
+ }
108
+
96
109
setAttributes ( ) { }
97
110
98
111
@computed get sourceNode ( ) {
Original file line number Diff line number Diff line change @@ -104,10 +104,23 @@ export default class BaseNodeModel implements IBaseModel {
104
104
if ( ! data . properties ) {
105
105
data . properties = { } ;
106
106
}
107
+
108
+ if ( ! data . id ) {
109
+ const { idGenerator } = this . graphModel ;
110
+ const globalId = idGenerator && idGenerator ( ) ;
111
+ if ( globalId ) data . id = globalId ;
112
+ const nodeId = this . createId ( ) ;
113
+ if ( nodeId ) data . id = nodeId ;
114
+ }
115
+
107
116
this . formatText ( data ) ;
108
117
assign ( this , pickNodeConfig ( data ) ) ;
109
118
}
110
119
120
+ createId ( ) {
121
+ return null ;
122
+ }
123
+
111
124
// 格式化text参数,未修改observable不作为action
112
125
formatText ( data ) : void {
113
126
if ( ! data . text ) {
Original file line number Diff line number Diff line change @@ -54,6 +54,8 @@ export type Definition = {
54
54
hideAnchors ?: boolean ; // 是否隐藏anchor
55
55
56
56
hoverOutline ?: boolean ; // 是否显示节点hover时的outline
57
+
58
+ idGenerator ?: ( ) => number | string ; // 元素id生成器
57
59
} ;
58
60
59
61
export interface GuardsTypes {
You can’t perform that action at this time.
0 commit comments