Code Monkey home page Code Monkey logo

dot's Introduction

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

dot's People

Contributors

drewrip avatar emicklei avatar gitgabz avatar luksa avatar matfax avatar wwmoraes avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

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