Skip to content

Zig module to flush console ascii line graphs ╭┈╯

License

Notifications You must be signed in to change notification settings

im-ng/asciigraph

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

8 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

asciigraph

Zig module to flush console ascii line graphs ╭┈╯

Crude derivation of the asciichart implementations in zig

Installation

Add asciigraph to your build.zig.zon:

zig fetch --save https://github.com/im-ng/asciigraph/archive/refs/heads/main.zip

Usage

const std = @import("std");
const asciigraph = @import("asciigraph");
const configs = asciigraph.options;
const colors = asciigraph.colors;

pub fn main() !void {
    var gpa = std.heap.GeneralPurposeAllocator(.{}){};
    const allocator = gpa.allocator();

    const c = configs.config{
        .rows = 1,
        .columns = 50,
        .height = 5,
        .offset = 0,
        .legendColor = colors.White,
        .legends = "X Axis",
        .caption = "Y Axis",
    };

    const matrix = try asciigraph.prepareMatrix(c.rows, c.columns, allocator);
    asciigraph.fillRandom(matrix);

    try asciigraph.PlotGraph(allocator, matrix, c);
}

Output

asciigraph/examples on  main [?] via ↯ v0.15.1 
❯ zig build basic
  ┤         ╭╮  ╭╮        ╭─╮      ╭╮                
  ┤ ╭╮     ╭╯│  │╰╮  ╭╮   │ │   ╭╮ ││ ╭╮  ╭─╮   ╭╮ ╭ 
  ┼╮││    ╭╯ │ ╭╯ ╰──╯╰╮  │ │   ││ ││ ││  │ ╰╮╭─╯╰╮│ 
  ┤│││╭─╮╭╯  ╰╮│       │  │ │ ╭╮│╰╮││ ││ ╭╯  ││   ││ 
  ┤╰╯╰╯ ╰╯    ││       │╭─╯ │ │╰╯ ╰╯╰╮│╰╮│   ╰╯   ││ 
  ┤           ╰╯       ╰╯   ╰─╯      ╰╯ ╰╯        ╰╯ 

Y Axis                      X Axis

Examples

This repository contains a number of ready-to-run examples demonstrates the use of the asciigraph.

  • Basic
  • Sine Wave
  • Stream - Real time data
  • Rainbow
git clone https://github.com/im-ng/asciigraph.git
cd asciigraph/examples
zig build

Run one of the sample use command zig build {sample_name} from examples folder.

zig build basic
zig build sine
ping -i1 google.com | grep -oP "time=\K\d+\.?\d*" --line-buffered | zig build stream

Real time plot

Real-time

Todos

Whatever options shown in asciichart

🤝 Attribution

The idea of this zig module taken from this asciigraph including the Plot logic.

📄 License

This project is licensed under the MIT License - see the LICENSE file for details.

About

Zig module to flush console ascii line graphs ╭┈╯

Topics

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages