Skip to main content

Diagram it yourself, then adjust.

A diagram language where you draw the layout as text, then refine it with relations and styles.

Diagram tools make you choose early. Diagram languages such as Mermaid and Graphviz give you a few diagram types and lay them out for you; anything outside those types is out of reach, and the layout is the algorithm's, not yours. Drawing languages such as TikZ, or layout libraries such as Bluefish, can draw anything, but you describe the picture as coordinates or as nested layout components, far from what it looks like.

Diya starts from a simpler observation: most diagrams have a shape before they have a type. You can see where things go before you know whether it's a "flowchart" or a "tree". So in Diya you write that shape down first, as a grid of text, and adjust it until it's right. There are no diagram types, and every step draws a picture.

1. Sketch it​

A Diya file starts with the sketch: lines of text, one row each. Every token is a cell, its text is both what's drawn and how you refer to it, and column n is the n-th token of every row. This sketch alone is a diagram:

Mercury
A B C D

A . is an empty cell, and ^ and < make a token span the cell above or to its left, as in CSS's grid-template-areas. Here a spans the top row and c a two-by-two block:

a < < <
b c < d
e ^ ^ f

The sketch is a soft layout: it says what exists and roughly where. Everything after it adjusts.

2. Adjust it with relations​

Under --- relations, each line is a rule the picture must hold. stack spaces its targets (along the row, because they're written on one row), and box surrounds them:

Mercury
A B C D

--- relations
stack [A..D] {gap=50}
stack [Mercury A] {gap=30}
box#highlight [Mercury A] {padding=10}
box#planets [A..D] {padding=80}

Relations are hard: a relation that places a token takes that axis over from the sketch, and the first target keeps its place, so the others move around it. Writing the same axis twice is an error that names both lines, never a silent choice. arrow and line connect tokens and empty cells; an empty cell in an arrow is a waypoint, so the sketch is also where you route.

3. Style it with SVG​

Under --- styles, each line styles what its selector names: tokens by their text, rows and columns by position (@r2, @c1), relations by #id or .class. Shapes and attributes are a subset of SVG, with SVG's names, so MDN documents them:

Mercury
A B C D

--- relations
stack [A..D] {gap=50}
stack [Mercury A] {gap=30}
box#highlight [Mercury A] {padding=10}
box#planets [A..D] {padding=80}

--- styles
A: circle r=15 fill=#EBE3CF
B: circle r=36 fill=#DC933C
C: circle r=38 fill=#179DD7
D: circle r=21 fill=#F1CF8E
A..D: stroke=black stroke-width=3 ::text hidden
Mercury: font-weight=bold
#highlight: stroke=black stroke-width=3 rx=10
#planets: fill=#859fc9 stroke=none

That's the whole of Diya: sketch, relations, styles, and a --- config section for the few settings the whole diagram needs. This is Figure 2 of the Bluefish paper.

4. One language, many kinds​

Because nothing depends on a diagram type, the same three sections draw algorithm figures, program state, circuits, flowcharts, sequence diagrams and infographics. The sketch reads like the picture in each:

Alice . John
. "Hello John" .
. Great! .

--- relations
line.lifeline [@c1] [@c3] {extend=24}
arrow "Hello John"@c-1 "Hello John"@c+1
arrow.reply Great!@c+1 Great!@c-1

--- styles
Alice, John: rect fill=#ede9fe
.lifeline: stroke=gray stroke-dasharray=6 z-index=-1
.reply: stroke-dasharray=5

--- config
row-gap=24

Every example can be edited live on the Examples page.

To test Diya on diagrams it wasn't designed for, we drew all eight diagrams of Bluefish's gallery (UIST '24, Figure 8) with today's syntax and no changes to it. All eight are drawable. Three were already our examples (insertion sort, Python Tutor and the quantum circuit); these are the other five:

DiagramBluefish linesDiya lines
DFSCQ file system40153
Ohm parse tree29731
Baking recipe27219
Pulleys24437
Three-point topologies16623

Bluefish's counts include imports and helper components, and its Ohm component draws any expression, so the ratio overstates the difference. But the shape of it holds: Bluefish writes layout as nested components, and Diya draws it. Bluefish's first stated limitation, aligning widths and heights, comes free from the grid: the DFSCQ panels and the recipe's cells are equal because they share columns.

6. Limits​

We also drew diagrams we expected to fail. They mark where Diya stops:

  • No routing. Edges are straight or gently curved, and an edge in the way of a group crosses it; you route with waypoints by hand.
  • Not every diagram is a grid. Venn diagrams and concave regions are geometry, and the regions can't hold tokens.
  • One grid per diagram. Panels with their own structure share one set of columns and distort each other.
  • Scale needs automatic layout. A 41-node graph is expressible, but its hand layout is poor. A no-sketch mode that lays the graph out, then writes the sketch for you to adjust, is planned.
  • Text is plain. No rotation, sub- or superscripts, or math.
  • Connectors are young. In a tight fan of edges, a label can read as its neighbor's.

The stress tests show each of these with the diagram that found it.

Get started​

Edit any diagram on the Examples page, or read the docs to learn the language and use it from JavaScript.