3 unstable releases

0.2.0 Jan 6, 2023
0.1.1 Jul 12, 2019
0.1.0 Jul 11, 2019

#1196 in Text processing

Download history 156/week @ 2024-08-01 135/week @ 2024-08-08 130/week @ 2024-08-15 106/week @ 2024-08-22 226/week @ 2024-08-29 460/week @ 2024-09-05 640/week @ 2024-09-12 408/week @ 2024-09-19 328/week @ 2024-09-26 1109/week @ 2024-10-03 652/week @ 2024-10-10 224/week @ 2024-10-17 163/week @ 2024-10-24 480/week @ 2024-10-31 512/week @ 2024-11-07 815/week @ 2024-11-14

2,011 downloads per month
Used in 7 crates

MIT license

26KB
461 lines

rasciigraph

Tiny Rust library to draw pretty line graphs using ascii characters.

Usage

Add this to your Cargo.toml

[dependencies]
rasciigraph = "0.2"

Add this line of code to top of your source code

extern crate rasciigraph;

If you prefer to use Rust 2018 edition you may prefer to add this line to your source code

use rasciigraph::{plot, Config}

Examples

This code

extern crate rasciigraph;

use rasciigraph::{plot, Config};

fn main() {
    println!(
        "{}",
        plot(
            vec![
                0.0, 0.0, 0.0, 0.0, 1.5, 0.0, 0.0, -0.5, 9.0, -3.0, 0.0, 0.0, 1.0, 2.0, 1.0, 0.0,
                0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 1.5, 0.0, 0.0, -0.5, 8.0, -3.0, 0.0, 0.0, 1.0,
                2.0, 1.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 1.5, 0.0, 0.0, -0.5, 10.0, -3.0,
                0.0, 0.0, 1.0, 2.0, 1.0, 0.0, 0.0, 0.0, 0.0
            ],
            Config::default()
                .with_offset(10)
                .with_height(10)
                .with_caption("I'm a doctor, not an engineer.".to_string())
        )
    );
}

Produces an output like this

  10.00   ┤                                             ╭╮          
  8.70    ┤       ╭╮                                    ││          
  7.40    ┼       ││                 ╭╮                 ││          
  6.10    ┤       ││                 ││                 ││          
  4.80    ┤       ││                 ││                 ││          
  3.50    ┤       ││                 ││                 ││          
  2.20    ┤       ││   ╭╮            ││   ╭╮            ││   ╭╮     
  0.90    ┤   ╭╮  ││  ╭╯╰╮       ╭╮  ││  ╭╯╰╮       ╭╮  ││  ╭╯╰╮    
 -0.40    ┼───╯╰──╯│╭─╯  ╰───────╯╰──╯│╭─╯  ╰───────╯╰──╯│╭─╯  ╰─── 
 -1.70    ┤        ││                 ││                 ││         
 -3.00    ┤        ╰╯                 ╰╯                 ╰╯        
             I'm a doctor, not an engineer.

With 0.2.0 version you can also plot multi series

fn main() {
    let res = rasciigraph::plot_many(
        vec![
            vec![0.0f64, 1.0, 0.0],
            vec![2.0, 3.0, 4.0, 3.0, 2.0],
            vec![4.0, 5.0, 6.0, 7.0, 6.0, 5.0, 4.0],
        ],
        rasciigraph::Config::default().with_width(21),
    );
    print!("{}", res);
}

This is the output

 7.00 ┤        ╭──╮
 6.00 ┤    ╭───╯  ╰───╮
 5.00 ┤ ╭──╯          ╰──╮
 4.00 ┼─╯  ╭───╮         ╰─
 3.00 ┤ ╭──╯   ╰──╮
 2.00 ┼─╯         ╰──
 1.00 ┤ ╭───╮
 0.00 ┼─╯   ╰─            

Acknowledgement

This crate is rustlang port of library asciigraph written by @guptarohit.

Above library is also port of library asciichart written by @kroitor.

No runtime deps