You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
|`label(Function<T, String>)`|*required*| Extracts display text from each node |
85
92
|`children(Function<T, List<T>>)`|*required*| Extracts children (null/empty = leaf) |
86
93
|`style(GraphStyle)`|`UNICODE`| Visual style for connectors |
94
+
|`maxWidth(int)`|`0`| Max output width (0 = no limit) |
87
95
88
96
Calling `build()` throws `IllegalStateException` if `label` or `children` are not set.
89
97
@@ -188,6 +196,46 @@ C D E
188
196
189
197
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.
190
198
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
+
191
239
## Using in Commands
192
240
193
241
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
0 commit comments