Matrix-like layout

I’m trying to do a layout that looks basically like this: https://bit.ly/3EUZmfz

The idea is that there should be two rows, where each element in the upper row corresponds to an element in the lower row (with a “hole” in the sequence where one element from the top row isn’t paired).

In order to get things to line up properly, I thought of:

  • having the pairs in a cluster
  • representing the hole with an invisible node
  • creating potentially invisible arrows between each node in the same row

This works out ok, except for the part where I need one arrow from the bottom row to the top row. This takes a decidely roundabout way, in order to avoid overlapping with the invisible node.

Is there a cleaner, more satisfying way of achieving what I’m trying to do? Here’s the DOT for reference:

digraph {
    rankdir=LR
    color=transparent

    Start
    Goal

    subgraph cluster_product {
        FA

    }

    subgraph cluster_uuid {
        FB
        B
    }

    subgraph cluster_lifted_seller {
        FC
        C[style="invis"]
    }

    subgraph cluster_seller {
        FD
        D
    }


    Start -> FA

    A -> B
    B -> C[style="invis"]
    B -> FD
    C -> D[style="invis"]

    FA -> FB
    FB -> FC
    FC -> FD
    FD -> Goal
}

Instead of clusters, this uses rank and the group attributes to align nodes.

  • rank=same always (or almost always?) keeps nodes aligned.
  • group=xyz usually keeps nodes aligned.
  • other changes are just cosmetic.
digraph {
    rankdir=LR
    color=transparent
    node [group="upper"]  // try to keep same Y value
    Start FA FB FC FD  Goal
    node [group="lower"]  // try to keep same Y value
    A B D
    
    { rank=same  // keep same X value
        FA->A [style="invis"]
    }

    { rank=same // keep same X value
        FB->B[style="invis"]
    }

    { rank=same // keep same X value
        FD->D[style="invis"]
    }

    Start -> FA -> FB -> FC -> FD -> Goal
    A -> B -> FD
}

That is brilliant, thank you very much!

What’s really needed is a simple layout machine that allows someone to specify how to put notes into a grid (with relative or absolute positions) and then edges are routed in that, in some way. It would be important to preserve grid alignment (and maybe uniformity) but allow enough space to route edges, possibly many edges, with labels, etc. Note that anything like that will be stress-tested by future generations, but it sounds like a good senior independent project for somebody.