# Is it possible to group "container nodes" in the visualizer?

**URL:** <https://alloytools.discourse.group/t/is-it-possible-to-group-container-nodes-in-the-visualizer/277>\
**Category:** Questions\
**Created:** [July 25, 2022, 5:26am UTC](https://alloytools.discourse.group/t/is-it-possible-to-group-container-nodes-in-the-visualizer/277 "2022-07-25T05:26:24Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![typesanitizer](https://yyz2.discourse-cdn.com/free1/user_avatar/alloytools.discourse.group/typesanitizer/32/146_2.png) [@typesanitizer](https://alloytools.discourse.group/u/typesanitizer)\
**Post date:** [July 25, 2022, 5:26am UTC](https://alloytools.discourse.group/t/is-it-possible-to-group-container-nodes-in-the-visualizer/277/1 "2022-07-25T05:26:24Z")

</div>

I’ve been toying around with using Alloy for understanding complex interactions between programming language features (it’s been fun so far!). Typical programming language constructs have lots of “contains” relationships (e.g. a type is defined inside a module).

Uniformly representing all of these using arrows gets messy in the visualizer, and it takes a bunch of hovering + projections to better understand what is going on. Here is an example:

 ![image](https://global.discourse-cdn.com/free1/uploads/alloytools/original/1X/72c2ee9ff0c6be32f1ce93b87a1c2ea14e13db2e.jpeg)

The details aren’t super important, but the point is that some of the arrows are about contains relationships. For example, if I could have a big box with the label Crate0, that box would contain the boxes for T0, `impl[Σ[α..ω]]1`. Similarly for `Crate1` and so on.

At the same time, just selectively hiding the arrows is not a solution (I’ve already hidden the non-essential ones above), because it is hard to understand the relationships otherwise.

GraphViz (for example) supports grouping nodes together using the `subgroup` construct (unfortunately, I don’t think it is flexible enough to support intersection between groups, but that’s OK for my use case).

Is it possible to do something similar in Alloy natively?

If not, any suggestions for how to develop a custom visualization? I took at look at [Sterling](https://sterling-js.github.io/) which looks like it consumes XML generated by Alloy. (via @shriram’s post: [Visualization for Alloy — what do you want?](https://alloytools.discourse.group/t/visualization-for-alloy-what-do-you-want/111)). I suppose it should not be terribly hard to set up a file watcher + reloading script where I consume the XML and have it regenerate a custom diagram in a separate window; this would avoid having to dive into internals of the Alloy visualizer.

---

<div class="post-metadata">

**Author:** ![typesanitizer](https://yyz2.discourse-cdn.com/free1/user_avatar/alloytools.discourse.group/typesanitizer/32/146_2.png) [@typesanitizer](https://alloytools.discourse.group/u/typesanitizer)\
**Post date:** [July 25, 2022, 5:27am UTC](https://alloytools.discourse.group/t/is-it-possible-to-group-container-nodes-in-the-visualizer/277/2 "2022-07-25T05:27:21Z")

</div>

Example GraphViz visualization with subgroups from [sketchviz.com](http://sketchviz.com) (posted in a separate comment since Discourse won’t let me post two media files in my first comment to the forum)

 ![image](https://global.discourse-cdn.com/free1/uploads/alloytools/original/1X/c6be498afedc21c6c9a1aebef2a84e6d57e0919f.jpeg)

---

<div class="post-metadata">

**Author:** ![typesanitizer](https://yyz2.discourse-cdn.com/free1/user_avatar/alloytools.discourse.group/typesanitizer/32/146_2.png) [@typesanitizer](https://alloytools.discourse.group/u/typesanitizer)\
**Post date:** [July 25, 2022, 6:02am UTC](https://alloytools.discourse.group/t/is-it-possible-to-group-container-nodes-in-the-visualizer/277/3 "2022-07-25T06:02:36Z")

</div>

I just saw that GraphViz output is supported. After some manual tweaking, it looks like

 ![image](https://global.discourse-cdn.com/free1/uploads/alloytools/original/1X/db98baecf53951332dc093f92383fed8226db608.jpeg)

This is still not easy as understand as it could be (I should probably “inline” the `subst_map` entries as `α_n = T_m`) but it seems like a good start in terms of direction. It might make sense to parse the graphviz directly since it’s a simple format.

---

<div class="post-metadata">

**Author:** ![typesanitizer](https://yyz2.discourse-cdn.com/free1/user_avatar/alloytools.discourse.group/typesanitizer/32/146_2.png) [@typesanitizer](https://alloytools.discourse.group/u/typesanitizer)\
**Post date:** [July 25, 2022, 2:02pm UTC](https://alloytools.discourse.group/t/is-it-possible-to-group-container-nodes-in-the-visualizer/277/4 "2022-07-25T14:02:50Z")

</div>

I ended up writing a custom visualizer using GraphViz by consuming the XML output, in about 150 lines of Python code.

 ![image](https://global.discourse-cdn.com/free1/uploads/alloytools/original/1X/423b17692a4aae99cd1efaccf43bf419009426c1.png)

This seems like the best way to go, since it let me tailor a bunch of things such as showing certain relations in only certain situations.

---

<div class="post-metadata">

**Author:** ![grayswandyr](https://yyz2.discourse-cdn.com/free1/user_avatar/alloytools.discourse.group/grayswandyr/32/17_2.png) [@grayswandyr](https://alloytools.discourse.group/u/grayswandyr)\
**Post date:** [July 26, 2022, 2:36pm UTC](https://alloytools.discourse.group/t/is-it-possible-to-group-container-nodes-in-the-visualizer/277/5 "2022-07-26T14:36:00Z")

</div>

Nice, it may be useful to others too: how generic is your script? Can you share it?

---

<div class="post-metadata">

**Author:** ![typesanitizer](https://yyz2.discourse-cdn.com/free1/user_avatar/alloytools.discourse.group/typesanitizer/32/146_2.png) [@typesanitizer](https://alloytools.discourse.group/u/typesanitizer)\
**Post date:** [July 26, 2022, 4:19pm UTC](https://alloytools.discourse.group/t/is-it-possible-to-group-container-nodes-in-the-visualizer/277/6 "2022-07-26T16:19:04Z")

</div>

It’s quite special-cased for my use case, but perhaps the overall structure/skeleton might be useful if you don’t write much code day-to-day? I’ve posted it as a gist here: [Example of converting Alloy's XML output to GraphViz with clusters (containers/groups) and tables. · GitHub](https://gist.github.com/typesanitizer/323f90bf16990a8403f7ca92b7f511c9)
