Tree Layout KMP
A Kotlin Multiplatform library for computing tidy tree layouts using the Walker/Buchheim algorithm in O(n) time. Includes transformation utilities for adapting coordinates to any rendering target, animation support for smooth transitions between layout states, and zero-dependency JSON serialization for caching or transmitting results.
Getting Started
Create a TreeAdapter for your tree structure, then pass it to WalkerTreeLayout:
val layout = WalkerTreeLayout(adapter, WalkerLayoutConfiguration(horizontalDistance = 2f))
val result = layout.layout()
val position = result.getPosition(myNode)Layout Algorithms
| Algorithm | Class | Use Case |
|---|---|---|
| Walker (Buchheim) | WalkerTreeLayout | Standard tidy tree layout |
| Radial Walker | RadialWalkerTreeLayout | Concentric ring layout |
| Direct Angular | DirectAngularPlacementLayout | Proportional angular partitioning |
Packages
Layout result types, transformation utilities, and bounding box helpers. TreeLayoutResult is a concrete class providing chainable coordinate transforms (mapped, centered, scaledTo, normalized, translated). LayoutTransition enables animated interpolation between two layout states. Extension functions toJson and fromJson provide zero-dependency JSON serialization.