Figure Suite

approvedunreviewed

by Joy Shen

Draw figures for algorithms, data structures and theoretical CS from short text: trees, graphs, automata, plots, Venn and sequence diagrams. Insert them as editable PNG or SVG.

↓ 18 downloadsUpdated 2d agoMIT

Figure Suite

Draw figures for algorithms, data structures and theoretical computer science from a few lines of text: arrays and DP tables, trees, graphs and automata, linked lists and hash tables, function plots, Venn diagrams, message sequences and timelines, in the clean style of textbooks such as Introduction to Algorithms (CLRS). Edit the text in a panel with a live preview, then insert the figure into your note as PNG or SVG. The source is stored inside the image, so you can reopen and change the figure at any time.

中文说明

Six figures drawn with Figure Suite: an array partition, a red-black tree, a shortest-path graph, an LCS table, a hash table with chaining, and an AVL tree

Six theory figures drawn with Figure Suite: an NFA, a Turing machine tape, a Hasse diagram, a parse tree, a Markov chain, and a CYK table

Six more figures: growth of functions, P/NP/coNP inside PSPACE, a TCP handshake, pointers from an array into a list, a shaded Venn region, and interval scheduling

Features

  • Ten building blocks cover most figures in algorithms, data structures, automata and formal languages, complexity, logic, discrete math, networking and operating systems: array, table, tree, graph, list / chains, plot, sets, seq, timeline, plus panels, arrows and text to combine them.
  • Arrows between blocks. link P[2] -> L[1] points from an array cell to a list node, a table cell to a frame, a B-tree leaf to the next.
  • Automatic layout. Trees use a tidy layout, and graphs can be layered, force-directed, circular, in a grid or in a row. You can also place nodes yourself, or drag them in the preview and the coordinates are written back to the source.
  • TeX-quality labels: x_1, n^2, \frac{n}{2}, \alpha, \le, \vdash, \subseteq, \oplus, \hat{x}, NIL in small caps, all in Computer Modern. The fonts are built into the plugin, so the preview, PNG and SVG look the same on every machine.
  • Export to a PNG at 1–4× resolution or an SVG, to the clipboard, or straight into the note. Inserted links carry the 1× width, so high-resolution images keep their size.
  • Re-editable. Hover over a figure in a note and click the pencil icon to reopen it. Update overwrites the file in place and keeps the links working.
  • Helpful editor.
    • 40 starter templates and a searchable built-in syntax reference (English and 中文) whose examples you can insert with one click.
    • Errors and warnings point at the line, including typos, out-of-range indices and unknown commands.

Getting started

  1. Run Figure Suite: New figure from the command palette or the ribbon, or right-click in the editor and choose Insert figure….

  2. Pick a template (the first toolbar button), or type a figure:

    tree
      6 right=0
        2 right=0
          1
          3
        9 right=+1
          _
          10
    
  3. Press Insert (or Mod+Enter). The figure is saved to your attachment folder and embedded at the cursor.

  4. To change it later, hover over the image and click the pencil icon. You can also right-click the link and choose Edit figure, or run Edit figure at cursor.

Open Syntax help (the ? button in the panel) for the full reference with examples.

What you can draw

BlockFor
arrayarrays, stacks and queues, sorting steps (pointers, braces, shaded ranges, arcs), counting sort, string matching, Turing machine tapes
tableDP tables with arrows (LCS, CYK), matrices, adjacency matrices, truth tables, transition tables, binary counters, radix sort
treeBSTs, heaps, AVL and red-black trees (NIL sentinels), B-trees, rotations (subtree triangles), recursion trees, Huffman trees, disjoint-set forests, parse trees, game trees, tries
graphdirected, undirected and weighted graphs, BFS/DFS states, shortest paths, MSTs, flow networks, SCCs, DAGs, bipartite matchings, finite automata (DFA, NFA), Markov chains, Hasse diagrams, reduction gadgets, point sets
list, chainssingly and doubly linked lists; hash tables with chaining, adjacency lists, buckets
plotgrowth of functions, asymptotic bounds (n₀), amortised cost bars, points
setsVenn diagrams with shaded regions and elements, nested sets, complexity-class pictures
seqprotocol message sequences (TCP, two-phase commit), space-time diagrams (Lamport clocks)
timelineinterval scheduling, activity selection, deadlines, Gantt charts (CPU scheduling)
linkarrows from part of one block to part of another: pointers, page tables, B+-tree leaves
panel, arrow, text(a) (b) (c) panels, labelled arrows between them, text

By course, that covers the usual figures of data structures and algorithms, automata and formal languages, computability and complexity (machines, reductions), discrete math (relations, posets, sets, graphs), probability (Markov chains), networking (protocols), distributed systems (space-time diagrams) and operating systems (scheduling, page tables).

Syntax at a glance

A figure is a list of blocks. A block header starts at the left margin; its body is indented. Lines like shade: … inside a body are directives. // starts a comment.

figure cols=2                    // optional: options for the whole figure
panel (a) before                 // a captioned panel
array A
  5 2 4 6 1 3
  shade: 2 black                 // colour cells
  arc: 2 -> 1 below
arrow "insert"                   // arrow to the next panel
panel (b) after
array A
  2 5 4 6 1 3
  • Labels are TeX math: x_1, a_{i,j}, v1 (shown as v₁), \infty, \lceil n/2 \rceil, \frac{a}{b}, \Gamma \vdash \phi, A \subseteq B, \hat{q}. Quote a label with spaces: "n - 1".
  • Colours: 5@red colours one cell or node. shade: 2..4 gray colours several. Names: white light shade gray dark black red pink blue lightblue green lightgreen yellow orange tan purple, or #hex.
  • array: ptr: i=2 j=5, span: 1..3 {\le x}, bar: 3, arc: 2 -> 1, index=below, start=0.
  • table: one line per row, plus cols:, rows:, shade: (1,2), arrow: (2,2) -> (1,1), brackets for matrices.
  • tree: indentation gives the children.
    • _ is an empty slot, nil a NIL sentinel, [G M P] a B-tree node, "α" tri a subtree triangle.
    • left= right= above= below= add notes next to a node; edge=, thick and dashed style the edge to the parent.
    • level: adds a note to a whole level.
  • graph: edges are written a -> b 10, a -- b or a <-> b.
    • Declare a node to set its label, position ((x,y)), shape or colour.
    • layout=auto|layered|force|circle|grid|line|manual; dir=up draws a layered layout bottom-up (Hasse diagrams).
    • group:, rank: and shade: work on nodes; bend=, loop= and swap shape edges.
  • list / chains: list L.head double with the keys in the body; chains T with a line like 1: k1 k4 for each slot.
  • plot: one expression per line, n \lg n, 2^n, \frac{n}{2} (label and style after it: n^2 "quadratic" dashed); x=1..8 y=0..64 xlabel=n; vline: 4 n_0, bars: 1 2 1 4, points: (1,2).
  • sets: one set per line; shade: A&B-C gray (& | -, ~A or A'); in: A-B 1 2 writes elements in a region; layout=venn|nested|manual with (x,y) rx= ry= for your own ellipses; universe.
  • seq: C -> S "SYN" delay=1 (slanted when it takes time), --> for a reply, lost, A -> A self message, A * "crash" event; dir=right for space-time diagrams.
  • timeline: a 0..3, a repeated name continues its row, d 9 "deadline" point event, mark: 5 t; gantt for a single row.
  • link: link A[2] -> B[1] "label" dashed bend=20; references are A[i], T[r,c], L[k], H[k,j], G.node, T[key] or a whole block; name a block by its header name or id=.

The in-app reference lists every option.

Settings

  • Default format (PNG or SVG) and PNG resolution
  • Background (white or transparent)
  • Font size
  • Fill colour for linked lists
  • File name prefix
  • Whether the source is stored in the image
  • Whether |width is added to inserted links
  • Language of the syntax reference

Notes

  • Desktop only. PNG export and the clipboard rely on desktop features.
  • No network access. Everything runs locally. The figure source is stored in the PNG (iTXt chunk) or SVG (<metadata>) it produces; turn off Embed source in images if you'd rather not keep it.
  • Characters missing from Computer Modern (for example CJK, and the letters of \mathbb and \mathcal) fall back to the system serif font. That font isn't embedded in SVG exports, so an SVG may look different on another machine; PNG is unaffected.
  • Automatic graph layouts are a starting point; for complex graphs, dragging a few nodes is the quickest fix.

Development

The plugin is plain JavaScript with no dependencies. build.py concatenates src/ into main.js, and tools/subset-fonts.js subsets the fonts into src/fontdata.js.

python3 build.py            # build main.js and styles.css
node tests/test-engine.js   # parser, labels, every template and help example, PNG/SVG round trips
FilePurpose
src/font.jsTrueType reader (cmap, hmtx, glyf)
src/mathtext.jsmini TeX typesetter
src/parse.jsfigure source parser and option checks
src/blocks.jsarray, table, list, chains, text, arrow
src/tree.jstidy tree layout
src/graph.jsgraph layouts, edges, loops, groups
src/links.jslink arrows between blocks
src/plot.jsexpression evaluator and plot
src/seq.js, src/timeline.js, src/sets.jsseq, timeline, sets
src/compose.jspanels and the final SVG
src/export.jsPNG rasterising, source embedding, clipboard
src/panel.jsthe editor panel
src/help.jsthe syntax reference
src/main.jscommands, menus, the edit button, settings

License

MIT, see LICENSE. The bundled CMU Serif fonts (Computer Modern by Donald E. Knuth, converted by Andrey V. Panov) are licensed under the SIL Open Font License 1.1, see fonts/OFL.txt.

For plugin developers

Search results and similarity scores are powered by semantic analysis of your plugin's README. If your plugin isn't appearing for searches you'd expect, try updating your README to clearly describe your plugin's purpose, features, and use cases.