Documentation from the repository README. View source
AlgiViz
Your algorithms and objects. Step-by-step playback and custom rendering.
A TypeScript toolkit for building interactive algorithm explanations. Write your algorithm as a generator, emit immutable states and choose how your objects look. AlgiViz handles playback and scene matching; optional array operations and a Canvas renderer help you get started.
Live sorting demo · Library overview · npm package · Getting started
- Your algorithm: control the loops, conditions and order of operations.
- Your objects: define custom types and handlers for Canvas, SVG or another target.
- Two playback modes: retain history for seeking, or consume a generator with adjacent snapshots by default, or a bounded window when rewind is enabled.
- No runtime dependencies: ESM and TypeScript declarations; playback works without DOM, React or Next.js.
Use it for educational demos, interactive articles and algorithm walkthroughs. Algorithms and layouts belong to your application; AlgiViz provides the playback and rendering API.
Version 1.10.0 adds nodeRadius to the graph and tree Canvas renderers.
Use drawEdge and edgeBend for dashed, curved failure links. Use drawNode
and per-frame doubleOutlineNodeIds to highlight trie terminals.
Graph Canvas reference ·
Tree Canvas reference ·
Release notes ·
Current API
Install
npm install @grundyjs/algivizThe package uses ESM subpath imports. There is no root entry point or CommonJS
build. Version 1.10.0 provides 16 entry points:
/player, /playback, /scene, /array, /canvas, /canvas/viewport,
/worker, /worker/runtime, /graph, /canvas/graph, /tree, /canvas/tree,
/grid, /canvas/grid, /list and /canvas/list.
Graph entries were introduced in 1.1.0, tree in 1.2.0, grid in 1.3.0 and list in 1.4.0. Algorithms live in application code and examples. Compatible features use minor releases under the 1.x compatibility policy; consult CHANGELOG.md when updating.
Quickstart: find a minimum on Canvas
The main quickstart uses stepSource/isTerminal and done({ result }), available
in 1.0.0. The guide installs exact npm version 1.0.0 into a separate app;
no repository checkout is required for this quickstart.
Copy one complete HTML file and the exact run commands. A one-pass minimum search compares [7,3,5,2,6]. Array operations capture snapshots, the standard renderer draws Canvas, and Player supplies Start/Next/Restart. The minimum stays green and the answer remains visible as “Minimum: 2”. The fixed nonempty example uses 28 nonblank JS lines; your algorithm stays application-owned.
Compare Player and one-button examples, or follow the progressive tutorial: plain states/pre → createArrayPlayer → standard Player → scenes/interpolation.
Modules and documentation
| Module | Purpose | First 1.x release |
|---|---|---|
/playback |
Steps, players, timelines, termination and lifecycle | 1.0.0 |
/scene |
Custom types, object matching and projection | 1.0.0 |
/array |
Immutable array operations, marks and results | 1.0.0 |
/canvas |
Ready-made array Canvas rendering and palettes. Custom item labels since 1.6.0 | 1.0.0 |
/canvas/viewport |
CSS Canvas sizing, DPR and cleanup | 1.0.0 |
/player |
Optional Player widget, media controls, recording/streams and on-demand loading | 1.0.0 |
/worker |
Dedicated browser Worker factory and transport errors | 1.0.0 |
/worker/runtime |
Worker-side endpoint; separate WebWorker types | 1.0.0 |
/graph |
Graph traces, marks, captions, results and scene projection. Dynamic edits since 1.5.0 | 1.1.0 |
/canvas/graph |
Arrows, topology transitions and edge labels. Configurable node radius, edge bends and drawing since 1.10.0 | 1.1.0 |
/tree |
Ordered/binary traces, atomic topology edits and scene projection | 1.2.0 |
/canvas/tree |
Explicit layout, binary slots and captions. Configurable radius, node drawing and double outlines since 1.10.0 | 1.2.0 |
/grid |
Dense grids, atomic operations, marks, result/path and scene | 1.3.0 |
/canvas/grid |
Regular cells, values/captions, green results and paths | 1.3.0 |
/list |
Singly linked lists with stable node and slot IDs, atomic edits and results | 1.4.0 |
/canvas/list |
Layout, animated pointers, head and null markers, captions and green results | 1.4.0 |
Dynamic graph API · Canvas transitions.
Headless entries need no DOM. Canvas/Player/viewport and the Worker host need their actual hosts and DOM types; the Worker endpoint uses WebWorker types. Import safety does not provide a drawing/mounting host. Environment boundary.
Complete TypeScript example · Getting started · Custom graph walkthrough
Sources and playback
Player accepts plain states through source, explicit steps through stepSource
and asynchronous states through asyncSource. Use history for a recording of
states or stepHistory for a recording that also carries step events.
Choose a source.
For streams, rewindCapacity enables backward navigation within a bounded window. maxStepsPerFrame caps next-state requests per frame while carrying remaining playback time; it does not bound the cost of an individual step or render.
createAsyncSource handles waiting, cancellation and cleanup. Async iteration alone does not move CPU work to another thread. The Worker adapter uses the same Player asyncSource option, with explicit ArrayBuffer transfer and observable completion through closed.
Examples
| Example | What it demonstrates |
|---|---|
| Your first Player | One-pass minimum search, standard Canvas renderer, Player controls and explicit result |
| How a frame is made | AlgiViz visualizes its own generator → player → scene → renderer pipeline (Russian walkthrough) |
| Sorting lab | Insertion and bubble sort using the array operations and renderer |
| Merge sort | Custom state and a two-row scene for the main array and buffer |
| Quick sort partitions | Lomuto and three-way partitioning with custom state and scene |
| Heap sort | Max-heap construction and extraction with synchronized tree and array identities |
| Heap sort with Player | The same sort on [2a, 2b, 1] with linked array and heap panels, rewind and Restart |
| Binary search | First occurrence in sorted input, closed search intervals and lazy playback |
| Detailed graph BFS | Custom scene with animated queue, vertex distances and path markers; standard Player |
| BFS with the stock graph renderer | The same algorithm with createGraphTrace, vertex distance captions, /canvas/graph and Player |
| BFS graph and queue | The graph and a linked-list FIFO queue animate together in one Player |
| Edge contraction | One edit removes a vertex and redirects two edges with stable IDs. Uses the dynamic graph API introduced in 1.5.0 |
| Kruskal’s minimum spanning tree | A weighted input graph and a growing forest advance together in one Player |
| Dijkstra’s shortest paths | One Player seeks through the weighted graph, distances and priority queue |
| Graph DFS | Recursive call frames, backtracking, tree depth and paths; history/generator playback |
| Maze | Randomized DFS generation, BFS wave, DFS backtracking, cycles and unreachable exits; history/generator playback |
| Grid BFS shortest path | Shortest path between obstacles with /grid, stock Canvas and Player; distances, green result, history and generator |
| Tree traversal | Custom nodes, edges and pointer with Canvas and retained SVG backends |
| Tree insertion and rotation | Fixed BST insertion, one right rotation, stock tree layout/Canvas and Player; green result and rewind |
| Linked list edits | Insert, remove and reverse a list with the stock Canvas renderer and Player |
| Boids flock | Seeded simulation, five obstacle layouts and one-bird inspection with neighbors and steering vectors |
| Falling sand | Seeded cell simulation, paintable obstacles, a hopper gate and exact one-grain inspection with conflict resolution |
Full catalog, local setup and algorithm details. Examples live in the repository and are not included in the npm package.
Development and license
Contributing · Changelog · Report an issue
Licensed under MIT.