Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Made Termgraph an API/Module and some new features #75

Merged
merged 11 commits into from
Jun 20, 2021

Conversation

AdityaTaggar05
Copy link
Contributor

@AdityaTaggar05 AdityaTaggar05 commented Jan 15, 2021

I have made termgraph an API/module to use in other scripts and would like it to be merged with the base repository.

I have kept the structure very simple and anyone can easily extend upon it and add other types of charts to the module. Some other features have also been added.

I have made some changes in termgraph.py itself and the API/module code can be found in module.py (I know I am really bad at naming things)

Issues Handled: #27, #39, #47

Features Added:

  • New param space-between that lets you print an extra space between two rows so that it looks cleaner
  • Human Readable Format for values as requested (Overwrite labels #43 (comment))

image

API/Module:

Colors

It houses all the colours that can be used in termgraph

Args

The Args class is basically the same thing as passing args through the command line. You can pass args as keyword arguments or use update_args on an Args instance. Args are directly passed into Chart.

Data

The Data class merges the data, labels and categories all in one. I wasn't able to add normal_data to it as well cause the normalize function required 'width' parameter for which we needed the access to the args but they are only accessible by Chart.
So the only resolution was passing the args to data as well which didn't seem like a good idea. So took the normalize function and put it in Chart class. You can also visualize the data by just printing it or by using the str() function on it. It also has a property called dims (I was inspired by NumPy for this) which may or may not be helpful but I added it for future use.

Chart

The Chart class takes in the data and the args. It is drawn by using the draw() method. It is an abstract-ish class and has nothing special in it except for the _normalize() method which is the same as before and _print_header() method which prints the title and category names.

Horizontal Chart

It is derived off of the Chart class and the main reason for deriving the new chart off of this is that it contains the print_row function. I did so because no other chart required access to the function except for the ones which are horizontal.

I was only able to implement Bar Chart due to time limitations and my exams approaching and some other reasons.
Below is the example code for usage (it can also be found in example.py)

from module import Data, BarChart, Args, Colors

data = Data(data=[[765, 787], [781, 769]], labels=["6th G", "7th G"], categories=["Boys", "Girls"])
chart = BarChart(data, Args(title="Total Marks Per Class", colors=[Colors.Red, Colors.Magenta], space_between=True))

chart.draw()

image

@alexge233
Copy link

Has this been merged? I'm very keen to use it as an imort module!

@mkaz mkaz merged commit 09e17cc into mkaz:main Jun 20, 2021
@mkaz
Copy link
Owner

mkaz commented Jun 20, 2021

Thanks @AdityaTaggar05 for the great contributions! 👍

mkaz added a commit that referenced this pull request Jun 20, 2021
@yuvadm yuvadm mentioned this pull request Jul 23, 2021
@vergelli
Copy link

Any way to change the numbers to integers instead of float, it seems to be the default type.

@AdityaTaggar05 AdityaTaggar05 deleted the module branch November 23, 2021 03:49
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants