GithubHelp home page GithubHelp logo

tsupei / treeviz Goto Github PK

View Code? Open in Web Editor NEW
10.0 2.0 0.0 16 KB

Lite python package for plotting tree stucture in bash manner

License: MIT License

Python 100.00%
tree-structure python plot visualization

treeviz's Introduction

treeviz

Visualize tree structure in bash manner using python

install

pip install treeviz

Structure

.
├── MANIFEST
├── MANIFEST.in
├── README.md
├── setup.py
├── test.py
└── treeviz
    ├── __init__.py
    └── treeviz.py

# showcases of usage
python test.py

Usage

Create Your tree structure

from treeviz.treeviz import Node
root = Node("Jason")
child1 = Node("Mary")
child2 = Node("John")
grandson1 = Node("Kevin")
grandson2 = Node("Doris")
grandson3 = Node("James")
grandson4 = Node("Momo")
grandgrandson1 = Node("Baby")

root.add_child(child1)
root.add_child(child2)
child1.add_child(grandson1)
child1.add_child(grandson2)
child2.add_child(grandson3)
child2.add_child(grandson4)
grandson1.add_child(grandgrandson1)
root.visualize()
Jason
├── Mary
│   ├── Kevin
│   │   └── Baby
│   └── Doris
└── John
    ├── James
    └── Momo

You can also print the sub-tree structure

child1.visualize()
Mary
├── Kevin
│   └── Baby
└── Doris

Two options are provided, to print in terminal or print to file

# print to file
# Giving path as the first parameter
root.visualize(".")

# If path is empty, then print to terminal
root.visualize()

# Default name is treeviz.txt, if the filename already exists, a number will be appended to it.

New Features

(2019.11.1) Adding max_len parameter to visualize(), which splits the message into multiple lines.

from treeviz.treeviz import Node
root = Node("Jason is our grandfather")
child1 = Node("Mary is Kevin's mother")
child2 = Node("John is James and Momo's father")
grandson1 = Node("Kevin")
grandson2 = Node("Doris")
grandson3 = Node("James")
grandson4 = Node("Momo")
grandgrandson1 = Node("Baby")

root.add_child(child1)
root.add_child(child2)
child1.add_child(grandson1)
child1.add_child(grandson2)
child2.add_child(grandson3)
child2.add_child(grandson4)
grandson1.add_child(grandgrandson1)
root.visualize(max_len=10)
Jason is our grandfather
├── Mary is Ke
│   vin's moth
│   er
│   ├── Kevin
│   │   └── Baby
│   └── Doris
└── John is Ja
    mes and Mo
    mo's fathe
    r
    ├── James
    └── Momo

(2019.11.2) Adding line_space parameter to visualize(), which enables to set space between each branch

root.visualize(line_space=2)
Jason is our grandfather
├── Mary is Kevin's mother
│   │
│   │
│   ├── Kevin
│   │   │
│   │   │
│   │   └── Baby
│   │
│   │
│   └── Doris


└── John is James and Momo's father
    │
    │
    ├── James
    │
    │
    └── Momo

(2019.11.4) Adding 'filename' parameter to visualize, which enables users to defince own filename

treeviz's People

Contributors

tsupei avatar

Stargazers

趙梓叡 avatar TonyLiu avatar  avatar Max Su avatar Ying-ru,Liu avatar Ilkut Kutlar avatar  avatar  avatar Chang, Yu-Cheng avatar  avatar

Watchers

James Cloos avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.