graphviz 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +17 -0
- data/Gemfile +4 -0
- data/README.md +53 -0
- data/graphviz.gemspec +27 -0
- data/lib/graphviz.rb +62 -0
- data/lib/graphviz/graph.rb +115 -0
- data/lib/graphviz/version.rb +3 -0
- data/rakefile.rb +1 -0
- data/sample.rb +10 -0
- metadata +96 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 53f53e53933990cd7d1db7893e889953abfcb29f
|
4
|
+
data.tar.gz: e5937034681308f0cc005cff8927427b5a14f8e4
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: e34c656a49ce0dc4ad30973e1093fef0bfc8fbef62622645e44d3f993bfc11c60a0ab8ad52a3f0badcd1102717132b8350b6c4632444d82a78ee8b7fe89057f4
|
7
|
+
data.tar.gz: 5b9196eed4421dc028400df9aa52a1610e8ddd8f20d654169823870ca90ff137c80f7b0b29f719db88bf13cfaca3ea56d624dbdd50c1de35488f12c15f5c548f
|
data/.gitignore
ADDED
data/Gemfile
ADDED
data/README.md
ADDED
@@ -0,0 +1,53 @@
|
|
1
|
+
# Graphviz
|
2
|
+
|
3
|
+
Graphviz is a graph visualisation system. This gem is a lightweight interface for generating graphs with Graphviz.
|
4
|
+
|
5
|
+
## Installation
|
6
|
+
|
7
|
+
Add this line to your application's Gemfile:
|
8
|
+
|
9
|
+
gem 'graphviz'
|
10
|
+
|
11
|
+
And then execute:
|
12
|
+
|
13
|
+
$ bundle
|
14
|
+
|
15
|
+
Or install it yourself as:
|
16
|
+
|
17
|
+
$ gem install graphviz
|
18
|
+
|
19
|
+
## Usage
|
20
|
+
|
21
|
+
TODO: Write usage instructions here
|
22
|
+
|
23
|
+
## Contributing
|
24
|
+
|
25
|
+
1. Fork it
|
26
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
27
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
28
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
29
|
+
5. Create new Pull Request
|
30
|
+
|
31
|
+
## License
|
32
|
+
|
33
|
+
Released under the MIT license.
|
34
|
+
|
35
|
+
Copyright, 2013, by [Samuel G. D. Williams](http://www.codeotaku.com/samuel-williams).
|
36
|
+
|
37
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
38
|
+
of this software and associated documentation files (the "Software"), to deal
|
39
|
+
in the Software without restriction, including without limitation the rights
|
40
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
41
|
+
copies of the Software, and to permit persons to whom the Software is
|
42
|
+
furnished to do so, subject to the following conditions:
|
43
|
+
|
44
|
+
The above copyright notice and this permission notice shall be included in
|
45
|
+
all copies or substantial portions of the Software.
|
46
|
+
|
47
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
48
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
49
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
50
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
51
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
52
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
53
|
+
THE SOFTWARE.
|
data/graphviz.gemspec
ADDED
@@ -0,0 +1,27 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'graphviz/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "graphviz"
|
8
|
+
spec.version = Graphviz::VERSION
|
9
|
+
spec.authors = ["Samuel Williams"]
|
10
|
+
spec.email = ["samuel.williams@oriontransfer.co.nz"]
|
11
|
+
spec.description = <<-EOF
|
12
|
+
Graphviz is a graph visualisation system. This gem is a lightweight interface for generating graphs with Graphviz.
|
13
|
+
EOF
|
14
|
+
spec.summary = "A lightweight interface for generating graphs with Graphviz."
|
15
|
+
spec.homepage = ""
|
16
|
+
spec.license = "MIT"
|
17
|
+
|
18
|
+
spec.files = `git ls-files`.split($/)
|
19
|
+
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
20
|
+
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
21
|
+
spec.require_paths = ["lib"]
|
22
|
+
|
23
|
+
spec.add_development_dependency "bundler", "~> 1.3"
|
24
|
+
spec.add_development_dependency "rake"
|
25
|
+
|
26
|
+
spec.add_dependency "rexec"
|
27
|
+
end
|
data/lib/graphviz.rb
ADDED
@@ -0,0 +1,62 @@
|
|
1
|
+
# Copyright (c) 2013 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 "graphviz/version"
|
22
|
+
|
23
|
+
require "graphviz/graph"
|
24
|
+
require 'rexec'
|
25
|
+
|
26
|
+
module Graphviz
|
27
|
+
class OutputError < StandardError
|
28
|
+
end
|
29
|
+
|
30
|
+
def self.output(graph, options = {})
|
31
|
+
text = graph.to_dot
|
32
|
+
|
33
|
+
output_format = options[:format]
|
34
|
+
|
35
|
+
if options[:path]
|
36
|
+
# Grab the output format from the file name:
|
37
|
+
if options[:path] =~ /\.(.*?)$/
|
38
|
+
output_format ||= $1
|
39
|
+
end
|
40
|
+
|
41
|
+
output_file = File.open(options[:path], "w")
|
42
|
+
else
|
43
|
+
output_file = IO.pipe
|
44
|
+
end
|
45
|
+
|
46
|
+
RExec::Task.open(["dot", "-T#{output_format}"], :out => output_file) do |task|
|
47
|
+
task.input.puts(graph.to_dot)
|
48
|
+
task.input.close
|
49
|
+
|
50
|
+
status = task.wait
|
51
|
+
|
52
|
+
if status != 0
|
53
|
+
raise OutputError.new(task.error.read)
|
54
|
+
end
|
55
|
+
|
56
|
+
# Did we use a local pipe for output?
|
57
|
+
if Array === output_file
|
58
|
+
return task.output.read
|
59
|
+
end
|
60
|
+
end
|
61
|
+
end
|
62
|
+
end
|
@@ -0,0 +1,115 @@
|
|
1
|
+
# Copyright (c) 2013 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
|
+
class Node
|
25
|
+
def initialize(graph, name, options)
|
26
|
+
@graph = graph
|
27
|
+
@graph.nodes[name] = self
|
28
|
+
|
29
|
+
@name = name
|
30
|
+
@options = options
|
31
|
+
|
32
|
+
@edges = []
|
33
|
+
end
|
34
|
+
|
35
|
+
attr :name
|
36
|
+
attr :options
|
37
|
+
|
38
|
+
attr :edges
|
39
|
+
|
40
|
+
def connect(destination, options = {})
|
41
|
+
edge = Edge.new(@graph, self, destination, options)
|
42
|
+
|
43
|
+
@edges << edge
|
44
|
+
|
45
|
+
return edge
|
46
|
+
end
|
47
|
+
|
48
|
+
def add_node(name, options = {})
|
49
|
+
node = Node.new(@graph, name, options)
|
50
|
+
|
51
|
+
connect(node)
|
52
|
+
|
53
|
+
return node
|
54
|
+
end
|
55
|
+
end
|
56
|
+
|
57
|
+
class Edge
|
58
|
+
def initialize(graph, source, destination, options = {})
|
59
|
+
@graph = graph
|
60
|
+
@graph.edges << self
|
61
|
+
|
62
|
+
@source = source
|
63
|
+
@destination = destination
|
64
|
+
|
65
|
+
@options = options
|
66
|
+
end
|
67
|
+
|
68
|
+
attr :source
|
69
|
+
attr :destination
|
70
|
+
|
71
|
+
attr :options
|
72
|
+
|
73
|
+
def to_s
|
74
|
+
"->"
|
75
|
+
end
|
76
|
+
end
|
77
|
+
|
78
|
+
class Graph
|
79
|
+
def initialize(name = 'G', options = {})
|
80
|
+
@name = name
|
81
|
+
|
82
|
+
@nodes = {}
|
83
|
+
@edges = []
|
84
|
+
end
|
85
|
+
|
86
|
+
attr :nodes
|
87
|
+
attr :edges
|
88
|
+
|
89
|
+
def add_node(name, options = {})
|
90
|
+
Node.new(self, name, options)
|
91
|
+
end
|
92
|
+
|
93
|
+
def to_dot(options = {})
|
94
|
+
buffer = StringIO.new
|
95
|
+
|
96
|
+
format = options[:format] || 'digraph'
|
97
|
+
|
98
|
+
buffer.puts "#{format} #{@name} {"
|
99
|
+
|
100
|
+
@nodes.each do |(name, node)|
|
101
|
+
if node.edges.size > 0
|
102
|
+
node.edges.each do |edge|
|
103
|
+
buffer.puts "\t#{edge.source.name.dump} #{edge} #{edge.destination.name.dump};"
|
104
|
+
end
|
105
|
+
else
|
106
|
+
buffer.puts "\t#{node.name.dump};"
|
107
|
+
end
|
108
|
+
end
|
109
|
+
|
110
|
+
buffer.puts "}"
|
111
|
+
|
112
|
+
return buffer.string
|
113
|
+
end
|
114
|
+
end
|
115
|
+
end
|
data/rakefile.rb
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
require "bundler/gem_tasks"
|
data/sample.rb
ADDED
metadata
ADDED
@@ -0,0 +1,96 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: graphviz
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Samuel Williams
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2013-10-04 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: bundler
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ~>
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '1.3'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ~>
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '1.3'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rake
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - '>='
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '0'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - '>='
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: rexec
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - '>='
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '0'
|
48
|
+
type: :runtime
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - '>='
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '0'
|
55
|
+
description: "\t\tGraphviz is a graph visualisation system. This gem is a lightweight
|
56
|
+
interface for generating graphs with Graphviz.\n"
|
57
|
+
email:
|
58
|
+
- samuel.williams@oriontransfer.co.nz
|
59
|
+
executables: []
|
60
|
+
extensions: []
|
61
|
+
extra_rdoc_files: []
|
62
|
+
files:
|
63
|
+
- .gitignore
|
64
|
+
- Gemfile
|
65
|
+
- README.md
|
66
|
+
- graphviz.gemspec
|
67
|
+
- lib/graphviz.rb
|
68
|
+
- lib/graphviz/graph.rb
|
69
|
+
- lib/graphviz/version.rb
|
70
|
+
- rakefile.rb
|
71
|
+
- sample.rb
|
72
|
+
homepage: ''
|
73
|
+
licenses:
|
74
|
+
- MIT
|
75
|
+
metadata: {}
|
76
|
+
post_install_message:
|
77
|
+
rdoc_options: []
|
78
|
+
require_paths:
|
79
|
+
- lib
|
80
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
81
|
+
requirements:
|
82
|
+
- - '>='
|
83
|
+
- !ruby/object:Gem::Version
|
84
|
+
version: '0'
|
85
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
86
|
+
requirements:
|
87
|
+
- - '>='
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
version: '0'
|
90
|
+
requirements: []
|
91
|
+
rubyforge_project:
|
92
|
+
rubygems_version: 2.0.6
|
93
|
+
signing_key:
|
94
|
+
specification_version: 4
|
95
|
+
summary: A lightweight interface for generating graphs with Graphviz.
|
96
|
+
test_files: []
|