graphs


License

License

Categories

Categories

Scala Languages
GroupId

GroupId

org.scalameta
ArtifactId

ArtifactId

ascii-graphs_2.13
Last Version

Last Version

0.1.2
Release Date

Release Date

Type

Type

jar
Description

Description

graphs
graphs
Project URL

Project URL

https://github.com/olafurpg/sbt-ci-release
Project Organization

Project Organization

org.scalameta
Source Code Management

Source Code Management

https://github.com/scalameta/ascii-graphs

Download ascii-graphs_2.13

How to add to project

<!-- https://jarcasting.com/artifacts/org.scalameta/ascii-graphs_2.13/ -->
<dependency>
    <groupId>org.scalameta</groupId>
    <artifactId>ascii-graphs_2.13</artifactId>
    <version>0.1.2</version>
</dependency>
// https://jarcasting.com/artifacts/org.scalameta/ascii-graphs_2.13/
implementation 'org.scalameta:ascii-graphs_2.13:0.1.2'
// https://jarcasting.com/artifacts/org.scalameta/ascii-graphs_2.13/
implementation ("org.scalameta:ascii-graphs_2.13:0.1.2")
'org.scalameta:ascii-graphs_2.13:jar:0.1.2'
<dependency org="org.scalameta" name="ascii-graphs_2.13" rev="0.1.2">
  <artifact name="ascii-graphs_2.13" type="jar" />
</dependency>
@Grapes(
@Grab(group='org.scalameta', module='ascii-graphs_2.13', version='0.1.2')
)
libraryDependencies += "org.scalameta" % "ascii-graphs_2.13" % "0.1.2"
[org.scalameta/ascii-graphs_2.13 "0.1.2"]

Dependencies

compile (1)

Group / Artifact Type Version
org.scala-lang : scala-library jar 2.13.5

test (2)

Group / Artifact Type Version
org.scalatest : scalatest_2.13 jar 3.0.9
org.scalacheck : scalacheck_2.13 jar 1.14.3

Project Modules

There are no modules declared in this project.

NOTE: This is a fork of https://github.com/mdr/ascii-graphs that has been updated to support Scala 2.12 and 2.13.

An ASCII-art diagram library for graphs. It supports both parsing existing diagrams and rendering graphs out as an ASCII diagram.

You can use it via sbt:

// Scala 2.13 and Scala 2.12 are supported.
libraryDependencies += "org.scalameta" %% "ascii-graphs" % "0.1.2"

Graph layout

import org.scalameta.ascii.layout._

val graph = Graph(
  vertices = List(
    "V1", "V2", "V3", "V4", "V5", "V6", "V7"),
  edges = List(
    "V1" -> "V2",
    "V7" -> "V1",
    "V1" -> "V3",
    "V1" -> "V4",
    "V2" -> "V5",
    "V2" -> "V6"))

val ascii = Layouter.renderGraph(graph)

println(ascii)

This would produce:

         +---+         
         |V7 |         
         +---+         
           |           
           v           
       +-------+       
       |  V1   |       
       +-------+       
         |  ||         
     -----  |--------  
     |      ---     |  
     v        |     |  
  +-----+     |     |  
  | V2  |     |     |  
  +-----+     |     |  
    | |       |     |  
  --- ---     |     |  
  |     |     |     |  
  v     v     v     v  
+---+ +---+ +---+ +---+
|V5 | |V6 | |V4 | |V3 |
+---+ +---+ +---+ +---+

Layout is Sugiyama-style layered graph drawing, and supports multi-edges, cycles, and vertex labels, but not self-loops or edge labels.

Other ASCII layout libraries

Graph parser

The graph parser is intended for constructing test DSLs, particularly for data which would be much more comprehensible in ASCII art than constructed through regular programming language expressions. For example, directed graphs, trees, 2D games, object graphs, and so on.

Typical usage is to parse the diagram into Diagram/Box/Edge objects, and then convert those objects into whatever your specific test data happens to be.

Syntax

Boxes

A Box is drawn as follows:

+------+
|      |
|      |
|      |
+------+

It can contain text:

+---------------+
|The quick brown|
|fox jumps over |
|the lazy dog.  |
+---------------+

Or other boxes:

+-----+
|+---+|
||+-+||
||| |||
||+-+||
|+---+|
+-----+

Edges

An Edge connects two boxes:

+-----+
|     |
|     |---------
|     |        |
+-----+        |
   |           |
   |           |
+-----+     +-----+
|     |     |     |
|     |-----|     |
|     |     |     |
+-----+     +-----+

Edges can have an arrow at either or both ends:

+-----+
|     |
|     |---------
|     |        |
+-----+        |
   ^           |
   |           v
+-----+     +-----+
|     |     |     |
|     |<--->|     |
|     |     |     |
+-----+     +-----+

You can connect a child box to its parent:

+--------------+
|              |
|   +-----+    |
|   |     |    |
|   |     |----|
|   +-----+    |
|              |
+--------------+   

Edges can cross using a +:

         +-----+
         |     |
         |     |
         |     |
         +-----+
            |
+-----+     |     +-----+
|     |     |     |     |
|     |-----+---->|     |
|     |     |     |     |
+-----+     |     +-----+
            v
         +-----+
         |     |
         |     |
         |     |
         +-----+    

Labels

Edges can have an associated label:

+-----+
|     |
|     |
|     |
+-----+
   |
   |[label]
   |
+-----+         +-----+
|     | [label] |     |
|     |---------|     |
|     |         |     |
+-----+         +-----+

The label's [ or ] bracket must be adjacent (horizontally or vertically) to part of the edge.

Usage

import org.scalameta.ascii._

val diagram = Diagram("""
             +-+             
    ---------|E|----------   
    |        +-+         |   
 [9]|                 [6]|   
    |                    |   
   +-+  [2]  +-+  [11]  +-+  
   |F|-------|C|--------|D|  
   +-+       +-+        +-+  
    |         |          |   
[14]|     [10]|      [15]|   
    |         |          |   
   +-+       +-+         |   
   |A|-------|B|----------   
   +-+  [7]  +-+      """)

// Print all the vertices neighbouring A along with the edge weight:
for {
  box ← diagram.allBoxes.find(_.text == "A")
  (edge, otherBox) ← box.connections()
  label ← edge.label
} println(box + " ==> " + label + " ==> " + otherBox)
org.scalameta
Developer tooling for Scala

Versions

Version
0.1.2