jArchi : duplicate a view ?

Started by ubibene, August 21, 2018, 14:14:48 PM

Previous topic - Next topic

ubibene

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 !

Jean-Baptiste Sarrodie

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 for that please?

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

Raises a more general issue which I posted on that GitHub issue...
If you value and use Archi, please consider making a donation!
Ask your ArchiMate related questions to the ArchiMate Community's Discussion Board.

ubibene

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 ?

Jean-Baptiste Sarrodie

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
If you value and use Archi, please consider making a donation!
Ask your ArchiMate related questions to the ArchiMate Community's Discussion Board.

ubibene

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.

Jean-Baptiste Sarrodie

They are visual objects. Type always return the type of underlying concept for visual objects.
If you value and use Archi, please consider making a donation!
Ask your ArchiMate related questions to the ArchiMate Community's Discussion Board.

ubibene

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)

Jean-Baptiste Sarrodie

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
If you value and use Archi, please consider making a donation!
Ask your ArchiMate related questions to the ArchiMate Community's Discussion Board.