π termplot-rs
High-performance terminal graphics engine (TUI).
termplot-rs allows you to render mathematical plots, 3D visualizations, and complex interfaces directly in the console using Unicode Braille characters (2Γ4 dot matrix per character) and ANSI colors.
Unlike other TUI plotting libraries, termplot-rs is designed for critical speed: it uses flat memory buffers (Vec<u8>), bitwise operations, and a zero-allocation rendering loop to achieve thousands of FPS in real-time applications.
π New in v0.8: Optimized rendering engine (1600+ FPS in stress tests), Dual Coordinate System (Cartesian/Screen), and robust handling of
NaN/Infinity values.
β¨ Key Features
-
High Resolution: 8 sub-pixels per character (Braille 2x4). A 100x50 terminal yields a 200x200 effective pixel canvas.
-
Extreme Performance:
-
Flat buffers for maximum CPU cache locality.
-
Minimized memory allocations during the render loop.
-
Optimized ANSI output (redundant color codes are stripped).
-
Robust: Safe data handling (ignores
NaN, prevents division by zero, auto-clamping). -
Drawing Primitives:
-
Lines (Bresenham), Circles, Polygons.
-
Text Layer (overlay).
-
Ready-to-use Charts:
-
scatter()(Scatter plots). -
line_chart()(Time series / connected points). -
bar_chart()(Bar graphs with auto-width). -
pie_chart()(Radar/Pie style). -
plot_function()(Direct plotting ofy = f(x)functions). -
Auto-Range: Automatic axis scaling based on your dataset.
π¦ Installation
Add this to your Cargo.toml:
[]
= "0.1.1"
= "0.8" # Optional, for generating test data
= "2.0"
π Quick Start
use ;
use Color;
π Coordinate System
To avoid mathematical confusion, termplot-rs offers two modes for pixel manipulation:
| Method | Origin (0,0) | Y Direction | Best For |
|---|---|---|---|
set_pixel(x, y) |
Bottom-Left | Grows Up | Math plots, functions, charts. |
set_pixel_screen(x, y) |
Top-Left | Grows Down | UI, Images, 3D Projections, Video. |
Note: High-level functions (
scatter,line_chart) internally use Cartesian (Math) coordinates.
π§ͺ Examples & Demos
The repository includes advanced examples to showcase the library's power.
1. "Plasma" Stress Test (+1000 FPS)
Calculates complex trigonometry per sub-pixel plus particle physics in real-time. Run in release mode to see real speed.
2. Interactive Fractals
Mandelbrot and Julia explorer with infinite Zoom and rotation.
3. 3D Cube
Wireframe 3D rendering with projection matrix and rotation.
4. Chart Gallery
Shows all available static chart types.
β‘ Performance
termplot-rs is optimized to avoid unnecessary allocations.
In a benchmark with a 236x104 sub-pixel canvas (full fill with trigonometric noise and particles), on a modern machine:
- Debug Mode: ~60 FPS
- Release Mode: ~1600+ FPS
This makes it viable for audio visualization, high-frequency server monitoring, or lightweight physics simulations directly in the terminal.
πΊοΈ Roadmap
- Memory optimization (Flat
Vec<u8>buffers). - Explicit coordinate APIs (
screenvscartesian). - Robustness in
bar_chartandauto_range(fix division by zero). -
plot_functionanddraw_circlemethods. - Logarithmic scaling support.
- Automatic Legend Box.
- Optional
serdesupport for configuration structs.
π License
This project is licensed under the MIT license. Feel free to use it in your CLI tools, dashboards, or graphical experiments.