143 lines
6.6 KiB
Markdown
143 lines
6.6 KiB
Markdown
# GraphTUI
|
||
|
||
A clean, fast, intuitive, and feature-packed mathematical graphing TUI (Terminal User Interface) application written in **C# and .NET 10** with **zero external packages or NuGet dependencies**.
|
||
|
||

|
||
|
||
---
|
||
|
||
## Highlights
|
||
|
||
- **Zero Dependencies**: 100% standalone standard .NET 10. Runs anywhere without restoring external packages.
|
||
- **Unicode Braille Subpixel Canvas**: Leverages $2 \times 4$ Braille dot matrices (`U+2800`–`U+28FF`) for an $8\times$ resolution boost per terminal cell, rendering continuous, crisp curves with almost square 1:1 subpixels.
|
||
- **Double-Buffered Differential Rendering**: In-memory virtual screen diffs consecutive frames and outputs only changed cells via ANSI truecolor (24-bit RGB) sequences for 60+ FPS flicker-free performance.
|
||
- **100% Keyboard Parity & Full Mouse Support**: Every feature is accessible via keyboard alone (Vim keys `h/j/k/l`, Arrows, Tab, Hotkeys, Command Bar), plus full mouse support (scroll wheel zoom, click-drag pan, direct clicking).
|
||
- **Handcrafted Scientific Math Engine**: Recursive-descent Pratt parser supporting implicit multiplication (`2x`, `3sin(x)`, `(x+1)(x-1)`), standard and hyperbolic trigonometry, logarithms, roots, powers, constants ($\pi, e, \tau, \phi$).
|
||
- **Live Numerical Calculus Overlays**:
|
||
- Tangent line tracing with real-time slope ($m = dy/dx$) calculation.
|
||
- Derivative curve overlay $f'(x)$.
|
||
- Definite numerical integration ($\int_a^b f(x) dx$) via Simpson's rule with visual area shading.
|
||
- Root finder ($f(x) = 0$) and local extrema detector (minima and maxima).
|
||
- **Dynamic Parameter Sliders**: Tweak variables ($a, b, c$) in real time with immediate graphical curve morphing.
|
||
- **Mathematical Presets Gallery**: One-key access to Fourier series approximations, Lissajous figures, Butterfly curves, damped harmonic oscillators, cardioids, and polynomials.
|
||
- **Session & Export**: Save/load sessions as JSON, and export graphs to vector SVG or Unicode Braille text files.
|
||
|
||
---
|
||
|
||
## Getting Started
|
||
|
||
### Prerequisites
|
||
- [.NET 10 SDK](https://dotnet.microsoft.com/)
|
||
|
||
### Run GraphTUI
|
||
```bash
|
||
# Launch interactive application
|
||
dotnet run --project src/GraphTUI/GraphTUI.csproj
|
||
|
||
# Launch directly with custom mathematical functions
|
||
dotnet run --project src/GraphTUI/GraphTUI.csproj -- "sin(x)" "cos(2x)"
|
||
|
||
# Launch by loading an existing saved session
|
||
dotnet run --project src/GraphTUI/GraphTUI.csproj -- --load session.json
|
||
```
|
||
|
||
### Run Tests
|
||
```bash
|
||
# Zero-dependency test runner
|
||
dotnet run --project tests/GraphTUI.Tests/GraphTUI.Tests.csproj
|
||
```
|
||
|
||
---
|
||
|
||
## Controls Reference (100% Keyboard Parity)
|
||
|
||
| Feature | Keyboard Shortcut | Mouse Action |
|
||
| :--- | :--- | :--- |
|
||
| **Pan Canvas** | Arrow Keys or `h, j, k, l` | Click & Drag canvas |
|
||
| **Zoom In / Out** | `+` (or `=`) / `-` (or `_`), `[` / `]` | Mouse Scroll Wheel (zooms at cursor) |
|
||
| **Reset View** | `Home` or `0` | Double-click canvas |
|
||
| **Cycle Focus (Pane)** | `Tab` / `Shift+Tab` | Click target pane |
|
||
| **Toggle Sidebar** | `F2` or `\` | Click `[ < ]` / `[ > ]` toggle icon |
|
||
| **Trace Mode** | `t` (toggle trace), `Left`/`Right` to glide along curve | Click directly on graph |
|
||
| **Function List** | `Up`/`Down` / `j`/`k` to select | Click row |
|
||
| **Toggle Visibility** | `Space` | Click `[x]` checkbox |
|
||
| **Cycle Color** | `c` | Click color bullet `●` |
|
||
| **Edit Formula** | `Enter` or `e` | Click formula text |
|
||
| **Delete Function** | `Delete` or `d` | - |
|
||
| **Add Function** | `a` | Click `[+ Add]` button |
|
||
| **Parameter Sliders** | `Left`/`Right` or `,`/`.` or `[`/`]` | Click/Drag slider track |
|
||
| **Calculus Tools** | `c` / `F3` (Roots, Extrema, Integral, Tangent) | Click Calculus button |
|
||
| **Presets Gallery** | `p` / `F4` (Fourier, Lissajous, Butterfly, etc.) | Click Presets button |
|
||
| **Command Bar** | `:` (`:save`, `:load`, `:export`, `:quit`) | - |
|
||
| **Quick Help** | `?` or `F1` | Click Help |
|
||
| **Quit** | `q` or `Ctrl+C` or `:quit` | Click `[X]` exit |
|
||
|
||
---
|
||
|
||
## Mathematical Syntax
|
||
|
||
### Expressions & Variables
|
||
- Cartesian functions: $y = f(x)$, e.g. `sin(x) * exp(-0.1x)`
|
||
- Parametric curves: $x(t) = \cos(3t)$, $y(t) = \sin(4t)$
|
||
- Polar curves: $r = f(\theta)$, e.g. `2*(1 - sin(theta))`
|
||
- Implicit multiplication: `2x`, `3sin(x)`, `(x+1)(x-1)`, `2pi`, `x y`
|
||
|
||
### Built-in Functions
|
||
- **Trigonometric**: `sin`, `cos`, `tan`, `cot`, `sec`, `csc`
|
||
- **Inverse Trig**: `asin`, `acos`, `atan`, `atan2(y, x)`
|
||
- **Hyperbolic**: `sinh`, `cosh`, `tanh`
|
||
- **Logarithms & Powers**: `ln`, `log` (base 10), `log2`, `exp`, `sqrt`, `cbrt`, `^`
|
||
- **Rounding & Utilities**: `abs`, `floor`, `ceil`, `round`, `sgn`, `min(a, b)`, `max(a, b)`, `clamp(x, min, max)`
|
||
- **Constants**: `pi` ($\pi$), `e`, `tau` ($2\pi$), `phi` ($\approx 1.618$)
|
||
|
||
---
|
||
|
||
## Architecture
|
||
|
||
```
|
||
GrapherTUI/
|
||
├── GraphTUI.sln
|
||
├── src/GraphTUI/
|
||
│ ├── Program.cs # CLI entry point
|
||
│ ├── App.cs # Main event loop, layout orchestration, state
|
||
│ ├── Core/
|
||
│ │ ├── Math/ # Zero-dependency lexer, Pratt parser, AST, calculus
|
||
│ │ │ ├── Token.cs
|
||
│ │ │ ├── Lexer.cs
|
||
│ │ │ ├── AstNodes.cs
|
||
│ │ │ ├── Parser.cs
|
||
│ │ │ ├── Evaluator.cs
|
||
│ │ │ └── Calculus.cs
|
||
│ │ └── Models/ # Viewport, functions, parameters, session DTO
|
||
│ │ ├── FunctionType.cs
|
||
│ │ ├── GraphFunction.cs
|
||
│ │ ├── Parameter.cs
|
||
│ │ ├── Viewport.cs
|
||
│ │ └── SessionData.cs
|
||
│ ├── Rendering/ # Braille subpixel canvas, plot renderer, SVG & text exporter
|
||
│ │ ├── ColorRgb.cs
|
||
│ │ ├── BrailleCanvas.cs
|
||
│ │ ├── PlotRenderer.cs
|
||
│ │ ├── SvgExporter.cs
|
||
│ │ └── TextExporter.cs
|
||
│ ├── Terminal/ # VT/ANSI codes, SGR mouse & keyboard input, virtual screen
|
||
│ │ ├── AnsiCodes.cs
|
||
│ │ ├── KeyAction.cs
|
||
│ │ ├── InputReader.cs
|
||
│ │ └── VirtualScreen.cs
|
||
│ └── UI/ # Split-pane layout, views, modals, command prompt
|
||
│ ├── LayoutManager.cs
|
||
│ └── Views/
|
||
│ ├── FunctionListView.cs
|
||
│ ├── ParameterSlidersView.cs
|
||
│ ├── PresetsGalleryModal.cs
|
||
│ ├── CalculusModal.cs
|
||
│ ├── HelpModal.cs
|
||
│ └── CommandBarView.cs
|
||
└── tests/GraphTUI.Tests/ # Zero-dependency unit test suite (21 unit tests)
|
||
```
|
||
|
||
---
|
||
|
||
## License
|
||
MIT
|