Metadata-Version: 2.3
Name: renderdag
Version: 0.1.1
Summary: Render directed acyclic graphs (DAGs) as text, ported from sapling-renderdag
Keywords: dag,graph,visualization,git,terminal
Author: Samuel S. Watson
Author-email: Samuel S. Watson <samuel.s.watson@gmail.com>
License: MIT License
         
         Copyright (c) Meta Platforms, Inc. and affiliates.
         
         Permission is hereby granted, free of charge, to any person obtaining a copy
         of this software and associated documentation files (the "Software"), to deal
         in the Software without restriction, including without limitation the rights
         to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
         copies of the Software, and to permit persons to whom the Software is
         furnished to do so, subject to the following conditions:
         
         The above copyright notice and this permission notice shall be included in all
         copies or substantial portions of the Software.
         
         THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
         IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
         FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
         AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
         LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
         OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
         SOFTWARE.
Classifier: License :: OSI Approved :: MIT License
Classifier: Programming Language :: Python :: 3
Classifier: Programming Language :: Python :: 3.10
Classifier: Programming Language :: Python :: 3.11
Classifier: Programming Language :: Python :: 3.12
Classifier: Programming Language :: Python :: 3.13
Classifier: Topic :: Software Development :: Version Control :: Git
Classifier: Topic :: Software Development :: Libraries :: Python Modules
Requires-Python: >=3.10
Project-URL: Homepage, https://github.com/sswatson/renderdag
Project-URL: Repository, https://github.com/sswatson/renderdag
Project-URL: Issues, https://github.com/sswatson/renderdag/issues
Description-Content-Type: text/markdown

# renderdag

A Python port of Meta's [sapling-renderdag](https://github.com/facebook/sapling/tree/main/eden/scm/lib/renderdag) Rust library for rendering directed acyclic graphs (DAGs) as text.


## Renderers

**ASCII** — basic characters, compact:

```
o    E  merge commit
|\
o |  D
| |
| o  C  branch
|/
o  B
|
o  A
```

**ASCII Large** — wider spacing, easier to read:

```
o     E  merge commit
|\
| \
o  |  D
|  |
|  o  C  branch
| /
|/
o  B
|
o  A
```

**Box Drawing** — Unicode line-drawing characters:

```
o    E  merge commit
├─╮
o │  D
│ │
│ o  C  branch
├─╯
o  B
│
o  A
```

## Install

```
pip install renderdag
# or
uv add renderdag
```

## Usage

```python
from renderdag import Ancestor, GraphRowRenderer

renderer = GraphRowRenderer().output().build_box_drawing()

# Render rows top-down (most recent commit first)
print(renderer.next_row("C", [Ancestor.parent("B")], "o", "C  latest"))
print(renderer.next_row("B", [Ancestor.parent("A")], "o", "B"))
print(renderer.next_row("A", [], "o", "A  root"))
```

The API follows a row-at-a-time model: call `next_row()` for each node in topological order (heads first), passing the node identifier, its parents as `Ancestor` values, a glyph string, and a message. The renderer tracks column state and returns the formatted string for that row.

### Ancestor types

- `Ancestor.parent(node)` — direct parent (solid line)
- `Ancestor.ancestor(node)` — indirect ancestor (dotted line)
- `Ancestor.anonymous()` — unknown/missing parent (terminator `~`)

### Builder options

```python
# ASCII renderer
renderer = GraphRowRenderer().output().build_ascii()

# ASCII Large with taller rows
renderer = GraphRowRenderer().output().with_min_row_height(3).build_ascii_large()

# Box Drawing with square corners instead of curved
renderer = GraphRowRenderer().output().build_box_drawing().with_square_glyphs()

# Reserve a column for a node before it appears
renderer.reserve("some-node")
```

## Development

Requires [uv](https://docs.astral.sh/uv/) and [just](https://just.systems/).

```
just demo          # see example output from all renderers
just test          # run all tests
just test-fast     # skip Rust cross-validation
just test-xval     # run only Rust cross-validation
```

## License

MIT. This is a derivative work of [sapling-renderdag](https://github.com/facebook/sapling/tree/main/eden/scm/lib/renderdag) by Meta Platforms, Inc. See [LICENSE](LICENSE) for details.

*Note: this library was created using LLMs.*

