Visual connections to view references

Started by DaveVint, July 15, 2020, 16:42:48 PM

Previous topic - Next topic

DaveVint

Hi,

I'm writing a script to export documentation and have a problem which is probably down to my lack of Javascript knowledge!

My diagrams have a 'breadcrumb' trail of view references along the top which allows me to navigate around the views in a controlled fashion when it's in HTML exported or within the tool. However when I generate formal documentation I don't want them in the output image. So I'm trying to look for view references within a diagram that are 'orphaned' and have no visual connection linking it to something in the view. I temporarily delete the 'orphaned' view references, render the image for output, then reinstate them. However, I'm struggling to get the right combination of properties, dollar signs and curly brackets to see whether a view reference is connected to anything!

My current attempt is:

diagrams = $(linkedView).find("diagram-model-reference");
connections = $(linkedView).find("diagram-model-connection");
console.log( "  Diagrams on " + linkedView.name + " = " + diagrams );
console.log( "  Connections on " + linkedView.name + " = " + connections );

  $(linkedView).find("diagram-model-reference").each(function(viewRef){
   
    orphaned = true;
    connections.each( function(connection){
      console.log( "    Checking connection from " + connection.source + " to " + connection.target + " with " + viewRef );
      if ( connection.source == viewRef ){
        console.log( "    That's a connection to source!!");
        orphaned=false;
      }
      if ( connection.target == viewRef ){
        console.log( "    That's a connection to target!!");
        orphaned=false;
      }
    });
    console.log( "     Check " + viewRef + ",  orphaned = " + orphaned );
  });


In that, even though the console log tells me that I'm iterating through everything, neither connection.source nor connection.target trigger as equal to viewRef and thus everything is being flagged as orphaned.The names displayed in the console log output all match correctly.

In what way am I being an idiot here? :)

Cheers,

Dave

Phil Beauvoir

If the aim is to get incoming and outgoing connections from the view references, this will do it:

$(currentView).find("diagram-model-reference").each(function(viewRef) {
    inConnections = $(viewRef).inRels();
    outConnections = $(viewRef).outRels();
});
If you value and use Archi, please consider making a donation!
Ask your ArchiMate related questions to the ArchiMate Community's Discussion Board.

DaveVint

Thanks Phil. Don't think that's my problem - I'm trying to figure out whether to remove a 'View ref' visual object when it has no visual connections to it.

Managed to get it working by comparing the IDs of the connection.source/target and the viewref

Phil Beauvoir

> Thanks Phil. Don't think that's my problem - I'm trying to figure out whether to remove a 'View ref' visual object when it has no visual connections to it.

If inRels() and outRels() are empty then it has no visual connections.
If you value and use Archi, please consider making a donation!
Ask your ArchiMate related questions to the ArchiMate Community's Discussion Board.

DaveVint

Thanks! Didn't read it properly.

Next question then - how do I query the view that an 'diagram-model-reference' is pointing to, rather than the one that the reference object is in? That would allow me to remember it and recreate.

Phil Beauvoir

#5
> Next question then - how do I query the view that an 'diagram-model-reference' is pointing to, rather than the one that the reference object is in? That would allow me to remember it and recreate.

You'll have to wait until the next release of jArchi :-) The code is there in the jArchi repo, if you really need it, though.

See https://github.com/archimatetool/archi-scripting-plugin/issues/58

If you value and use Archi, please consider making a donation!
Ask your ArchiMate related questions to the ArchiMate Community's Discussion Board.

DaveVint

Thanks! I'll work around it for now using some other stuff.