Coder Social home page Coder Social logo

go-diagrams's Introduction

Go-Diagrams

Fast and easy application diagrams

Go-Diagrams is a loose port of diagrams.

Contents

Features

Turn this:

d, err := diagram.New(diagram.Filename("app"), diagram.Label("App"), diagram.Direction("LR"))
if err != nil {
    log.Fatal(err)
}

dns := gcp.Network.Dns(diagram.NodeLabel("DNS"))
lb := gcp.Network.LoadBalancing(diagram.NodeLabel("NLB"))
cache := gcp.Database.Memorystore(diagram.NodeLabel("Cache"))
db := gcp.Database.Sql(diagram.NodeLabel("Database"))

dc := diagram.NewGroup("GCP")
dc.NewGroup("services").
    Label("Service Layer").
    Add(
        gcp.Compute.ComputeEngine(diagram.NodeLabel("Server 1")),
        gcp.Compute.ComputeEngine(diagram.NodeLabel("Server 2")),
        gcp.Compute.ComputeEngine(diagram.NodeLabel("Server 3")),
    ).
    ConnectAllFrom(lb.ID(), diagram.Forward()).
    ConnectAllTo(cache.ID(), diagram.Forward())

dc.NewGroup("data").Label("Data Layer").Add(cache, db).Connect(cache, db)

d.Connect(dns, lb, diagram.Forward()).Group(dc)

if err := d.Render(); err != nil {
    log.Fatal(err)
}

Into this:

app-diagram

Usage

go get github.com/blushft/go-diagrams

Create a diagram:

d, err := diagram.New(diagram.Label("my-diagram"), diagram.Filename("diagram"))
if err != nil {
    log.Fatal(err)
}

fw := generic.Network.Firewall().Label("fw")
sw := generic.Network.Switch().Label("sw")

d.Connect(fw, sw)

Render the output:

if err := d.Render(); err != nil {
    log.Fatal(err)
}

Go-Diagrams will create a folder in the current working directory with the graphviz DOT file and any image assets.

Create an ouput image with any graphviz compatible renderer:

dot -Tpng diagram.dot > diagram.png

go-diagrams's People

Contributors

alekser avatar kdungs avatar mstryoda avatar tntobias 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  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  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  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 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  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

go-diagrams's Issues

Support rank same

I think this would require supporting newrank="true" as a valid DiagramOption and support rank="same" on subgraphs.

It might also be nice to support contraint=false as an EdgeOption

Question about license of images

Hi,

Thank you for your code! The code is under the MIT license, but I have noticed a sizable number of image assets that cover logos of various brands and entities, e.g. nginx, various clouds, languages, etc. What is the source of the images?

Still active?

Hello,

I would kindly ask, if this repo is still maintained and kept up-to-date with features from diagrams?

Thank you

Label quote error

Use as label first 8 bytes from SHA1 digest in label and I think that I found some escape problem:

        vkhkhzkc [ fixedsize=true, fontcolor="#2D3436", fontname="Sans-Serif", fontsize=13, height=2.1999999999999997, image="assets/gcp/database/sql.png", imagescale=true, label="2822b7f1...", labelloc=b, shape=none, style=rounded, width=1.4 ];
        xnxdisdb [ fixedsize=true, fontcolor="#2D3436", fontname="Sans-Serif", fontsize=13, height=2.1999999999999997, image="assets/gcp/database/sql.png", imagescale=true, label=ca20af73..., labelloc=b, shape=none, style=rounded, width=1.4 ];

Look like label label=ca20af73... sounds like string is't escape properly by go-diagrams.

As result cath an error in dot processing:

Error: diagram.dot: syntax error in line 30 near '.'

Customize arrows

Thanks for this nice port!

If I checked the code correctly something like adding a label text to an arrow is not implemented yet, correct?
I'm thinking about something like mingrammer/diagrams#54, implemented in mingrammer/diagrams#48.

What would be required to add this to this port?

### Hi there

{
  "type": "FeatureCollection",
  "features": [
    {
      "type": "Feature",
      "id": 1,
      "properties": {
        "ID": 0
      },
      "geometry": {
        "type": "Polygon",
        "coordinates": [
          [
              [-90,35],
              [-90,30],
              [-85,30],
              [-85,35],
              [-90,35]
          ]
        ]
      }
    }
  ]
}

``` topojson 
{ 
  "type": "Topology", 
  "transform": { 
    "scale": [0.0005000500050005, 0.00010001000100010001], 
    "translate": [100, 0] 
  }, 
  "objects": { 
    "example": { 
      " type": "GeometryCollection", 
      "geometries": [ 
        { 
          "type": "Point", 
          "properties": {"prop0": "value0"}, 
          "coordinates": [4000, 5000] 
        }, 
        { 
          "type" : "LineString", 
          "คุณสมบัติ": {"prop0":"value0", "prop1": 0}, 
          "arcs": [0] 
        }, 
        { 
          "type": "Polygon",
          "คุณสมบัติ": {"prop0": "value0", 
            "prop1": {"นี้": "นั่น"} 
          }, 
          "ส่วนโค้ง": [[1]] } 
        ] 
      } 
    } 
  , 
  "ส่วนโค้ง": [[[4000 , 0], [1999, 9999], [2000, -9999], [2000, 9999]],[[0, 0], [0, 9999], [2000, 0], [0, -9999], [-2000, 0]]] 
} 
Loading
solid cube_corner 
  facet ปกติ 0.0 -1.0 0.0 จุดยอด 
    วงรอบนอก
      0.0 0.0 0.0 
      จุดยอด 1.0 0.0 0.0 
      จุดยอด 0.0 0.0 1.0 
    endloop 
  endfacet 
  facet ปกติ 0.0 0.0 -1.0 จุด ยอดวง 
    รอบนอก 0.0 0.0 0.0 
      จุดยอด 0.0 
      1.0 0.0 
      จุดยอด 1.0 0.0 0.0 
    endloop 
  endfacet 
  facet ปกติ -1.0 0.0 0.0 จุดยอด 
    วงรอบนอก
      0.0 0.0 0.0 
      จุดยอด 0.0 0.0 1.0 จุด ยอด 0.0 1.0 
      0.0 
    endloop 
  endfacet 
  facet ปกติ 0.577 0.577 0.577 
    จุดยอดวงรอบนอก
      1.0 0.0 0.0
      จุดสุดยอด 0.0 1.0 0.0 
      จุดยอด 0.0 0.0 1.0 
    endloop 
  endfacet 
endsolid 
Loading

node render does not support custom images

Small usability issue. I'm attempting to render a diagram that uses the GCP Pubsub icon (which the asset package does not appear to have).
pubsub

I thought I might be able to diagram.NewNode(diagram.Icon("pubsub.png")).Label("QueueName") but I noticed that node render expects the image path to be in the asset box. Would it be possible to fall back to local disk? Or maybe better yet provide a NodeOption like CustomImage to support custom icons?

Connect some to few

Hi guys!
All saw the examples and all of them use all to all on connect function.
It is possible to create like a tree structure?
example:

image

Render method errors on subsequent runs (file exists)

When running a go-diagram more then once, the Render method errors with the following message:

mkdir go-diagrams: file exists

Ideally Render supports the option to overwrite the dot file in the go-diagrams directory.

Thank you for creating this library!

Hi. I'm a creator of Diagrams :)

I recently discovered this library and I'm happy that someone ported my Diagrams to my favorite language, Go. Thanks for your efforts!! 👍

I'd like to link this library in the Diagrams readme!

differ from diagrams

Go-Diagrams is a loose port of diagram, is there a compare table to show what go-diagrams miss?

Default labels for groups and nodes

Hello there,

first of all thanks a lot for this library. :)

tl;dr: i've found issues with the default labels for groups and prepared a corresponding PR.

When trying it out, I found some issues with default labels, that can cause problems for newcomers especially if they don't know anything about graphviz.

The default label for a group is the empty string. When rendered, it produces label=; which to graphviz is a syntax error. So, in order to produce a valid graph, at least the diagram.Label option is needed, as far as I see it. If I'm not mistaken, this could be fixed by adding a call to trimAttrs here: https://github.com/blushft/go-diagrams/blob/master/diagram/options.go#L39

d, err := diagram.New(
	diagram.Label("TEST"),
)

The default label for a node is "node". This is a reserved keyword in graphviz and when left unescaped causes problems. Since graphviz has logic for automatically labelling nodes, I would suggest using empty string here, as well and letting graphviz set the label. The alternative would be something like "\"node\"" which doesn't feel right to me. But feel free to suggest that on the PR if you see it differently.

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.