{"id":29965392,"url":"https://github.com/tammoippen/zig-plotille","last_synced_at":"2025-10-28T22:59:05.883Z","repository":{"id":72272737,"uuid":"384375654","full_name":"tammoippen/zig-plotille","owner":"tammoippen","description":"Plot graphs and histograms in the terminal. ","archived":false,"fork":false,"pushed_at":"2025-07-31T20:54:24.000Z","size":1656,"stargazers_count":4,"open_issues_count":0,"forks_count":0,"subscribers_count":3,"default_branch":"master","last_synced_at":"2025-07-31T22:35:22.278Z","etag":null,"topics":["ansi-colors","braille","graph","histogram","plot","terminal","zig","zig-library","zig-package","ziglang"],"latest_commit_sha":null,"homepage":"","language":"Zig","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/tammoippen.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE.txt","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null}},"created_at":"2021-07-09T08:41:08.000Z","updated_at":"2025-07-31T20:54:27.000Z","dependencies_parsed_at":"2025-07-31T21:04:44.016Z","dependency_job_id":"14eacbcf-6328-4697-9876-ceee48427566","html_url":"https://github.com/tammoippen/zig-plotille","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/tammoippen/zig-plotille","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tammoippen%2Fzig-plotille","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tammoippen%2Fzig-plotille/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tammoippen%2Fzig-plotille/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tammoippen%2Fzig-plotille/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/tammoippen","download_url":"https://codeload.github.com/tammoippen/zig-plotille/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tammoippen%2Fzig-plotille/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":281527380,"owners_count":26516845,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","status":"online","status_checked_at":"2025-10-28T02:00:06.022Z","response_time":60,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["ansi-colors","braille","graph","histogram","plot","terminal","zig","zig-library","zig-package","ziglang"],"created_at":"2025-08-04T02:01:22.905Z","updated_at":"2025-10-28T22:59:05.875Z","avatar_url":"https://github.com/tammoippen.png","language":"Zig","readme":"![CI](https://github.com/tammoippen/zig-plotille/actions/workflows/main.yml/badge.svg)\n\n# zig-plotille\n\nTerminal plotting library for Zig with full C API support.\n\n**Draw beautiful plots, histograms, and visualizations directly in your terminal using Unicode braille characters.**\n\n![Sine](img/sine.png)\n\n## Features\n\n- 🌈 **Rich Color Support**: ANSI, 8-bit, and 24-bit true color support\n- 🎨 **Canvas Drawing**: General purpose braille dot canvas for custom graphics\n- 📊 **Multiple Plot Types**: Line plots, scatter plots, histograms, text annotations\n- 📐 **Flexible Layouts**: Support for axis lines, spans, and custom coordinate systems\n- 🔧 **Dual API**: Native Zig API and complete C API for interoperability\n- 🖥️ **Terminal Detection**: Automatic terminal capability detection\n- 📏 **High Resolution**: 2×4 dots per character cell using Unicode braille patterns\n\nRe-implementation of the Python [plotille](https://github.com/tammoippen/plotille) library with enhanced performance and C compatibility.\n\n## Quick Start\n\n### Building\n\n```bash\n# Build the library (creates both static and dynamic libraries)\nzig build\n\n# Build optimized release libraries\nzig build -Doptimize=ReleaseFast\nzig build -Doptimize=ReleaseSmall\nzig build -Doptimize=ReleaseSafe\n\n# Build with debug symbols stripped\nzig build -Dstrip=true\n\n# Build for specific target\nzig build -Dtarget=x86_64-linux-gnu\nzig build -Dtarget=aarch64-macos\n\n# Build release library for distribution\nzig build -Doptimize=ReleaseFast -Dstrip=true\n\n# Run tests\nzig build test\n\n# Output will be in:\n# - zig-out/lib/libplotille.a (static library)\n# - zig-out/lib/libplotille.so (dynamic library, Linux)\n# - zig-out/lib/libplotille.dylib (dynamic library, macOS)\n```\n\n## Examples\n\nIn `zig-examples`, there are several examples demonstrating the library's capabilities. To build and run these examples, navigate to the `zig-examples` directory and execute the following commands:\n\n```bash\n# Build all examples and run all examples\nzig build run\n\n# Output will be in:\n# - zig-out/bin/dots (executable)\n# - zig-out/bin/hist (executable)\n# - zig-out/bin/house (executable)\n# - zig-out/bin/hsl (executable)\n# - zig-out/bin/lookup (executable)\n# - zig-out/bin/names (executable)\n# - zig-out/bin/sine (executable)\n# - zig-out/bin/terminfo (executable)\n```\n\n### Color Showcase\n\nDisplay all available named colors in a grid:\n\n```zig\nconst plt = @import(\"plotille\");\n\n// Detect terminal capabilities\n// ALWAYS required, before printing with color support\n// (either set or detect)\ntry plt.terminfo.TermInfo.detect(allocator);\n\n// Display color grid\nfor (std.enums.values(plt.color.ColorName)) |bg_value| {\n    const bg = plt.color.Color.by_name(bg_value);\n    for (std.enums.values(plt.color.ColorName)) |fg_value| {\n        const fg = plt.color.Color.by_name(fg_value);\n        try plt.color.colorPrint(writer, \"Text \", .{}, .{ .fg = fg, .bg = bg });\n    }\n}\n```\n\n![Color Names](img/names.png)\n\n(see [names.zig](zig-examples/names.zig) for more details and edge cases)\n\n### HSL Color Space\n\nExplore HSL color gradients:\n\n```zig\nconst plt = @import(\"plotille\");\n\n// Create HSL color and display\nconst hue = 240.0; // Blue hue\nfor (0..20) |row| {\n    for (0..40) |col| {\n        const saturation = @as(f64, @floatFromInt(col)) / 40.0;\n        const lightness = @as(f64, @floatFromInt(20 - row)) / 20.0;\n        const color = plt.color.Color.by_hsl(hue, saturation, lightness);\n        try plt.color.colorPrint(writer, \" \", .{}, .{ .bg = color });\n    }\n    try writer.print(\"\\n  \", .{});\n}\n```\n\n![HSL Colors](img/hsl.png)\n\n(see [hsl.zig](zig-examples/hsl.zig) for more details)\n\n### Canvas Drawing\n\nCreate custom graphics with the canvas API:\n\n```zig\nconst plt = @import(\"plotille\");\n\nvar canvas = try plt.canvas.Canvas.init(allocator, 40, 20, plt.color.Color.by_name(.white));\ndefer canvas.deinit(allocator);\n\n// Draw a house\ntry canvas.rect(.{ .x = 0.1, .y = 0.1 }, .{ .x = 0.8, .y = 0.6 }, plt.color.Color.by_name(.red), null);\ntry canvas.line(.{ .x = 0.1, .y = 0.1 }, .{ .x = 0.8, .y = 0.6 }, plt.color.Color.by_name(.red), null);\ntry canvas.line(.{ .x = 0.8, .y = 0.1 }, .{ .x = 0.1, .y = 0.6 }, plt.color.Color.by_name(.red), null);\n\n// Draw roof\ntry canvas.line(.{ .x = 0.1, .y = 0.6 }, .{ .x = 0.45, .y = 0.8 }, plt.color.Color.by_name(.red), null);\ntry canvas.line(.{ .x = 0.8, .y = 0.6 }, .{ .x = 0.45, .y = 0.8 }, plt.color.Color.by_name(.red), null);\n\ntry writer.print(\"{}\\n\", .{canvas});\n```\n\n![House Drawing](img/house.png)\n\n(see [house.zig](zig-examples/house.zig) for more details)\n\n### Scientific Plotting\n\nCreate _publication-ready_ (if you plan to publish in terminal 😇) plots with the Figure API:\n\n```zig\nvar fig = try plt.figure.Figure.init(allocator, 60, 20, null);\ndefer fig.deinit();\n\n// Configure the plot\nfig.xmin = 0;\nfig.xmax = 10;\nfig.ymin = -2;\nfig.ymax = 2;\n\n// Generate sine wave data\nvar x_data: [100]f64 = undefined;\nvar y_data: [100]f64 = undefined;\nfor (0..100) |i| {\n    x_data[i] = @as(f64, @floatFromInt(i)) * 10.0 / 99.0;\n    y_data[i] = @sin(x_data[i]);\n}\n\n// Add plots\ntry fig.plot(\u0026x_data, \u0026y_data, .{ .lc = plt.color.Color.by_name(.blue), .label = \"sin(x)\" });\n\n// Add scatter points\nconst points_x = [_]f64{ 1, 3, 5, 7, 9 };\nconst points_y = [_]f64{ 0.8, -0.5, 0.2, -0.9, 0.1 };\ntry fig.scatter(\u0026points_x, \u0026points_y, .{ .lc = plt.color.Color.by_name(.red), .label = \"data\", .marker = 'o' });\n\n// Add annotations\ntry fig.text(5, 1.5, \"Peak\", plt.color.Color.by_name(.green));\ntry fig.axhline(0.8, .{ .lc = plt.color.Color.by_name(.yellow) });\n\ntry fig.prepare();\ntry writer.print(\"{}\\n\", .{fig});\n```\n\n![Sine](img/sine.png)\n\n(see [sine.zig](zig-examples/sine.zig) for more details)\n\n### Histograms\n\nVisualize data distributions. Either using Histogram directly:\n\n```zig\nconst plt = @import(\"plotille\");\n\nconst data = [_]f64{ 1.2, 2.3, 1.8, 2.1, 1.9, 2.4, 1.7, 2.0, 1.6, 2.2 };\nvar hist = try plt.hist.Histogram.init(allocator, \u0026data, 5);\ndefer hist.deinit();\n\ntry writer.print(\"{}\\n\", .{hist});\n```\n\n![Histogram](img/hist.png)\n\n(see [hist.zig](zig-examples/hist.zig) for more details)\n\nOR using a Figure with a histogram:\n\n```zig\nconst plt = @import(\"plotille\");\n\nconst data = [_]f64{ 1.2, 2.3, 1.8, 2.1, 1.9, 2.4, 1.7, 2.0, 1.6, 2.2 };\n\nvar fig = try plt.figure.Figure.init(allocator, 80, 20, null);\ndefer fig.deinit();\n\n// Configure the plot\nfig.xmin, fig.xmax = std.mem.minMax(f64, values.items);\nfig.ymin = 0;\nfig.ymax = 12;\n\ntry fig.histogram(values.items, 10, null);\n\ntry fig.prepare();\ntry writer.print(\"{}\\n\", .{fig});\n```\n\n![Histogram](img/histogram.png)\n\n(see [histogram.zig](zig-examples/histogram.zig) for more details)\n\n### Individual Braille Dots\n\nLow-level control with the Dots API:\n\n```zig\nconst plt = @import(\"plotille\");\n\nvar dot = plt.dots.Dots{};\ndot.set(0, 0); // Top-left\ndot.set(1, 3); // Bottom-right\ndot.color.fg = plt.color.Color.by_name(.red);\n\ntry writer.print(\"Dot pattern: {}\\n\", .{dot});\n```\n\n![Dots](img/dots.png)\n\n(see [dots.zig](zig-examples/dots.zig) for more details)\n\n## API Overview\n\n### Core Modules\n\n- **`plotille.canvas`**: Low-level canvas for drawing points, lines, rectangles\n- **`plotille.figure`**: High-level plotting interface with legends and axes\n- **`plotille.hist`**: Histogram generation and rendering\n- **`plotille.dots`**: Individual braille character manipulation\n- **`plotille.color`**: Comprehensive color support (names, RGB, HSL, 8-bit)\n- **`plotille.terminfo`**: Terminal capability detection\n\n### Canvas API\n\n```zig\n// Create canvas\nvar canvas = try plt.canvas.Canvas.init(allocator, width, height, bg_color);\ndefer canvas.deinit(allocator);\n\n// Set coordinate system\ncanvas.setReferenceSystem(xmin, ymin, xmax, ymax);\n\n// Drawing operations\ncanvas.point(.{ .x = 0.5, .y = 0.5 }, color, 'X');\ntry canvas.line(.{ .x = 0, .y = 0 }, .{ .x = 1, .y = 1 }, color, null);\ntry canvas.rect(.{ .x = 0.2, .y = 0.2 }, .{ .x = 0.8, .y = 0.8 }, color, null);\ncanvas.text(.{ .x = 0.5, .y = 0.9 }, \"Label\", color);\n```\n\n### Figure API\n\n```zig\n// Create figure\nvar fig = try plt.figure.Figure.init(allocator, width, height, bg_color);\ndefer fig.deinit();\n\n// Add data series\ntry fig.plot(x_data, y_data, .{ .lc = color, .label = \"Series 1\" });\ntry fig.scatter(x_data, y_data, .{ .lc = color, .marker = 'o' });\ntry fig.histogram(data, bins, color);\n\n// Add annotations\ntry fig.text(x, y, \"Note\", color);\n// all ax* methods take relative coordinates for x and y\ntry fig.axvline(x_pos, .{ .lc = color });\ntry fig.axhline(y_pos, .{ .lc = color });\ntry fig.axvspan(x_min, x_max, .{ .lc = color });\ntry fig.axhspan(y_min, y_max, .{ .lc = color });\n\n// Render\ntry fig.prepare();\n```\n\n### Color System\n\n```zig\n// Named colors\nconst red = plt.color.Color.by_name(.red);\n\n// RGB colors\nconst custom = plt.color.Color.by_rgb(255, 128, 0);\n\n// HSL colors\nconst hsl = plt.color.Color.by_hsl(240, 1.0, 0.5);\n\n// 8-bit palette\nconst indexed = plt.color.Color.by_lookup(196);\n\n// Print with color\ntry plt.color.colorPrint(writer, \"Colored text\", .{}, .{ .fg = red, .bg = indexed });\n```\n\n## C API\n\nFor C/C++ integration, include `plotille.h` and link against `libplotille.a` / `libplotille.so` / `libplotille.dylib`:\n\n```c\n#include \"plotille.h\"\n\n// C API mirrors the Zig API\nCanvas canvas;\ncanvas_init(40, 20, color_no_color(), \u0026canvas);\ncanvas_set_reference_system(\u0026canvas, 0.0, 0.0, 1.0, 1.0);\n\nPoint p = {0.5, 0.5};\ncanvas_point(\u0026canvas, p, color_by_name(COLOR_RED), 0);\n\nuint8_t buffer[4096];\nsize_t len = canvas_str(canvas, buffer, sizeof(buffer));\nprintf(\"%.*s\\n\", (int)len, buffer);\n\ncanvas_free(\u0026canvas);\n```\n\nSee `plotille.h` for the complete C API documentation and the `c-examples/` directory for usage examples.\n\n## Coordinate System\n\n- **Canvas Resolution**: Each character represents 2×4 braille dots\n- **Reference System**: Floating-point coordinates (default: 0,0 to 1,1)\n- **Automatic Scaling**: Coordinates are automatically mapped to canvas dimensions\n- **Origin**: Bottom-left (0,0) to top-right (max,max)\n\n## Terminal Support\n\nThe library automatically detects terminal capabilities:\n\n- **True Color**: 24-bit RGB support\n- **8-bit Color**: 256-color palette\n- **Named Colors**: Basic 16-color ANSI\n- **No Color**: Monochrome fallback\n\nRespects `NO_COLOR` and `FORCE_COLOR` environment variables.\n\n## Building and Integration\n\n### As a Zig Module\n\nAdd to your `build.zig.zon`:\n\n```bash\nzig fetch --save git+https://github.com/tammoippen/zig-plotille\n```\n\nThen add the module to your `build.zig`:\n\n```zig\nconst plotille = b.dependency(\"plotille\", .{\n    .target = target,\n    .optimize = mode,\n});\n```\n\n### As a C Library\n\n```bash\n# Build libraries (both static and dynamic)\nzig build\n\n# Build optimized release libraries for distribution\nzig build -Doptimize=ReleaseFast -Dstrip=true\n\n# Output libraries:\n# - zig-out/lib/libplotille.a (static library)\n# - zig-out/lib/libplotille.so/.dylib (dynamic library)\n\n# Include plotille.h in your C/C++ project\n#\n# See Makefile for build instructions\n```\n\n## Examples and Tests\n\n- **`src/*.zig`**: Unit tests demonstrating all features\n- **`zig-examples/`**: Complete Zig example programs\n- **`examples/dots.c`**: C API usage example\n\nRun all examples: `make test`\n","funding_links":[],"categories":["Multimedia \u0026 Graphics"],"sub_categories":["Graphics Library"],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftammoippen%2Fzig-plotille","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Ftammoippen%2Fzig-plotille","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftammoippen%2Fzig-plotille/lists"}