11import uniqBy from 'lodash.uniqby' ;
22
3- export function transformGraphMap ( data , style ) {
3+ export function transformGraphMap ( data , graphMap ) {
4+ const style = graphMap && graphMap . styles && graphMap . styles . style ;
5+ const captionField = graphMap && graphMap . captionFields && graphMap . captionFields . captionField ;
6+
47 const rst = { nodes : [ ] , edges : [ ] } ;
58 data . forEach ( ( item ) => {
69 const pathData = item . path ;
710 if ( pathData ) {
8- const { nodes, edges } = transformPath ( pathData , style ) ;
11+ const { nodes, edges } = transformPath ( pathData , style , captionField ) ;
912 rst . nodes . push ( ...nodes ) ;
1013 rst . edges . push ( ...edges ) ;
1114 } else if ( isEdge ( item ) ) {
1215 const edge = edgeFromGraphMap ( item , style ) ;
1316 rst . edges . push ( edge ) ;
1417 } else {
15- const node = nodeFromGraphMap ( item , style ) ;
18+ const node = nodeFromGraphMap ( item , style , captionField ) ;
1619 rst . nodes . push ( node ) ;
1720 }
1821 } ) ;
@@ -27,24 +30,24 @@ function isEdge(entity) {
2730 return entity . hasOwnProperty ( 'start' ) && entity . hasOwnProperty ( 'end' ) ;
2831}
2932
30- function transformPath ( pathData , style ) {
33+ function transformPath ( pathData , style , captionField ) {
3134 const rst = { nodes : [ ] , edges : [ ] } ;
3235 pathData . forEach ( ( item ) => {
3336 if ( isEdge ( item ) ) {
3437 const edge = edgeFromGraphMap ( item , style ) ;
3538 rst . edges . push ( edge ) ;
3639 } else {
37- const node = nodeFromGraphMap ( item , style ) ;
40+ const node = nodeFromGraphMap ( item , style , captionField ) ;
3841 rst . nodes . push ( node ) ;
3942 }
4043 } ) ;
4144 return rst ;
4245}
4346
44- export function nodeFromGraphMap ( entity , style ) {
47+ export function nodeFromGraphMap ( entity , style , captionField ) {
4548 const { id, properties, lables } = entity ;
4649 const styleData = style ? getNodeStyle ( entity , style ) : { } ;
47- const label = getNodeLabel ( entity ) ;
50+ const label = getNodeLabel ( entity , captionField ) ;
4851 const fillColor = styleData . fillColor || '' ;
4952 const node = {
5053 id : id + '' ,
@@ -133,10 +136,20 @@ function getNodeStyle(entity, style) {
133136 return { } ;
134137}
135138
136- function getNodeLabel ( entity ) {
137- const { properties } = entity ;
138- const name = properties . _labelfieldname ;
139- return properties [ name ] || '' ;
139+ function getNodeLabel ( entity , captionField ) {
140+ const { id, labels, properties } = entity ;
141+ if ( captionField ) {
142+ const data = captionField instanceof Array ? captionField : [ captionField ] ;
143+ for ( let i = 0 ; i < data . length ; i ++ ) {
144+ const { name, entityTypes, entityIds } = data [ i ] ;
145+ const ids = JSON . parse ( entityIds || '[]' ) ;
146+ const types = JSON . parse ( entityTypes || '[]' ) ;
147+ if ( ids . includes ( id ) || types . includes ( labels [ 0 ] ) ) {
148+ return properties [ name ] || '' ;
149+ }
150+ }
151+ }
152+ return properties [ properties . _labelfieldname ] || '' ;
140153}
141154
142155function formatFontStyle ( fontStyle ) {
0 commit comments