11# graph-dsl
22
3- A groovy dsl for creating and traversing graphs. Graphs can be extended with types which allows developers to create a
4- graph with the desired behavior and values for their algorithm.
3+ A groovy dsl for creating and traversing graphs. Graphs can be extended
4+ with types and plugins which allows developers to create graphs with
5+ the desired behavior and values for their algorithm.
56
7+ [ ![ GitHub top language] ( https://img.shields.io/github/languages/top/moaxcp/graph-dsl.svg )] ( )
8+ [ ![ GitHub last commit] ( https://img.shields.io/github/last-commit/moaxcp/graph-dsl.svg )] ( )
69[ ![ Build Status] ( https://travis-ci.org/moaxcp/graph-dsl.svg?branch=master )] ( https://travis-ci.org/moaxcp/graph-dsl )
10+ [ ![ Maven Central] ( https://img.shields.io/maven-central/v/com.github.moaxcp/graph-dsl.svg )] ( https://mvnrepository.com/artifact/com.github.moaxcp/graph-dsl )
11+ [ ![ Javadocs] ( https://www.javadoc.io/badge/com.github.moaxcp/graph-dsl.svg )] ( https://www.javadoc.io/doc/com.github.moaxcp/graph-dsl )
12+ [ ![ Libraries.io for GitHub] ( https://img.shields.io/librariesio/github/moaxcp/graph-dsl.svg )] ( https://libraries.io/github/moaxcp/graph-dsl )
13+ [ ![ license] ( https://img.shields.io/github/license/moaxcp/graph-dsl.svg )] ( LICENSE )
714
815# Usage
916
@@ -52,15 +59,6 @@ There are a few rules the dsl follows as it is being processed.
52591 . All referenced vertices are created if they don't exist.
53602 . If an edge or vertex already exists it will be reused by and operation.
5461
55- Future rules:
56-
57- These rules will address the api leak with Vertex or Edge. When these objects are returned or in scope some properties
58- may be changed which will break the graph. These rules will address those issues.
59-
60- 3 . Changing name in Vertex renames the vertex in the graph
61- 4 . Changing one or two in Edge moves the edge to different vertices. The vertices will be created if they do not exist.
62- 5 . delegates in Vertex and Edge are read-only
63-
6462## directed graphs
6563
6664The Default behavior of a graph is undirected. These graphs have a set of edges where only one edge
@@ -163,9 +161,10 @@ an undirected graph are considered bi-directional in `classifyEdges`.
163161
164162Vertex keys are used to refer to a Vertex in the dsl. Keys can be any object which implements equals and hashCode.
165163
166- ## Properties
164+ ## Edge and Vertex are Maps
167165
168- Properties can be added to Edge and Vertex dynamically simply by assigning them.
166+ Since Edge and Vertex are maps, all of the syntax for maps apply to them. In a dsl closure assignments create
167+ and entry in the Edge or Vertex.
169168
170169``` groovy
171170edge(A, B) {
@@ -177,8 +176,23 @@ vertex step1, {
177176}
178177```
179178
179+ If non dsl entries are used in a dsl method they are added to the object.
180+
181+ ``` groovy
182+ edge(A, B, [weight:10]) //weight is a non dsl entry
183+
184+ vertex(step1, [connectsTo:step1, color:'red']) //color is a non dsl entry
185+ ```
186+
180187# Types
181188
189+ Types can be changed with the type methods.
190+
191+ ``` groovy
192+ type 'directed-graph'
193+ type graph.type.DirectedGraphType
194+ ```
195+
182196A graph's type determines specific behavior. A type can change a normal graph to an directed-graph. It can add wieght
183197to the graph. It can change the graph to a DAG. Developers can make their own type and apply it to a graph. Types can:
184198
@@ -224,15 +238,6 @@ edge A, B, [weight:10]
224238edge (A, B) { weight = 10 }
225239```
226240
227- Weight can be a lazy property by assigning a closure.
228-
229- ``` groovy
230- type 'weighted-graph'
231-
232- edge(A, B) {
233- weight = { queue.size() }
234- }
235-
236241## WeightedDirectedGraphType
237242
238243``` groovy
@@ -242,6 +247,40 @@ type 'weighted-directed-graph'
242247WeightedDirectedGraphType is a directed graph where edges can have weight. Traversal methods follow edges with the least
243248weight.
244249
250+
251+ # Plugins
252+
253+ Plugins may be applied with the plugin methods.
254+
255+ ``` groovy
256+ plugin 'graphviz'
257+ plugin graph.plugin.GraphViz
258+ ```
259+
260+ ## Graphviz
261+
262+ Graphviz is a graph visualization toolset. The project provides a dsl called dot for visualizing graphs. The graphviz
263+ plugin provides methods to create dot strings, BufferedImages and to view the graph. Edge and Vertex attributes will be used as dot attributes.
264+
265+ ``` groovy
266+ type 'directed-graph'
267+ plugin 'graphviz'
268+ vertex A {
269+ connectsTo B {
270+ connectsTo C, D
271+ }
272+ connectsTo D {
273+ connectsTo C
274+ connectsTo E
275+ }
276+ connectsFrom D
277+ }
278+ vertex F, [connectsTo:G]
279+ edge G, D
280+ image 'images/graphviz.png'
281+ ```
282+ ![ Image of graph] ( /images/graphviz.png?raw=true " Grpah ")
283+
245284# Getting Started With Development/Contributing
246285
247286## install git
@@ -302,8 +341,23 @@ If there are any issues contact me moaxcp@gmail.com.
302341
303342# Releases
304343
344+ ## 0.23.0
345+
346+ Adding graphviz plugin.
347+
348+ Vertices and edges are now maps. Closures in entries are not resolved as was the case when dynamic properties were set.
349+
350+ Example
351+
352+ ``` groovy
353+ edge.weight = { queue.size() }
354+ assert edge.weight == 10 //in 0.22.0 would call the closure. In this release the closure is returned.
355+ ```
356+
305357## 0.22.0
306358
359+ [ #102 ] ( https://github.com/moaxcp/graph-dsl/issues/102 ) Switch from name to key
360+
307361In this release Vertex.name has been repalced with Vertex.key. The key may be any object that implements equals and
308362hashCode.
309363
0 commit comments