layout

package module
v0.0.2-0...-86f8249 Latest Latest
Warning

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

Go to latest
Published: Feb 26, 2022 License: MIT Imports: 3 Imported by: 0

README

layout GoDoc Go Report Card

Experimental

Current version and API is in experimental stage. Property names may change.

Installation

The graph layouting can be used as a command-line tool and as a library.

To install the command-line tool:

go get -u github.com/loov/layout/cmd/glay

To install the package:

go get -u github.com/loov/layout

Usage

Minimal usage:

package main

import (
    "os"

    "github.com/loov/layout"
    "github.com/loov/layout/format/svg"
)

func main() {
    graph := layout.NewDigraph()
    graph.Edge("A", "B")
    graph.Edge("A", "C")
    graph.Edge("B", "D")
    graph.Edge("C", "D")

    layout.Hierarchical(graph)

    svg.Write(os.Stdout, graph)
}

Output

See other examples in examples folder.

Quality

Currently the layout.Hierarchy algorithm output is significantly worse than graphviz. It is recommended to use graphviz dot, if possible.

Documentation

Overview

Package layout implements different graph layouting functions

Index

Constants

View Source
const (
	Auto    Shape = ""
	None          = "none"
	Box           = "box"
	Square        = "square"
	Circle        = "circle"
	Ellipse       = "ellipse"
)
View Source
const (
	Point = 1
	Inch  = 72
	Twip  = Inch / 1440

	Meter      = 39.3701 * Inch
	Centimeter = Meter * 0.01
	Millimeter = Meter * 0.001
)

Variables

This section is empty.

Functions

func Hierarchical

func Hierarchical(graphdef *Graph)

Types

type Color

type Color interface {
	// RGBA returns the non-alpha-premultiplied red, green, blue and alpha values
	// for the color. Each value ranges within [0, 0xff].
	RGBA8() (r, g, b, a uint8)
}

func ColorByName

func ColorByName(name string) (Color, bool)

ColorByName returns RGB color based on X11 scheme

type Edge

type Edge struct {
	Directed bool
	From, To *Node
	Weight   float64

	Tooltip string

	Label     string
	FontName  string
	FontSize  Length
	FontColor Color

	LineWidth Length
	LineColor Color

	// computed in layouting
	Path []Vector
}

func NewEdge

func NewEdge(from, to *Node) *Edge

func (*Edge) String

func (edge *Edge) String() string

type Graph

type Graph struct {
	ID       string
	Directed bool

	// Defaults
	LineHeight Length
	FontSize   Length
	Shape      Shape

	NodePadding Length
	RowPadding  Length
	EdgePadding Length

	NodeByID map[string]*Node
	Nodes    []*Node
	Edges    []*Edge
}

func NewDigraph

func NewDigraph() *Graph

func NewGraph

func NewGraph() *Graph

func (*Graph) AddEdge

func (graph *Graph) AddEdge(edge *Edge)

func (*Graph) AddNode

func (graph *Graph) AddNode(node *Node) bool

AddNode adds a new node.

When a node with the specified id already it will return false and the node is not added.

func (*Graph) AssignMissingValues

func (graph *Graph) AssignMissingValues()

func (*Graph) Bounds

func (graph *Graph) Bounds() (min, max Vector)

func (*Graph) Edge

func (graph *Graph) Edge(from, to string) *Edge

Edge finds or creates new edge based on ids

func (*Graph) Node

func (graph *Graph) Node(id string) *Node

Node finds or creates node with id

type HSL

type HSL struct{ H, S, L float32 }

HSL represents an color in hue, saturation and lightness space

func (HSL) RGBA8

func (hsl HSL) RGBA8() (r, g, b, a uint8)

type HSLA

type HSLA struct{ H, S, L, A float32 }

HSLA represents an color in hue, saturation and lightness space

func (HSLA) RGBA8

func (hsl HSLA) RGBA8() (r, g, b, a uint8)

type Length

type Length float64

Length is a value represented in points

type Node

type Node struct {
	ID string

	Label  string
	Weight float64

	Tooltip   string
	FontName  string
	FontSize  Length
	FontColor Color

	LineWidth Length
	LineColor Color

	Shape     Shape
	FillColor Color
	Radius    Vector

	// computed in layouting
	Center Vector
}

func NewNode

func NewNode(id string) *Node

func (*Node) Bottom

func (node *Node) Bottom() Length

func (*Node) BottomCenter

func (node *Node) BottomCenter() Vector

func (*Node) BottomRight

func (node *Node) BottomRight() Vector

func (*Node) DefaultLabel

func (node *Node) DefaultLabel() string

func (*Node) Left

func (node *Node) Left() Length

func (*Node) Right

func (node *Node) Right() Length

func (*Node) String

func (node *Node) String() string

func (*Node) Top

func (node *Node) Top() Length

func (*Node) TopCenter

func (node *Node) TopCenter() Vector

func (*Node) TopLeft

func (node *Node) TopLeft() Vector

type RGB

type RGB struct{ R, G, B uint8 }

RGB represents an 24bit color

func (RGB) RGBA8

func (rgb RGB) RGBA8() (r, g, b, a uint8)

type RGBA

type RGBA struct{ R, G, B, A uint8 }

RGBA represents an 24bit color

func (RGBA) RGBA8

func (rgb RGBA) RGBA8() (r, g, b, a uint8)

type Shape

type Shape string

type Vector

type Vector struct{ X, Y Length }

Directories

Path Synopsis
cmd
format
dot
package dot implements dot file format parsing
package dot implements dot file format parsing
svg
tgf
internal

Jump to

Keyboard shortcuts

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