Author Topic: Visual connections to view references  (Read 405 times)

DaveVint

  • Active Member
  • ***
  • Posts: 51
Visual connections to view references
« on: July 15, 2020, 16:42:48 PM »
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

  • Administrator
  • Hero Member
  • *****
  • Posts: 1619
  • Code Punk
    • Archi
Re: Visual connections to view references
« Reply #1 on: July 15, 2020, 17:25:00 PM »
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! https://www.archimatetool.com/donate

DaveVint

  • Active Member
  • ***
  • Posts: 51
Re: Visual connections to view references
« Reply #2 on: July 15, 2020, 17:38:04 PM »
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

  • Administrator
  • Hero Member
  • *****
  • Posts: 1619
  • Code Punk
    • Archi
Re: Visual connections to view references
« Reply #3 on: July 15, 2020, 17:40:47 PM »
> 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! https://www.archimatetool.com/donate

DaveVint

  • Active Member
  • ***
  • Posts: 51
Re: Visual connections to view references
« Reply #4 on: July 15, 2020, 17:46:27 PM »
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

  • Administrator
  • Hero Member
  • *****
  • Posts: 1619
  • Code Punk
    • Archi
Re: Visual connections to view references
« Reply #5 on: July 15, 2020, 17:49:36 PM »
> 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

« Last Edit: July 15, 2020, 18:03:46 PM by Phil Beauvoir »
If you value and use Archi please consider making a donation! https://www.archimatetool.com/donate

DaveVint

  • Active Member
  • ***
  • Posts: 51
Re: Visual connections to view references
« Reply #6 on: July 15, 2020, 18:57:51 PM »
Thanks! I'll work around it for now using some other stuff.