jArchi issue

Started by AdGerrits, August 16, 2018, 21:47:01 PM

Previous topic - Next topic

AdGerrits

Hi Phil, I'm not experienced enough in using javascript/jArchi so great chance it's not a bug but an error on my side.
I've been trying to understand whats going on in this short script but I rest my case...

Why is 'type' not replaced in the first selection as expected ( as  'name' is) just like in the second selection?
btw: I select the goal-element with name '1' before running the code.

$(selection).each(function(e){
   console.log('Before Name=', e.name, '-Type=', e.type);
   e.name = '2';
   e.type = 'principle';
   console.log('After Name=', e.name, '-Type=', e.type);
});
/* output:
Before Name=1-Type=goal
After Name=2-Type=goal  => (huh?)
*/

console.log('------');
$('.2').each(function(e){
   console.log('Before Name=', e.name, '-Type=', e.type);
   e.name = '3';
   e.type = 'principle';
   console.log('After Name=', e.name, '-Type=', e.type);
});
/* output:
Before Name=2-Type=goal
After Name=3-Type=principle  => (as expected)
*/




Phil Beauvoir

Hi Ad,

it depends on the "selection". If you are selecting visual objects in a diagram then you have to access the underlying ArchiMate concept in order to set its type. So:

$(selection).each(function(e){
   console.log('Before Name=', e.name, '-Type=', e.type);
   e.name = '2';
   e.concept.type = 'principle';
   console.log('After Name=', e.name, '-Type=', e.type);
});

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

AdGerrits

Thanks. Difference between visual elements and concepts is much clearer now.
One additional remark: 'API-overview' says "visual objects inherit name, description and properties if they are linked to an underlying ArchiMate concept". But it looks like  "type" is also inherited but read-only (I can display type via 'selected-element.type' but cannot change it).

Phil Beauvoir

Yes, in the case of a visual object, "type" returns the type of the underlying ArchiMate object as a convenience method (and not something like "diagram-model-archimate-object"). It is the equivalent of:

var type = visualArchiMateObject.concept.type;

is the same as:

var type = visualArchiMateObject.type;

And so setType(type) does not work on a visual object directly because setType() is only a method on an ArchiMate concept type (element or relationship).

To change the underlying type (and this will change all instances of it in all diagrams) then you need to do:

visualObject.concept.type = "node";
If you value and use Archi, please consider making a donation!
Ask your ArchiMate related questions to the ArchiMate Community's Discussion Board.

AdGerrits

Understood. One last question after experimenting for a while: is there a way to exit a script early? Return doesn't seem to work (and exit() is a bit rough...).

Phil Beauvoir

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

Jean-Baptiste Sarrodie

Hi,

It's true that exit is a bit hard (it simply kills Archi itself). We should make it unavailable (see this post).

Instead, we could write a 'buitin' exit function that simply throw an exception...

Regards,

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

Phil Beauvoir

Done and done.  8)

Next version of jArchi redefines exit() to throw an exception which is caught by jArchi and a nice, polite message is written to the console:

"Exited at line 13 - have a nice day, Ad!"

(OK, maybe not the "have a nice day" bit...)
If you value and use Archi, please consider making a donation!
Ask your ArchiMate related questions to the ArchiMate Community's Discussion Board.

AdGerrits

Nice. Even without the 'have a nice day' part more than satisfied ;)