Coder Social home page Coder Social logo

wayoung7 / mono-diagram Goto Github PK

View Code? Open in Web Editor NEW
2.0 1.0 0.0 126 KB

(WIP) A tool for generating plain-text diagrams from a certain syntax

Home Page: https://crates.io/crates/mono-diagram

License: MIT License

Rust 100.00%
ascii-art binary-tree command-line-tool diagram diagram-generator directed-acyclic-graph grid layout table ascii-diagram

mono-diagram's Introduction

███╗   ███╗ ██████╗ ███╗   ██╗ ██████╗       ██████╗ ██╗ █████╗  ██████╗ ██████╗  █████╗ ███╗   ███╗
████╗ ████║██╔═══██╗████╗  ██║██╔═══██╗      ██╔══██╗██║██╔══██╗██╔════╝ ██╔══██╗██╔══██╗████╗ ████║
██╔████╔██║██║   ██║██╔██╗ ██║██║   ██║█████╗██║  ██║██║███████║██║  ███╗██████╔╝███████║██╔████╔██║
██║╚██╔╝██║██║   ██║██║╚██╗██║██║   ██║╚════╝██║  ██║██║██╔══██║██║   ██║██╔══██╗██╔══██║██║╚██╔╝██║
██║ ╚═╝ ██║╚██████╔╝██║ ╚████║╚██████╔╝      ██████╔╝██║██║  ██║╚██████╔╝██║  ██║██║  ██║██║ ╚═╝ ██║
╚═╝     ╚═╝ ╚═════╝ ╚═╝  ╚═══╝ ╚═════╝       ╚═════╝ ╚═╝╚═╝  ╚═╝ ╚═════╝ ╚═╝  ╚═╝╚═╝  ╚═╝╚═╝     ╚═╝
                                                                                    


Mono-Diagram

crates.io License

A cross-platform command line tool for generating plain-text diagrams from a certain syntax. The biggest advantage of plain-text diagrams is that it can fit in anywhere.

Usage

Define diagrams

The basic idea of mono-diagram is to define diagram in a file, and pass it to the program to generate planar diagrams. A file can contain multiple diagrams. Each diagram must start with a tag such as [table] to tell the program what kind of diagram it is.

Binary Tree

Tag: [binary_tree]

Input file:

[binary_tree] {style: ascii}  // Specify diagram category
a->b,c          // Node 'a' has left child 'b' and right child 'c'
b->d,f          // Node name is just like variables
f->fa,fb
c->k,m
k->e,           // Node 'k' only has one left child
m->,x

a:2             // Assign values to node
b:0.42
c:9.5
f:-3
k:abc
m:2             // Different nodes can have same value
d:001
fa:451
fb:8.9
x:1.2

The key-value pair in curly brakets gives attributes to the diagram, every attribute has a default value if you didn't specify. We set style to ascii, but you can also set it to unicode to change the appearance of the diagram.

Output diagram (ascii):

            ___2___
        ___/       \___
     0.42             9.5
    _/   \_         _/   \_
  001     -3      abc      2
          / \     /         \
        451 8.9  e          1.2

Output diagram (unicode):

               2
       ┌───────┴───────┐
     0.42             9.5
   ┌───┴───┐       ┌───┴───┐
  001     -3      abc      2
         ┌─┴─┐   ┌─┘       └─┐
        451 8.9  e          1.2

Use binary_tree only if the node value is very simple, because nodes on the bottom line of binary tree can only hold up to 3 characters. For node with complicated value, use dag instead.

Directed Acyclic Graph (DAG)

Tag: [dag]

Input file:

[dag]
a->b    // <NODE-NAME>-><NODE-NAME> represents an edge in the graph
a->c    // The graph cannot have cycles
b->d
c->f
c->g
a->f
d->da
d->db
g->gg
a->gg


a:Home Page     // Assign values
b:Main Section 1
c:Main Section 2
d:Subsection 1
f:Subsection 2
g:Subsection 3
da:Sub-sub
db:Sub-sub
gg:#page#

Output diagram (dag only has unicode version):

 ┌───────────────────────────────────────────────────┐
 │ Home Page                                         │
 └┬─────────────────┬──┬────────────────────────────┬┘
 ┌V───────────────┐ │ ┌V───────────────┐            │
 │ Main Section 1 │ │ │ Main Section 2 │            │
 └┬───────────────┘ │ └┬────────────┬──┘            │
 ┌V─────────────┐ ┌─V──V─────────┐ ┌V─────────────┐ │
 │ Subsection 1 │ │ Subsection 2 │ │ Subsection 3 │ │
 └┬───────────┬─┘ └──────────────┘ └┬─────────────┘ │
 ┌V────────┐ ┌V────────┐ ┌──────────V───────────────V┐
 │ Sub-sub │ │ Sub-sub │ │ #page#                    │
 └─────────┘ └─────────┘ └───────────────────────────┘

Note: this dag graph is not stable, meaning you may get graph with different looking each time

Table

Tag: [table]

Input file:

[table]     // Each column is seperated by '|' and each row is seperated by newline
Base Class Member|Public Inheritance|Protected Inheritance|Private Inheritance
Public|Public|Protected|Private
Protected|Protected|Protected|Private
Private|Hidden|Hidden|Hidden

Output diagram (ascii):

+-------------------+--------------------+-----------------------+---------------------+
| Base Class Member | Public Inheritance | Protected Inheritance | Private Inheritance |
+-------------------+--------------------+-----------------------+---------------------+
| Public            | Public             | Protected             | Private             |
+-------------------+--------------------+-----------------------+---------------------+
| Protected         | Protected          | Protected             | Private             |
+-------------------+--------------------+-----------------------+---------------------+
| Private           | Hidden             | Hidden                | Hidden              |
+-------------------+--------------------+-----------------------+---------------------+

Output diagram (unicode):

┌───────────────────┬────────────────────┬───────────────────────┬─────────────────────┐
│ Base Class Member │ Public Inheritance │ Protected Inheritance │ Private Inheritance │
├───────────────────┼────────────────────┼───────────────────────┼─────────────────────┤
│ Public            │ Public             │ Protected             │ Private             │
├───────────────────┼────────────────────┼───────────────────────┼─────────────────────┤
│ Protected         │ Protected          │ Protected             │ Private             │
├───────────────────┼────────────────────┼───────────────────────┼─────────────────────┤
│ Private           │ Hidden             │ Hidden                │ Hidden              │
└───────────────────┴────────────────────┴───────────────────────┴─────────────────────┘
Grid

Tag: [grid]

Input file:

[grid]

width: 10       // The grid has 10 colums
height: 7       // And 7 rows

1,1:a 
6,2:l           // The cell at column 6, row 2 has content 'l'
3,3:j
10,5:m
2,7:k

Output diagram(ascii):

+---+---+---+---+---+---+---+---+---+---+
| a |   |   |   |   |   |   |   |   |   |
+---+---+---+---+---+---+---+---+---+---+
|   |   |   |   |   | l |   |   |   |   |
+---+---+---+---+---+---+---+---+---+---+
|   |   | j |   |   |   |   |   |   |   |
+---+---+---+---+---+---+---+---+---+---+
|   |   |   |   |   |   |   |   |   |   |
+---+---+---+---+---+---+---+---+---+---+
|   |   |   |   |   |   |   |   |   | m |
+---+---+---+---+---+---+---+---+---+---+
|   |   |   |   |   |   |   |   |   |   |
+---+---+---+---+---+---+---+---+---+---+
|   | k |   |   |   |   |   |   |   |   |
+---+---+---+---+---+---+---+---+---+---+

Output diagram(unicode):

┌───┬───┬───┬───┬───┬───┬───┬───┬───┬───┐
│ a │   │   │   │   │   │   │   │   │   │
├───┼───┼───┼───┼───┼───┼───┼───┼───┼───┤
│   │   │   │   │   │ l │   │   │   │   │
├───┼───┼───┼───┼───┼───┼───┼───┼───┼───┤
│   │   │ j │   │   │   │   │   │   │   │
├───┼───┼───┼───┼───┼───┼───┼───┼───┼───┤
│   │   │   │   │   │   │   │   │   │   │
├───┼───┼───┼───┼───┼───┼───┼───┼───┼───┤
│   │   │   │   │   │   │   │   │   │ m │
├───┼───┼───┼───┼───┼───┼───┼───┼───┼───┤
│   │   │   │   │   │   │   │   │   │   │
├───┼───┼───┼───┼───┼───┼───┼───┼───┼───┤
│   │ k │   │   │   │   │   │   │   │   │
└───┴───┴───┴───┴───┴───┴───┴───┴───┴───┘
Gantt Diagram

Tag: [gantt]

Input file:

[gantt] {style: unicode}

timeline: Week 1|Week 2|Week 3|Week 4|Week 5    // Specify the time line

task 1|   0 ~ 0.6      // Specify the time period of each task
task 2| 0.9 ~ 2.3      // This means task 2 starts at Week 0.9 and ends at Week 2.3 (you know what I mean)
task 3| 2.0 ~ 2.8
task 4| 2.8 ~ 3.5
task 5| 3.5 ~ 5.0

Output diagram(ascii):

        |  Week 1  |  Week 2  |  Week 3  |  Week 4  |  Week 5
--------+----------+----------+----------+----------+-----------
 task 1 |<=====>   .          .          .          .
 task 2 |         <===============>      .          .
 task 3 |          .          .<=======> .          .
 task 4 |          .          .        <=======>    .
 task 5 |          .          .          .     <================>
        |

Output diagram(unicode):

           Week 1     Week 2     Week 3     Week 4     Week 5
────────────────────────────────────────────────────────────────
 task 1 │[━━━━━]   ·          ·          ·          ·
 task 2 │         [━━━━━━━━━━━━━━━]      ·          ·
 task 3 │          ·          ·[━━━━━━━] ·          ·
 task 4 │          ·          ·        [━━━━━━━]    ·
 task 5 │          ·          ·          ·     [━━━━━━━━━━━━━━━━]
        │
Timeline

Tag: [timeline]

Input file:

[timeline] {style: unicode}

2022.06|Some things happened in 2022        // The format is <TIME>|<EVENT>
2023|                                       // Time can have no event
2024.11|Some things that is happening now
2030.01|Some things that will happen in the future

Output diagram(ascii):

    |
    |
    |
----v----
 2022.06  >--- Some things happened in 2022
----v----
    |
 ---v---
   2023
 ---v---
    |
----v----
 2024.11  >--- Some things that is happening now
----v----
    |
----v----
 2030.01  >--- Some things that will happen in the future
----v----
    |
    |
    |
    V

Output diagram(unicode):

    ║
    ║
    ║
    ╨
 2022.06  ┄┄┄┄ Some things happened in 2022
    ╥
    ║
    ╨
   2023
    ╥
    ║
    ╨
 2024.11  ┄┄┄┄ Some things that is happening now
    ╥
    ║
    ╨
 2030.01  ┄┄┄┄ Some things that will happen in the future
    ╥
    ║
    ║
    ║
    ▼

Attributes

Attributes are used to give diagram styled looking. The format is:

[<DIAGRAM TAG>] {<KEY1: VALUE1>, <KEY2: VALUE2>, ...}
...

All attributs:

  • style: ascii / unicode

Currently, Attrib only contain style, but more will be added in the future.

Command Line Arguments

Usage: mono-diagram [OPTIONS] <FILE_PATH>

Arguments:
  <FILE_PATH>
          The path to the input file

Options:
  -p, --prefix <PREFIX>
          Add a prefix to each line in the output

          This is useful when you want to paste the diagram to code comments

  -c, --copy
          Copy the output to your computer clipboard

  -h, --help
          Print help (see a summary with '-h')

  -V, --version
          Print version

Example commands

Parse the file examples/test, and output with prefix '# ', then copy to clipboard:

mono-diagram examples/test -c -p "# " 

Examples

You can find some sample input files in examples/ in the project directory.

Installation

Please first install rust.

Then, simply run the following commands:

cargo install mono-diagram

TODO

  1. Node in dag can be a table. This enables you to draw class diagram
  2. Improve edge drawing in dag
  3. Add plain-text Venn diagram
  4. Add plain-text sequence diagram
  5. Make more flexible table with cells spanning multiple rows and columns

Contribution and Help

Any contribution is welcome, even just ideas.

Feel free to open an issue or contact me if you find any bugs.

mono-diagram's People

Contributors

wayoung7 avatar

Stargazers

Walid Amro avatar  avatar

Watchers

 avatar

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.