├── .document ├── .gitignore ├── .rdebugrc ├── .rspec ├── Gemfile ├── Gemfile.lock ├── Guardfile ├── LICENSE.txt ├── README.md ├── Rakefile ├── VERSION ├── lib ├── graph_viz │ ├── mind_map.rb │ └── mind_map │ │ └── node.rb └── ruby-graphviz-mindmap.rb ├── ruby-graphviz-mindmap.gemspec └── spec ├── lib └── graph_viz │ ├── mind_map │ └── node_spec.rb │ └── mind_map_spec.rb └── spec_helper.rb /.document: -------------------------------------------------------------------------------- 1 | lib/**/*.rb 2 | bin/* 3 | - 4 | features/**/*.feature 5 | LICENSE.txt 6 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # rcov generated 2 | coverage 3 | coverage.data 4 | 5 | # rdoc generated 6 | rdoc 7 | 8 | # yard generated 9 | doc 10 | .yardoc 11 | 12 | # bundler 13 | .bundle 14 | 15 | # jeweler generated 16 | pkg 17 | 18 | # Have editor/IDE/OS specific files you need to ignore? Consider using a global gitignore: 19 | # 20 | # * Create a file at ~/.gitignore 21 | # * Include files you want ignored 22 | # * Run: git config --global core.excludesfile ~/.gitignore 23 | # 24 | # After doing this, these files will be ignored in all your git projects, 25 | # saving you from having to 'pollute' every project you touch with them 26 | # 27 | # Not sure what to needs to be ignored for particular editors/OSes? Here's some ideas to get you started. (Remember, remove the leading # of the line) 28 | # 29 | # For MacOS: 30 | # 31 | #.DS_Store 32 | 33 | # For TextMate 34 | #*.tmproj 35 | #tmtags 36 | 37 | # For emacs: 38 | #*~ 39 | #\#* 40 | #.\#* 41 | 42 | # For vim: 43 | #*.swp 44 | 45 | # For redcar: 46 | #.redcar 47 | 48 | # For rubinius: 49 | #*.rbc 50 | -------------------------------------------------------------------------------- /.rdebugrc: -------------------------------------------------------------------------------- 1 | set autoeval on 2 | set autolist 3 | -------------------------------------------------------------------------------- /.rspec: -------------------------------------------------------------------------------- 1 | --color 2 | -------------------------------------------------------------------------------- /Gemfile: -------------------------------------------------------------------------------- 1 | # 3621wirbmybfvap2 2 | source "http://rubygems.org" 3 | 4 | gem 'ruby-graphviz' 5 | # gem 'activesupport', '~> 3.0.0' 6 | # gem 'i18n' #required by activesupport inflections 7 | 8 | # Add dependencies required to use your gem here. 9 | # Example: 10 | # gem "activesupport", ">= 2.3.5" 11 | 12 | # Add dependencies to develop your gem here. 13 | # Include everything needed to run rake, tests, features, etc. 14 | group :development do 15 | gem "rspec" 16 | gem "rdoc" 17 | gem "bundler" 18 | gem "jeweler" 19 | gem "guard" 20 | gem "guard-rspec" 21 | end 22 | -------------------------------------------------------------------------------- /Gemfile.lock: -------------------------------------------------------------------------------- 1 | GEM 2 | remote: http://rubygems.org/ 3 | specs: 4 | addressable (2.4.0) 5 | builder (3.2.3) 6 | coderay (1.1.2) 7 | descendants_tracker (0.0.4) 8 | thread_safe (~> 0.3, >= 0.3.1) 9 | diff-lcs (1.3) 10 | faraday (0.9.2) 11 | multipart-post (>= 1.2, < 3) 12 | ffi (1.9.23) 13 | formatador (0.2.5) 14 | git (1.3.0) 15 | github_api (0.16.0) 16 | addressable (~> 2.4.0) 17 | descendants_tracker (~> 0.0.4) 18 | faraday (~> 0.8, < 0.10) 19 | hashie (>= 3.4) 20 | mime-types (>= 1.16, < 3.0) 21 | oauth2 (~> 1.0) 22 | guard (2.14.2) 23 | formatador (>= 0.2.4) 24 | listen (>= 2.7, < 4.0) 25 | lumberjack (>= 1.0.12, < 2.0) 26 | nenv (~> 0.1) 27 | notiffany (~> 0.0) 28 | pry (>= 0.9.12) 29 | shellany (~> 0.0) 30 | thor (>= 0.18.1) 31 | guard-compat (1.2.1) 32 | guard-rspec (4.7.3) 33 | guard (~> 2.1) 34 | guard-compat (~> 1.1) 35 | rspec (>= 2.99.0, < 4.0) 36 | hashie (3.5.7) 37 | highline (1.7.10) 38 | jeweler (2.3.9) 39 | builder 40 | bundler 41 | git (>= 1.2.5) 42 | github_api (~> 0.16.0) 43 | highline (>= 1.6.15) 44 | nokogiri (>= 1.5.10) 45 | psych 46 | rake 47 | rdoc 48 | semver2 49 | jwt (1.5.6) 50 | listen (3.1.5) 51 | rb-fsevent (~> 0.9, >= 0.9.4) 52 | rb-inotify (~> 0.9, >= 0.9.7) 53 | ruby_dep (~> 1.2) 54 | lumberjack (1.0.13) 55 | method_source (0.9.0) 56 | mime-types (2.99.3) 57 | mini_portile2 (2.3.0) 58 | multi_json (1.13.1) 59 | multi_xml (0.6.0) 60 | multipart-post (2.0.0) 61 | nenv (0.3.0) 62 | nokogiri (1.8.2) 63 | mini_portile2 (~> 2.3.0) 64 | notiffany (0.1.1) 65 | nenv (~> 0.1) 66 | shellany (~> 0.0) 67 | oauth2 (1.4.0) 68 | faraday (>= 0.8, < 0.13) 69 | jwt (~> 1.0) 70 | multi_json (~> 1.3) 71 | multi_xml (~> 0.5) 72 | rack (>= 1.2, < 3) 73 | pry (0.11.3) 74 | coderay (~> 1.1.0) 75 | method_source (~> 0.9.0) 76 | psych (3.0.2) 77 | rack (2.0.4) 78 | rake (12.3.1) 79 | rb-fsevent (0.10.3) 80 | rb-inotify (0.9.10) 81 | ffi (>= 0.5.0, < 2) 82 | rdoc (6.0.3) 83 | rspec (3.7.0) 84 | rspec-core (~> 3.7.0) 85 | rspec-expectations (~> 3.7.0) 86 | rspec-mocks (~> 3.7.0) 87 | rspec-core (3.7.1) 88 | rspec-support (~> 3.7.0) 89 | rspec-expectations (3.7.0) 90 | diff-lcs (>= 1.2.0, < 2.0) 91 | rspec-support (~> 3.7.0) 92 | rspec-mocks (3.7.0) 93 | diff-lcs (>= 1.2.0, < 2.0) 94 | rspec-support (~> 3.7.0) 95 | rspec-support (3.7.1) 96 | ruby-graphviz (1.2.3) 97 | ruby_dep (1.5.0) 98 | semver2 (3.4.2) 99 | shellany (0.0.1) 100 | thor (0.20.0) 101 | thread_safe (0.3.6) 102 | 103 | PLATFORMS 104 | ruby 105 | 106 | DEPENDENCIES 107 | bundler 108 | guard 109 | guard-rspec 110 | jeweler 111 | rdoc 112 | rspec 113 | ruby-graphviz 114 | 115 | BUNDLED WITH 116 | 1.14.6 117 | -------------------------------------------------------------------------------- /Guardfile: -------------------------------------------------------------------------------- 1 | # A sample Guardfile 2 | # More info at https://github.com/guard/guard#readme 3 | 4 | guard 'rspec', :cli => '-d -c', :version => 2 do 5 | watch(%r{^spec/.+_spec\.rb$}) 6 | watch(%r{^lib/(.+)\.rb$}) { |m| "spec/lib/#{m[1]}_spec.rb" } 7 | watch('spec/spec_helper.rb') { "spec" } 8 | end 9 | 10 | -------------------------------------------------------------------------------- /LICENSE.txt: -------------------------------------------------------------------------------- 1 | Copyright (c) 2018 Jessica Szmajda 2 | 3 | Permission is hereby granted, free of charge, to any person obtaining 4 | a copy of this software and associated documentation files (the 5 | "Software"), to deal in the Software without restriction, including 6 | without limitation the rights to use, copy, modify, merge, publish, 7 | distribute, sublicense, and/or sell copies of the Software, and to 8 | permit persons to whom the Software is furnished to do so, subject to 9 | the following conditions: 10 | 11 | The above copyright notice and this permission notice shall be 12 | included in all copies or substantial portions of the Software. 13 | 14 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 15 | EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 16 | MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 17 | NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE 18 | LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION 19 | OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION 20 | WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 21 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # ruby-graphviz-mindmap 2 | 3 | So this actually isn't using the ruby GraphViz library right now, but I mean to make it do so. It mostly just generates [dot][1] format files at the moment. 4 | 5 | ## Installation 6 | 7 | You need [graphviz][2] installed. On ubuntu it's just `sudo apt-get install graphviz` 8 | 9 | Then `gem install ruby-graphviz-mindmap` 10 | 11 | ## Usage 12 | 13 | Create a script in which you layout your mind map: 14 | 15 | require 'ruby-graphviz-mindmap' 16 | map = GraphViz::MindMap.build "foo", overlap: false 17 | map.node 'baz', color: :red, shape: :box do 18 | node 'bar' do 19 | node 'ha' 20 | end 21 | 22 | node 'two', color: :blue do 23 | inherit! 24 | node 'three' do 25 | node 'Four And' 26 | node 'ha', color: :green 27 | end 28 | end 29 | end 30 | 31 | File.open('output.dot', 'wb'){|f| f << map.to_dot } 32 | 33 | That will output a dot file ready for processing with a graphviz 34 | command. I like `neato` for this ([documentation on neato][3]): 35 | 36 | neato -Tjpeg output.dot -o output.jpg 37 | 38 | You'll get something that looks like this: 39 | 40 | ![output.jpg](http://haven.loki.ws/img/omap.jpg) 41 | 42 | 43 | ## Contributing to ruby-graphviz-mindmap 44 | 45 | * Check out the latest master to make sure the feature hasn't been implemented or the bug hasn't been fixed yet. 46 | * Check out the issue tracker to make sure someone already hasn't requested it and/or contributed it. 47 | * Fork the project. 48 | * Start a feature/bugfix branch. 49 | * Commit and push until you are happy with your contribution. 50 | * Make sure to add tests for it. This is important so I don't break it in a future version unintentionally. 51 | * Please try not to mess with the Rakefile, version, or history. If you want to have your own version, or is otherwise necessary, that is fine, but please isolate to its own commit so I can cherry-pick around it. 52 | 53 | ## Copyright 54 | 55 | Copyright (c) 2018 Jessica Szmajda. See LICENSE.txt for 56 | further details. 57 | 58 | [1]: http://www.graphviz.org/pdf/dotguide.pdf 59 | [2]: http://www.graphviz.org/ 60 | [3]: http://www.graphviz.org/pdf/neatoguide.pdf 61 | -------------------------------------------------------------------------------- /Rakefile: -------------------------------------------------------------------------------- 1 | # encoding: utf-8 2 | 3 | require 'rubygems' 4 | require 'bundler' 5 | begin 6 | Bundler.setup(:default, :development) 7 | rescue Bundler::BundlerError => e 8 | $stderr.puts e.message 9 | $stderr.puts "Run `bundle install` to install missing gems" 10 | exit e.status_code 11 | end 12 | require 'rake' 13 | 14 | require 'jeweler' 15 | Jeweler::Tasks.new do |gem| 16 | # gem is a Gem::Specification... see http://docs.rubygems.org/read/chapter/20 for more options 17 | gem.name = "ruby-graphviz-mindmap" 18 | gem.homepage = "http://github.com/jszmajda/ruby-graphviz-mindmap" 19 | gem.license = "MIT" 20 | gem.summary = %Q{A library that takes a ruby description of a mind map and outputs a graphviz dot file} 21 | gem.description = gem.summary 22 | gem.email = "jess.szmajda@gmail.com" 23 | gem.authors = ["Jessica Szmajda"] 24 | # dependencies defined in Gemfile 25 | end 26 | Jeweler::RubygemsDotOrgTasks.new 27 | 28 | require 'rspec/core' 29 | require 'rspec/core/rake_task' 30 | RSpec::Core::RakeTask.new(:spec) do |spec| 31 | spec.pattern = FileList['spec/**/*_spec.rb'] 32 | end 33 | 34 | RSpec::Core::RakeTask.new(:rcov) do |spec| 35 | spec.pattern = 'spec/**/*_spec.rb' 36 | spec.rcov = true 37 | end 38 | 39 | task :default => :spec 40 | 41 | require 'rdoc/task' 42 | Rake::RDocTask.new do |rdoc| 43 | version = File.exist?('VERSION') ? File.read('VERSION') : "" 44 | 45 | rdoc.rdoc_dir = 'rdoc' 46 | rdoc.title = "ruby-graphviz-mindmap #{version}" 47 | rdoc.rdoc_files.include('README*') 48 | rdoc.rdoc_files.include('lib/**/*.rb') 49 | end 50 | -------------------------------------------------------------------------------- /VERSION: -------------------------------------------------------------------------------- 1 | 1.1.0 -------------------------------------------------------------------------------- /lib/graph_viz/mind_map.rb: -------------------------------------------------------------------------------- 1 | class GraphViz 2 | class MindMap 3 | 4 | def self.build(*args) 5 | Node.new *args 6 | end 7 | end 8 | end 9 | -------------------------------------------------------------------------------- /lib/graph_viz/mind_map/node.rb: -------------------------------------------------------------------------------- 1 | class GraphViz 2 | class MindMap 3 | 4 | class Node 5 | attr_accessor :name 6 | attr_accessor :options 7 | attr_accessor :parent 8 | attr_accessor :nodes 9 | attr_accessor :used_identifiers 10 | attr_accessor :pass_on_options 11 | 12 | def initialize *args 13 | @options = args.last.is_a?(Hash) ? args.pop : {} 14 | @name = args.first 15 | @nodes = [] 16 | @used_identifiers = [] 17 | @pass_on_options = false 18 | raise ArgumentError.new("You need to name this mind map") unless name 19 | end 20 | 21 | def inherit!; @pass_on_options = true end 22 | def no_inherit!; @pass_on_options = false end 23 | 24 | def node(*args, &block) 25 | @nodes << Node.new(*args).tap do |n| 26 | n.parent = self 27 | if @pass_on_options 28 | n.options = options.dup.merge(n.options) 29 | n.pass_on_options = true 30 | end 31 | end 32 | if block_given? 33 | @nodes.last.instance_eval &block 34 | end 35 | end 36 | 37 | # tree walking things 38 | 39 | def at(dot_path) 40 | path = dot_path.split(/\./) 41 | if path.any? 42 | index = path.shift.to_i 43 | nodes[index].at(path.join('.')) 44 | else 45 | self 46 | end 47 | end 48 | 49 | def root 50 | parent ? parent.root : self 51 | end 52 | 53 | # dot generation things 54 | 55 | def node_def 56 | opts = dot_options 57 | o = [dot_identifier] 58 | if opts.length > 0 59 | o << ' ' 60 | o << opts 61 | end 62 | o.join 63 | end 64 | 65 | def dot_identifier 66 | @dot_identifier ||= make_dot_identifier 67 | end 68 | 69 | def make_dot_identifier 70 | id = name.downcase.gsub(/[^ a-z]/,'').sub(/ +$/,'').gsub(/ +/,'_') 71 | if root.used_identifiers.include? id 72 | id = "#{parent.dot_identifier}_#{id}" 73 | end 74 | root.used_identifiers << id 75 | id 76 | end 77 | 78 | def dot_options 79 | o=[] 80 | unless parent.nil? 81 | o << "label=\"#{name}\"" 82 | end 83 | options.each_pair do |k,v| 84 | o << "#{k}=\"#{v}\"" 85 | end 86 | if o.any? 87 | "[#{o.join(' ')}]" 88 | else 89 | '' 90 | end 91 | end 92 | 93 | # assumes the node you call #to_dot on is the root of the graph and should be treated like a graph 94 | def to_dot(output=nil, indent=0) 95 | if indent == 0 96 | build_dot_from_root 97 | else 98 | build_dot_at_index(output,indent) 99 | end 100 | end 101 | 102 | def build_dot_from_root 103 | o = [] 104 | o << "graph #{dot_identifier} {" 105 | opts = dot_options 106 | if opts.length > 0 107 | o << " graph #{dot_options}" 108 | end 109 | nodes.each do |node| 110 | node.to_dot(o, 1) 111 | end 112 | o << "}" 113 | o.join("\n") 114 | end 115 | 116 | def build_dot_at_index(o, idx) 117 | leader = " "*(idx * 2) 118 | o << "#{leader}#{node_def}" 119 | if parent && idx > 1 120 | o << "#{leader}#{parent.dot_identifier} -- #{dot_identifier}" 121 | end 122 | if nodes.any? 123 | o << "#{leader}subgraph sg_#{dot_identifier} {" 124 | nodes.each do |node| 125 | node.to_dot(o, idx + 1) 126 | end 127 | o << "#{leader}}" 128 | end 129 | end 130 | end 131 | end 132 | end 133 | -------------------------------------------------------------------------------- /lib/ruby-graphviz-mindmap.rb: -------------------------------------------------------------------------------- 1 | require 'graphviz' 2 | require File.join(File.dirname(__FILE__), 'graph_viz', 'mind_map', 'node') 3 | require File.join(File.dirname(__FILE__), 'graph_viz', 'mind_map') 4 | -------------------------------------------------------------------------------- /ruby-graphviz-mindmap.gemspec: -------------------------------------------------------------------------------- 1 | # Generated by jeweler 2 | # DO NOT EDIT THIS FILE DIRECTLY 3 | # Instead, edit Jeweler::Tasks in Rakefile, and run 'rake gemspec' 4 | # -*- encoding: utf-8 -*- 5 | # stub: ruby-graphviz-mindmap 1.1.0 ruby lib 6 | 7 | Gem::Specification.new do |s| 8 | s.name = "ruby-graphviz-mindmap".freeze 9 | s.version = "1.1.0" 10 | 11 | s.required_rubygems_version = Gem::Requirement.new(">= 0".freeze) if s.respond_to? :required_rubygems_version= 12 | s.require_paths = ["lib".freeze] 13 | s.authors = ["Jessica Szmajda".freeze] 14 | s.date = "2018-04-16" 15 | s.description = "A library that takes a ruby description of a mind map and outputs a graphviz dot file".freeze 16 | s.email = "jess.szmajda@gmail.com".freeze 17 | s.extra_rdoc_files = [ 18 | "LICENSE.txt", 19 | "README.md" 20 | ] 21 | s.files = [ 22 | ".document", 23 | ".rdebugrc", 24 | ".rspec", 25 | "Gemfile", 26 | "Gemfile.lock", 27 | "Guardfile", 28 | "LICENSE.txt", 29 | "README.md", 30 | "Rakefile", 31 | "VERSION", 32 | "lib/graph_viz/mind_map.rb", 33 | "lib/graph_viz/mind_map/node.rb", 34 | "lib/ruby-graphviz-mindmap.rb", 35 | "ruby-graphviz-mindmap.gemspec", 36 | "spec/lib/graph_viz/mind_map/node_spec.rb", 37 | "spec/lib/graph_viz/mind_map_spec.rb", 38 | "spec/spec_helper.rb" 39 | ] 40 | s.homepage = "http://github.com/jszmajda/ruby-graphviz-mindmap".freeze 41 | s.licenses = ["MIT".freeze] 42 | s.rubygems_version = "2.6.10".freeze 43 | s.summary = "A library that takes a ruby description of a mind map and outputs a graphviz dot file".freeze 44 | 45 | if s.respond_to? :specification_version then 46 | s.specification_version = 4 47 | 48 | if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then 49 | s.add_runtime_dependency(%q.freeze, [">= 0"]) 50 | s.add_development_dependency(%q.freeze, [">= 0"]) 51 | s.add_development_dependency(%q.freeze, [">= 0"]) 52 | s.add_development_dependency(%q.freeze, [">= 0"]) 53 | s.add_development_dependency(%q.freeze, [">= 0"]) 54 | s.add_development_dependency(%q.freeze, [">= 0"]) 55 | s.add_development_dependency(%q.freeze, [">= 0"]) 56 | else 57 | s.add_dependency(%q.freeze, [">= 0"]) 58 | s.add_dependency(%q.freeze, [">= 0"]) 59 | s.add_dependency(%q.freeze, [">= 0"]) 60 | s.add_dependency(%q.freeze, [">= 0"]) 61 | s.add_dependency(%q.freeze, [">= 0"]) 62 | s.add_dependency(%q.freeze, [">= 0"]) 63 | s.add_dependency(%q.freeze, [">= 0"]) 64 | end 65 | else 66 | s.add_dependency(%q.freeze, [">= 0"]) 67 | s.add_dependency(%q.freeze, [">= 0"]) 68 | s.add_dependency(%q.freeze, [">= 0"]) 69 | s.add_dependency(%q.freeze, [">= 0"]) 70 | s.add_dependency(%q.freeze, [">= 0"]) 71 | s.add_dependency(%q.freeze, [">= 0"]) 72 | s.add_dependency(%q.freeze, [">= 0"]) 73 | end 74 | end 75 | 76 | -------------------------------------------------------------------------------- /spec/lib/graph_viz/mind_map/node_spec.rb: -------------------------------------------------------------------------------- 1 | require 'spec_helper' 2 | 3 | describe GraphViz::MindMap::Node do 4 | it "exists" do 5 | GraphViz::MindMap::Node.should_not be_nil 6 | end 7 | 8 | describe "#initialize" do 9 | it "initializes with a graph name" do 10 | map = GraphViz::MindMap::Node.new "foo" 11 | map.name.should == "foo" 12 | end 13 | 14 | it "initializes with options" do 15 | map = GraphViz::MindMap::Node.new "foo", a: 2 16 | map.options[:a].should == 2 17 | end 18 | end 19 | 20 | let(:node) do 21 | GraphViz::MindMap::Node.new "foo", a: 2 22 | end 23 | 24 | let(:spaced_node) do 25 | GraphViz::MindMap::Node.new "Some Thing", a: 4, shape: :box 26 | end 27 | 28 | let(:weird_node) do 29 | GraphViz::MindMap::Node.new "dumb other thing ++?* !" 30 | end 31 | 32 | let(:complex_graph) do 33 | base = GraphViz::MindMap::Node.new "foo", overlap: false 34 | base.node 'baz', color: :red do 35 | node 'bar' do 36 | node 'ha' 37 | end 38 | 39 | node 'two', color: :blue do 40 | node 'three' do 41 | node 'Four And' 42 | node 'ha' 43 | end 44 | end 45 | end 46 | base 47 | end 48 | 49 | let(:graph_with_carries) do 50 | base = GraphViz::MindMap::Node.new "foo", overlap: false 51 | base.node 'baz', color: :red, shape: :box do 52 | node 'bar' do 53 | node 'ha' 54 | end 55 | 56 | node 'two', color: :blue do 57 | inherit! 58 | node 'three' do 59 | node 'Four And' 60 | node 'ha', color: :green 61 | end 62 | end 63 | end 64 | base 65 | end 66 | 67 | describe "#dot_identifier" do 68 | it "outputs something dot understands" do 69 | node.dot_identifier.should == 'foo' 70 | spaced_node.dot_identifier.should == 'some_thing' 71 | weird_node.dot_identifier.should == 'dumb_other_thing' 72 | end 73 | 74 | it "doesn't cross names when multiple nodes exist in the same tree with the same name" do 75 | map = complex_graph 76 | map.at('0.0.0').name.should == 'ha' 77 | map.at('0.1.0.1').name.should == 'ha' 78 | map.at('0.0.0').dot_identifier.should == 'ha' 79 | map.at('0.1.0.1').dot_identifier.should == 'three_ha' 80 | end 81 | end 82 | 83 | describe "#dot_options" do 84 | it "outputs something dot understands" do 85 | node.dot_options.should == '[a="2"]' 86 | spaced_node.dot_options.should == '[a="4" shape="box"]' 87 | weird_node.dot_options.should == '' 88 | end 89 | end 90 | 91 | describe "#node_def" do 92 | it "outputs the correct definitions" do 93 | node.node_def.should == 'foo [a="2"]' 94 | spaced_node.node_def.should == 'some_thing [a="4" shape="box"]' 95 | weird_node.node_def.should == 'dumb_other_thing' 96 | end 97 | end 98 | 99 | describe "#node" do 100 | it "creates a child node" do 101 | base = GraphViz::MindMap::Node.new "foo" 102 | base.node 'bar' 103 | 104 | base.nodes.first.name.should == 'bar' 105 | end 106 | 107 | it "creates a child node with options too" do 108 | base = GraphViz::MindMap::Node.new "foo" 109 | base.node 'bar', color: :red 110 | 111 | base.nodes.first.options[:color].should == :red 112 | end 113 | 114 | describe "block builder syntax" do 115 | it "constructs a tree" do 116 | base = GraphViz::MindMap::Node.new "foo" 117 | base.node 'baz' do 118 | node 'bar' 119 | end 120 | 121 | base.nodes.first.name.should == 'baz' 122 | base.nodes.first.nodes.first.name.should == 'bar' 123 | end 124 | 125 | it "makes a complex graph" do 126 | base = complex_graph 127 | 128 | base.nodes.size.should == 1 129 | base.nodes.first.name.should == 'baz' 130 | base.nodes.first.nodes.size.should == 2 131 | base.nodes.first.nodes.first.name.should == 'bar' 132 | base.nodes.first.nodes.first.nodes.first.name.should == 'ha' 133 | base.nodes.first.nodes.last.name.should == 'two' 134 | base.nodes.first.nodes.last.nodes.first.name.should == 'three' 135 | base.nodes.first.nodes.last.nodes.first.nodes.first.name.should == 'Four And' 136 | end 137 | end 138 | end 139 | 140 | it "allows dot-index mapping into the tree" do 141 | complex_graph.at('0.1.0.1').name.should == 'ha' 142 | end 143 | 144 | describe "inheriting options" do 145 | it "assigns the same options to its children when inerhit! is called" do 146 | map = graph_with_carries 147 | map.at('0.1.0').options[:color].should == :blue 148 | map.at('0.1.0.0').options[:color].should == :blue 149 | map.at('0.1.0.1').options[:color].should == :green 150 | end 151 | end 152 | 153 | describe "the whole shebang" do 154 | it "converts the complex_graph into the right dot syntax" do 155 | expected = <<-EOT.chop 156 | graph foo { 157 | graph [overlap="false"] 158 | baz [label="baz" color="red" shape="box"] 159 | subgraph sg_baz { 160 | bar [label="bar"] 161 | baz -- bar 162 | subgraph sg_bar { 163 | ha [label="ha"] 164 | bar -- ha 165 | } 166 | two [label="two" color="blue"] 167 | baz -- two 168 | subgraph sg_two { 169 | three [label="three" color="blue"] 170 | two -- three 171 | subgraph sg_three { 172 | four_and [label="Four And" color="blue"] 173 | three -- four_and 174 | three_ha [label="ha" color="green"] 175 | three -- three_ha 176 | } 177 | } 178 | } 179 | } 180 | EOT 181 | graph_with_carries.to_dot.should == expected 182 | File.open("/tmp/out.dot",'wb'){|f| f << graph_with_carries.to_dot } 183 | end 184 | 185 | end 186 | end 187 | -------------------------------------------------------------------------------- /spec/lib/graph_viz/mind_map_spec.rb: -------------------------------------------------------------------------------- 1 | require 'spec_helper' 2 | 3 | describe GraphViz::MindMap do 4 | it "exists" do 5 | GraphViz::MindMap.should_not be_nil 6 | end 7 | 8 | describe "#build" do 9 | it "returns a Node" do 10 | map = GraphViz::MindMap.build "foo" 11 | map.should be_kind_of(GraphViz::MindMap::Node) 12 | end 13 | end 14 | 15 | end 16 | -------------------------------------------------------------------------------- /spec/spec_helper.rb: -------------------------------------------------------------------------------- 1 | $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib')) 2 | $LOAD_PATH.unshift(File.dirname(__FILE__)) 3 | require 'rspec' 4 | require 'ruby-graphviz-mindmap' 5 | 6 | # Requires supporting files with custom matchers and macros, etc, 7 | # in ./support/ and its subdirectories. 8 | Dir["#{File.dirname(__FILE__)}/support/**/*.rb"].each {|f| require f} 9 | 10 | RSpec.configure do |config| 11 | 12 | end 13 | --------------------------------------------------------------------------------