Coder Social home page Coder Social logo

sambrightman / asciidag Goto Github PK

View Code? Open in Web Editor NEW
27.0 3.0 7.0 190 KB

Draw DAGs (directed acyclic graphs) as ASCII art, à la Git

License: GNU General Public License v2.0

Python 100.00%
python python2 python3 ascii ascii-art gitgraph tree dag directed-acyclic-graph

asciidag's Introduction

asciidag - draw DAGs as ASCII art

Travis CI status AppVeyor CI status Coveralls coverage Codecov coverage PyPI version PyPI wheel

Overview

This is a direct port of the Git log graphing code, which draws directed acyclic commit graphs as ASCII art. It was done very mechanically and quickly, so the code is not Pythonic. Dependencies on Git specifics should be gone but look and feel remains.

This project is alpha quality and subject to breaking API changes.

Note

💡 If you are thinking about doing a large refactoring, please submit an issue for discussion first; I consider it potentially worthwhile to stay close to the Git source.

Installation

Available for install/upgrade from PyPI:

pip install -U asciidag

As usual, it is best to install your packages into a virtual environment.

Usage

examples/demo.py is included in the installation directory and is executable. The core functionality is:

from asciidag.graph import Graph
from asciidag.node import Node

graph = Graph()

root = Node('root')
grandpa = Node('grandpa', parents=[root])
tips = [
    Node('child', parents=[
        Node('mom', parents=[
            Node('grandma', parents=[
                Node('greatgrandma', parents=[]),
            ]),
            grandpa,
        ]),
        Node('dad', parents=[
            Node('bill', parents=[
                Node('martin'),
                Node('james'),
                Node('paul'),
                Node('jon'),
            ])]),
        Node('stepdad', parents=[grandpa]),
    ]),
    Node('foo', [Node('bar')]),
]

graph.show_nodes(tips)

Output:

Demonstration screenshot

copyright:© 2016 Sam Brightman
license:GNU General Public License v2.0, see LICENSE for more details.

asciidag's People

Contributors

matthiasdiener avatar sambrightman avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

asciidag's Issues

Clarify simple linear dag

A simple linear dag has a slightly confusing output like this:

step_1
step_2
step_3
step_4

Which maybe someone wouldn't realize is a dag at first glance (without context). I thought maybe it would be nice to have pipes to indicate that there is still a transition like:

step_1
|
step_2
|
step_3
|
step_4

I started to look into this change, but I thought that maybe this was inconsistent with the goal of reaching 1-1 parity with the git dag output. If so feel go ahead and close this one.

graph cause asciidag break

When I run this code, an error occurred.

from asciidag.graph import Graph
from asciidag.node import Node

graph = Graph()

nodeA = Node('A', parents=[])
nodeB = Node('B', parents=[])
nodeC = Node('C', parents=[])
nodeD = Node('D', parents=[nodeA, nodeB, nodeC])

tips = [
    Node('E',
         parents=[
             Node('F', parents=[nodeC, nodeD]),
             Node('G', parents=[Node('H', parents=[nodeD]), nodeD])
         ])
]

graph.show_nodes(tips)

This is the log.

WeChat573717b395e1376afa67889a9e41d931

Sometimes "asciidag" may succeed, which will print the right graph.

WeChat58d8bdeda6a15fbbad1fdaea2fcc4959

I have tested on python3.5.2, and it will pass when first run but failed afterward. I never success on python 3.9.2.

Tests need improving

Two of the three tests are being skipped because tree evaluation order looks wrong.

Other tests from Git's t/t6016-rev-list-graph-simplify-history.sh should be converted and added.

Direct acyclic graph fails to render

The following graph seems to break:

n1 = Node('N1')
n2 = Node('N2')
n3 = Node('N3')
n4 = Node('N4')
n5 = Node('N5')
n6 = Node('N6')
n7 = Node('N7')
n8 = Node('N8')
n9 = Node('N9')
n10 = Node('N10')
n11 = Node('N11')
n12 = Node('N12')
n13 = Node('N13')
n14 = Node('N14')
n15 = Node('N15')
n16 = Node('N16')
n17 = Node('N17')
n18 = Node('N18')
n19 = Node('N19')
n20 = Node('N20')
n21 = Node('N21')
n22 = Node('N22')
n23 = Node('N23')
n24 = Node('N24')
n25 = Node('N25')
n26 = Node('N26')
n27 = Node('N27', parents=[n1, n2, n3, n4, n5, n6, n7, n8, n9, n10, n11, n12, n13, n14, n15, n16, n17, n18, n19, n20, n21, n22, n23, n24, n25, n26])
n28 = Node('N28', parents=[n27])
n29 = Node('N29', parents=[n27])
n30 = Node('N30', parents=[n28, n29])
n31 = Node('N31', parents=[n30])
n32 = Node('N32', parents=[n31])
n33 = Node('N33', parents=[n32, n31])
n34 = Node('N34', parents=[n30])
n35 = Node('N35', parents=[n34])
n36 = Node('N36', parents=[n35, n34])
n37 = Node('N37', parents=[n30])
n38 = Node('N38', parents=[n37])
n39 = Node('N39', parents=[n38, n37])
n40 = Node('N40', parents=[n1, n2, n3, n4, n5, n6, n7, n8, n9, n10, n11, n12, n13, n14, n15, n16, n17, n18, n19, n20, n21, n22, n23, n24, n25, n26, n33, n36, n39])
n41 = Node('N41', parents=[n40, n27])
graph = Graph()
graph.show_nodes([n41])

whereas GrapViz suggests that this is still a DAG:

digraph {N1;N2;N3;N4;N5;N6;N7;N8;N9;N10;N11;N12;N13;N14;N15;N16;N17;N18;N19;N20;N21;N22;N23;N24;N25;N26;N27;N28;N29;N30;N31;N32;N33;N34;N35;N36;N37;N38;N39;N40;N41;N1 -> N27;N2 -> N27;N3 -> N27;N4 -> N27;N5 -> N27;N6 -> N27;N7 -> N27;N8 -> N27;N9 -> N27;N10 -> N27;N11 -> N27;N12 -> N27;N13 -> N27;N14 -> N27;N15 -> N27;N16 -> N27;N17 -> N27;N18 -> N27;N19 -> N27;N20 -> N27;N21 -> N27;N22 -> N27;N23 -> N27;N24 -> N27;N25 -> N27;N26 -> N27;N27 -> N28;N27 -> N29;N28 -> N30;N29 -> N30;N30 -> N31;N31 -> N32;N32 -> N33;N31 -> N33;N30 -> N34;N34 -> N35;N35 -> N36;N34 -> N36;N30 -> N37;N37 -> N38;N38 -> N39;N37 -> N39;N1 -> N40;N2 -> N40;N3 -> N40;N4 -> N40;N5 -> N40;N6 -> N40;N7 -> N40;N8 -> N40;N9 -> N40;N10 -> N40;N11 -> N40;N12 -> N40;N13 -> N40;N14 -> N40;N15 -> N40;N16 -> N40;N17 -> N40;N18 -> N40;N19 -> N40;N20 -> N40;N21 -> N40;N22 -> N40;N23 -> N40;N24 -> N40;N25 -> N40;N26 -> N40;N33 -> N40;N36 -> N40;N39 -> N40;N40 -> N41;N27 -> N41;}

(can be vizualized here: https://dreampuf.github.io/GraphvizOnline/#digraph%20%7BN1%3BN2%3BN3%3BN4%3BN5%3BN6%3BN7%3BN8%3BN9%3BN10%3BN11%3BN12%3BN13%3BN14%3BN15%3BN16%3BN17%3BN18%3BN19%3BN20%3BN21%3BN22%3BN23%3BN24%3BN25%3BN26%3BN27%3BN28%3BN29%3BN30%3BN31%3BN32%3BN33%3BN34%3BN35%3BN36%3BN37%3BN38%3BN39%3BN40%3BN41%3BN1%20-%3E%20N27%3BN2%20-%3E%20N27%3BN3%20-%3E%20N27%3BN4%20-%3E%20N27%3BN5%20-%3E%20N27%3BN6%20-%3E%20N27%3BN7%20-%3E%20N27%3BN8%20-%3E%20N27%3BN9%20-%3E%20N27%3BN10%20-%3E%20N27%3BN11%20-%3E%20N27%3BN12%20-%3E%20N27%3BN13%20-%3E%20N27%3BN14%20-%3E%20N27%3BN15%20-%3E%20N27%3BN16%20-%3E%20N27%3BN17%20-%3E%20N27%3BN18%20-%3E%20N27%3BN19%20-%3E%20N27%3BN20%20-%3E%20N27%3BN21%20-%3E%20N27%3BN22%20-%3E%20N27%3BN23%20-%3E%20N27%3BN24%20-%3E%20N27%3BN25%20-%3E%20N27%3BN26%20-%3E%20N27%3BN27%20-%3E%20N28%3BN27%20-%3E%20N29%3BN28%20-%3E%20N30%3BN29%20-%3E%20N30%3BN30%20-%3E%20N31%3BN31%20-%3E%20N32%3BN32%20-%3E%20N33%3BN31%20-%3E%20N33%3BN30%20-%3E%20N34%3BN34%20-%3E%20N35%3BN35%20-%3E%20N36%3BN34%20-%3E%20N36%3BN30%20-%3E%20N37%3BN37%20-%3E%20N38%3BN38%20-%3E%20N39%3BN37%20-%3E%20N39%3BN1%20-%3E%20N40%3BN2%20-%3E%20N40%3BN3%20-%3E%20N40%3BN4%20-%3E%20N40%3BN5%20-%3E%20N40%3BN6%20-%3E%20N40%3BN7%20-%3E%20N40%3BN8%20-%3E%20N40%3BN9%20-%3E%20N40%3BN10%20-%3E%20N40%3BN11%20-%3E%20N40%3BN12%20-%3E%20N40%3BN13%20-%3E%20N40%3BN14%20-%3E%20N40%3BN15%20-%3E%20N40%3BN16%20-%3E%20N40%3BN17%20-%3E%20N40%3BN18%20-%3E%20N40%3BN19%20-%3E%20N40%3BN20%20-%3E%20N40%3BN21%20-%3E%20N40%3BN22%20-%3E%20N40%3BN23%20-%3E%20N40%3BN24%20-%3E%20N40%3BN25%20-%3E%20N40%3BN26%20-%3E%20N40%3BN33%20-%3E%20N40%3BN36%20-%3E%20N40%3BN39%20-%3E%20N40%3BN40%20-%3E%20N41%3BN27%20-%3E%20N41%3B%7D )

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.