Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion taskflow.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package gotaskflow

import "io"
import (
"io"
)

// TaskFlow represents a series of tasks
type TaskFlow struct {
Expand Down
1 change: 0 additions & 1 deletion taskflow_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,6 @@ func TestTaskFlow(t *testing.T) {
chains := newRgChain[string]()
chains.grouping("C1", "A1", "B1", "A", "C")
chains.grouping("B")

A.Precede(B)
C.Precede(B)
A1.Precede(B)
Expand Down
60 changes: 30 additions & 30 deletions visualizer_dot.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,57 +8,57 @@ import (

type dotVizer struct{}

// DotGraph represents a graph in DOT format
type DotGraph struct {
// dotGraph represents a graph in DOT format
type dotGraph struct {
name string
isSubgraph bool
nodes map[string]*DotNode
edges []*DotEdge
nodes map[string]*dotNode
edges []*dotEdge
attributes map[string]string
subgraphs []*DotGraph
subgraphs []*dotGraph
indent string
}

// DotNode represents a node in DOT format
type DotNode struct {
// dotNode represents a node in DOT format
type dotNode struct {
id string
attributes map[string]string
}

// DotEdge represents an edge in DOT format
type DotEdge struct {
from *DotNode
to *DotNode
// dotEdge represents an edge in DOT format
type dotEdge struct {
from *dotNode
to *dotNode
attributes map[string]string
}

func newDotGraph(name string) *DotGraph {
return &DotGraph{
func newDotGraph(name string) *dotGraph {
return &dotGraph{
name: name,
isSubgraph: false,
nodes: make(map[string]*DotNode),
edges: make([]*DotEdge, 0),
nodes: make(map[string]*dotNode),
edges: make([]*dotEdge, 0),
attributes: make(map[string]string),
subgraphs: make([]*DotGraph, 0),
subgraphs: make([]*dotGraph, 0),
indent: "",
}
}

func (g *DotGraph) CreateNode(name string) *DotNode {
func (g *dotGraph) CreateNode(name string) *dotNode {
if node, exists := g.nodes[name]; exists {
return node
}

node := &DotNode{
node := &dotNode{
id: name,
attributes: make(map[string]string),
}
g.nodes[name] = node
return node
}

func (g *DotGraph) CreateEdge(from, to *DotNode, label string) *DotEdge {
edge := &DotEdge{
func (g *dotGraph) CreateEdge(from, to *dotNode, label string) *dotEdge {
edge := &dotEdge{
from: from,
to: to,
attributes: make(map[string]string),
Expand All @@ -70,21 +70,21 @@ func (g *DotGraph) CreateEdge(from, to *DotNode, label string) *DotEdge {
return edge
}

func (g *DotGraph) SubGraph(name string) *DotGraph {
subgraph := &DotGraph{
func (g *dotGraph) SubGraph(name string) *dotGraph {
subgraph := &dotGraph{
name: name,
isSubgraph: true,
nodes: make(map[string]*DotNode),
edges: make([]*DotEdge, 0),
nodes: make(map[string]*dotNode),
edges: make([]*dotEdge, 0),
attributes: make(map[string]string),
subgraphs: make([]*DotGraph, 0),
subgraphs: make([]*dotGraph, 0),
indent: g.indent + " ",
}
g.subgraphs = append(g.subgraphs, subgraph)
return subgraph
}

func (g *DotGraph) String() string {
func (g *dotGraph) String() string {
var sb strings.Builder

if g.isSubgraph {
Expand Down Expand Up @@ -113,7 +113,7 @@ func (g *DotGraph) String() string {
return sb.String()
}

func (node *DotNode) Format(indent string) string {
func (node *dotNode) Format(indent string) string {
attrs := formatAttributes(node.attributes)

if attrs == "" {
Expand All @@ -123,7 +123,7 @@ func (node *DotNode) Format(indent string) string {
return indent + quote(node.id) + " [" + attrs + "];\n"
}

func (edge *DotEdge) Format(indent string) string {
func (edge *dotEdge) Format(indent string) string {
from := edge.from.id
to := edge.to.id

Expand Down Expand Up @@ -153,11 +153,11 @@ func formatAttributes(attrs map[string]string) string {
}

// visualizeG recursively visualizes the graph and its subgraphs in DOT format
func (v *dotVizer) visualizeG(g *eGraph, parentGraph *DotGraph) error {
func (v *dotVizer) visualizeG(g *eGraph, parentGraph *dotGraph) error {
graph := parentGraph
graph.attributes["rankdir"] = "LR"

nodeMap := make(map[string]*DotNode)
nodeMap := make(map[string]*dotNode)

for _, node := range g.nodes {
color := "black"
Expand Down
8 changes: 4 additions & 4 deletions visualizer_dot_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,7 @@ func TestDotVizer_VisualizeComplex(t *testing.T) {
}

func TestDotNode_Format(t *testing.T) {
node := &DotNode{
node := &dotNode{
id: "test_node",
attributes: make(map[string]string),
}
Expand All @@ -179,10 +179,10 @@ func TestDotNode_Format(t *testing.T) {
}

func TestDotEdge_Format(t *testing.T) {
from := &DotNode{id: "from"}
to := &DotNode{id: "to"}
from := &dotNode{id: "from"}
to := &dotNode{id: "to"}

edge := &DotEdge{
edge := &dotEdge{
from: from,
to: to,
attributes: make(map[string]string),
Expand Down