3个不稳定版本

0.2.0 2023年1月6日
0.1.1 2019年7月12日
0.1.0 2019年7月11日

文本处理 中排名第490

Download history 339/week @ 2024-03-13 339/week @ 2024-03-20 339/week @ 2024-03-27 299/week @ 2024-04-03 297/week @ 2024-04-10 350/week @ 2024-04-17 330/week @ 2024-04-24 381/week @ 2024-05-01 280/week @ 2024-05-08 304/week @ 2024-05-15 320/week @ 2024-05-22 205/week @ 2024-05-29 212/week @ 2024-06-05 522/week @ 2024-06-12 235/week @ 2024-06-19 141/week @ 2024-06-26

每月下载量 1,138
7 个Crates中使用

MIT 许可证

26KB
461

rasciigraph

一个微小的Rust库,使用ASCII字符绘制漂亮的折线图。

用法

将此添加到您的Cargo.toml中

[dependencies]
rasciigraph = "0.2"

将此行代码添加到源代码顶部

extern crate rasciigraph;

如果您更喜欢使用Rust 2018版,您可能希望将此行添加到源代码中

use rasciigraph::{plot, Config}

示例

此代码

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())
        )
    );
}

生成如下输出

  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.

使用0.2.0版本,您还可以绘制多系列

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);
}

这是输出结果

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

致谢

此crate是rustlang对由asciigraph编写的库的移植,由@guptarohit编写。

上述库也是由asciichart编写的库的移植,由@kroitor编写。

无运行时依赖