mikado_graph_generator 0.2.2 → 0.3.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 9668c3aa3a4cbac985e84579b150178e63a3b155
4
- data.tar.gz: de1a9a1372befe308df515bc7af3385b6d39f75e
3
+ metadata.gz: f3c75276f5053c1f45d6fd5e88ff3a0c276eaae1
4
+ data.tar.gz: dbea48efaa1e281a7909bf990f9c6fb5a7f81160
5
5
  SHA512:
6
- metadata.gz: c294f274b5a39dc63f13ad80bf3cd7c1a78ea37ac58a1980018f59aac5f8e21ffc879695c556926ded48b1f2197ce0fae038465dbb6bf739d47aa689efa6de3d
7
- data.tar.gz: d6a43e88070ce788e8cad2c79ade43ff102bfbbe658a9fc34d665e6a0fef207360a680ad41a2e94b377e7ec8e33ccd49fe84364ed10b13e62b1a736adddf93cd
6
+ metadata.gz: cb5d06068c26ef4a6cbf7ac97f471c8f642046bc6159c55df1c77a61b42481eea02e124b43403ad0f8fd9ec9c5f02ea6887b2fab2e3369caa0fe0f58554b9b10
7
+ data.tar.gz: 36f1d8b650b48d2aa28fd57ff35d01477bcee22a6303a0ab6956c0350e7580faaa797f9e32f1a950b7bdf88696bd19c9e7d9813bd18076fb80ef75db71705bd4
data/.envrc ADDED
@@ -0,0 +1,3 @@
1
+ #!/usr/bin/env bash
2
+
3
+ export PATH=`pwd`/bin:$PATH
@@ -0,0 +1,3 @@
1
+ #!/usr/bin/env bash
2
+
3
+ export PATH=`pwd`/bin:$PATH
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- mikado_graph_generator (0.2.2)
4
+ mikado_graph_generator (0.3.0)
5
5
 
6
6
  GEM
7
7
  remote: https://rubygems.org/
data/README.md CHANGED
@@ -44,21 +44,50 @@ MikadoGraph::Generator.define do
44
44
  state("State G")
45
45
  end
46
46
  end
47
- end.generate("png", "img/example_usage.png") # generate takes GraphViz format and output path
47
+ end.generate("png", "img/example_usage_vertical.png") # generate takes GraphViz format and output path
48
48
  ```
49
49
 
50
- Save this file to `example_usage.rb` and then you can then execute this file in the terminal using:
50
+ Save this file to `example_usage_vertical.rb` and then you can then execute this file in the terminal using:
51
51
 
52
52
  ```bash
53
- ruby example_usage.rb
53
+ ruby example_usage_vertical.rb
54
54
  ```
55
55
 
56
- This will utilize the *GraphViz* `dot` command to create this PNG output of the above Mikado Graph generator definition:
56
+ This will utilize *GraphViz* to create this PNG output of the above Mikado Graph generator definition:
57
57
 
58
- ![Example Usage](https://github.com/snasirca/mikado_graph_generator/blob/master/img/example_usage.png)
58
+ ![Example Usage Vertical](https://github.com/snasirca/mikado_graph_generator/blob/master/img/example_usage_vertical.png)
59
59
 
60
60
  NOTE: If you don't provide any parameters to `generate`, it'll default to a `dot` output in the STDOUT.
61
61
 
62
+ If you want to instead do a horizontal orientation of your graph, simply provide the direction flag to `#generate` like so:
63
+
64
+ ```ruby
65
+ generate(direction: :horizontal)
66
+ ```
67
+
68
+ Here is an example usage:
69
+
70
+ ```ruby
71
+ require "mikado_graph"
72
+
73
+ MikadoGraph::Generator.define do
74
+ state("State A").depends_on do
75
+ state("State B").depends_on do
76
+ state("State D")
77
+ state("State E")
78
+ end
79
+ state("State C").depends_on do
80
+ state("State F")
81
+ state("State G")
82
+ end
83
+ end
84
+ end.generate(format: "png", path: "img/example_usage_horizontal.png", direction: :horizontal)
85
+ ```
86
+
87
+ This will generate this graph:
88
+
89
+ ![Example Usage Horizontal](https://github.com/snasirca/mikado_graph_generator/blob/master/img/example_usage_horizontal.png)
90
+
62
91
  ## Development
63
92
 
64
93
  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.
@@ -0,0 +1,14 @@
1
+ require "mikado_graph"
2
+
3
+ MikadoGraph::Generator.define do
4
+ state("State A").depends_on do
5
+ state("State B").depends_on do
6
+ state("State D")
7
+ state("State E")
8
+ end
9
+ state("State C").depends_on do
10
+ state("State F")
11
+ state("State G")
12
+ end
13
+ end
14
+ end.generate(format: "png", path: "img/example_usage_horizontal.png", direction: :horizontal)
@@ -11,4 +11,4 @@ MikadoGraph::Generator.define do
11
11
  state("State G")
12
12
  end
13
13
  end
14
- end.generate("png", "img/example_usage.png")
14
+ end.generate(format: "png", path: "img/example_usage_vertical.png")
@@ -10,10 +10,10 @@ module MikadoGraph
10
10
  generator_instance
11
11
  end
12
12
 
13
- def generate(format = "dot", path = nil)
13
+ def generate(options = {})
14
14
  add_states_to_graph(dependencies.dependent_states)
15
- output_options = {}
16
- output_options[format] = path
15
+ arrange_graph_direction(options)
16
+ output_options = build_output_options(options)
17
17
  graph.output(output_options)
18
18
  end
19
19
 
@@ -26,7 +26,6 @@ module MikadoGraph
26
26
 
27
27
  def initialize_graph
28
28
  @graph = GraphViz.new(nil)
29
- @graph[:rankdir] = "LR"
30
29
  @graph.node[:shape] = "box"
31
30
  end
32
31
 
@@ -46,5 +45,16 @@ module MikadoGraph
46
45
  dependent_state_node = graph.add_nodes(dependent_state.name)
47
46
  graph.add_edges(dependent_state_node, state_node)
48
47
  end
48
+
49
+ def arrange_graph_direction(options)
50
+ direction = options.fetch(:direction, :vertical)
51
+ graph[:rankdir] = "LR" if direction == :horizontal
52
+ end
53
+
54
+ def build_output_options(options)
55
+ output_options = {}
56
+ output_options[options.fetch(:format, "dot")] = options.fetch(:path, nil)
57
+ output_options
58
+ end
49
59
  end
50
60
  end
@@ -1,3 +1,3 @@
1
1
  module MikadoGraph
2
- VERSION = "0.2.2"
2
+ VERSION = "0.3.0"
3
3
  end
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.2.2
4
+ version: 0.3.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-06 00:00:00.000000000 Z
11
+ date: 2017-02-09 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -145,6 +145,8 @@ extra_rdoc_files: []
145
145
  files:
146
146
  - ".codeclimate.yml"
147
147
  - ".editorconfig"
148
+ - ".envrc"
149
+ - ".envrc.sample"
148
150
  - ".gitignore"
149
151
  - ".rspec"
150
152
  - ".rubocop"
@@ -161,8 +163,10 @@ files:
161
163
  - Rakefile
162
164
  - bin/console
163
165
  - bin/setup
164
- - example_usage.rb
165
- - img/example_usage.png
166
+ - example_usage_horizontal.rb
167
+ - example_usage_vertical.rb
168
+ - img/example_usage_horizontal.png
169
+ - img/example_usage_vertical.png
166
170
  - lib/mikado_graph.rb
167
171
  - lib/mikado_graph/dependencies.rb
168
172
  - lib/mikado_graph/generator.rb