Skip to content

Commit 5308122

Browse files
authored
Update Documentation (#121)
* Update README with latest * Add SVGs to README * Allow named args and flattened data for lists - Enables using named arguements such as Data(labels=[], data=[]) - Support flat data, simple lists: Data(labels=['Q1', 'Q2'], data=[10, 20]) - Maintains backwards compatibility * Add API docs * Update main README with links to docs/
1 parent c5ba8fe commit 5308122

File tree

14 files changed

+2132
-112
lines changed

14 files changed

+2132
-112
lines changed

.gitignore

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,20 +3,21 @@
33
.DS_Store
44

55
# Python
6-
*.pyc
7-
venv/
86
.coverage
7+
dist/
98
htmlcov/
10-
uv.lock
11-
termgraph.egg-info/
9+
*.pyc
1210
.python-version
1311
.ropeproject/
12+
termgraph.egg-info/
13+
uv.lock
14+
venv/
1415

1516
# Editors
17+
.claude/
18+
CLAUDE.md
19+
.gemini/
1620
.vim/
1721
.vimrc
1822
.vscode/
19-
.claude/
20-
.gemini/
21-
CLAUDE.md
2223

README.md

Lines changed: 94 additions & 68 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,23 @@
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
87
- 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
```
19-
termgraph data/ex1.dat
20+
$ termgraph data/ex1.dat
2021
2122
# Reading data from data/ex1.dat
2223
@@ -29,6 +30,41 @@ 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+
## More Examples
65+
66+
### Custom Tick Marks
67+
3268
An example using emoji as custom tick:
3369

3470
```
@@ -46,55 +82,37 @@ termgraph data/ex1.dat --custom-tick "🏃" --width 20 --title "Running Data"
4682
4783
```
4884

85+
### Color Charts
4986

50-
An example using stdin and emoji:
51-
52-
```
53-
echo "Label,3,9,1" | termgraph --custom-tick "😀" --no-label
54-
55-
56-
😀😀😀 3.00
57-
😀😀😀😀😀😀😀😀😀 9.00
58-
😀 1.00
87+
Note: Color charts use ANSI escape codes, so may not be able to copy/paste from terminal into other uses.
5988

89+
```bash
90+
$ termgraph data/ex4.dat --color {cyan/yellow} --space-between
6091
```
6192

62-
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:
63-
64-
```
65-
termgraph data/ex4.dat --color {blue,red}
66-
```
93+
![Bar chart with multiple variables](/docs/assets/barchart-multivar.svg)
6794

68-
<img src="https://user-images.githubusercontent.com/45363/43405623-1a2cc4d4-93cf-11e8-8c96-b7134d8986a2.png" width="655" alt="Multi variable bar chart with colors" />
95+
---
6996

7097
```
71-
termgraph data/ex7.dat --color {yellow,magenta} --stacked --title "Stacked Data"
98+
termgraph data/ex7.dat --color {green,magenta} --stacked
7299
```
73100

74-
<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" />
101+
![Stacked Bar Chart](/docs/assets/barchart-stacked.svg)
75102

103+
### Calendar Heatmap
76104

77105
Calendar Heatmap, expects first column to be date in yyyy-mm-dd
78106

79107
```
80-
termgraph --calendar --start-dt 2017-07-01 data/cal.dat
108+
$ termgraph --calendar --start-dt 2017-07-01 data/cal.dat
81109
```
82110

83-
<img src="https://user-images.githubusercontent.com/45363/43405619-1a15998a-93cf-11e8-8a3f-abfd2f6104a5.png" width="596" alt="Calendar Heatmap" />
84-
85-
86-
87-
### Install
88-
89-
Requires Python 3.9+, install from [PyPI project](https://pypi.org/project/termgraph/)
111+
![Calendar Heatmap](/docs/assets/cal-heatmap.svg)
90112

91-
```
92-
python3 -m pip install termgraph
93-
```
94113

95-
Note: Be sure your PATH includes the pypi install directory, for me it is `~/.local/bin/`
96114

97-
### Usage
115+
## Usage
98116

99117
#### Command Line Interface
100118

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

106124
* Help: termgraph -h
107125

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-
```
126+
#### Command Line Arguments
140127

141128
```
142129
usage: termgraph [-h] [options] [filename]
@@ -173,8 +160,47 @@ options:
173160
--version Display version and exit
174161
```
175162

163+
### Python API
164+
165+
All chart types are available as classes:
166+
167+
```python
168+
from termgraph import (
169+
Data, Args,
170+
BarChart, StackedChart, VerticalChart, HistogramChart
171+
)
172+
173+
# Basic setup
174+
data = Data([[10], [20]], ["A", "B"])
175+
args = Args(title="My Chart")
176+
177+
# Choose your chart type
178+
chart = BarChart(data, args) # Horizontal bars
179+
# chart = StackedChart(data, args) # Stacked bars
180+
# chart = VerticalChart(data, args) # Vertical bars
181+
# chart = HistogramChart(data, args) # Histogram
182+
183+
chart.draw()
184+
```
185+
186+
**📚 [Complete Python API Documentation](docs/)**
187+
188+
For comprehensive examples, detailed API reference, and advanced usage patterns, see the complete documentation:
189+
- **[Getting Started Guide](docs/README.md)** - Examples and best practices
190+
- **[Data Class API](docs/data-class.md)** - Data preparation and validation
191+
- **[Chart Classes API](docs/chart-classes.md)** - All chart types with examples
192+
- **[Args Configuration](docs/args-class.md)** - Complete configuration options
193+
194+
Quick Args options:
195+
- `title`: Chart title
196+
- `width`: Width in characters (default: 50)
197+
- `format`: Number format string (default: "{:<5.2f}")
198+
- `suffix`: Add suffix to all values
199+
- `no_labels`: Don't show labels
200+
- `no_values`: Don't show values
201+
- `colors`: List of color names
176202

177-
### Background
203+
## Background
178204

179205
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.
180206

@@ -186,7 +212,7 @@ All contributions are welcome! For detailed information about the project struct
186212

187213
**Quick Start:**
188214
- 🐛 **Bug reports** and 🚀 **feature requests**: Use [GitHub Issues](https://github.com/mkaz/termgraph/issues)
189-
- 🔧 **Code contributions**: See our [development workflow](CONTRIBUTING.md#development-workflow)
215+
- 🔧 **Code contributions**: See our [development workflow](CONTRIBUTING.md#development-workflow)
190216
- 📚 **Documentation**: Help improve our guides and examples
191217

192218
**Code Quality:** We use `ruff` for linting and formatting, `mypy` for type checking, and maintain comprehensive test coverage.

0 commit comments

Comments
 (0)