Launch Week Day 5: Introducing Reachability for PHP.Learn More
Socket
Book a DemoSign in
Socket

@antv/hierarchy

Package Overview
Dependencies
Maintainers
72
Versions
44
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@antv/hierarchy

layout algorithms for visualizing hierarchical data

latest
Source
npmnpm
Version
0.7.1
Version published
Weekly downloads
222K
2.96%
Maintainers
72
Weekly downloads
 
Created
Source

@antv/hierarchy

Layout algorithms for visualizing hierarchical data.

Build Status npm Version npm Download npm License

Features

TypeScript Support: Fully typed with TypeScript for better IDE support and type safety

🚀 Modern Build System: Built with Vite for faster builds and smaller bundle sizes

📦 Multiple Formats: Supports both ES modules and UMD formats

🎯 Tree-shakeable: ES module format allows for efficient tree-shaking

Installation

npm install @antv/hierarchy

Usage

import { compactBox } from '@antv/hierarchy';
// or
import * as Hierarchy from '@antv/hierarchy';

CommonJS

const Hierarchy = require('@antv/hierarchy');

TypeScript

This library includes TypeScript definitions. You'll get full IntelliSense support:

import { compactBox, type HierarchyNode, type CompactBoxOptions } from '@antv/hierarchy';

const options: CompactBoxOptions = {
  direction: 'LR',
  getId: (d) => d.id,
  getWidth: (d) => 100,
  getHeight: (d) => 50
};

API

example

import { compactBox } from '@antv/hierarchy';
// or for CommonJS
// const { compactBox } = require('@antv/hierarchy');

// your tree data
const root = {
  isRoot: true,
  id: 'Root',
  children: [
    {
      id: 'SubTreeNode1',
      children: [
        {
          id: 'SubTreeNode1.1'
        },
        {
          id: 'SubTreeNode1.2'
        }
      ]
    },
    {
      id: 'SubTreeNode2'
    }
  ]
};

// apply layout
const NODE_SIZE = 16;
const PEM = 5;
const ctx = document.getElementById('id-of-canvas-element').getContext('2d');
const rootNode = compactBox(root, {
  direction: 'H', // H / V / LR / RL / TB / BT
  getId(d) {
    return d.id;
  },
  getHeight(d) {
    if (d.isRoot) {
      return NODE_SIZE * 2;
    }
    return NODE_SIZE;
  },
  getWidth(d) {
    if (d.isRoot) {
      return ctx.measureText(d.id).width * 2 + PEM * 1.6;
    }
    return ctx.measureText(d.id).width + PEM * 1.6;
  },
  getHGap(d) {
    if (d.isRoot) {
      return PEM * 2;
    }
    return PEM;
  },
  getVGap(d) {
    if (d.isRoot) {
      return PEM * 2;
    }
    return PEM;
  },
  getSubTreeSep(d) {
    if (!d.children || !d.children.length) {
      return 0;
    }
    return PEM;
  }
});

layout types

Hierarchy[type]

compactBox

this layout differs from d3-hierarcy.tree, it is a compact box tidy layout that is tidy in both horizontal and vertical directions.

demos

LRRLH
LRRLH
TBBTV
TBBTV

dendrogram

demos

LRRLH
LRRLH
TBBTV
TBBTV

indented

demos

LRRLH
LRRLH

mindmap

this layout is inspired by XMind.

demos

mindmap

Keywords

antv

FAQs

Package last updated on 25 Dec 2025

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts