dags

package module
v0.0.0-...-bb7abb0 Latest Latest
Warning

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

Go to latest
Published: Mar 20, 2022 License: AGPL-3.0 Imports: 5 Imported by: 6

Documentation

Overview

Package dags visualizes a DAG graph into a structured, layered planer map.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CheckDAG

func CheckDAG(g *Graph) error

CheckDAG checks if a graph is a valid DAG. It returns true when all the graph, links are valid and has no circular dependency.

func Layout

func Layout(g *Graph) (*Map, *MapView, error)

Layout layouts a DAG into a map.

func LayoutJSON

func LayoutJSON(g *Graph) ([]byte, error)

LayoutJSON layouts a DAG into a map in json format.

func RevLayout

func RevLayout(g *Graph) (*Map, *MapView, error)

RevLayout layouts a DAG into a map from right to left its more suitable for top-down designed projects.

func RevLayoutJSON

func RevLayoutJSON(g *Graph) ([]byte, error)

RevLayoutJSON layouts a DAG into a map in json format.

func TopoSort

func TopoSort(g *Graph) ([]string, error)

TopoSort topologically sorts the graph.

Types

type Graph

type Graph struct {
	Nodes map[string][]string
}

Graph is a directed graph

func NewGraph

func NewGraph(nodes map[string][]string) *Graph

NewGraph create a new graph with the given nodes.

func (*Graph) Remove

func (g *Graph) Remove(node string) *Graph

Remove removes a node in a graph and returns the new graph.

func (*Graph) Rename

func (g *Graph) Rename(f func(string) (string, error)) (*Graph, error)

Rename renames the name of each node in the graph

func (*Graph) Reverse

func (g *Graph) Reverse() *Graph

Reverse the graph

func (*Graph) SubGraph

func (g *Graph) SubGraph(f func(string) bool) *Graph

SubGraph returns a sub graph of the current graph, which only contains nodes that passes the filter.

type M

type M struct {
	Height int           `json:"h"`
	Width  int           `json:"w"`
	Nodes  map[string]*N `json:"n"`
}

M is a node in the minified DAG visualization result.

func Output

func Output(v *MapView) *M

Output returns a json'able object of a map.

type Map

type Map struct {
	Nodes map[string]*MapNode

	Nedge  int
	Ncrit  int
	Nlayer int
}

Map is a visualized DAG

func Closure

func Closure(m *Map, nodes []string) *Map

Closure makes the minimum sub map of a map that contains all the given nodes, and nodes that are in between these nodes.

func NewMap

func NewMap(g *Graph) (*Map, error)

NewMap creates a map from a graph where all the ins and outs are populated, and nodes are mapped into layers.

func (*Map) Reverse

func (m *Map) Reverse()

Reverse reverses the map.

func (*Map) SortedLayers

func (m *Map) SortedLayers() [][]*MapNode

SortedLayers returns nodes that are sorted in topological layers. Each node resides in its lowest possible layer.

func (*Map) SortedNodes

func (m *Map) SortedNodes() []*MapNode

SortedNodes returns a nodes that are sorted in topological order.

type MapNode

type MapNode struct {
	Name string

	Ins  map[string]*MapNode // direct input nodes
	Outs map[string]*MapNode // direct output nodes

	AllIns  map[string]*MapNode // direct and indirect input nodes
	AllOuts map[string]*MapNode // direct and indirect output nodes

	// critical nodes is the minimum set of nodes that keeps
	// the same partial order of the nodes in the DAG graph
	CritIns  map[string]*MapNode // critical input nodes
	CritOuts map[string]*MapNode // critical output nodes
	// contains filtered or unexported fields
}

MapNode is a node in the DAG graph

func AllInsSorted

func AllInsSorted(node *MapNode) []*MapNode

AllInsSorted returns all the input nodes of a node in layering order.

type MapNodeView

type MapNodeView struct {
	Name        string
	DisplayName string
	X, Y        int
	CritIns     []string
	CritOuts    []string
}

MapNodeView is the position of a map node.

type MapView

type MapView struct {
	Height    int
	Width     int
	Nodes     map[string]*MapNodeView
	IsTopDown bool
}

MapView is a layout view of a Map.

func LayoutMap

func LayoutMap(m *Map) *MapView

LayoutMap creates the MapView for the given Map.

func (*MapView) AssignDisplayName

func (v *MapView) AssignDisplayName(f func(s string) string)

AssignDisplayName assigns display names in a map.

func (*MapView) Reverse

func (v *MapView) Reverse()

Reverse reverse a map view.

type N

type N struct {
	N    string   `json:"n"`
	F    string   `json:"f,omitempty"`
	X    int      `json:"x"`
	Y    int      `json:"y"`
	Ins  []string `json:"i"`
	Outs []string `json:"o"`
}

N is a node in the minified DAG visualization result.

type Repo

type Repo struct {
	Name     string
	RepoTopo *M
	PkgTopos map[string]*M
}

Repo is the overview dependency structure of a repository.

func NewRepo

func NewRepo(name string) *Repo

NewRepo creates an empty overview for a repo.

Jump to

Keyboard shortcuts

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