@@ -33,13 +33,16 @@ class GraphViewNode {
3333 var outHeight = ( nodeSchema . outPorts . length * 25 ) + 10 ;
3434 if ( outHeight > portHeight ) portHeight = outHeight ;
3535 }
36- if ( nodeSchema . attributes && nodeSchema . attributes . length > 0 ) {
37- attributeHeight = nodeSchema . attributes . length * 32 + 10 ;
36+ const visibleAttributes = nodeSchema . attributes && nodeSchema . attributes . filter ( a => ! a . hidden ) ;
37+ if ( visibleAttributes && visibleAttributes . length > 0 ) {
38+ attributeHeight = visibleAttributes . length * 32 + 10 ;
3839 }
3940 var rectSize = { x : this . getSchemaValue ( 'baseWidth' ) , y : rectHeight + portHeight + attributeHeight } ;
4041
4142 var labelName ;
42- if ( nodeSchema . outPorts || nodeSchema . inPorts ) {
43+ if ( nodeSchema . headerTextFormatter ) {
44+ labelName = nodeSchema . headerTextFormatter ( nodeData . attributes ) ;
45+ } else if ( nodeSchema . outPorts || nodeSchema . inPorts ) {
4346 labelName = nodeData . attributes && nodeData . attributes . name ? `${ nodeData . attributes . name } (${ nodeSchema . name } )` : nodeSchema . name ;
4447 } else {
4548 labelName = nodeData . attributes && nodeData . attributes . name || nodeData . name ;
@@ -196,13 +199,13 @@ class GraphViewNode {
196199 id : `in${ i } ` ,
197200 group : 'in' ,
198201 edgeType : port . edgeType ,
199- markup : `<circle class="port-body" edgeType="${ port . type } "></circle><circle class="port-inner-body" visibility="hidden"></circle>` ,
202+ markup : `<circle class="port-body" id=" ${ nodeData . id } -in ${ i } " edgeType="${ port . type } "></circle><circle class="port-inner-body" visibility="hidden"></circle>` ,
200203 attrs : {
201204 '.port-body' : {
202205 stroke : this . _graphSchema . edges [ port . type ] . stroke || this . _config . defaultStyles . edge . stroke
203206 } ,
204207 text : {
205- text : port . name ,
208+ text : port . textFormatter ? port . textFormatter ( nodeData . attributes ) : port . name ,
206209 fill : this . getSchemaValue ( 'textColorSecondary' ) ,
207210 'font-size' : 14
208211 }
@@ -242,14 +245,14 @@ class GraphViewNode {
242245 nodeSchema . outPorts . forEach ( ( port , i ) => rect . addPort ( {
243246 id : `out${ i } ` ,
244247 group : 'out' ,
245- markup : `<circle class="port-body" edgeType="${ port . type } "></circle><circle class="port-inner-body" visibility="hidden"></circle>` ,
248+ markup : `<circle class="port-body" id=" ${ nodeData . id } -out ${ i } " edgeType="${ port . type } "></circle><circle class="port-inner-body" visibility="hidden"></circle>` ,
246249 attrs : {
247250 type : port . type ,
248251 '.port-body' : {
249252 stroke : this . _graphSchema . edges [ port . type ] . stroke || this . _config . defaultStyles . edge . stroke
250253 } ,
251254 text : {
252- text : port . name ,
255+ text : port . textFormatter ? port . textFormatter ( nodeData . attributes ) : port . name ,
253256 fill : this . getSchemaValue ( 'textColorSecondary' ) ,
254257 'font-size' : 14
255258 }
@@ -258,8 +261,8 @@ class GraphViewNode {
258261 }
259262
260263 var containers = [ ] ;
261- if ( nodeSchema . attributes ) {
262- nodeSchema . attributes . forEach ( ( attribute , i ) => {
264+ if ( visibleAttributes ) {
265+ visibleAttributes . forEach ( ( attribute , i ) => {
263266 const container = new this . _graphView . pcui . Container ( { class : 'graph-node-container' } ) ;
264267 const label = new this . _graphView . pcui . Label ( { text : attribute . name , class : 'graph-node-label' } ) ;
265268 let input ;
@@ -387,16 +390,28 @@ class GraphViewNode {
387390 return arr ;
388391 }
389392
390- updateAttribute ( attribute , value ) {
391- if ( attribute === 'name' ) {
392- var labelName ;
393- if ( this . nodeSchema . outPorts || this . nodeSchema . inPorts ) {
394- labelName = `${ value } (${ this . nodeSchema . name } )` ;
395- } else {
396- labelName = value ;
397- }
398- this . model . attr ( 'label/text' , labelName ) ;
393+ updateFormattedTextFields ( ) {
394+ if ( this . nodeSchema . headerTextFormatter ) {
395+ this . model . attr ( 'label/text' , this . nodeSchema . headerTextFormatter ( this . nodeData . attributes ) ) ;
399396 }
397+ if ( this . nodeSchema . outPorts ) {
398+ this . nodeSchema . outPorts . forEach ( ( port , i ) => {
399+ if ( port . textFormatter ) {
400+ document . getElementById ( `${ this . nodeData . id } -out${ i } ` ) . parentElement . parentElement . querySelector ( 'tspan' ) . innerHTML = port . textFormatter ( this . nodeData . attributes ) ;
401+ }
402+ } ) ;
403+ }
404+ if ( this . nodeSchema . inPorts ) {
405+ this . nodeSchema . inPorts . forEach ( ( port , i ) => {
406+ if ( port . textFormatter ) {
407+ document . getElementById ( `${ this . nodeData . id } -in${ i } ` ) . parentElement . parentElement . querySelector ( 'tspan' ) . innerHTML = port . textFormatter ( this . nodeData . attributes ) ;
408+ }
409+ } ) ;
410+ }
411+ }
412+
413+ updateAttribute ( attribute , value ) {
414+ this . nodeData . attributes [ attribute ] = value ;
400415 const attributeElement = document . querySelector ( `#nodediv_${ this . model . id } ` ) . querySelector ( `#input_${ attribute } ` ) ;
401416 if ( attributeElement ) {
402417 attributeElement . ui . suspendEvents = true ;
@@ -408,6 +423,7 @@ class GraphViewNode {
408423 attributeElement . ui . error = false ;
409424 attributeElement . ui . suspendEvents = false ;
410425 }
426+ this . updateFormattedTextFields ( ) ;
411427 }
412428
413429 updateNodeType ( nodeType ) {
@@ -431,7 +447,9 @@ class GraphViewNode {
431447 break ;
432448 }
433449 case 'updateAttribute' : {
434- document . querySelector ( `#nodediv_${ this . model . id } ` ) . querySelector ( `#input_${ attribute . name } ` ) . ui . on ( 'change' , ( value ) => {
450+ const attributeElement = document . querySelector ( `#nodediv_${ this . model . id } ` ) . querySelector ( `#input_${ attribute . name } ` ) ;
451+ if ( ! attributeElement ) break ;
452+ attributeElement . ui . on ( 'change' , ( value ) => {
435453 if ( attribute . name === 'name' ) {
436454 var nameTaken = false ;
437455 Object . keys ( this . _graphView . _graphData . get ( 'data.nodes' ) ) . forEach ( ( nodeKey ) => {
@@ -446,13 +464,6 @@ class GraphViewNode {
446464 return ;
447465 }
448466 attributeElement . ui . error = false ;
449- var labelName ;
450- if ( this . nodeSchema . outPorts || this . nodeSchema . inPorts ) {
451- labelName = `${ this . nodeSchema . name } (${ value } )` ;
452- } else {
453- labelName = value ;
454- }
455- this . model . attr ( 'label/text' , labelName ) ;
456467 }
457468 callback ( this . nodeData . id , attribute , value ) ;
458469 } ) ;
0 commit comments