Skip to content
/ dot Public

a lightweight, pure golang graphviz-compatible dot language implementation

License

Notifications You must be signed in to change notification settings

wwmoraes/dot

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

dot

a lightweight, pure golang graphviz-compatible dot language implementation

Status GitHub tag (latest SemVer) GitHub Issues GitHub Pull Requests License

Go Report Card GoDoc

Quality Gate Status Reliability Rating Bugs Security Rating Vulnerabilities

Maintainability Rating Coverage Code Smells Technical Debt

πŸ“ Table of Contents

🧐 About

WARNING: this package is a WIP and will introduce breaking changes while on major version zero.

Dot provides interfaces and ready-to-use concrete types to create graphviz-compatible graphs using its dot language.

This package was inspired/initially forked from emicklei/dot, but has too many breaking changes compared to the original - namely interface usage and other distinct design decisions - that I decided to maintain it separately. If you need a simpler, no-brainy option, use emicklei's dot package.

🏁 Getting Started

Clone the repository and then run make to build, test, generate coverage and lint the code.

Prerequisites

Golang 1.12+ and ideally a modules-enabled application. Dot has no dependencies.

🎈 Usage

Add it to your modules with

go get -u github.com/wwmoraes/dot

And then:

package main

import (
  "os"
  "github.com/wwmoraes/dot"
)

func main() {
  graph := dot.New()
  graph.SetAttributeString("label", "an amazing graph")
  clusterA := graph.Subgraph(WithID("Cluster A"), WithCluster())
  clusterA.SetAttributeString("label", "Cluster A")
  clusterB := graph.Subgraph(WithID("Cluster B"), WithCluster())
  clusterB.SetAttributeString("label", "Cluster B")

  clusterA.
    Node("one").
    Edge(clusterA.Node("two")).
    Edge(clusterB.Node("three")).
    Edge(graph.Node("Outside")).
    Edge(clusterB.Node("four")).
    Edge(clusterA.Node("one"))

  fd, _ := os.Create("sample.dot")
  graph.WriteTo(fd)
}

The constants sub-package has all supported keys defined as variables, and can be used instead of plain strings to avoid both duplication and errors:

package main

import (
  "os"
  "github.com/wwmoraes/dot"
  "github.com/wwmoraes/dot/constants"
)

func main() {
  graph := dot.New()
  graph.SetAttributeString(constants.KeyLabel, "a graph")
  node := graph.Node("n1")
  node.SetAttributeString(constants.KeyLabel, "a node")
  edge := graph.Edge(graph.Node("n2"), graph.Node("n3"))
  edge.SetAttributeString(constants.KeyLabel, "a edge")

  fd, _ := os.Create("sample.dot")
  graph.WriteTo(fd)
}

You can also set literals and HTML values using the helper functions:

package main

import (
  "os"
  "github.com/wwmoraes/dot"
  "github.com/wwmoraes/dot/constants"
)

func main() {
  graph := dot.New()
  graph.Node("n1").SetAttributeLiteral(constants.KeyLabel, `a left label\l`)
  graph.Node("n2").SetAttributeHTML(constants.KeyLabel, `<b>a bold label</b>`)
  fd, _ := os.Create("sample.dot")
  graph.WriteTo(fd)
}

✍️ Authors

πŸŽ‰ Acknowledgements