graphviz 0.3.0 → 0.4.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: 3c4f0f3b611287cceb14c4dac3e77e2497ffae13
4
- data.tar.gz: fe7cf2f64b8febce78609be21cce9ef81f7cccc7
3
+ metadata.gz: 26ed6f42266187f65af641382518c0d00e2eabd8
4
+ data.tar.gz: 3ac7a918a5f7da7288fec080a712b572eddecfbb
5
5
  SHA512:
6
- metadata.gz: 65d2682330f3b2d3aaa63590950eeb0c52db5a7071d3e0d89a110ab19de7df2a3f4759cc3f007529db310e8c1d8aa8f742133dca3270b17031332c4ea5193252
7
- data.tar.gz: 36c924356952539a6856848857607d4b1d67d512132595f09f02373becc85aae462f214490ace2912699e560e8a231531a6f6ae2957af606b1c2fe330777c9c4
6
+ metadata.gz: 23e5b1deba81bd053beb0dab4c03450b16324df909999233d5a344f8e205682d412f1d27c3c80a81693b0dbbdadcaae3eb463dda72f7eb9b1d6f16b235420602
7
+ data.tar.gz: 82088298acc5dd68c759a1ae87ed5c40a15d7b863da5e643e9d402d94c2ffa465dc124608bb058e69570c492c9a9fcd985c3a9d6943a6973325f29e1b04063a6
data/.rspec CHANGED
@@ -1,2 +1,5 @@
1
- --color
2
- --format documentation
1
+ --color
2
+ --format documentation
3
+ --backtrace
4
+ --require spec_helper
5
+ --warnings
@@ -1,17 +1,15 @@
1
1
  language: ruby
2
- sudo: required
3
- before_install:
4
- # We need GraphViz for testing:
5
- - sudo apt-get install graphviz
2
+ sudo: false
3
+ dist: trusty
4
+
5
+ addons:
6
+ apt:
7
+ packages:
8
+ - graphviz
9
+
6
10
  rvm:
7
- - 2.0.0
8
- - 2.1.8
9
- - 2.2.4
10
- - 2.3.0
11
+ - 2.1
12
+ - 2.2
13
+ - 2.3
14
+ - 2.4
11
15
  - ruby-head
12
- - rbx-2
13
- env: COVERAGE=true
14
- matrix:
15
- allow_failures:
16
- - rvm: "rbx-2"
17
-
data/Gemfile CHANGED
@@ -2,3 +2,8 @@ source 'https://rubygems.org'
2
2
 
3
3
  # Specify your gem's dependencies in graphviz.gemspec
4
4
  gemspec
5
+
6
+ group :development do
7
+ gem "guard-rspec"
8
+ gem "simplecov"
9
+ end
@@ -0,0 +1,12 @@
1
+ # frozen_string_literal: true
2
+
3
+ directories %w(lib spec)
4
+ clearing :on
5
+
6
+ ENV['COVERAGE'] = 'y'
7
+
8
+ guard :rspec, cmd: "bundle exec rspec" do
9
+ watch(%r{^spec/.+_spec\.rb$})
10
+ watch(%r{^lib/(.+)\.rb$}) { |m| "spec/#{m[1]}_spec.rb" }
11
+ watch("spec/spec_helper.rb") { "spec" }
12
+ end
data/README.md CHANGED
@@ -3,7 +3,8 @@
3
3
  Graphviz is a graph visualisation system. This gem is a lightweight interface for generating graphs with Graphviz.
4
4
 
5
5
  [![Build Status](https://travis-ci.org/ioquatix/graphviz.svg)](https://travis-ci.org/ioquatix/graphviz)
6
- [![Code Climate](https://codeclimate.com/github/ioquatix/graphviz.png)](https://codeclimate.com/github/ioquatix/graphviz)
6
+ [![Code Climate](https://codeclimate.com/github/ioquatix/graphviz.svg)](https://codeclimate.com/github/ioquatix/graphviz)
7
+ [![Coverage Status](https://coveralls.io/repos/ioquatix/graphviz/badge.svg)](https://coveralls.io/r/ioquatix/graphviz)
7
8
 
8
9
  ## Installation
9
10
 
@@ -0,0 +1,37 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require_relative 'lib/graphviz.rb'
4
+
5
+ # Hello
6
+ # |
7
+ # People
8
+
9
+ hello = Graphviz::Graph.new("Hello")
10
+ keywords = []
11
+ keywords[0] = hello.add_node("Hello")
12
+ keywords[1] = hello.add_node("People")
13
+
14
+ # We link Hello to People
15
+ hello_people = keywords[0].connect(keywords[1])
16
+
17
+ # People
18
+ # / | \
19
+ # Bob Jim Kev
20
+
21
+ people = Graphviz::Graph.new("People")
22
+ persons = []
23
+ persons[0] = people.add_node("Bob")
24
+ persons[1] = people.add_node("Jim")
25
+ persons[2] = people.add_node("Kev")
26
+
27
+ # We link people (People = {Bob, Jim, Kev})
28
+ people_bob = keywords[1].connect(persons[0])
29
+ people_jim = keywords[1].connect(persons[1])
30
+ people_kev = keywords[1].connect(persons[2])
31
+
32
+ # Attributes for "Hello"
33
+ keywords[0].attributes[:shape] = 'box3d'
34
+ keywords[0].attributes[:color] = 'red'
35
+
36
+ # Generate the Graph (pdf format)
37
+ Graphviz::output(hello, :path => "test.pdf")
@@ -18,8 +18,8 @@
18
18
  # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
19
19
  # THE SOFTWARE.
20
20
 
21
- require "graphviz/version"
22
- require "graphviz/graph"
21
+ require_relative "graphviz/version"
22
+ require_relative "graphviz/graph"
23
23
 
24
24
  module Graphviz
25
25
  # Signals that the process exited with a non-zero status.
@@ -54,7 +54,7 @@ module Graphviz
54
54
  output.close
55
55
 
56
56
  # Send graph data to process:
57
- input.write(graph.to_dot)
57
+ input.write(text)
58
58
  input.close
59
59
 
60
60
  _, status = Process.wait2(pid)
@@ -0,0 +1,52 @@
1
+ # Copyright, 2014, by Samuel G. D. Williams. <http://www.codeotaku.com>
2
+ #
3
+ # Permission is hereby granted, free of charge, to any person obtaining a copy
4
+ # of this software and associated documentation files (the "Software"), to deal
5
+ # in the Software without restriction, including without limitation the rights
6
+ # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
7
+ # copies of the Software, and to permit persons to whom the Software is
8
+ # furnished to do so, subject to the following conditions:
9
+ #
10
+ # The above copyright notice and this permission notice shall be included in
11
+ # all copies or substantial portions of the Software.
12
+ #
13
+ # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
14
+ # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
15
+ # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
16
+ # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
17
+ # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
18
+ # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
19
+ # THE SOFTWARE.
20
+
21
+ require 'stringio'
22
+
23
+ module Graphviz
24
+ # Represents a visual edge between two nodes.
25
+ class Edge
26
+ # Initialize the edge in the given graph, with a source and destination node.
27
+ # @param attributes [Hash] The associated graphviz attributes for this edge.
28
+ def initialize(graph, source, destination, attributes = {})
29
+ @graph = graph
30
+ @graph.edges << self
31
+
32
+ @source = source
33
+ @destination = destination
34
+
35
+ @attributes = attributes
36
+ end
37
+
38
+ # @return [Node] The source node.
39
+ attr :source
40
+
41
+ # @return [Node] The destination node.
42
+ attr :destination
43
+
44
+ # @return [Hash] Any attributes specified for this edge.
45
+ attr_accessor :attributes
46
+
47
+ # @return [String] A convenient ASCII arrow.
48
+ def to_s
49
+ "#{@source} -> #{@destination}"
50
+ end
51
+ end
52
+ end
@@ -20,118 +20,9 @@
20
20
 
21
21
  require 'stringio'
22
22
 
23
+ require_relative 'node'
24
+
23
25
  module Graphviz
24
- # Represents a visual node in the graph, which can be connected to other nodes.
25
- class Node
26
- # Initialize the node in the graph with the unique name.
27
- # @param attributes [Hash] The associated graphviz attributes for this node.
28
- def initialize(name, graph = nil, **attributes)
29
- @name = name
30
- @attributes = attributes
31
-
32
- @connections = []
33
-
34
- graph << self if graph
35
- end
36
-
37
- # Attach this node to the given graph:
38
- def attach(parent)
39
- @graph = parent
40
- end
41
-
42
- # @return [String] The unique name of the node.
43
- attr :name
44
-
45
- # @return [Array<Edge>] Any edges connecting to other nodes.
46
- attr :connections
47
-
48
- # @return [Hash] Any attributes specified for this node.
49
- attr_accessor :attributes
50
-
51
- # Create an edge between this node and the destination with the specified options.
52
- # @param attributes [Hash] The associated graphviz attributes for the edge.
53
- def connect(destination, attributes = {})
54
- edge = Edge.new(@graph, self, destination, attributes)
55
-
56
- @connections << edge
57
-
58
- return edge
59
- end
60
-
61
- # Calculate if this node is connected to another. +O(N)+ search required.
62
- def connected?(node)
63
- return @connections.find{|edge| edge.destination == node}
64
- end
65
-
66
- # Add a node and #connect to it.
67
- # @param attributes [Hash] The associated graphviz attributes for the new node.
68
- def add_node(name = nil, **attributes)
69
- node = @graph.add_node(name, **attributes)
70
-
71
- connect(node)
72
-
73
- return node
74
- end
75
-
76
- def identifier
77
- @name
78
- end
79
-
80
- def dump_graph(buffer, indent, options)
81
- node_attributes_text = dump_attributes(@attributes)
82
- node_name = dump_value(self.identifier)
83
-
84
- buffer.puts "#{indent}#{node_name}#{node_attributes_text};"
85
- end
86
-
87
- # Dump the value to dot text format.
88
- def dump_value(value)
89
- if Symbol === value
90
- value.to_s
91
- else
92
- value.inspect
93
- end
94
- end
95
-
96
- # Dump the attributes to dot text format.
97
- def dump_attributes(attributes)
98
- if attributes.size > 0
99
- "[" + attributes.collect{|(name, value)| "#{name}=#{dump_value(value)}"}.join(", ") + "]"
100
- else
101
- ""
102
- end
103
- end
104
- end
105
-
106
- # Represents a visual edge between two nodes.
107
- class Edge
108
- # Initialize the edge in the given graph, with a source and destination node.
109
- # @param attributes [Hash] The associated graphviz attributes for this edge.
110
- def initialize(graph, source, destination, attributes = {})
111
- @graph = graph
112
- @graph.edges << self
113
-
114
- @source = source
115
- @destination = destination
116
-
117
- @attributes = attributes
118
- end
119
-
120
- # @return [Node] The source node.
121
- attr :source
122
-
123
- # @return [Node] The destination node.
124
- attr :destination
125
-
126
- # @return [Hash] Any attributes specified for this edge.
127
- attr_accessor :attributes
128
-
129
- # @return [String] A convenient ASCII arrow.
130
- def to_s
131
- '->'
132
- end
133
- end
134
-
135
26
  # Contains a set of nodes, edges and subgraphs.
136
27
  class Graph < Node
137
28
  # Initialize the graph with the specified unique name.
@@ -148,9 +39,6 @@ module Graphviz
148
39
  # @return [Array<Node>] All nodes in the graph.
149
40
  attr :nodes
150
41
 
151
- # @return [Array<Graph>] Any subgraphs.
152
- attr :graphs
153
-
154
42
  # @return [Hash] Any associated graphviz attributes.
155
43
  attr_accessor :attributes
156
44
 
@@ -206,11 +94,9 @@ module Graphviz
206
94
 
207
95
  def dump_edges(buffer, indent, options)
208
96
  @edges.each do |edge|
209
- from_name = dump_value(edge.source.identifier)
210
- to_name = dump_value(edge.destination.identifier)
211
97
  edge_attributes_text = dump_attributes(edge.attributes)
212
98
 
213
- buffer.puts "#{indent}#{from_name} #{edge} #{to_name}#{edge_attributes_text};"
99
+ buffer.puts "#{indent}#{edge}#{edge_attributes_text};"
214
100
  end
215
101
  end
216
102
 
@@ -220,11 +106,11 @@ module Graphviz
220
106
 
221
107
  buffer.puts "#{indent}#{format} #{dump_value(self.identifier)} {"
222
108
 
223
- @attributes.each do |(name, value)|
109
+ @attributes.each do |name, value|
224
110
  buffer.puts "#{indent}\t#{name}=#{dump_value(value)};"
225
111
  end
226
112
 
227
- @nodes.each do |(name, node)|
113
+ @nodes.each do |name, node|
228
114
  node.dump_graph(buffer, indent + "\t", options)
229
115
  end
230
116
 
@@ -0,0 +1,111 @@
1
+ # Copyright, 2017, by Samuel G. D. Williams. <http://www.codeotaku.com>
2
+ #
3
+ # Permission is hereby granted, free of charge, to any person obtaining a copy
4
+ # of this software and associated documentation files (the "Software"), to deal
5
+ # in the Software without restriction, including without limitation the rights
6
+ # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
7
+ # copies of the Software, and to permit persons to whom the Software is
8
+ # furnished to do so, subject to the following conditions:
9
+ #
10
+ # The above copyright notice and this permission notice shall be included in
11
+ # all copies or substantial portions of the Software.
12
+ #
13
+ # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
14
+ # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
15
+ # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
16
+ # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
17
+ # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
18
+ # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
19
+ # THE SOFTWARE.
20
+
21
+ require_relative 'edge'
22
+
23
+ module Graphviz
24
+ # Represents a visual node in the graph, which can be connected to other nodes.
25
+ class Node
26
+ # Initialize the node in the graph with the unique name.
27
+ # @param attributes [Hash] The associated graphviz attributes for this node.
28
+ def initialize(name, graph = nil, **attributes)
29
+ @name = name
30
+ @attributes = attributes
31
+
32
+ @connections = []
33
+
34
+ # This sets up the connection between the node and the parent.
35
+ @graph = nil
36
+ graph << self if graph
37
+ end
38
+
39
+ # Attach this node to the given graph:
40
+ def attach(parent)
41
+ @graph = parent
42
+ end
43
+
44
+ # @return [String] The unique name of the node.
45
+ attr :name
46
+
47
+ # @return [Array<Edge>] Any edges connecting to other nodes.
48
+ attr :connections
49
+
50
+ # @return [Hash] Any attributes specified for this node.
51
+ attr_accessor :attributes
52
+
53
+ # Create an edge between this node and the destination with the specified options.
54
+ # @param attributes [Hash] The associated graphviz attributes for the edge.
55
+ def connect(destination, attributes = {})
56
+ edge = Edge.new(@graph, self, destination, attributes)
57
+
58
+ @connections << edge
59
+
60
+ return edge
61
+ end
62
+
63
+ # Calculate if this node is connected to another. +O(N)+ search required.
64
+ def connected?(node)
65
+ return @connections.find{|edge| edge.destination == node}
66
+ end
67
+
68
+ # Add a node and #connect to it.
69
+ # @param attributes [Hash] The associated graphviz attributes for the new node.
70
+ def add_node(name = nil, **attributes)
71
+ node = @graph.add_node(name, **attributes)
72
+
73
+ connect(node)
74
+
75
+ return node
76
+ end
77
+
78
+ def identifier
79
+ @name
80
+ end
81
+
82
+ def dump_graph(buffer, indent, options)
83
+ node_attributes_text = dump_attributes(@attributes)
84
+ node_name = dump_value(self.identifier)
85
+
86
+ buffer.puts "#{indent}#{node_name}#{node_attributes_text};"
87
+ end
88
+
89
+ def to_s
90
+ dump_value(@name)
91
+ end
92
+
93
+ # Dump the value to dot text format.
94
+ def dump_value(value)
95
+ if Symbol === value
96
+ value.to_s
97
+ else
98
+ value.inspect
99
+ end
100
+ end
101
+
102
+ # Dump the attributes to dot text format.
103
+ def dump_attributes(attributes)
104
+ if attributes.size > 0
105
+ "[" + attributes.collect{|name, value| "#{name}=#{dump_value(value)}"}.join(", ") + "]"
106
+ else
107
+ ""
108
+ end
109
+ end
110
+ end
111
+ end
@@ -19,6 +19,5 @@
19
19
  # THE SOFTWARE.
20
20
 
21
21
  module Graphviz
22
- # The version.
23
- VERSION = "0.3.0"
22
+ VERSION = "0.4.0"
24
23
  end
@@ -0,0 +1,15 @@
1
+
2
+ RSpec.describe Graphviz::Edge do
3
+ let(:graph) {Graphviz::Graph.new}
4
+
5
+ let(:a) {Graphviz::Node.new(:a, graph)}
6
+ let(:b) {Graphviz::Node.new(:b, graph)}
7
+
8
+ describe '#to_s' do
9
+ subject{a.connect(b)}
10
+
11
+ it 'should generate edge string' do
12
+ expect(subject.to_s).to be == 'a -> b'
13
+ end
14
+ end
15
+ end
@@ -0,0 +1,29 @@
1
+
2
+ if ENV['COVERAGE'] || ENV['TRAVIS']
3
+ begin
4
+ require 'simplecov'
5
+
6
+ SimpleCov.start do
7
+ add_filter "/spec/"
8
+ end
9
+
10
+ if ENV['TRAVIS']
11
+ require 'coveralls'
12
+ Coveralls.wear!
13
+ end
14
+ rescue LoadError
15
+ warn "Could not load simplecov: #{$!}"
16
+ end
17
+ end
18
+
19
+ require "bundler/setup"
20
+ require "graphviz"
21
+
22
+ RSpec.configure do |config|
23
+ # Enable flags like --only-failures and --next-failure
24
+ config.example_status_persistence_file_path = ".rspec_status"
25
+
26
+ config.expect_with :rspec do |c|
27
+ c.syntax = :expect
28
+ end
29
+ end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: graphviz
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.0
4
+ version: 0.4.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Samuel Williams
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-02-05 00:00:00.000000000 Z
11
+ date: 2017-04-24 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: yard
@@ -78,13 +78,19 @@ files:
78
78
  - ".rspec"
79
79
  - ".travis.yml"
80
80
  - Gemfile
81
+ - Guardfile
81
82
  - README.md
82
83
  - Rakefile
84
+ - examples/demo.rb
83
85
  - graphviz.gemspec
84
86
  - lib/graphviz.rb
87
+ - lib/graphviz/edge.rb
85
88
  - lib/graphviz/graph.rb
89
+ - lib/graphviz/node.rb
86
90
  - lib/graphviz/version.rb
91
+ - spec/graphviz/edge_spec.rb
87
92
  - spec/graphviz/graph_spec.rb
93
+ - spec/spec_helper.rb
88
94
  homepage: ''
89
95
  licenses:
90
96
  - MIT
@@ -105,10 +111,12 @@ required_rubygems_version: !ruby/object:Gem::Requirement
105
111
  version: '0'
106
112
  requirements: []
107
113
  rubyforge_project:
108
- rubygems_version: 2.2.2
114
+ rubygems_version: 2.6.10
109
115
  signing_key:
110
116
  specification_version: 4
111
117
  summary: A lightweight interface for generating graphs with Graphviz.
112
118
  test_files:
119
+ - spec/graphviz/edge_spec.rb
113
120
  - spec/graphviz/graph_spec.rb
121
+ - spec/spec_helper.rb
114
122
  has_rdoc: yard