Skip to content

Commit 6d8b740

Browse files
committed
Added documentation for changes to graph api
1 parent c3d184f commit 6d8b740

1 file changed

Lines changed: 55 additions & 5 deletions

File tree

content/docs/aesh/graph.md

Lines changed: 55 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,12 @@ String output = Graph.render(root);
6161

6262
// Custom style
6363
String output = Graph.render(root, GraphStyle.ASCII);
64+
65+
// With max width (wraps wide layers)
66+
String output = Graph.render(root, 25);
67+
68+
// Custom style + max width
69+
String output = Graph.render(root, GraphStyle.ASCII, 25);
6470
```
6571

6672
## Builder API
@@ -75,6 +81,7 @@ String output = Graph.<Task>builder()
7581
.label(Task::getName)
7682
.children(Task::getDependencies)
7783
.style(GraphStyle.UNICODE)
84+
.maxWidth(40)
7885
.build()
7986
.render(rootTask);
8087
```
@@ -84,6 +91,7 @@ String output = Graph.<Task>builder()
8491
| `label(Function<T, String>)` | *required* | Extracts display text from each node |
8592
| `children(Function<T, List<T>>)` | *required* | Extracts children (null/empty = leaf) |
8693
| `style(GraphStyle)` | `UNICODE` | Visual style for connectors |
94+
| `maxWidth(int)` | `0` | Max output width (0 = no limit) |
8795

8896
Calling `build()` throws `IllegalStateException` if `label` or `children` are not set.
8997

@@ -188,6 +196,46 @@ C D E
188196

189197
Here D is shared between A and B — it appears once with edges from both parents. Each parent's edges are drawn on separate routing rows to avoid visual ambiguity.
190198

199+
## Width Limiting
200+
201+
When a node has many children, the graph can grow very wide. The `maxWidth` parameter constrains the output by wrapping wide layers onto multiple rows. Children that don't fit are moved to additional rows, with vertical connectors routing edges through the intermediate layers automatically.
202+
203+
```java
204+
GraphNode root = GraphNode.of("Pipeline")
205+
.child("Compile")
206+
.child("Test")
207+
.child("Lint")
208+
.child("Package")
209+
.child("Deploy")
210+
.child("Notify");
211+
212+
// Without maxWidth — all children on one wide row:
213+
Graph.render(root);
214+
```
215+
216+
```
217+
Pipeline
218+
┌───────┬─────┬────┴─┬────────┬───────┐
219+
Compile Test Lint Package Deploy Notify
220+
```
221+
222+
```java
223+
// With maxWidth=25 — children wrap to fit:
224+
Graph.render(root, 25);
225+
```
226+
227+
```
228+
Pipeline
229+
┌─────┬──┬─┴──┬───┬────┐
230+
Compile │ │ Test │ Lint
231+
┌───┘ │ │
232+
│ └─┐ │
233+
│ │ └┐
234+
Package Deploy Notify
235+
```
236+
237+
A `maxWidth` of `0` (the default) means no limit. The wrapping applies to the node label layers; routing lines between layers may extend slightly beyond `maxWidth` when connecting nodes across split rows.
238+
191239
## Using in Commands
192240

193241
Here is a complete command example that displays a build dependency graph:
@@ -266,11 +314,13 @@ Use `Tree` for simple hierarchies (file systems, org charts). Use `Graph` when n
266314

267315
### Graph (static)
268316

269-
| Method | Returns | Description |
270-
|---------------------------------|------------|------------------------------|
271-
| `render(GraphNode)` | `String` | Render with UNICODE style |
272-
| `render(GraphNode, GraphStyle)` | `String` | Render with specified style |
273-
| `builder()` | `Builder` | Create a generic builder |
317+
| Method | Returns | Description |
318+
|-------------------------------------------|------------|------------------------------------------|
319+
| `render(GraphNode)` | `String` | Render with UNICODE style |
320+
| `render(GraphNode, int)` | `String` | Render with UNICODE style + max width |
321+
| `render(GraphNode, GraphStyle)` | `String` | Render with specified style |
322+
| `render(GraphNode, GraphStyle, int)` | `String` | Render with specified style + max width |
323+
| `builder()` | `Builder` | Create a generic builder |
274324

275325
### GraphStyle
276326

0 commit comments

Comments
 (0)