Debian Codegraph @

README.md

raw symbols SCIP
1 # rasciigraph
2 Tiny Rust library to draw pretty line graphs using ascii characters.
3
4 # Usage
5 Add this to your Cargo.toml
6 ``` toml
7 [dependencies]
8 rasciigraph = "0.2"
9 ```
10 Add this line of code to top of your source code
11 ``` rust
12 extern crate rasciigraph;
13 ```
14
15 If you prefer to use Rust 2018 edition you may prefer to add this line to your source code
16 ``` rust
17 use rasciigraph::{plot, Config}
18 ```
19
20 # Examples
21 This code
22 ``` rust
23 extern crate rasciigraph;
24
25 use rasciigraph::{plot, Config};
26
27 fn main() {
28 println!(
29 "{}",
30 plot(
31 vec![
32 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,
33 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,
34 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,
35 0.0, 0.0, 1.0, 2.0, 1.0, 0.0, 0.0, 0.0, 0.0
36 ],
37 Config::default()
38 .with_offset(10)
39 .with_height(10)
40 .with_caption("I'm a doctor, not an engineer.".to_string())
41 )
42 );
43 }
44
45 ```
46 Produces an output like this
47 ```
48 10.00 ┤ ╭╮
49 8.70 ┤ ╭╮ ││
50 7.40 ┼ ││ ╭╮ ││
51 6.10 ┤ ││ ││ ││
52 4.80 ┤ ││ ││ ││
53 3.50 ┤ ││ ││ ││
54 2.20 ┤ ││ ╭╮ ││ ╭╮ ││ ╭╮
55 0.90 ┤ ╭╮ ││ ╭╯╰╮ ╭╮ ││ ╭╯╰╮ ╭╮ ││ ╭╯╰╮
56 -0.40 ┼───╯╰──╯│╭─╯ ╰───────╯╰──╯│╭─╯ ╰───────╯╰──╯│╭─╯ ╰───
57 -1.70 ┤ ││ ││ ││
58 -3.00 ┤ ╰╯ ╰╯ ╰╯
59 I'm a doctor, not an engineer.
60 ```
61
62 With 0.2.0 version you can also plot multi series
63 ``` rust
64 fn main() {
65 let res = rasciigraph::plot_many(
66 vec![
67 vec![0.0f64, 1.0, 0.0],
68 vec![2.0, 3.0, 4.0, 3.0, 2.0],
69 vec![4.0, 5.0, 6.0, 7.0, 6.0, 5.0, 4.0],
70 ],
71 rasciigraph::Config::default().with_width(21),
72 );
73 print!("{}", res);
74 }
75 ```
76
77 This is the output
78 ```
79 7.00 ┤ ╭──╮
80 6.00 ┤ ╭───╯ ╰───╮
81 5.00 ┤ ╭──╯ ╰──╮
82 4.00 ┼─╯ ╭───╮ ╰─
83 3.00 ┤ ╭──╯ ╰──╮
84 2.00 ┼─╯ ╰──
85 1.00 ┤ ╭───╮
86 0.00 ┼─╯ ╰─
87 ```
88
89 # Acknowledgement
90 This crate is rustlang port of library [asciigraph](https://github.com/guptarohit/asciigraph) written by [@guptarohit](https://github.com/guptarohit).
91
92 Above library is also port of library [asciichart](https://github.com/kroitor/asciichart) written by [@kroitor](https://github.com/kroitor).