visualize

package
v1.3.0 Latest Latest
Warning

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

Go to latest
Published: Sep 27, 2026 License: MIT Imports: 5 Imported by: ? modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package visualize draws the dependency graph of a container.

The container describes its graph with the model below and hands it to a Renderer, which decides what the drawing looks like: Graphviz DOT, a text tree for the terminal, an HTML page, or anything else implementing the interface.

c.Visualize(os.Stdout, visualize.WithRenderer(visualize.ASCII{}))

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func DefaultOptions

func DefaultOptions(fallback Renderer) *options

DefaultOptions returns the options a drawing starts from, fallback being the renderer used when none is given.

Types

type ASCII

type ASCII struct {
	// Color draws highlighted items in red and dashed ones dimmed, using ANSI escape
	// codes. Leave it off when the output does not go to a terminal.
	Color bool
}

ASCII renders graphs as plain text trees for the terminal, one per cluster, listing under every node the nodes it points to:

root
|-- main.Database (singleton, resolved)
`-- main.Shape (transient)
    `-> main.Database

scope "request"
`-- main.Logger (singleton)
    `-> main.Database [root]

A target outside the cluster of its node is followed by the label of its own cluster. A highlighted node or edge is marked with (!) and drawn as =>, a dashed one is left as its label describes it.

func (ASCII) ContentType

func (ASCII) ContentType() string

func (ASCII) Render

func (a ASCII) Render(w io.Writer, g Graph) error

Render writes the graph to w.

type Cluster

type Cluster struct {
	Label string
	Nodes []Node
}

Cluster is a group of nodes drawn in a labelled box of its own.

type DOT

type DOT struct{}

DOT renders graphs in the Graphviz DOT language:

dot -Tsvg container.dot -o container.svg

func (DOT) ContentType

func (DOT) ContentType() string

func (DOT) Render

func (DOT) Render(w io.Writer, g Graph) error

Render writes the graph to w.

type Edge

type Edge struct {
	From  int
	To    int
	Style Style
}

Edge points from one node to another.

type Graph

type Graph struct {
	Name     string
	Clusters []Cluster
	Nodes    []Node // nodes outside of any cluster
	Edges    []Edge
}

Graph is a directed graph ready to be rendered.

type HTML

type HTML struct {
	// Title is the title of the page, "Dependency graph" when empty.
	Title string
}

HTML renders graphs as a standalone web page. The page lays the DOT drawing of the graph out in the browser with Viz.js, loaded from a CDN, and falls back to the ASCII drawing when scripts do not run.

http.Handle("/debug/container", c.VisualizeHandler())

func (HTML) ContentType

func (HTML) ContentType() string

func (HTML) Render

func (h HTML) Render(w io.Writer, g Graph) error

Render writes the page to w.

type Node

type Node struct {
	ID    int
	Label string
	Style Style
}

Node is a single box, identified by a number unique within the Graph. The first line of its label names it, the others describe it.

type Option

type Option func(*options)

Option is a functional option for configuring a drawing.

func WithRenderer

func WithRenderer(r Renderer) Option

WithRenderer sets the renderer drawing the graph.

type Renderer

type Renderer interface {
	Render(w io.Writer, g Graph) error

	// ContentType returns the media type of what Render writes, for serving it over HTTP.
	ContentType() string
}

Renderer draws a graph and writes it to w.

type Style

type Style uint8

Style is how a node or an edge is drawn.

const (
	Solid Style = iota
	Dashed
	Highlighted
)

Jump to

Keyboard shortcuts

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