$ show antvis/hierarchy
@antv/hierarchy is a TypeScript library providing layout algorithms for visualizing hierarchical data. It implements four primary layout types: compact box, dendrogram, indented, and mindmap layouts. The library takes tree-structured data as input and returns positioned nodes with x/y coordinates for rendering. Built with a modular architecture, it separates core tree construction from layout algorithms and directional handling, enabling clean extension and customization. The package is published as an ES module with UMD fallback and includes comprehensive type definitions.
The LLM identified 3 files worth highlighting for reuse:
Handles logical direction mapping (LR, RL, TB, BT, H, V) to actual layout transformations. Isolates the complexity of flipping, splitting, and combining layouts based on direction. Demonstrates clean separation of concerns by decoupling directional logic from core layout algorithms. An engineer could extract this module by replacing the separateTree import and adapting the HierarchyNode/HierarchyOptions interfaces to their tree structure.
Splits a tree hierarchy into left and right subtrees for horizontal/vertical layouts that require bifurcated processing. Implements a clean, focused algorithm with configurable side assignment. Shows strong encapsulation of a common tree operation. To reuse, one would need to provide a hierarchy function matching the expected signature (data, options, isolated) => HierarchyNode, which is a standard tree-building pattern.
Provides the core Node class and hierarchy-building functionality that all layout algorithms depend on. Includes useful methods for tree traversal (DFTraverse, BFTraverse), bounding box calculation, and geometric transformations (translate, right2left, bottom2top). The Node class implements standard tree node behavior with layout-specific enhancements like gap handling. Extractable by adapting the HierarchyData/HierarchyOptions interfaces and the assign utility, yielding a reusable tree construction library with rich node APIs.