Generic colorizer jArchi script

Started by rchevallier, November 17, 2021, 13:13:39 PM

Previous topic - Next topic

rchevallier

November 17, 2021, 13:13:39 PM Last Edit: November 17, 2021, 13:15:49 PM by rchevallier
Hello all,

Just laziness to avoir writing one if one already exist ;D

Has anyone created a generic jArchi script which allow interactively (custom dialog box) to define/select a color and some filter expression/selection on properties or element type to colorize the elements (heatmap, hiliter, etc...) matching the filter in the current view?

There are some example of script in Gist, but not full generic ones:
https://gist.github.com/search?q=%23jarchi+extension%3Aajs+color

Thanks in advance

-RC

Jean-Baptiste Sarrodie

Hi,

I have one which allow a user to select some flow relationships and then sets their style according to the style of a legend with shared properties' values.

It should be easy to extend it so that it works for any concept.

Here it is:
console.show();
console.clear();

var flows = selection.filter('flow-relationship');
var view = flows.first().view;

var legendName = window.prompt('Confirm the name of your legend visual group:', "Legend");
var legendGroup = $(view).find('diagram-model-group.'+legendName);

if (!legendGroup.size()) {
  window.alert('Unable to find legend visual group!');
  exit();
} else {
  legendGroup = legendGroup.get(0);
}

console.log('Legend found');

// Use 'children()' instead of 'find()' (later doesn't work on visual groups)
$(legendGroup).children('diagram-model-note').outRels().add($(legendGroup).children('element').outRels()).each(function(cnx) {
  var hasProperties = cnx.prop().size();
 
  if (hasProperties) {
    cnx.prop().forEach(function(propName) {
      var propValue = cnx.prop(propName);
     
      flows.filter(function(rel) {
        return rel.prop(propName) == propValue;
      }).each(function(rel) {
        console.log('Updating color of: ', rel);
        rel.lineColor = cnx.lineColor;
        rel.lineWidth = cnx.lineWidth;
        rel.fontColor = cnx.fontColor;
        rel.fontName = cnx.fontName;
        rel.fontStyle = cnx.fontStyle;
        rel.fontSize = cnx.fontSize;
      });
    });
  }
});

Regards,

JB
If you value and use Archi please consider making a donation! https://www.archimatetool.com/donate

rchevallier

Idea to use a legend instead of a dialog box to define the configuration is very clever! (query by example + legend already exists!)
Big thanks!