Skip to content

Commit

Permalink
Merge branch 'release/0.23.0'
Browse files Browse the repository at this point in the history
  • Loading branch information
moaxcp committed Dec 16, 2017
2 parents b3e3ab8 + fa414fa commit ccea63e
Show file tree
Hide file tree
Showing 49 changed files with 1,321 additions and 596 deletions.
6 changes: 5 additions & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,11 @@ cache:
- "$HOME/.gradle/caches/"
- "$HOME/.gradle/wrapper/"
install: true
script: "./travis.sh"
script:
- "./travis.sh"
- ./gradlew jacocoTestReport
before_install:
- openssl aes-256-cbc -K $encrypted_89c9bd3bab4e_key -iv $encrypted_89c9bd3bab4e_iv
-in signingkey.gpg.enc -out signingkey.gpg -d
after_success:
- bash <(curl -s https://codecov.io/bash)
98 changes: 76 additions & 22 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,9 +1,16 @@
# graph-dsl

A groovy dsl for creating and traversing graphs. Graphs can be extended with types which allows developers to create a
graph with the desired behavior and values for their algorithm.
A groovy dsl for creating and traversing graphs. Graphs can be extended
with types and plugins which allows developers to create graphs with
the desired behavior and values for their algorithm.

[![GitHub top language](https://img.shields.io/github/languages/top/moaxcp/graph-dsl.svg)]()
[![GitHub last commit](https://img.shields.io/github/last-commit/moaxcp/graph-dsl.svg)]()
[![Build Status](https://travis-ci.org/moaxcp/graph-dsl.svg?branch=master)](https://travis-ci.org/moaxcp/graph-dsl)
[![Maven Central](https://img.shields.io/maven-central/v/com.github.moaxcp/graph-dsl.svg)](https://mvnrepository.com/artifact/com.github.moaxcp/graph-dsl)
[![Javadocs](https://www.javadoc.io/badge/com.github.moaxcp/graph-dsl.svg)](https://www.javadoc.io/doc/com.github.moaxcp/graph-dsl)
[![Libraries.io for GitHub](https://img.shields.io/librariesio/github/moaxcp/graph-dsl.svg)](https://libraries.io/github/moaxcp/graph-dsl)
[![license](https://img.shields.io/github/license/moaxcp/graph-dsl.svg)](LICENSE)

# Usage

Expand Down Expand Up @@ -52,15 +59,6 @@ There are a few rules the dsl follows as it is being processed.
1. All referenced vertices are created if they don't exist.
2. If an edge or vertex already exists it will be reused by and operation.

Future rules:

These rules will address the api leak with Vertex or Edge. When these objects are returned or in scope some properties
may be changed which will break the graph. These rules will address those issues.

3. Changing name in Vertex renames the vertex in the graph
4. Changing one or two in Edge moves the edge to different vertices. The vertices will be created if they do not exist.
5. delegates in Vertex and Edge are read-only

## directed graphs

The Default behavior of a graph is undirected. These graphs have a set of edges where only one edge
Expand Down Expand Up @@ -163,9 +161,10 @@ an undirected graph are considered bi-directional in `classifyEdges`.

Vertex keys are used to refer to a Vertex in the dsl. Keys can be any object which implements equals and hashCode.

## Properties
## Edge and Vertex are Maps

Properties can be added to Edge and Vertex dynamically simply by assigning them.
Since Edge and Vertex are maps, all of the syntax for maps apply to them. In a dsl closure assignments create
and entry in the Edge or Vertex.

```groovy
edge(A, B) {
Expand All @@ -177,8 +176,23 @@ vertex step1, {
}
```

If non dsl entries are used in a dsl method they are added to the object.

```groovy
edge(A, B, [weight:10]) //weight is a non dsl entry
vertex(step1, [connectsTo:step1, color:'red']) //color is a non dsl entry
```

# Types

Types can be changed with the type methods.

```groovy
type 'directed-graph'
type graph.type.DirectedGraphType
```

A graph's type determines specific behavior. A type can change a normal graph to an directed-graph. It can add wieght
to the graph. It can change the graph to a DAG. Developers can make their own type and apply it to a graph. Types can:

Expand Down Expand Up @@ -224,15 +238,6 @@ edge A, B, [weight:10]
edge (A, B) { weight = 10 }
```

Weight can be a lazy property by assigning a closure.

```groovy
type 'weighted-graph'
edge(A, B) {
weight = { queue.size() }
}
## WeightedDirectedGraphType

```groovy
Expand All @@ -242,6 +247,40 @@ type 'weighted-directed-graph'
WeightedDirectedGraphType is a directed graph where edges can have weight. Traversal methods follow edges with the least
weight.


# Plugins

Plugins may be applied with the plugin methods.

```groovy
plugin 'graphviz'
plugin graph.plugin.GraphViz
```

## Graphviz

Graphviz is a graph visualization toolset. The project provides a dsl called dot for visualizing graphs. The graphviz
plugin provides methods to create dot strings, BufferedImages and to view the graph. Edge and Vertex attributes will be used as dot attributes.

```groovy
type 'directed-graph'
plugin 'graphviz'
vertex A {
connectsTo B {
connectsTo C, D
}
connectsTo D {
connectsTo C
connectsTo E
}
connectsFrom D
}
vertex F, [connectsTo:G]
edge G, D
image 'images/graphviz.png'
```
![Image of graph](/images/graphviz.png?raw=true "Grpah")

# Getting Started With Development/Contributing

## install git
Expand Down Expand Up @@ -302,8 +341,23 @@ If there are any issues contact me moaxcp@gmail.com.

# Releases

## 0.23.0

Adding graphviz plugin.

Vertices and edges are now maps. Closures in entries are not resolved as was the case when dynamic properties were set.

Example

```groovy
edge.weight = { queue.size() }
assert edge.weight == 10 //in 0.22.0 would call the closure. In this release the closure is returned.
```

## 0.22.0

[#102](https://github.com/moaxcp/graph-dsl/issues/102) Switch from name to key

In this release Vertex.name has been repalced with Vertex.key. The key may be any object that implements equals and
hashCode.

Expand Down
37 changes: 26 additions & 11 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -34,14 +34,17 @@ versioneye {

jacocoTestReport {
dependsOn test
reports {
xml.enabled = true
}
}

jacocoTestCoverageVerification {
dependsOn test
violationRules {
rule {
limit {
minimum = 0.83
minimum = 0.8
}
limit {
counter = 'BRANCH'
Expand Down Expand Up @@ -87,6 +90,12 @@ jacocoTestCoverageVerification {
}
}

test {
systemProperty 'com.athaydes.spockframework.report.hideEmptyBlocks', 'true'
systemProperty 'com.athaydes.spockframework.report.showCodeBlocks', 'true'
systemProperty 'com.athaydes.spockframework.report.projectVersion', version.toString()
}

gradle.taskGraph.whenReady { graph ->
if (graph.hasTask(':jacocoTestReport') || graph.hasTask(':jacocoTestCoverageVerification')) {
compileGroovy.groovyOptions.optimizationOptions.all = false
Expand All @@ -102,16 +111,6 @@ codenarc {
ignoreFailures = true
}

repositories {
jcenter()
}

configurations {
codnarc {
extendsFrom compile
}
}

groovydoc {
link 'https://docs.oracle.com/javase/8/docs/api/', 'java', 'javax', 'org'
link "http://docs.groovy-lang.org/docs/groovy-$groovyVersion/html/api/", 'groovy', 'org'
Expand Down Expand Up @@ -202,15 +201,31 @@ nexusStaging {
delayBetweenRetriesInMillis = 10000
}

repositories {
jcenter()
}

configurations {
codnarc {
extendsFrom compile
}
}

dependencies {
compile "org.codehaus.groovy:groovy:$groovyVersion"
compile 'org.groovyfx:groovyfx:8.0.0'

testCompile( 'com.athaydes:spock-reports:1.3.2' ) {
transitive = false
}
testCompile 'org.slf4j:slf4j-api:1.7.13'
testCompile 'org.slf4j:slf4j-simple:1.7.13'

testCompile ('org.spockframework:spock-core:1.1-groovy-2.4') {
exclude group: 'org.codehaus.groovy', module:'groovy-all'
}
testCompile "org.codehaus.groovy:groovy-all:$groovyVersion"
testCompile 'cglib:cglib-nodep:3.2.5'

testCompile 'org.hamcrest:hamcrest-all:1.3'
}
Binary file added images/graphviz.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
49 changes: 22 additions & 27 deletions src/main/groovy/graph/Edge.groovy
Original file line number Diff line number Diff line change
@@ -1,43 +1,38 @@
package graph

import graph.internal.PropertyDelegator
import groovy.transform.PackageScope
import groovy.transform.ToString

/**
* An edge between two vertices. Properties may be added to Edge by setting values. Assigning a property to a
* {@link Closure} will make it lazy. When the property is read the value returned is the result of calling the closure.
* If a missing method is called on Edge and a property is set with a closure the closure will be called and the
* resulting value returned.
*/
@ToString(includeNames=true)
class Edge extends PropertyDelegator {
Object one
Object two
class Edge {
@Delegate
Map map = [:]

@PackageScope
void setOne(Object one) {
this.one = one
Object getOne() {
get('one')
}

@PackageScope
void setTwo(Object two) {
this.two = two
Object setOne(Object value) {
put('one', value)
}

/**
* Returns the property with the given name.
* @param name
* @return
*/
Object getAt(String name) {
if (name == 'one') {
return one
}
if (name == 'two') {
return two
}
delegate[name]
Object getTwo() {
get('two')
}

Object setTwo(Object value) {
put('two', value)
}

boolean asBoolean() {
one && two
}

boolean equals(Edge edge) {
(one == edge.one || one == edge.two) && (two == edge.two || two == edge.one)
}

/**
Expand All @@ -56,7 +51,7 @@ class Edge extends PropertyDelegator {
return true
}
Edge rhs = (Edge) o
(one == rhs.one || one == rhs.two) && (two == rhs.two || two == rhs.one)
equals(rhs)
}

/**
Expand Down
3 changes: 0 additions & 3 deletions src/main/groovy/graph/EdgeSpec.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,6 @@ abstract class EdgeSpec {
Graph graph

protected EdgeSpec(Graph graph) {
if (this.graph) {
throw new IllegalArgumentException('Graph already set.')
}
this.graph = graph
}

Expand Down
Loading

0 comments on commit ccea63e

Please sign in to comment.