Link validation fields

Hi,

in order to check which object can be linked to others I’ve developed a function to check this behavior, called “onlydriver”, activated by this two event:

      myDiagram.toolManager.linkingTool.linkValidation = onlydriver;

      myDiagram.toolManager.relinkingTool.linkValidation = onlydriver;

here’s the function “onlydriver”:

      function onlydriver(fromnode, fromport, tonode, toport) {
    	  
    	  if(fromnode.data.group!=tonode.data.group){
    		  if(fromnode.data.category=='Drivers' && tonode.data.category=='Dominio'){
    			  if(fromnode.data.cname==tonode.data.cname){
    				  if(fromport.tp==toport.tp){
    					  return true;
    				  }else{
    					  return false;
    				  }
    			  }else{
    				  //if(fromport.ot=='totale' || toport.ot=='totale'){ chg version 2.10
       				  if(fromport.tp=='totale' || toport.tp=='totale'){
    					  //if(tonode.data.cname=='Ingresso Singolo' && fromport.ot!='totale'){ chg version 2.10
       					  if(tonode.data.cname=='Ingresso Singolo' && fromport.tp!='totale'){ 
    						  return true;
    					  }else{
    						  return false;
    					  }
    				  }else{
    					  return true;
    				  }
    			  }
    		  }else{
    			  if(fromnode.data.category=='Startvoce' && tonode.data.category=='Dominio'){
    				  if(tonode.data.cname=='Ingresso Singolo'){
    					  return true;
    				  }else{
    					  //if(toport.ot!='totale'){ chg version 2.10
       					  if(toport.tp!='totale'){
    						  return true;
    					  }else{
    						  return false;
    					  }
    				  }
    			  }else{
    		    	  //if(fromport.ot=='totale' && toport.ot=='totale') chg version 2.10
       		    	  if(fromport.tp=='totale' && toport.tp=='totale')
    		    	  {
    		    		  if(fromnode.data.cname != tonode.data.cname){
    		    			  return false;
    		    		  }
    		    	  }
    				  return true;
    			  }
    		  }  
    	  } else {
    		  if(fromnode.data.category=='Startvoce' && tonode.data.category=='Servizi'){
    			  return true;
    		  }else{
   				  return false;
    		  }
    	  }
    	  
      }	  

In the last version of the library I’ve used one of the checked fields is the xxxx.tp while in the previous version was xxxx.ot… (I commented out with “chg version 2.10”).
Now my question is: are there best practices to create a check list of rules without checking fields that can change among different version of the library?
Thx in advance
regards
F

As you have now discovered, you should always write code only making use of the documented API, not referring to the minified property names that result from making the library smaller.

I don’t know what those “ot” and “tp” properties are referring to, so I cannot suggest which API members you want to use instead.

BTW, your code could be more legible if instead of:

    				  if(fromport.tp==toport.tp){
    					  return true;
    				  }else{
    					  return false;
    				  }

you wrote:

    				  return fromport.tp==toport.tp;

(but using proper API property names, of course)

Ok… I’m quite sure that documented API are the best approach and of course I’m quite new to these libraries so probably I did many mistakes creating these rules…but I didn’t find anything in API referring to the text written in the link.data.toPort/fromPort while validating links…so I’ve searched in debug mode a property showing text created during link creation…and these properties, ot before and tp after (in the 2.1 release) are the unique I’ve found…maybe it’s a my limit but can you suggest properties in the API showing what I need?
Thx
F

Maybe GraphObject.portId or GraphObject.name? It really depends on how you have defined the ports on your nodes.

Right, too few details, let me explain: I’ve an object that can be linked from each single element contained in a panel table and from the header of this panel. In that case the fromPort in the link array is written as “totale”. ex:

“linkDataArray”: [ {“FSrc”:“Origine”, “FText”:“Elemento contabile”, “TSrc”:“DR022”, “TText”:“Terminal FCO”, “from”:“Origine”, “to”:“DR0222”, “fromPort”:“Elemento contabile”, “toPort”:“totale”} ]}
Take a look a this image:


I want to link DR022 from the header called “Terminal FCO” to the header “AREE FCO” of the DR026 object. The result is tested in the function you’ve just seen. Each of these headers has a port with value “totale”.
How can I test in validation this property coming from the header of the panel? You can see is written in the created json… where’s the “toPort” value of the header in validation event?
If you need more elements ask me pls.
Thx

If GraphLinksModel.linkToPortIdProperty is “toPort”, then you want to look at the port element’s GraphObject.portId property.

Sorry but I keep not understand…in that validation function (onlydriver) I’ve only references to 4 objects: two nodes, (from & to) and two ports, fromport and toport. Where’s that property? fromnode and tonode have an object “data” that is not containing any property portid or nothing that is referencing header’s port, same for objects fromport and toport…I took this example in link validation and I guess these imported objects can’t be changed…or not? Do “fromport” and “toport” have other objects inside referring to the properties you’ve just mentioned? Pls help

when you’re talking about GraphObject, you’re referring to the two ports objects in the linkvalidation function?

Ok, now I get what you’ve said…I didn’t get the meaning of that objects in the function, so I didn’t get them to work properly…
Thank you
Regards
F