mikado_graph_generator 0.1.0 → 0.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.travis.yml +4 -2
- data/Gemfile.lock +3 -1
- data/README.md +13 -11
- data/example_usage.rb +14 -0
- data/lib/mikado_graph/generator.rb +31 -25
- data/lib/mikado_graph/version.rb +1 -1
- data/mikado_graph.gemspec +1 -0
- metadata +17 -3
- data/img/multi_level_mikado_graph.png +0 -0
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 50d127099e97a095948b836a9cd6d547caf4961f
|
4
|
+
data.tar.gz: 7a9dc695f1e142367483d130b0388d0dd6959337
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: fb466184253fd7dd6882c9939e5e18a34553604a1952ddd3195cc1956ee4abfc872258346d154dc511e2c2447e6948bfa3bfc764fc15f34ea5c90c33c0d51495
|
7
|
+
data.tar.gz: daf8ef624d17918aafaf78aa9aa498da21d0c33992396296f513dcf4360d5e41f6d33e6978f47a1aaf57135ebe1fb5d1a6cbdaa75bafe27d028c3a0b8c8f898e
|
data/.travis.yml
CHANGED
data/Gemfile.lock
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
mikado_graph_generator (0.
|
4
|
+
mikado_graph_generator (0.2.0)
|
5
5
|
|
6
6
|
GEM
|
7
7
|
remote: https://rubygems.org/
|
@@ -21,6 +21,7 @@ GEM
|
|
21
21
|
diff-lcs (>= 1.2.0, < 2.0)
|
22
22
|
rspec-support (~> 3.5.0)
|
23
23
|
rspec-support (3.5.0)
|
24
|
+
ruby-graphviz (1.2.2)
|
24
25
|
|
25
26
|
PLATFORMS
|
26
27
|
ruby
|
@@ -30,6 +31,7 @@ DEPENDENCIES
|
|
30
31
|
mikado_graph_generator!
|
31
32
|
rake (~> 10.0)
|
32
33
|
rspec (~> 3.0)
|
34
|
+
ruby-graphviz
|
33
35
|
|
34
36
|
BUNDLED WITH
|
35
37
|
1.14.3
|
data/README.md
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
# Mikado Graph Generator
|
1
|
+
# Mikado Graph Generator [![Build Status](https://travis-ci.org/snasirca/mikado_graph_generator.svg?branch=master)](https://travis-ci.org/snasirca/mikado_graph_generator) [![Code Climate](https://codeclimate.com/github/snasirca/mikado_graph_generator/badges/gpa.svg)](https://codeclimate.com/github/snasirca/mikado_graph_generator)
|
2
2
|
|
3
3
|
Welcome to a DSL for creating Mikado Graphs using *GraphViz*.
|
4
4
|
|
@@ -33,30 +33,32 @@ You can use this gem's DSL in the following way to create a Mikado Graph generat
|
|
33
33
|
```ruby
|
34
34
|
require "mikado_graph"
|
35
35
|
|
36
|
-
MikadoGraph::Generator.
|
37
|
-
state("State A").depends_on
|
38
|
-
state("State B").depends_on
|
36
|
+
MikadoGraph::Generator.define do
|
37
|
+
state("State A").depends_on {
|
38
|
+
state("State B").depends_on {
|
39
39
|
state("State D")
|
40
40
|
state("State E")
|
41
|
-
|
42
|
-
state("State C").depends_on
|
41
|
+
}
|
42
|
+
state("State C").depends_on {
|
43
43
|
state("State F")
|
44
44
|
state("State G")
|
45
|
-
|
46
|
-
|
47
|
-
end
|
45
|
+
}
|
46
|
+
}
|
47
|
+
end.generate("png", "img/example_usage.png") # generate takes GraphViz format and output path
|
48
48
|
```
|
49
49
|
|
50
|
-
|
50
|
+
Save this file to `example_usage.rb` and then you can then execute this file in the terminal using:
|
51
51
|
|
52
52
|
```bash
|
53
|
-
ruby
|
53
|
+
ruby example_usage.rb
|
54
54
|
```
|
55
55
|
|
56
56
|
This will utilize the *GraphViz* `dot` command to create this PNG output of the above Mikado Graph generator definition:
|
57
57
|
|
58
58
|
![Multi-Level Mikado Graph](https://github.com/snasirca/mikado_graph_generator/blob/master/img/multi_level_mikado_graph.png)
|
59
59
|
|
60
|
+
NOTE: If you don't provide any parameters to `generate`, it'll default to a `dot` output in the STDOUT.
|
61
|
+
|
60
62
|
## Development
|
61
63
|
|
62
64
|
After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
|
data/example_usage.rb
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
require "mikado_graph"
|
2
|
+
|
3
|
+
MikadoGraph::Generator.define do
|
4
|
+
state("State A").depends_on {
|
5
|
+
state("State B").depends_on {
|
6
|
+
state("State D")
|
7
|
+
state("State E")
|
8
|
+
}
|
9
|
+
state("State C").depends_on {
|
10
|
+
state("State F")
|
11
|
+
state("State G")
|
12
|
+
}
|
13
|
+
}
|
14
|
+
end.generate("png", "img/example_usage.png")
|
@@ -1,44 +1,50 @@
|
|
1
|
+
require "graphviz"
|
2
|
+
|
1
3
|
module MikadoGraph
|
2
|
-
|
3
|
-
|
4
|
+
class Generator
|
5
|
+
attr_reader :dependencies, :graph
|
6
|
+
|
7
|
+
def self.define(&block)
|
8
|
+
generator_instance = new
|
9
|
+
generator_instance.dependencies.instance_eval(&block)
|
10
|
+
generator_instance
|
11
|
+
end
|
4
12
|
|
5
|
-
def generate(
|
6
|
-
dependencies
|
7
|
-
|
8
|
-
|
13
|
+
def generate(format = "dot", path = nil)
|
14
|
+
add_states_to_graph(dependencies.dependent_states)
|
15
|
+
output_options = {}
|
16
|
+
output_options[format] = path
|
17
|
+
graph.output(output_options)
|
9
18
|
end
|
10
19
|
|
11
20
|
private
|
12
21
|
|
13
|
-
def
|
14
|
-
|
15
|
-
|
16
|
-
convert_footer
|
22
|
+
def initialize
|
23
|
+
@dependencies = Dependencies.new
|
24
|
+
initialize_graph
|
17
25
|
end
|
18
26
|
|
19
|
-
def
|
20
|
-
|
21
|
-
|
22
|
-
|
27
|
+
def initialize_graph
|
28
|
+
@graph = GraphViz.new(nil)
|
29
|
+
@graph[:rankdir] = "LR"
|
30
|
+
@graph.node[:shape] = "box"
|
23
31
|
end
|
24
32
|
|
25
|
-
def
|
26
|
-
states.each { |state|
|
33
|
+
def add_states_to_graph(states)
|
34
|
+
states.each { |state| add_state_dependencies(state) }
|
27
35
|
end
|
28
36
|
|
29
|
-
def
|
37
|
+
def add_state_dependencies(state)
|
30
38
|
state.dependent_states.each do |dependent_state|
|
31
|
-
|
32
|
-
|
39
|
+
add_dependency(state, dependent_state)
|
40
|
+
add_state_dependencies(dependent_state)
|
33
41
|
end
|
34
42
|
end
|
35
43
|
|
36
|
-
def
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
def convert_footer
|
41
|
-
puts "}"
|
44
|
+
def add_dependency(state, dependent_state)
|
45
|
+
state_node = graph.add_nodes(state.name)
|
46
|
+
dependent_state_node = graph.add_nodes(dependent_state.name)
|
47
|
+
graph.add_edges(dependent_state_node, state_node)
|
42
48
|
end
|
43
49
|
end
|
44
50
|
end
|
data/lib/mikado_graph/version.rb
CHANGED
data/mikado_graph.gemspec
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: mikado_graph_generator
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Shahriyar Nasir
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2017-02-
|
11
|
+
date: 2017-02-02 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -52,6 +52,20 @@ dependencies:
|
|
52
52
|
- - "~>"
|
53
53
|
- !ruby/object:Gem::Version
|
54
54
|
version: '3.0'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: ruby-graphviz
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - ">="
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0'
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - ">="
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '0'
|
55
69
|
description: Provides a simple DSL for generating Mikado Graphs using GraphViz.
|
56
70
|
email:
|
57
71
|
- contact@snasir.ca
|
@@ -70,7 +84,7 @@ files:
|
|
70
84
|
- Rakefile
|
71
85
|
- bin/console
|
72
86
|
- bin/setup
|
73
|
-
-
|
87
|
+
- example_usage.rb
|
74
88
|
- lib/mikado_graph.rb
|
75
89
|
- lib/mikado_graph/dependencies.rb
|
76
90
|
- lib/mikado_graph/generator.rb
|
Binary file
|