1
1
import uniqBy from 'lodash.uniqby' ;
2
2
3
3
export function transformGraphMap ( data , graphMap ) {
4
- const style = graphMap && graphMap . styles && graphMap . styles . style ;
5
- const captionField = graphMap && graphMap . captionFields && graphMap . captionFields . captionField ;
4
+ graphMap = graphMap || { } ;
5
+ const style = graphMap . styles && graphMap . styles . style ;
6
+ const captionField = graphMap . captionFields && graphMap . captionFields . captionField ;
7
+ const showRelationTypes = graphMap . showRelationTypes ;
6
8
7
9
const rst = { nodes : [ ] , edges : [ ] } ;
8
10
data . forEach ( ( item ) => {
9
11
const pathData = item . path ;
10
12
if ( pathData ) {
11
- const { nodes, edges } = transformPath ( pathData , style , captionField ) ;
13
+ const { nodes, edges } = transformPath ( pathData , style , captionField , showRelationTypes ) ;
12
14
rst . nodes . push ( ...nodes ) ;
13
15
rst . edges . push ( ...edges ) ;
14
16
} else if ( isEdge ( item ) ) {
15
- const edge = edgeFromGraphMap ( item , style ) ;
17
+ const edge = edgeFromGraphMap ( item , style , showRelationTypes ) ;
16
18
rst . edges . push ( edge ) ;
17
19
} else {
18
20
const node = nodeFromGraphMap ( item , style , captionField ) ;
@@ -30,11 +32,11 @@ function isEdge(entity) {
30
32
return entity . hasOwnProperty ( 'start' ) && entity . hasOwnProperty ( 'end' ) ;
31
33
}
32
34
33
- function transformPath ( pathData , style , captionField ) {
35
+ function transformPath ( pathData , style , captionField , showRelationTypes ) {
34
36
const rst = { nodes : [ ] , edges : [ ] } ;
35
37
pathData . forEach ( ( item ) => {
36
38
if ( isEdge ( item ) ) {
37
- const edge = edgeFromGraphMap ( item , style ) ;
39
+ const edge = edgeFromGraphMap ( item , style , showRelationTypes ) ;
38
40
rst . edges . push ( edge ) ;
39
41
} else {
40
42
const node = nodeFromGraphMap ( item , style , captionField ) ;
@@ -51,7 +53,7 @@ export function nodeFromGraphMap(entity, style, captionField) {
51
53
const fillColor = styleData . fillColor || '' ;
52
54
const node = {
53
55
id : id + '' ,
54
- label : label ,
56
+ label : label === undefined ? '' : label + '' ,
55
57
properties,
56
58
lables
57
59
} ;
@@ -73,7 +75,7 @@ export function nodeFromGraphMap(entity, style, captionField) {
73
75
}
74
76
return node ;
75
77
}
76
- export function edgeFromGraphMap ( entity , style ) {
78
+ export function edgeFromGraphMap ( entity , style , showRelationTypes ) {
77
79
const { start, end, id, type, properties } = entity ;
78
80
const styleData = style ? getEdgeStyle ( entity , style ) : { } ;
79
81
const edge = {
@@ -85,6 +87,9 @@ export function edgeFromGraphMap(entity, style) {
85
87
labelCfg : { } ,
86
88
properties
87
89
} ;
90
+ if ( showRelationTypes === false ) {
91
+ delete edge . label ;
92
+ }
88
93
if ( styleData . stroke ) {
89
94
edge . style . stroke = styleData . stroke ;
90
95
edge . style . endArrow = {
@@ -161,11 +166,11 @@ function getNodeLabel(entity, captionField) {
161
166
const types = JSON . parse ( entityTypes || '[]' ) ;
162
167
const labelStr = labels && labels . join ( '&' ) ;
163
168
if ( ids . includes ( id ) || types . includes ( labelStr ) ) {
164
- return properties [ name ] || '' ;
169
+ return properties [ name ] ;
165
170
}
166
171
}
167
172
}
168
- return properties [ properties . _labelfieldname ] || '' ;
173
+ return properties [ properties . _labelfieldname ] ;
169
174
}
170
175
171
176
function formatFontStyle ( fontStyle ) {
0 commit comments