You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
|
|
4 months ago | |
|---|---|---|
| .. | ||
| .github/workflows | 4 months ago | |
| assets | 4 months ago | |
| bin | 4 months ago | |
| build | 4 months ago | |
| dist | 4 months ago | |
| lib | 4 months ago | |
| src | 4 months ago | |
| .babelrc | 4 months ago | |
| .editorconfig | 4 months ago | |
| .eslintignore | 4 months ago | |
| .eslintrc | 4 months ago | |
| CHANGELOG.md | 4 months ago | |
| CONTRIBUTING.md | 4 months ago | |
| CONTRIBUTING.zh-CN.md | 4 months ago | |
| LICENSE | 4 months ago | |
| README.md | 4 months ago | |
| package.json | 4 months ago | |
README.md
@antv/hierarchy
Layout algorithms for visualizing hierarchical data.
API
example
const Hierarchy = 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 = Hierarchy.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 |
|---|---|---|
![]() |
![]() |
![]() |
| TB | BT | V |
|---|---|---|
![]() |
![]() |
![]() |
dendrogram
demos
| LR | RL | H |
|---|---|---|
![]() |
![]() |
![]() |
| TB | BT | V |
|---|---|---|
![]() |
![]() |
![]() |
indented
demos
| LR | RL | H |
|---|---|---|
![]() |
![]() |
![]() |
mindmap
this layout is inspired by XMind.
demos















