All Projects → chenjiandongx → pytreemap

chenjiandongx / pytreemap

Licence: MIT license
🌲 树图渲染命令行工具

Programming Languages

python
139335 projects - #7 most used programming language

Labels

Projects that are alternatives of or similar to pytreemap

postsack
Visually cluster your emails by sender, domain, and more to identify waste
Stars: ✭ 288 (+1152.17%)
Mutual labels:  treemap
php-sorted-collections
Sorted Collections for PHP
Stars: ✭ 22 (-4.35%)
Mutual labels:  treemap
Webpack Bundle Analyzer
Webpack plugin and CLI utility that represents bundle content as convenient interactive zoomable treemap
Stars: ✭ 11,472 (+49778.26%)
Mutual labels:  treemap
Source Map Explorer
Analyze and debug space usage through source maps
Stars: ✭ 3,396 (+14665.22%)
Mutual labels:  treemap
grafana-treemap-panel
A panel plugin for Grafana to visualize treemaps.
Stars: ✭ 18 (-21.74%)
Mutual labels:  treemap
treemap-chart
A treemap interactive chart web component for visualizing hierarchical data
Stars: ✭ 27 (+17.39%)
Mutual labels:  treemap
flextreemap
TreeMap data visualization component for Adobe Flex
Stars: ✭ 22 (-4.35%)
Mutual labels:  treemap
android-treemap
Treemap visualizations for Android
Stars: ✭ 32 (+39.13%)
Mutual labels:  treemap
d3-gridding
grids for rapid D3 charts mockups
Stars: ✭ 100 (+334.78%)
Mutual labels:  treemap

树图渲染命令行工具 PyPI version License: MIT

pytreemap 封装了 antvis/g6,利用 JSON 数据生成 HTML 格式的树图

安装

pip 安装

$ pip install pytm-cli

源码安装

 $ git clone https://github.com/chenjiandongx/pytreemap.git
 $ cd pytreemap
 $ pip install -r requirements.txt
 $ python setup.py install

使用

命令行参数

C:\Users\chenjiandongx>pytm-cli
uusage: pytm-cli [-i INPUT] [-o OUTPUT] [-d DIRECTION] [-t TYPE]
                    [-I INDENT] [-v] [-h]

树图渲染命令行工具-利用 JSON 数据生成 HTML 格式的树图

optional arguments:
  -i INPUT, --input INPUT
                        JSON 数据路径.
  -o OUTPUT, --output OUTPUT
                        输出 HTML 文件路径.(默认为`.\TreeMap.html`)
  -d DIRECTION, --direction DIRECTION
                        树图的布局方向, 有 LR/RL/H/TB/BT/V 可选.(默认为 LR)
  -t TYPE, --type TYPE  树图类型, 1.分层树 2.缩进树 3.生态树.(默认为 1)
  -I INDENT, --indent INDENT
                        缩进树的缩进量.(默认为 40)
  -v, --version         版本信息
  -h, --help            帮助页面

JSON 数据

首先假设你有一份数据需要生产树图,大概长这样

     |----B     |----E----|----I
     |          |
     |----C-----|----F         |----J
A----|                         |
     |----D-----|----G----|----|----K
                |
                |----H

这时候思路就很清晰了,你需要来编写成 JSON 数据了,节点都是以 {name, children} 为基础的递归嵌套模式,如下

{
    "children": [
        {
            "children": [],
            "name": "B"
        },
        {
            "children": [
                {
                    "children": [
                        {
                            "children": [],
                            "name": "I"
                        }
                    ],
                    "name": "E"
                },
                {
                    "children": [],
                    "name": "F"
                }
            ],
            "name": "C"
        },
        {
            "children": [
                {
                    "children": [
                        {
                            "children": [],
                            "name": "J"
                        },
                        {
                            "children": [],
                            "name": "K"
                        }
                    ],
                    "name": "G"
                },
                {
                    "children": [],
                    "name": "H"
                }
            ],
            "name": "D"
        }
    ],
    "name": "A"
}

怎么样,结构很清晰吧,将文件保存为 json 格式,如 data.json

生成树图

接下来之执行 pytm-cli -i data.json -o demo.html,然后用浏览器打开根目录下的 demo.html 文件,就可以看到已经生产了这样的一张图了

当指定 -t/--type 参数分别为 2 3 时,得到的图是这样的

type 为 2

type 为 3

其余参数尝试一下就知道效果了,这里提供官网提供的 数据 生产的效果

pytm-cli -i data.json

pytm-cli -i data.json -d H

pytm-cli -i data.json -t 3

pytm-cli -i data.json -t 2 -I 100

以模块方式使用

from pytreemap import render

render(input,
       output="TreeMap.html",
       direction="LR",
       indent=40,
       type=None):

:param input: 输入 json 文件路径
:param direction: 树图方向,有 LR/RL/H/TB/BT/V 可选
:param output: 输出 html 文件路径
:param indent: 缩进树缩进量
:param type: 树图类型

MIT 许可证

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].