layli
This tools produces diagrams and has 2 simple aims:
- Define components and connections as code
- Look pretty



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
Discovering Available Options
To see all available layout algorithms, pathfinding algorithms, and heuristics:
$ layli config
Output:
{
"algorithms": ["dijkstra", "astar", "bidirectional"],
"heuristics": ["euclidean", "manhattan"],
"layouts": ["flow-square", "topo-sort", "tarjan", "absolute", "random-shortest-square"]
}
Programmatic access (Go):
import "github.com/dnnrly/layli/layout"
layouts := layout.GetLayoutOptions()
algorithms := layout.GetPathfindingAlgorithms()
heuristics := layout.GetHeuristics()
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:
- Edge paths must travel across a "path grid"
- Node borders must be on the "path grid"
- Edges must meet nodes at "ports"
- Ports must sit on the "path grid"
- Where a port is not specified, layli may select a "default" port on any side of the node
- Nodes must be layed out so that the total area marked by the outside bounds of every node is as small as possible
- Nodes must be seperated by at least 1 space on the "path grid"
- Edges must must not cross!
- Edges must follow a grid path (ie. not curved or diagonal)
- Edges must be as short as possible
- Edges must have as few corners as possible
- 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"
Defining the layout style:
layout: flow-square
There are currently 3 different layout styles:
flow-square - nodes are arranged into rows and columns, much the way you read words on a page
topo-sort - nodes are sorted in order of the edges, all in a single row
tarjan - uses Tarjan's Algorithm to arrange the nodes an a 'pleasing' way
absolute - lets you specify where you want nodes to appear on the diagram
An example diagram
Here's an image that is generated by this command layli ./demo.layli --show-grid:
Layli definition for this file
layout: flow-square
nodes:
- id: a
contents: Node A
- id: b
contents: Node B
- id: c
contents: Node C
- id: d
contents: Node D
- id: e
contents: Node E
- id: f
contents: Node F
- id: g
contents: Node G
- id: h
contents: Node H
- id: i
contents: Node J
edges:
- from: a
to: b
- from: b
to: c
- from: c
to: d
- from: d
to: e
- from: c
to: e
- from: e
to: d
- from: d
to: f
- from: f
to: g
- from: f
to: h
- from: g
to: i
width: 7
height: 4
border: 2
margin: 2
# You can also add comments to your file, like so.
You can see further examples here
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.
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.
To contribute a new layout algorithm, see CONTRIBUTING_LAYOUTS.md for step-by-step instructions.
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.