A Graph Description Language with Spatial Semantics

Tags: Diagram, Graphs, Semantics, Spatial, Tools, Visualization

Posted on 03 December 2026.

If you use graph description languages like DOT and Mermaid, you already know what makes them useful. You write down the nodes and edges and get a diagram you can embed in your docs. The source is easy to read, and (unlike raw images) updates are easy to track in version control. In short, you describe what the graph contains, and the language spares you from figuring out how to draw it (e.g., computing node coordinates, routing edges, and placing labels).

Layout, however, often constitutes an important part of what the author is trying to communicate via their diagram. The figure below shows the Mermaid source for the expression (6 ÷ 2) × 3 and the tree it produces.

flowchart TD
  mul -->|lhs| div
  mul -->|rhs| 3
  div -->|rhs| 2
  div -->|lhs| 6

Did you catch it?

If you go by where the operands are drawn, you’d be forgiven for reading this as (2 ÷ 6) × 3 instead of the actual (6 ÷ 2) × 3. At the division node, the lhs operand (6) is drawn on the right and the rhs operand (2) on the left. This kind of conflict between the labels and the layout makes the tree easy to misread. Ceding control over layout, therefore, also cedes control over the actual diagram semantics.

GDL authors have been asking for this kind of control for years (e.g., mermaid#815, mermaid#6438, graphviz#1569). In the meantime, they’ve built up a whole cottage industry of hacks for steering layout in GDLs. Some, like adding invisible edges, setting ranks, or using subgraphs, have made their way into official documentation. Others circulate as folk knowledge.

Here’s how we could use invisible edges to get the lhs to show up on the left and rhs to the right.
flowchart TD
  mul -->|lhs| div
  mul -->|rhs| 3
  div -->|rhs| 2
  div -->|lhs| 6

  %% Invisible links to influence layout
  div ~~~ 6
  3 ~~~ 2

This undermines the central abstraction of a graph description language. We’ve polluted the expression tree with bogus edges just to control where Mermaid draws the nodes. If we add another node to the tree, we may have to figure out a new set of invisible links. We’re stuck gaming the layout engine’s heuristics just to keep left operands on the left.

If where things go is part of what a diagram says, it should be a first-class construct in a graph description language, with well-defined semantics and guarantees. That’s why we built Spytial-GDL, a language that combines traditional graph description syntax with the lightweight, cognitively informed spatial requirements of the Spytial language.

Here’s the same expression tree in Spytial-GDL with three layout requirements. Each operator’s left and right subtrees stay below it, on their respective sides. Nodes at the same depth share a row.

mul -->|lhs| div
mul -->|rhs| 3
div -->|rhs| 2
div -->|lhs| 6

@orientation(selector='lhs.*(lhs + rhs)', directions=[left, below])
@orientation(selector='rhs.*(lhs + rhs)', directions=[right, below])
@align(selector='{x, y: univ | #x.^~_links = #y.^~_links}', direction=horizontal)

%% Uncomment the lines below to add to the expression
%% add -->|lhs| mul
%% add -->|rhs| 10

This graph is live! Try dragging 2 to the left of div. You can’t! If you drag 2 upwards or downwards, 6 moves to stay aligned with it. Spytial-GDL enforces the requirements even while you interact with the diagram. We find this particularly useful for exploration. In a more crowded diagram, readers can move things apart to follow an edge while the spatial relationships you specified still hold.

You don’t have to rewrite requirements as you grow your graph. Add more nodes to the tree by uncommenting the last two lines and clicking Update diagram. The orientation requirements on lhs and rhs apply to the new graph elements as well!


Suppose we add an rhs edge from div back to mul. We’ve made a cycle in what’s supposed to be an expression tree. In a traditional GDL, lhs and rhs are just edge labels. The graph renderer draws both edges without flagging the cycle. In a larger diagram, you might never notice it.

When layout is part of the graph description, as in Spytial-GDL, the system can detect when the graph’s structure conflicts with author requirements. Here, we’ve required every operand to sit below its operator. With the new edge, div would have to sit below mul and mul below div. Spytial-GDL could tell you that in an error message. If there’s something unexpected about the shape of your graph, however, you want to look at it to understand why. So Spytial-GDL also draws a counterfactual diagram showing what the same graph would look like with the conflicting requirements relaxed. In the diagram below, you can see the cycle, with the offending node highlighted.

mul -->|lhs| div
mul -->|rhs| 3
div -->|rhs| 2
div -->|lhs| 6
div -->|rhs| mul

@orientation(selector='lhs.*(lhs + rhs)', directions=[left, below])
@orientation(selector='rhs.*(lhs + rhs)', directions=[right, below])
@align(selector='{x, y: univ | #x.^~_links = #y.^~_links}', direction=horizontal)

Spytial-GDL gets its spatial requirements from Spytial, a language we designed to turn program values into interactive diagrams. Each requirement defines a set of allowable arrangements in 2D space. Requirements compose predictably and are order-independent. See our PLDI paper for the semantics of these requirements, including a full mechanization in Lean.