Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 8 additions & 7 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,20 +3,21 @@
.DS_Store

# Python
*.pyc
venv/
.coverage
dist/
htmlcov/
uv.lock
termgraph.egg-info/
*.pyc
.python-version
.ropeproject/
termgraph.egg-info/
uv.lock
venv/

# Editors
.claude/
CLAUDE.md
.gemini/
.vim/
.vimrc
.vscode/
.claude/
.gemini/
CLAUDE.md

162 changes: 94 additions & 68 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,22 +1,23 @@
# Termgraph

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

Graph types supported:

- Bar Graphs
- Color charts
- Multi-variable
- Stacked charts
- Histograms
- Horizontal or Vertical
- Calendar heatmaps
- Emoji!

## Quick Start

### Examples
### Command Line Usage

```
termgraph data/ex1.dat
$ termgraph data/ex1.dat

# Reading data from data/ex1.dat

Expand All @@ -29,6 +30,41 @@ termgraph data/ex1.dat
2014: ▏ 1.00
```

### Python Module Usage

```python
from termgraph import Data, Args, BarChart

# Create data
data = Data([[10], [25], [50], [40]], ["Q1", "Q2", "Q3", "Q4"])

# Configure chart options
args = Args(
title="Quarterly Sales",
width=50,
format="{:.0f}",
suffix="K"
)

# Create and display chart
chart = BarChart(data, args)
chart.draw()
```

Output:
```
# Quarterly Sales

Q1: ▇▇▇▇▇▇▇▇▇▇ 10K
Q2: ▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇ 25K
Q3: ▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇ 50K
Q4: ▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇ 40K
```

## More Examples

### Custom Tick Marks

An example using emoji as custom tick:

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

```

### Color Charts

An example using stdin and emoji:

```
echo "Label,3,9,1" | termgraph --custom-tick "😀" --no-label


😀😀😀 3.00
😀😀😀😀😀😀😀😀😀 9.00
😀 1.00
Note: Color charts use ANSI escape codes, so may not be able to copy/paste from terminal into other uses.

```bash
$ termgraph data/ex4.dat --color {cyan/yellow} --space-between
```

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:

```
termgraph data/ex4.dat --color {blue,red}
```
![Bar chart with multiple variables](/docs/assets/barchart-multivar.svg)

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

```
termgraph data/ex7.dat --color {yellow,magenta} --stacked --title "Stacked Data"
termgraph data/ex7.dat --color {green,magenta} --stacked
```

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

### Calendar Heatmap

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

```
termgraph --calendar --start-dt 2017-07-01 data/cal.dat
$ termgraph --calendar --start-dt 2017-07-01 data/cal.dat
```

<img src="https://user-images.githubusercontent.com/45363/43405619-1a15998a-93cf-11e8-8a3f-abfd2f6104a5.png" width="596" alt="Calendar Heatmap" />



### Install

Requires Python 3.9+, install from [PyPI project](https://pypi.org/project/termgraph/)
![Calendar Heatmap](/docs/assets/cal-heatmap.svg)

```
python3 -m pip install termgraph
```

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

### Usage
## Usage

#### Command Line Interface

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

* Help: termgraph -h

#### Programmatic API

Termgraph can also be used as a Python library for creating charts programmatically:

```python
from termgraph import Data, Args, BarChart

# Create data
data = Data([[10], [25], [50], [40]], ["Q1", "Q2", "Q3", "Q4"])

# Configure chart options
args = Args(
title="Quarterly Sales",
width=50,
format="{:.0f}",
suffix="K"
)

# Create and display chart
chart = BarChart(data, args)
chart.draw()
```

This produces:
```
# Quarterly Sales

Q1: ▇▇▇▇▇▇▇▇▇▇ 10K
Q2: ▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇ 25K
Q3: ▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇ 50K
Q4: ▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇ 40K
```
#### Command Line Arguments

```
usage: termgraph [-h] [options] [filename]
Expand Down Expand Up @@ -173,8 +160,47 @@ options:
--version Display version and exit
```

### Python API

All chart types are available as classes:

```python
from termgraph import (
Data, Args,
BarChart, StackedChart, VerticalChart, HistogramChart
)

# Basic setup
data = Data([[10], [20]], ["A", "B"])
args = Args(title="My Chart")

# Choose your chart type
chart = BarChart(data, args) # Horizontal bars
# chart = StackedChart(data, args) # Stacked bars
# chart = VerticalChart(data, args) # Vertical bars
# chart = HistogramChart(data, args) # Histogram

chart.draw()
```

**📚 [Complete Python API Documentation](docs/)**

For comprehensive examples, detailed API reference, and advanced usage patterns, see the complete documentation:
- **[Getting Started Guide](docs/README.md)** - Examples and best practices
- **[Data Class API](docs/data-class.md)** - Data preparation and validation
- **[Chart Classes API](docs/chart-classes.md)** - All chart types with examples
- **[Args Configuration](docs/args-class.md)** - Complete configuration options

Quick Args options:
- `title`: Chart title
- `width`: Width in characters (default: 50)
- `format`: Number format string (default: "{:<5.2f}")
- `suffix`: Add suffix to all values
- `no_labels`: Don't show labels
- `no_values`: Don't show values
- `colors`: List of color names

### Background
## Background

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.

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

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

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