Coder Social home page Coder Social logo

term-piechart's Introduction

Term-Piechart

Tests codecov PyPI - Python Version

Displays pie charts in your terminal. This is a direct python rewrite of the Ruby Gem TTY-Pie. Maybe someone else would find this usefull as well. It requires no external dependencies and supports ASCII and HEX color codes as well as automatic generation of random colors.

Installation

python -m pip install term-piechart

Examples

from term_piechart import Pie

requests = [
    {"name": "GET", "value": 9983},
    {"name": "POST", "value": 7005},
    {"name": "DELETE", "value": 3323},
    {"name": "PUT", "value": 2794},
    {"name": "PATCH", "value": 1711},
]

pie = Pie(
    requests,
    radius=5,
    autocolor=True,
    autocolor_pastel_factor=0.7,
    legend={"line": 0, "format": "{label} {name:<8} {percent:>5.2f}% [{value}]"},
)

More in examples

Class Arguments:

  • data (default: []): A list of dicts with following elements representing the slices
    • name: Name of the element
    • value: Value of the element
    • fill (default: ): String to fill the slice with
    • color: Hexcode or ANSII Colorname
  • radius (default: 10): Amount of columns/rows as the radius to change size
  • autocolor (default: False): Can be enabled if there are no colors specified in the data dict
  • autocolor_pastel_factor (default: 0): Can be increased until 1
  • fill (default: ): Overwrite the fill symboll for every element
  • legend (default: True): Can be disabled via False or configured with a dict with those keys:
    • line (default: 1): Number of lines between legend elements
    • left (default: 4): Number of spaces between chart and left of legend
    • format (default: {label} {name} {percent:.2f}): Supports {value} as well
  • aspect_ratio (default: 2): Aspect ratio of the printed chart
  • top (default: None): Amount of rows from top of the visible terminal
  • left (default: None): Amount of columns from the left of the visible terminal

References

term-piechart is a direct python derivate of:

Developement

Tox

There's a minimal tox.ini with a requirement on pyenv and un-def/tox-pyenv-redux. Zsh users can use this as a reference.

curl https://pyenv.run | bash
echo 'export PYENV_ROOT="$HOME/.pyenv"' >> ~/.zshrc
echo '[[ -d $PYENV_ROOT/bin ]] && export PATH="$PYENV_ROOT/bin:$PATH"' >> ~/.zshrc
echo 'eval "$(pyenv init -)"' >> ~/.zshrc
. ~/.zshrc
pyenv install -s 3.12 3.11 3.10 3.9 3.8
tox

term-piechart's People

Contributors

va-h avatar valentin-ok avatar

Stargazers

 avatar

Watchers

 avatar

term-piechart's Issues

Piechart portions visually incorrect when under certain conditions

When data input to piechart not divisible to 100 (or certain data inputs), Piechart portions visually seems incorrect. For instance, in this example, while E < C, it seems larger on the chart.

from term_piechart import Pie

data=[
    {"name": "A", "value": 80},
    {"name": "C", "value": 60},
    {"name": "E", "value": 50},
    {"name": "B", "value": 20},
    {"name": "D", "value": 13}
]
print((Pie(data, radius=10, autocolor=True, fill="o")))

term_piechart_BUG

When data input is divisible to 100 , things works like normal

data=[
    {"name": "A", "value": 50},
    {"name": "B", "value": 25},
    {"name": "C", "value": 10},
    {"name": "D", "value": 9},
    {"name": "E", "value": 6}
]

print((Pie(data, radius=10, autocolor=True, fill="o")))

term_piechart_PASSED

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.