layli

package module
v0.0.1 Latest Latest
Warning

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

Go to latest
Published: Jul 21, 2023 License: Apache-2.0 Imports: 8 Imported by: 0

README

layli

This tools produces diagrams and has 2 simple aims:

  1. Define components and connections as code
  2. Look pretty

GitHub release (latest SemVer) GitHub Workflow Status report card godoc

GitHub watchers GitHub stars Twitter URL

Using layli

Installation
$ go install github.com/dnnrly/layli/cmd/layli
A simple examples

Your first layli file:

node: "Hello World"
$ layli hello-world.layli

layli principles

layli aims to let you specify nodes and edges (boxes and lines) and looks after arranging them in a pleasing way. If you've ever used plantuml you'll be familiar with describing the diagrams in a simple to understand text file to generate a pretty diagram. Well, perhaps not as pretty as you would hope. This tool aims to solve this.

Here are some principles that hope to tackle this problem head on:

  1. Nodes must be centered points that sit on a "node grid"
  2. Edge paths must travel across a "path grid"
  3. Node borders must be on the "path grid"
  4. Edges must meet nodes at "ports"
  5. Ports must sit on the "path grid"
  6. Where a port is not specified, layli may select a "default" port on any side of the node
  7. Nodes must be layed out so that the total area marked by the outside bounds of every node is as small as possible
  8. Nodes must be seperated by at least 1 space on the "path grid"
  9. Edges must must not cross!
  10. Edges must follow a grid path (ie. not curved or diagonal)
  11. Edges must be as short as possible
  12. Edges must have as few corners as possible
  13. Edge paths may sit on top of each other at the beginning or at the end
Defining nodes

Specifying a simple node:

Complex nodes:

nodes:
  - id: node-1
    contents: "A\nwith formatting"

Connecting nodes:

edges:
  - from: node-1
    to: "The node name"

Developing layli

These instructions will get you a copy of the project up and running on your local machine for development and testing purposes. See deployment for notes on how to deploy the project on a live system.

Prerequisites

What things you need to install the software and how to install them

Give examples
Installing from source
$ git clone http://github.com/dnnrly/layli.git
$ cd layli
$ make install
Running Unit Tests
$ make test
Running Acceptance tests
$ make acceptance-test

Important make targets

  • deps - downloads all of the deps you need to build, test, and release
  • install - installs your application
  • build - builds your application
  • test - runs unit tests
  • ci-test - run tests for CI validation
  • acceptance-test - run the acceptance tests
  • coverage-report - merge coverage statistics from all sources
  • mocks - generate mocks for interface
  • lint - run linting
  • clean - clean project dependencies
  • clean-deps - remove all of the build dependencies too

Contributing

Please read CONTRIBUTING.md for details on our code of conduct, and the process for submitting pull requests to us.

Versioning

We use SemVer for versioning. For the versions available, see the tags on this repository.

Authors

  • Pascal Dennerly - Initial work - dnnrly

See also the list of contributors who participated in this project.

License

This project is licensed under the Apache 2.0 License - see the LICENSE file for details

Acknowledgments

  • There is a blog that I read a couple of years ago that described solving a similar problem. For the life of me, I can't remember find it anywhere to give the appropriate credit. But believe me when I say that a lot of the ideas are based on this blog and a lot of credit belongs to the author.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Arc added in v0.0.1

type Arc struct {
	From     Point
	To       Point
	Distance int
}

type Arcs added in v0.0.1

type Arcs []Arc

func (*Arcs) Add added in v0.0.1

func (all *Arcs) Add(from Point, to Point, distance int)

func (Arcs) AddToGraph added in v0.0.1

func (all Arcs) AddToGraph(g Graph)

func (Arcs) Exists added in v0.0.1

func (all Arcs) Exists(from Point, to Point) bool

func (Arcs) Get added in v0.0.1

func (all Arcs) Get(from Point, to Point) Arc

func (Arcs) String added in v0.0.1

func (all Arcs) String() string

type Config added in v0.0.1

type Config struct {
	Nodes   ConfigNodes `yaml:"nodes"`
	Edges   ConfigEdges `yaml:"edges"`
	Spacing int         `yaml:"-"`

	NodeWidth  int `yaml:"width"`
	NodeHeight int `yaml:"height"`
	Border     int `yaml:"border"`
	Margin     int `yaml:"margin"`
}

type ConfigEdge added in v0.0.1

type ConfigEdge struct {
	From string `yaml:"from"`
	To   string `yaml:"to"`
}

type ConfigEdges added in v0.0.1

type ConfigEdges []ConfigEdge

type ConfigNode added in v0.0.1

type ConfigNode struct {
	Id       string `yaml:"id"`
	Contents string `yaml:"contents"`
}

type ConfigNodes added in v0.0.1

type ConfigNodes []ConfigNode

type Diagram added in v0.0.1

type Diagram struct {
	// contains filtered or unexported fields
}

func NewDiagramFromFile added in v0.0.1

func NewDiagramFromFile(r io.ReadCloser, output OutputFunc, showGrid bool) (*Diagram, error)

NewDiagramFromFile reads the configuration and parses it in to a Diagram object

func (*Diagram) Draw added in v0.0.1

func (d *Diagram) Draw() error

Draw turns the diagram in to an image

type Graph added in v0.0.1

type Graph interface {
	AddMappedArc(Source, Destination string, Distance int64) error
	AddMappedVertex(ID string) int
	GetMapped(a int) (string, error)
}

type Layout added in v0.0.1

type Layout struct {
	Nodes LayoutNodes
	Paths LayoutPaths
	// contains filtered or unexported fields
}

func NewLayoutFromConfig added in v0.0.1

func NewLayoutFromConfig(c Config) *Layout

func (*Layout) AddPath added in v0.0.1

func (l *Layout) AddPath(from, to string) error

func (*Layout) Draw added in v0.0.1

func (l *Layout) Draw(canvas LayoutDrawer, spacing int)

func (*Layout) InsideAny added in v0.0.1

func (l *Layout) InsideAny(x, y int) bool

func (*Layout) IsAnyPort added in v0.0.1

func (l *Layout) IsAnyPort(x, y int) bool

func (*Layout) LayoutHeight added in v0.0.1

func (l *Layout) LayoutHeight() int

LayoutHeight is the height in path units

func (*Layout) LayoutWidth added in v0.0.1

func (l *Layout) LayoutWidth() int

LayoutWidth is the width in path units

func (*Layout) ShowGrid added in v0.0.1

func (l *Layout) ShowGrid(canvas LayoutDrawer, spacing int)

type LayoutDrawer added in v0.0.1

type LayoutDrawer interface {
	Circle(x int, y int, r int, s ...string)
	Path(d string, s ...string)
	Roundrect(x int, y int, w int, h int, rx int, ry int, s ...string)
	Textspan(x int, y int, t string, s ...string)
	TextEnd()
}

type LayoutNode added in v0.0.1

type LayoutNode struct {
	Id       string
	Contents string
	// contains filtered or unexported fields
}

func NewLayoutNode added in v0.0.1

func NewLayoutNode(id, contents string, left, top, width, height int) LayoutNode

func (*LayoutNode) Draw added in v0.0.1

func (n *LayoutNode) Draw(d LayoutDrawer, spacing int)

func (*LayoutNode) GetCentre added in v0.0.1

func (n *LayoutNode) GetCentre() Point

func (*LayoutNode) GetPorts added in v0.0.1

func (n *LayoutNode) GetPorts() Points

func (*LayoutNode) IsInside added in v0.0.1

func (n *LayoutNode) IsInside(x, y int) bool

func (*LayoutNode) IsPort added in v0.0.1

func (n *LayoutNode) IsPort(x, y int) bool

type LayoutNodes added in v0.0.1

type LayoutNodes []LayoutNode

func (LayoutNodes) ByID added in v0.0.1

func (nodes LayoutNodes) ByID(id string) *LayoutNode

type LayoutPath added in v0.0.1

type LayoutPath struct {
	// contains filtered or unexported fields
}

func (*LayoutPath) Draw added in v0.0.1

func (p *LayoutPath) Draw(canvas LayoutDrawer, spacing int)

type LayoutPaths added in v0.0.1

type LayoutPaths []LayoutPath

func (*LayoutPaths) Draw added in v0.0.1

func (paths *LayoutPaths) Draw(canvas LayoutDrawer, spacing int)

type OutputFunc added in v0.0.1

type OutputFunc func(output string) error

type Point added in v0.0.1

type Point struct {
	X float64
	Y float64
}

func (Point) Distance added in v0.0.1

func (p Point) Distance(to Point) float64

func (Point) String added in v0.0.1

func (p Point) String() string

type Points added in v0.0.1

type Points []Point

func NewPointsFromBestPath added in v0.0.1

func NewPointsFromBestPath(g Graph, path dijkstra.BestPath) Points

func (Points) AddToGraph added in v0.0.1

func (p Points) AddToGraph(g Graph)

func (Points) Path added in v0.0.1

func (p Points) Path(spacing int) string

type VertexMap added in v0.0.1

type VertexMap struct {
	// contains filtered or unexported fields
}

func BuildVertexMap added in v0.0.1

func BuildVertexMap(l *Layout) VertexMap

func NewVertexMap added in v0.0.1

func NewVertexMap(x, y int) VertexMap

func (*VertexMap) CountAvailable added in v0.0.1

func (v *VertexMap) CountAvailable(available bool) int

func (*VertexMap) Get added in v0.0.1

func (v *VertexMap) Get(x, y int) bool

func (VertexMap) GetArcs added in v0.0.1

func (vm VertexMap) GetArcs() Arcs

func (VertexMap) GetVertexPoints added in v0.0.1

func (v VertexMap) GetVertexPoints() Points

func (*VertexMap) MapAnd added in v0.0.1

func (v *VertexMap) MapAnd(m VertexMapper)

func (*VertexMap) MapOr added in v0.0.1

func (v *VertexMap) MapOr(m VertexMapper)

func (*VertexMap) MapSet added in v0.0.1

func (v *VertexMap) MapSet(m VertexMapper)

func (*VertexMap) MapUnset added in v0.0.1

func (v *VertexMap) MapUnset(m VertexMapper)

func (*VertexMap) Set added in v0.0.1

func (v *VertexMap) Set(x, y int, val bool)

func (VertexMap) String added in v0.0.1

func (v VertexMap) String() string

type VertexMapper added in v0.0.1

type VertexMapper func(x, y int) bool

Directories

Path Synopsis
cmd
layli command
Package test contains test definitions, code, and data.
Package test contains test definitions, code, and data.

Jump to

Keyboard shortcuts

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