Tuesday, September 26, 2023

Partitioning the Diagram


In some ideal world, the resultant diagram from parsing would be fully connected.

This isn't true for a number of reasons. The most obvious one is just user "error". As the user is entering information, they simply may not be aware of one or more connections, or unsure how to describe them. It is better to handle this case than to complain and force the user to take corrective action.

Another is that we want to explicitly support the idea of "modules" or "subsystems" which deliberately target a set of nodes.

And it seems to me that if you have two diagrams that aren't connected, then you should have two separate diagrams drawn, not put all the information onto one diagram.

So the next phase is to try and follow the edges between the nodes and partition the diagram into a number of smaller, independent diagrams. In the case of subsystems (which are not yet supported), the expectation would be to create a "duplicate" diagram where we copy across the requested nodes and edges, allowing a number of edges to be "dangling" with no nodes to attach them to.

(Note that dangling edges should not normally be allowed, but as yet we have not done any verification on our model: this also covers the fact that we shouldn't allow multiple nodes to have the same name.)

We are going to create a number (which may be 1) of diagrams based on the information in the original parsed diagram in the partitionInto method in DiagramModel. Each one will be given a name so that we can identify them, and this name will be the name of the (alphabetically) first node in the diagram. I am hoping this will be (relatively) tolerant to change when we go through the relayout-redraw cycle so that the visual display is relatively static.

The process by which we are going to do this is really very simple. We add a node to a diagram, keeping track of the nodes we've added as we go. We then find all the edges that connect to that node, and ask them for all the nodes they want to connect to. We then add all those nodes in turn, repeating the process until no more nodes turn up. We then move on to the next diagram, starting with the first unused node, until there are no more unused nodes. At that point, we are done.
  partitionInto(c) {
    // Collect together all the node names in order, and create a map back to the actual nodes
    var unseen = [];
    var map = {};
    for (var i=0;i<this.nodes.length;i++) {
      var n = this.nodes[i];
      unseen.push(n.name);
      map[n.name] = n;
    }

No comments:

Post a Comment