asciigraph 0.6.0

Ascii Graph
Documentation

Ascii Graph

Draw beautiful graphs in ascii art!

Showcase

  • Basic use case.
let d = Graph::new(36, 18)  // (width, height)
    .set_1d_data(
        vec![256, 128, 192, 160, 176, 168, 172, 170]
    )
    .draw();
println!("{d}");
273 |                                    
    |▄▄▄▄▄                               
    |█████                               
246 |█████                               
    |█████                               
    |█████                               
219 |█████                               
    |█████                               
    |█████                               
192 |█████    █████                      
    |█████    █████    ▄▄▄▄▄             
    |█████    █████    █████▄▄▄▄█████████
165 |█████    █████▄▄▄▄██████████████████
    |█████    ███████████████████████████
    |█████    ███████████████████████████
138 |█████    ███████████████████████████
    |████████████████████████████████████
    |████████████████████████████████████
    └------------------------------------
     0       1       3       5       7   
  • Handle outliers
let d = Graph::new(42, 21)
    .set_block_width(2)  // calc the plot width based on the length of data
    .set_1d_data(
        vec![1, 2, 3, 4, 1005, 1006, 1007, 1008, 9, 10, 11, 12, 13]
    )
    .draw();
println!("{d}");
1009 |                          
     |              ██          
     |            ████          
1006 |          ██████          
     |        ████████          
     |        ████████          
1003 |        ████████          
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  13 |        ████████      ▄▄██
     |        ████████  ▄▄██████
     |        ██████████████████
   7 |        ██████████████████
     |      ▄▄██████████████████
     |  ▄▄██████████████████████
   1 |██████████████████████████
     |██████████████████████████
     |██████████████████████████
  -5 |██████████████████████████
     |██████████████████████████
     |██████████████████████████
     └--------------------------
      0       4       8       12
  • Highly customizable
let d = Graph::new(42, 21)
    .set_title("Test Graph".to_string())
    .set_y_axis_label("y_axis".to_string())
    .set_x_axis_label("x_axis".to_string())
    .set_paddings([2, 2, 2, 2])
    .set_1d_data(
        vec![
            (0..1024).collect::<Vec<i64>>(),
            (4096..5120).collect::<Vec<i64>>(),
        ].concat()
    )
    .draw();
println!("{d}");
                                                    
                                                    
                     Test Graph                     
      y_axis                                        
  5242 |                                            
       |                                         █  
       |                                       ███  
  4957 |                                     █████  
       |                                   ███████  
       |                                 █████████  
  4672 |                               ███████████  
       |                             █████████████  
       |                           ███████████████  
  4387 |                         ▄▄███████████████  
       |                       ▄▄█████████████████  
       |                     ▄▄███████████████████  
  4102 |                     █████████████████████  
  ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~  
  ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~  
   923 |               ▄▄█████████████████████████  
       |           ▄▄█████████████████████████████  
       |         █████████████████████████████████  
   398 |     ▄▄███████████████████████████████████  
       | ▄▄███████████████████████████████████████  
       |██████████████████████████████████████████  
       └------------------------------------------  
        0       390     780     1170    1560        
                                            x_axis