项目作者: antvis

项目描述 :
Layout algorithms for visualizing hierarchical data.
高级语言: JavaScript
项目地址: git://github.com/antvis/hierarchy.git
创建时间: 2018-04-17T07:09:49Z
项目社区:https://github.com/antvis/hierarchy

开源协议:MIT License

下载



@antv/hierarchy

Layout algorithms for visualizing hierarchical data.

Build Status
@antv/hierarchy"">npm Version
@antv/hierarchy"">npm Download
@antv/hierarchy"">npm License

API

example

  1. const Hierarchy = require('@antv/hierarchy');
  2. // your tree data
  3. const root = {
  4. isRoot: true,
  5. id: 'Root',
  6. children: [
  7. {
  8. id: 'SubTreeNode1',
  9. children: [
  10. {
  11. id: 'SubTreeNode1.1'
  12. },
  13. {
  14. id: 'SubTreeNode1.2'
  15. }
  16. ]
  17. },
  18. {
  19. id: 'SubTreeNode2'
  20. }
  21. ]
  22. };
  23. // apply layout
  24. const NODE_SIZE = 16;
  25. const PEM = 5;
  26. const ctx = document.getElementById('id-of-canvas-element').getContext('2d');
  27. const rootNode = Hierarchy.compactBox(root, {
  28. direction: 'H', // H / V / LR / RL / TB / BT
  29. getId(d) {
  30. return d.id;
  31. },
  32. getHeight(d) {
  33. if (d.isRoot) {
  34. return NODE_SIZE * 2;
  35. }
  36. return NODE_SIZE;
  37. },
  38. getWidth(d) {
  39. if (d.isRoot) {
  40. return ctx.measureText(d.id).width * 2 + PEM * 1.6;
  41. }
  42. return ctx.measureText(d.id).width + PEM * 1.6;
  43. },
  44. getHGap(d) {
  45. if (d.isRoot) {
  46. return PEM * 2;
  47. }
  48. return PEM;
  49. },
  50. getVGap(d) {
  51. if (d.isRoot) {
  52. return PEM * 2;
  53. }
  54. return PEM;
  55. },
  56. getSubTreeSep(d) {
  57. if (!d.children || !d.children.length) {
  58. return 0;
  59. }
  60. return PEM;
  61. }
  62. });

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