Skip to content

Commit

Permalink
chore: add sample application and vscode launch config
Browse files Browse the repository at this point in the history
  • Loading branch information
wwmoraes committed Nov 11, 2020
1 parent b74dc9b commit 804f28b
Show file tree
Hide file tree
Showing 3 changed files with 73 additions and 0 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
/*.png
.idea

**/sample.dot

# SonarQube
.scannerwork/

Expand Down
14 changes: 14 additions & 0 deletions .vscode/launch.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
{
"version": "0.2.0",
"configurations": [
{
"name": "Launch",
"type": "go",
"request": "launch",
"mode": "auto",
"program": "${workspaceFolder}/doc/sample.go",
"env": {},
"args": []
}
]
}
57 changes: 57 additions & 0 deletions doc/sample.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
package main

import (
"log"
"os"

"github.com/wwmoraes/dot"
"github.com/wwmoraes/dot/attributes"
)

func main() {
log.Println("creating graph instance...")
rootGraph := dot.NewGraph(nil)

log.Println("creating outside node...")
outsideGraph := rootGraph.Node("Outside")

log.Println("creating cluster subgraph A...")
clusterA := rootGraph.Subgraph(&dot.GraphOptions{
ID: "A",
Cluster: true,
})
clusterA.SetAttributeString(attributes.KeyLabel, "Cluster A")

log.Println("creating node one...")
insideOne := clusterA.Node("one")

log.Println("creating node two...")
insideTwo := clusterA.Node("two")

log.Println("creating cluster subgraph B...")
clusterB := rootGraph.Subgraph(&dot.GraphOptions{
ID: "B",
Cluster: true,
})
clusterB.SetAttributeString(attributes.KeyLabel, "Cluster B")

log.Println("creating node three...")
insideThree := clusterB.Node("three")

log.Println("creating node four...")
insideFour := clusterB.Node("four")

log.Println("creating edges...")
outsideGraph.Edge(insideFour).Edge(insideOne).Edge(insideTwo).Edge(insideThree).Edge(outsideGraph)

log.Println("opening sample.dot file for write...")
fd, err := os.Create("sample.dot")
if err != nil {
log.Fatalln(err)
}

log.Println("writing graph to sample.dot...")
rootGraph.Write(fd)

log.Println("done!")
}

0 comments on commit 804f28b

Please sign in to comment.