MIT License

项目介绍

antvis/hierarchy 是一个托管在 GitHub 上的开源项目,主要使用 TypeScript 编写,采用 MIT License 许可证,目前获得 304 个 Star、36 次 Fork。

仓库全名
antvis/hierarchy
开源许可证
MIT License
Star 数
304
Fork 数
36
未关闭 Issue
6

README 摘要

@antv/hierarchy Layout algorithms for visualizing hierarchical data. 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 Usage ES Module…

完整内容见 GitHub 原始 README 或本页 。

常见问题

hierarchy 用什么语言开发?

主要使用 TypeScript 编写,采用 MIT License 许可证,目前有 304 个 Star。

hierarchy 可以免费商用吗?

仓库采用 MIT License 许可证,可免费使用与修改,商业使用请遵守许可证条款(例如保留版权声明与许可声明)。

如何获取 hierarchy 的源码?

可以直接克隆仓库:git clone https://github.com/antvis/hierarchy.git,默认分支为 master;安装与运行步骤见仓库 README。

hierarchy 最近还在维护吗?

仓库最近一次更新为 1月9日,当前有 6 个未关闭 Issue;Star 数为 304,可作为社区活跃度的参考。

关于

Layout algorithms for visualizing hierarchical data.

描述取自 GitHub 官方 API,中文内容由 GitRead 中文社区 编辑团队整理。

简要分析

热度分
390
价值分
194
活跃状态
活跃

语言占比

JavaScript
TypeScript

Release

README

@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

LR RL H
LR RL H
TB BT V
TB BT V
dendrogram

demos

LR RL H
LR RL H
TB BT V
TB BT V
indented

demos

LR RL H
LR RL H
mindmap

this layout is inspired by XMind.

demos

mindmap

评论

暂无评论