Skip to content

Commit da550a2

Browse files
committed
Update README with latest
1 parent c5ba8fe commit da550a2

File tree

1 file changed

+92
-48
lines changed

1 file changed

+92
-48
lines changed

README.md

Lines changed: 92 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,20 @@
11
# Termgraph
22

3-
A command-line tool that draws basic graphs in the terminal, written in Python.
3+
A command-line tool and Python library that draws basic graphs in the terminal.
44

55
Graph types supported:
6-
76
- Bar Graphs
8-
- Color charts
7+
- Color charts
98
- Multi-variable
109
- Stacked charts
1110
- Histograms
1211
- Horizontal or Vertical
12+
- Calendar heatmaps
1313
- Emoji!
1414

15+
## Quick Start
1516

16-
### Examples
17+
### Command Line Usage
1718

1819
```
1920
termgraph data/ex1.dat
@@ -29,6 +30,56 @@ termgraph data/ex1.dat
2930
2014: ▏ 1.00
3031
```
3132

33+
### Python Module Usage
34+
35+
```python
36+
from termgraph import Data, Args, BarChart
37+
38+
# Create data
39+
data = Data([[10], [25], [50], [40]], ["Q1", "Q2", "Q3", "Q4"])
40+
41+
# Configure chart options
42+
args = Args(
43+
title="Quarterly Sales",
44+
width=50,
45+
format="{:.0f}",
46+
suffix="K"
47+
)
48+
49+
# Create and display chart
50+
chart = BarChart(data, args)
51+
chart.draw()
52+
```
53+
54+
Output:
55+
```
56+
# Quarterly Sales
57+
58+
Q1: ▇▇▇▇▇▇▇▇▇▇ 10K
59+
Q2: ▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇ 25K
60+
Q3: ▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇ 50K
61+
Q4: ▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇ 40K
62+
```
63+
64+
For stacked charts with categories:
65+
66+
```python
67+
from termgraph import Data, Args, StackedChart
68+
69+
# Multi-category data: [Desktop, Mobile] for each quarter
70+
data = Data([[20, 15], [25, 30], [35, 40], [30, 35]],
71+
["Q1", "Q2", "Q3", "Q4"],
72+
categories=["Desktop", "Mobile"])
73+
74+
args = Args(title="Sales by Platform", width=50, suffix="K")
75+
chart = StackedChart(data, args)
76+
chart.draw()
77+
```
78+
79+
## More Examples
80+
81+
### Custom Tick Marks
82+
3283
An example using emoji as custom tick:
3384

3485
```
@@ -59,6 +110,8 @@ echo "Label,3,9,1" | termgraph --custom-tick "😀" --no-label
59110
60111
```
61112

113+
### Color Charts
114+
62115
Most results can be copied and pasted wherever you like, since they use standard block characters. However the color charts will not show, since they use terminal escape codes for color. A couple images to show color examples:
63116

64117
```
@@ -73,6 +126,7 @@ termgraph data/ex7.dat --color {yellow,magenta} --stacked --title "Stacked Data"
73126

74127
<img src="https://user-images.githubusercontent.com/45363/43405624-1a4a821c-93cf-11e8-84f3-f45c65b7ca98.png" width="686" alt="Multi variable stacked bar chart with colors" />
75128

129+
### Calendar Heatmap
76130

77131
Calendar Heatmap, expects first column to be date in yyyy-mm-dd
78132

@@ -84,17 +138,7 @@ termgraph --calendar --start-dt 2017-07-01 data/cal.dat
84138

85139

86140

87-
### Install
88-
89-
Requires Python 3.9+, install from [PyPI project](https://pypi.org/project/termgraph/)
90-
91-
```
92-
python3 -m pip install termgraph
93-
```
94-
95-
Note: Be sure your PATH includes the pypi install directory, for me it is `~/.local/bin/`
96-
97-
### Usage
141+
## Usage
98142

99143
#### Command Line Interface
100144

@@ -105,38 +149,7 @@ Note: Be sure your PATH includes the pypi install directory, for me it is `~/.lo
105149

106150
* Help: termgraph -h
107151

108-
#### Programmatic API
109-
110-
Termgraph can also be used as a Python library for creating charts programmatically:
111-
112-
```python
113-
from termgraph import Data, Args, BarChart
114-
115-
# Create data
116-
data = Data([[10], [25], [50], [40]], ["Q1", "Q2", "Q3", "Q4"])
117-
118-
# Configure chart options
119-
args = Args(
120-
title="Quarterly Sales",
121-
width=50,
122-
format="{:.0f}",
123-
suffix="K"
124-
)
125-
126-
# Create and display chart
127-
chart = BarChart(data, args)
128-
chart.draw()
129-
```
130-
131-
This produces:
132-
```
133-
# Quarterly Sales
134-
135-
Q1: ▇▇▇▇▇▇▇▇▇▇ 10K
136-
Q2: ▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇ 25K
137-
Q3: ▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇ 50K
138-
Q4: ▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇ 40K
139-
```
152+
#### Command Line Arguments
140153

141154
```
142155
usage: termgraph [-h] [options] [filename]
@@ -173,8 +186,39 @@ options:
173186
--version Display version and exit
174187
```
175188

189+
### Python API
190+
191+
All chart types are available as classes:
192+
193+
```python
194+
from termgraph import (
195+
Data, Args,
196+
BarChart, StackedChart, VerticalChart, HistogramChart
197+
)
198+
199+
# Basic setup
200+
data = Data([[10], [20]], ["A", "B"])
201+
args = Args(title="My Chart")
202+
203+
# Choose your chart type
204+
chart = BarChart(data, args) # Horizontal bars
205+
# chart = StackedChart(data, args) # Stacked bars
206+
# chart = VerticalChart(data, args) # Vertical bars
207+
# chart = HistogramChart(data, args) # Histogram
208+
209+
chart.draw()
210+
```
211+
212+
Available Args options:
213+
- `title`: Chart title
214+
- `width`: Width in characters (default: 50)
215+
- `format`: Number format string (default: "{:<5.2f}")
216+
- `suffix`: Add suffix to all values
217+
- `no_labels`: Don't show labels
218+
- `no_values`: Don't show values
219+
- `colors`: List of color names
176220

177-
### Background
221+
## Background
178222

179223
I wanted a quick way to visualize data stored in a simple text file. I initially created some scripts in R that generated graphs but this was a two step process of creating the graph and then opening the generated graph.
180224

0 commit comments

Comments
 (0)