dotx

package
v1.6.2 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Apr 15, 2024 License: MIT Imports: 5 Imported by: 0

README

dotx package (dot extensions)

This package contains utilities to create graphs on top of the emicklei/dot package.

Composite

The Composite type can be used to create composition hierarchies like clustering.

Let's examine this diagram.

On the most right, you find a node called subsystem which is a Composite with 2 inputs and 1 output edge.

On the most left, you see the contents of the same subsystem with both inputs and an output (point shaped with label on edge).

The subsystem contains other nodes, 2 regular nodes (subcomponent 1 and subcomponent 2) and another Composite labeled subsystem2.

So, subsystem is a composition of 3 components and 1 of these components is itself a composition of a component (subcomponent 3).

external option

If you create a Composite using the ExternalGraph kind then its graph is exported separately from the containing graph. If you visualize such a graph using SVG then you can nagivate into the subsystems.

And clicking on subsystem, your browse will show:

And clicking on subsystem2, your browse will show:

See subsystem_test.go for the code of these examples.

usage pattern

import (
    "github.com/emicklei/dot"
    "github.com/emicklei/dot/dotx"
)

func YourService(parent *dot.Graph) *dotx.Composite {
    // external means it exports its own DOT file
    sub := dotx.NewComposite("Your Service", parent, dotx.ExternalGraph)

    // export right after building the inner graph
    return sub.Export(func(g *dot.Graph) {
        
        // build the inner graph of the Composite
        myComp := g.Node("myComp")
        
        // connect any inputs,outputs
        sub.Input("in", myComp)
    })
}

Documentation

Index

Constants

View Source
const (
	// SameGraph means that the composite graph will be a cluster within the graph.
	SameGraph compositeGraphKind = iota
	// ExternalGraph means the composite graph will be exported on its own, linked by the node within the graph
	ExternalGraph
)

Variables

This section is empty.

Functions

This section is empty.

Types

type Composite

type Composite struct {
	*dot.Graph
	// contains filtered or unexported fields
}

Composite is a graph and node to create abstractions in graphs.

func NewComposite

func NewComposite(id string, g *dot.Graph, kind compositeGraphKind) *Composite

NewComposite creates a Composite abstraction that is represented as a Node (box3d shape) in the graph. The kind determines whether the graph of the composite is embedded (same graph) or external.

func (*Composite) Attr

func (s *Composite) Attr(label string, value interface{}) dot.Node

Attr sets label=value and returns the Node in the graph

func (*Composite) Export

func (s *Composite) Export(build func(g *dot.Graph)) *Composite

Export writes the DOT file for a Composite after building the content (child) graph using the build function. Use ExportName() on the Composite to modify the filename used. If writing of the file fails then a warning is logged.

func (*Composite) ExportFile

func (s *Composite) ExportFile() error

ExportFile creates a DOT file using the default name (based on name) or overridden using ExportName().

func (*Composite) ExportFilename added in v1.4.1

func (s *Composite) ExportFilename() string

ExportFilename returns the name of the file used by ExportFile. Override it using ExportName.

func (*Composite) ExportName

func (s *Composite) ExportName(name string)

ExportName argument name will be used for the .dot export and the HREF link using svg So if name = "my example" then export will create "my_example.dot" and the link will be "my_example.svg"

func (*Composite) Input

func (s *Composite) Input(id string, from Connectable) dot.Edge

Input creates an edge. If the from Connectable is part of the parent graph then the edge is added to the parent graph. If the from Connectable is part of the composite then the edge is added to the inner graph.

func (*Composite) Output

func (s *Composite) Output(id string, to Connectable) dot.Edge

Output creates an edge. If the to Connectable is part of the parent graph then the edge is added to the parent graph. If the to Connectable is part of the composite then the edge is added to the inner graph.

type Connectable added in v1.4.2

type Connectable interface {
	Attr(label string, value interface{}) dot.Node
}

Connectable is a dot.Node or a *dotx.Composite

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL