indented-tree.tsx


Overview

The indented-tree.tsx file implements a customizable, interactive indented tree visualization component using React and the AntV G6 graph visualization library. It provides a horizontally laid-out tree structure where nodes are visually indented according to their depth, and supports user interactions such as node collapse/expand, selection, and hover effects.

Key features include:

This file is intended for use in applications needing a visually clear, interactive tree visualization with collapsible nodes and smooth user experience.


Classes and Components

1. IndentedNode (extends BaseNode)

Custom node class representing a single node in the indented tree.

Properties

Key Methods

Usage Example

const node = new IndentedNode({
  id: 'node1',
  style: { color: '#5B8FF9', labelText: 'Node 1' },
});
node.render();

2. IndentedEdge (extends Polyline)

Custom edge class for edges in the indented tree.

Methods

Usage Example

Edges connecting nodes will be instances of IndentedEdge with smooth elbow curves.


3. CollapseExpandTree (extends BaseBehavior)

Behavior class managing collapse/expand interactions on tree nodes.

Constructor

Methods

Usage

Automatically registered as a graph behavior and used internally by the IndentedTree component.


4. IndentedTree (React Functional Component)

Main React component rendering the indented tree graph.

Props (IProps)

Prop

Type

Description

data

TreeData

Tree data structure to visualize.

show

boolean

Controls visibility of the tree container.

style

React.CSSProperties (optional)

Additional CSS styles for the container.

Internal Logic

Usage Example

<IndentedTree data={treeData} show={true} style={{ height: '600px' }} />

Important Implementation Details


System Interaction


Visual Diagram

classDiagram
    class IndentedNode {
        +childrenData
        +getKeyStyle(attributes)
        +drawKeyShape(attributes, container)
        +getLabelStyle(attributes)
        +drawIconArea(attributes, container)
        +forwardEvent(target, type, listener)
        +getCountStyle(attributes)
        +drawCountShape(attributes, container)
        +isShowCollapse(attributes)
        +getCollapseStyle(attributes)
        +drawCollapseShape(attributes, container)
        +getAddStyle(attributes)
        +render(attributes, container)
    }

    class IndentedEdge {
        +getControlPoints(attributes, sourcePoint, targetPoint)
    }

    class CollapseExpandTree {
        -status: string
        +constructor(context, options)
        +update(options)
        +bindEvents()
        +unbindEvents()
        +showIcon(event)
        +hideIcon(event)
        +setIcon(event, show)
        +onCollapseExpand(event)
    }

    class IndentedTree {
        +data: TreeData
        +show: boolean
        +style?: React.CSSProperties
        +assignIds(node, parentId, index)
        +render(data)
    }

    IndentedTree "1" *-- "1" CollapseExpandTree : uses
    IndentedTree "1" *-- "many" IndentedNode : renders
    IndentedTree "1" *-- "many" IndentedEdge : renders
    CollapseExpandTree "1" o-- IndentedNode : controls

Summary

The indented-tree.tsx file delivers a sophisticated React component for rendering and interacting with indented tree graphs. It leverages AntV G6's extensibility to define custom nodes and edges, handles user interactions for collapsing and expanding nodes, and integrates seamlessly into React applications with theming and error boundaries. This makes it a powerful and flexible tool for visualizing hierarchical data in a clear and user-friendly manner.