rasciichart
Beautiful ASCII line charts in Rust with smooth rendering, inspired by asciichartpy.
Features
- 📊 Smooth line rendering with Unicode box-drawing characters
- 🎨 Highly customizable - height, width, colors, symbols, labels
- 🚀 Zero dependencies - lightweight and fast
- 💪 Type-safe - leverages Rust's type system
- 📝 Well documented - comprehensive examples and API docs
- 🔧 Helper functions - for common use cases
- 🎯 Production ready - proper error handling and edge cases
Demo
Installation
Add this to your Cargo.toml:
or
[]
= "0.2.9"
Quick Start
use plot;
Output:
Examples
Basic Usage
use plot;
let data = vec!;
println!;
Custom Size
use plot_sized;
let data = vec!;
println!; // height: 15, width: 60
Custom Range
use plot_range;
let data = vec!;
println!; // min: 0, max: 10
Without Labels
use plot_no_labels;
let data = vec!;
println!;
ASCII-only Characters
For better compatibility with terminals that don't support Unicode:
use plot_ascii;
let data = vec!;
println!;
Advanced Configuration
use ;
let data = vec!;
let config = new
.with_height
.with_width
.with_min
.with_max
.with_label_ticks
.with_label_format;
match plot_with_config
Generate Test Data
use ;
// Sine wave
let sine_data = generate_sine;
println!;
// Cosine wave
let cosine_data = generate_cosine;
println!;
Multiple Series (Overlaid)
use plot_multiple;
let series1 = vec!;
let series2 = vec!;
println!;
Configuration Options
| Option | Type | Default | Description |
|---|---|---|---|
height |
usize |
10 |
Height of the chart in rows |
width |
usize |
80 |
Width of the chart in columns |
offset |
usize |
3 |
Left margin for labels |
min |
Option<f64> |
None |
Minimum Y-axis value (auto if None) |
max |
Option<f64> |
None |
Maximum Y-axis value (auto if None) |
show_labels |
bool |
true |
Show Y-axis labels |
label_ticks |
usize |
5 |
Number of Y-axis label ticks |
label_format |
String |
"{:.2}" |
Format string for labels |
symbols |
Symbols |
Unicode | Characters for drawing |
API Reference
Main Functions
plot(series: &[f64]) -> String- Simple plot with defaultsplot_sized(series: &[f64], height: usize, width: usize) -> String- Plot with custom sizeplot_range(series: &[f64], min: f64, max: f64) -> String- Plot with custom rangeplot_no_labels(series: &[f64]) -> String- Plot without Y-axis labelsplot_ascii(series: &[f64]) -> String- Plot with ASCII-only charactersplot_multiple(series: &[&[f64]]) -> String- Plot multiple seriesplot_with_config(series: &[f64], config: Config) -> Result<String>- Plot with full configuration
Helper Functions
generate_sine(points: usize, frequency: f64, phase: f64) -> Vec<f64>- Generate sine wavegenerate_cosine(points: usize, frequency: f64, phase: f64) -> Vec<f64>- Generate cosine wavegenerate_random_walk(points: usize, start: f64, volatility: f64) -> Vec<f64>- Generate random walk
Types
Config- Chart configuration with builder patternSymbols- Custom drawing charactersChartError- Error types for the library
Running Examples
The library includes several examples:
# Simple example
# Advanced configuration
# Multiple series
# Real-time simulation
# Stock chart simulation
Error Handling
The library provides proper error handling:
use ;
let data = vec!;
let config = new;
match plot_with_config
Edge Cases Handled
- Empty data sets
- Single data point
- NaN and Infinity values
- Invalid ranges (min >= max)
- Zero dimensions
- Very large or very small numbers
Performance
The library is designed to be fast and memory-efficient:
- No heap allocations in hot paths
- Efficient string building
- Minimal copies of data
- O(n) time complexity where n is the number of data points
Comparison with asciichartpy
| Feature | rasciichart | asciichartpy |
|---|---|---|
| Language | Rust | Python |
| Dependencies | 0 | 0 |
| Type Safety | ✅ Strong | ❌ Dynamic |
| Performance | ⚡ Fast | 🐌 Slower |
| Error Handling | ✅ Result | ❌ Exceptions |
| Unicode Support | ✅ Yes | ✅ Yes |
| ASCII Fallback | ✅ Yes | ✅ Yes |
Contributing
Contributions are welcome! Please feel free to submit a Pull Request.
- Fork the repository
- Create your feature branch (
git checkout -b feature/amazing-feature) - Commit your changes (
git commit -am 'Add some amazing feature') - Push to the branch (
git push origin feature/amazing-feature) - Open a Pull Request
License
This project is licensed under the MIT License - see the LICENSE file for details.
Author
Hadi Cahyadi - cumulus13@gmail.com
Acknowledgments
- Inspired by asciichartpy by Igor Kroitor
- Unicode box-drawing characters from the Unicode Standard
Changelog
see the CHANGELOG
Support
If you find this library useful, please give it a ⭐ on GitHub!
