Archi Forum

Archi Plug-ins => jArchi => Topic started by: ubibene on August 21, 2018, 13:14:48 PM

Title: jArchi : duplicate a view ?
Post by: ubibene on August 21, 2018, 13:14:48 PM
Hi guys,
is it possible to duplicate a view with jArchi (as it can be done in the GUI) ?
Maybe I'm missing something but I could not find this on jArchi wiki.

I would like to make duplicate views of the same view to generate different heatmaps.

Thanks !
Title: Re: jArchi : duplicate a view ?
Post by: Jean-Baptiste Sarrodie on August 21, 2018, 13:18:40 PM
Hi,

Unfortunately this is not possible for the moment directly in jArchi.

Maybe we should add this on our TODO list. Could you open an issue on GitHub (https://github.com/archimatetool/archi-scripting-plugin/issues) for that please?

Regards,

JB
Title: Re: jArchi : duplicate a view ?
Post by: ubibene on August 21, 2018, 13:50:10 PM
done

https://github.com/archimatetool/archi-scripting-plugin/issues/33
Title: Re: jArchi : duplicate a view ?
Post by: Phil Beauvoir on August 21, 2018, 14:13:37 PM
Raises a more general issue which I posted on that GitHub issue...
Title: Re: jArchi : duplicate a view ?
Post by: ubibene on August 23, 2018, 07:18:03 AM
Hi again,

Well I don't mind duplicating the views manually for the time being.

But browsing through the API I'm wondering if I'll be able to do what I want , that is :
1)  create a view with some elements
2)  duplicate the view manually
3)  using a script : for each view, color the objects according to the value of some property of the corresponding archimate elements

Let' say I will duplicate a view showing application components, and I'd like to have a view colored by application  type (home made app, or vendors app), another one colored by technology ( .net apps, sap apps, ...) and so on.

Looking at the Heat script in the sample library bundled with jarchi I understand that 1) model elements are retrieved from the model 2) visual objects are retrieved from the model elements and then a new color is applied to them

In my case, a given archimate element (an application component for example), will have many visual elements, one in each different view, each one with a different color.

So I guess I would need for a given view (Diagram) to get the list of its objects (Diagram contents) , but the API lists only these functions for a view : createObject(), add(element), add(relationship), but none for getting the content objects in the view.

Any idea ?
Title: Re: jArchi : duplicate a view ?
Post by: Jean-Baptiste Sarrodie on August 23, 2018, 07:27:27 AM
Hi,

In this "visual" context a view is seen as a kind of container or parent. Traversing this tree is made possible through the Collection API, so you simple have to create a collection that contains your view and then get its children: $(your_view).children()

Of course, children gets only direct children, so you might want to use find() instead.

Regards,

JB
Title: Re: jArchi : duplicate a view ?
Post by: ubibene on August 23, 2018, 08:02:41 AM
I see.

But ($myview).find() seems to be a collection of archimate model content elements and not a collection of diagram content objetcs.

That is the elements of the collection are (in my case) of type "application-component" and not the visual objects of the diagram I want to set the fill colors.

I'll dig a little deeper.
Title: Re: jArchi : duplicate a view ?
Post by: Jean-Baptiste Sarrodie on August 23, 2018, 11:17:25 AM
They are visual objects. Type always return the type of underlying concept for visual objects.
Title: Re: jArchi : duplicate a view ?
Post by: ubibene on August 23, 2018, 12:26:38 PM
Thanks for your help, I got it finally.

So, for those interested, here is my first jArchi script (and my first javascript code) for producing heatmap on a specific diagram


// no error checking
// get a diagram by name
function selectDiagram(diagramName)
{
  return $("archimate-diagram-model").filter("."+diagramName).first() ;
}


// given a value return a color code
function colorize(status)
{
  if (status=="planned") return "#FF0000";
  else if (status =="deployed") return "#00FF00";
  else return "#0000FF";
}

//  for diagram diagramName , colorize  components of componentType according to their propertyName values

function makeHeatMap(diagramName,componentType,propertyName)
{
  diagram = selectDiagram(diagramName);
  visuals = $(diagram).find(componentType);


  visuals.forEach(function(vis) {
    var propertyValue = vis.prop(propertyName);
    var color = colorize(propertyValue);
    $(vis).attr("fillColor",color);
  })
}

// callexample
makeHeatMap("heatmap-cycle","application-component","cycle")



I still have some work to do (I'd like to pass the colorizing function as an argument of makeHeatMap , still need to learn more javascript)
Title: Re: jArchi : duplicate a view ?
Post by: Jean-Baptiste Sarrodie on August 23, 2018, 13:06:57 PM
Good !

Passing a function is exacty the same as passing a value, so you can just write:
function makeHeatMap(diagramName,componentType,propertyName, colorFct)

and call it like that:
makeHeatMap("heatmap-cycle","application-component","cycle", colorize)

Of course, instead using a named function "colorize" this could be an "inline" function:
makeHeatMap("heatmap-cycle","application-component","cycle", function(propValue){...})

In addition, you could replace:
$(vis).attr("fillColor",color);

By:
vis.fillColor = color;

And you could use the current (tree) selection instead of using a named view, and a filter to make sure only the first ArchiMate views is worked on:
function selectDiagram(diagramName)
{
  return $(selection).filter("archimate-diagram-model").first();
}



So we end up with:
// get selected diagram (archimate view)
function selectDiagram(diagramName)
{
  return $(selection).filter("archimate-diagram-model").first();
}


// given a value return a color code
function colorize(status)
{
  if (status=="planned") return "#FF0000";
  else if (status =="deployed") return "#00FF00";
  else return "#0000FF";
}

//  for diagram diagramName , colorize  components of componentType according to their propertyName values

function makeHeatMap(diagramName,componentType,propertyName, colorFct)
{
  diagram = selectDiagram(diagramName);
  visuals = $(diagram).find(componentType);


  visuals.forEach(function(vis) {
    var propertyValue = vis.prop(propertyName);
    var color = colorFct(propertyValue);
    vis.fillColor = color;
  })
}

// callexample
makeHeatMap("heatmap-cycle","application-component","cycle", colorize)


JB