/graphviz-plain-to-ascii

Rendering Graphviz graph in ASCII

Primary LanguageJava

Rendering Graphviz graph in ASCII

Example

This graph

Work tab

Is rendered like this

                                                                                                             
                                      "CTCMY...SCEWX"                                                        
                                     ↙-----←↙ ↘→-↘                                                           
                                  ↙←↙             ↘→↘                                                        
                               ↙←↙                   ↘→↘                                                     
                              ↙                         ↘→↓                                                  
                            ↙     "EBLNX...DALUT"         "KZLM9...9APUJ"                                    
                           ↙            ↙ ↘                 ↙-←↙↓                                            
                         ←↙            ↙    ↘              ↙    |                                            
                          ↘           ↙      ↘           ↙      |                                            
                           ↘         ↙         ↓       ↙        |                                            
                            ↘       ↙     "ERNHS...DARXO"       |                                            
                             ↘      ↓         ↙←↙ ↘            ↙                                             
                              ↘     |        ↙      ↘       ↙←↙                                              
                               ↘   ↙     ↙←↙       ↙--↘---←↙                                                 
                                 ↓ ↓    ↙   ↙----←↙    ↓                                                     
                            "KXYWE...SGOSU"←        "9XDQC...NIGLS"                                          
                             ↙---←↙↓                      ↓↘→---↘                                            
                          ↙←↙      |                      |      ↘→↘                                         
                     ↙--←↙         |                      |         ↘→--↘                                    
                 ↓-←↙              ↓                      ↓              ↘→-↓                                
     "OWYFP...GMJPR"        "UVMYC...RGTPP"        "SBZZM...NDGLQ"          "NGWYY...BZEW9"                  
                                                                                                             

Usage

Prerequisites:

<dependency>
   <groupId>guru.nidi</groupId>
   <artifactId>graphviz-java</artifactId>
</dependency>
  File tmpFile = File.createTempFile("myGraph", ".txt");
  Graphviz.fromGraph(graph).render(Format.PLAIN_EXT).toFile(tmpFile);
  try (FileInputStream fis = new FileInputStream(tmpFile)) {
    tmpFile.deleteOnExit();
    AsciiRenderer asciiRenderer = new AsciiRenderer(fis, 10, 6);
      return asciiRenderer.render();
    } catch (IOException e) {
      e.printStackTrace();
    }
  return null;