Giter Site home page Giter Site logo

ruby-graphviz's Introduction

Ruby/GraphViz

All Contributors Travis CI build Gem Version

Copyright (C) 2004-2018 Gregoire Lejeune

INSTALLATION

Add this line to your application's Gemfile:

gem 'ruby-graphviz'

And then execute:

$ bundle

Or install it yourself as:

$ gem install ruby-graphviz

DESCRIPTION

Interface to the GraphViz graphing tool

TODO

  • New FamilyTree

SYNOPSIS

A basic example

require 'ruby-graphviz'

# Create a new graph
g = GraphViz.new( :G, :type => :digraph )

# Create two nodes
hello = g.add_nodes( "Hello" )
world = g.add_nodes( "World" )

# Create an edge between the two nodes
g.add_edges( hello, world )

# Generate output image
g.output( :png => "hello_world.png" )

The same but with a block

require 'ruby-graphviz'

GraphViz::new( :G, :type => :digraph ) { |g|
  g.world( :label => "World" ) << g.hello( :label => "Hello" )
}.output( :png => "hello_world.png" )

Or with the DSL

    require 'ruby-graphviz/dsl'
    digraph :G do
      world[:label => "World"] << hello[:label => "Hello"]

      output :png => "hello_world.png"
    end

Create a graph from a file

    require 'ruby-graphviz'

    # In this example, hello.dot is :
    #   digraph G {Hello->World;}

    GraphViz.parse( "hello.dot", :path => "/usr/local/bin" ) { |g|
      g.get_node("Hello") { |n|
        n[:label] = "Bonjour"
      }
      g.get_node("World") { |n|
        n[:label] = "Le Monde"
      }
    }.output(:png => "sample.png")

GraphML support

    require 'ruby-graphviz/graphml'

    g = GraphViz::GraphML.new( "graphml/cluster.graphml" )
    g.graph.output( :path => "/usr/local/bin", :png => "#{$0}.png" )

TOOLS

Ruby/GraphViz also includes :

  • ruby2gv, a simple tool that allows you to create a dependency graph from a ruby script. Example : http://drp.ly/dShaZ
ruby2gv -Tpng -oruby2gv.png ruby2gv
  • gem2gv, a tool that allows you to create a dependency graph between gems. Example : http://drp.ly/dSj9Y
gem2gv -Tpng -oruby-graphviz.png ruby-graphviz
  • dot2ruby, a tool that allows you to create a ruby script from a graphviz script
$ cat hello.dot
digraph G {Hello->World;}

$ dot2ruby hello.dot
# This code was generated by dot2ruby.g

require 'rubygems'
require 'ruby-graphviz'
graph_g = GraphViz.digraph( "G" ) { |graph_g|
  graph_g[:bb] = '0,0,70,108'
  node_hello = graph_g.add_nodes( "Hello", :height => '0.5', :label => '\N', :pos => '35,90', :width => '0.88889' )
  graph_g.add_edges( "Hello", "World", :pos => 'e,35,36.413 35,71.831 35,64.131 35,54.974 35,46.417' )
  node_world = graph_g.add_nodes( "World", :height => '0.5', :label => '\N', :pos => '35,18', :width => '0.97222' )
}
puts graph_g.output( :canon => String )
  • git2gv, a tool that allows you to show your git commits

  • xml2gv, a tool that allows you to show a xml file as graph.

GRAPH THEORY

require 'ruby-graphviz'
require 'ruby-graphviz/theory'

g = GraphViz.new( :G ) { ... }

t = GraphViz::Theory.new( g )

puts "Adjancy matrix : "
puts t.adjancy_matrix

puts "Symmetric ? #{t.symmetric?}"

puts "Incidence matrix :"
puts t.incidence_matrix

g.each_node do |name, node|
  puts "Degree of node `#{name}' = #{t.degree(node)}"
end

puts "Laplacian matrix :"
puts t.laplacian_matrix

puts "Dijkstra between a and f"
r = t.moore_dijkstra(g.a, g.f)
if r.nil?
  puts "No way !"
else
  print "\tPath : "; p r[:path]
  puts "\tDistance : #{r[:distance]}"
end

print "Ranges : "
rr = t.range
p rr
puts "Your graph contains circuits" if rr.include?(nil)

puts "Critical path : "
rrr = t.critical_path
print "\tPath "; p rrr[:path]
puts "\tDistance : #{rrr[:distance]}"

INSTALLATION

sudo gem install ruby-graphviz

You also need to install GraphViz

On Windows you also need to install win32-open3. This is not an absolute requirement.

LICENCES

Ruby/GraphViz

Ruby/GraphViz is freely distributable according to the terms of the GNU General Public License (see the file 'COPYING').

This program is distributed without any warranty. See the file 'COPYING' for details.

GNU General Public Licence: https://en.wikipedia.org/wiki/Gpl

nothugly.xsl

By Vidar Hokstad and Ryan Shea; Contributions by Jonas Tingborn, Earl Cummings, Michael Kennedy (Graphviz 2.20.2 compatibility, bug fixes, testing, lots of gradients)

Copyright (c) 2009 Vidar Hokstad

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

MIT license: https://en.wikipedia.org/wiki/MIT_License

Contributors

Thanks goes to these wonderful people (emoji key):


Dave Burt

πŸ’»

obruening

πŸ’»

Chip Malice

πŸ’»

Stefan StΓΌben

πŸ’»

oupo

πŸ’»

Gregoire Lejeune

πŸ’» 🎨 πŸ“–

Markus Hauck

πŸ’»

Khalil Fazal

πŸ’»

Kenichi Kamiya

πŸ’»

Neven Has

πŸ’»

Andrew

πŸ’»

Daniel Zollinger

πŸ’»

Guilherme Simoes

πŸ’»

Oleg Orlov

πŸ’»

Gabe Kopley

πŸ’»

Jake Goulding

πŸ’»

hirochachacha

πŸ’»

ronen barzel

πŸ’»

Jamison Dance

πŸ’» πŸ“–

Joseph Anthony Pasquale Holsten

πŸ’»

Miguel Cabrera

πŸ’»

Mike Fiedler

πŸ’»

Nathan Long

πŸ’» πŸ“–

Olle Jonsson

πŸ’» πŸ“–

Postmodern

πŸ’»

Robert Reiz

πŸ’»

GΓΆran Bodenschatz

πŸ’»

SHIBATA Hiroshi

πŸ’»

moracca

πŸ’»

TPei

πŸ“–

Villu Orav

πŸ“–

David RodrΓ­guez

πŸ’» πŸ“¦

This project follows the all-contributors specification. Contributions of any kind welcome!

ruby-graphviz's People

Contributors

andrewkvalheim avatar dburt avatar deivid-rodriguez avatar dznz avatar glejeune avatar guilhermesimoes avatar hipe avatar hirochachacha avatar hsbt avatar jergason avatar josephholsten avatar kachick avatar kha-faz avatar khalilfazal avatar markus1189 avatar mfcabrera avatar miketheman avatar msnexploder avatar nathanl avatar nevenh avatar obruening avatar olleolleolle avatar orelsokolov avatar oupo avatar postmodern avatar reiz avatar ronen avatar shepmaster avatar tpei avatar yrral86 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

ruby-graphviz's Issues

Tempfiles created in current working directory only in Windows

Reading the code shows that there is a special handling for Windows, the temp files are created in the current working directory. This is strange, because Tempfile::open() acts well on windows by creating the file in the configured temp directory. It may really be worse to create the file on the cwd because permissions may be restricted.
So I propose to remove this special handling (see graphviz.rb method output near line 367).

How to unflatten the graph?

I have a graph with one central element and different surrounding elements, all linked to the center element.
My output file is a 10k pixel wide image with two rows. One with the center element, and one with all the surrounding elements.

I can't find any documentation how to change the layout so that the center element is indeed in the center of a circle, built with the surrounding elements.

There is an unflatten preprocessor in the graphviz package, maybe this is the solution, but i can't figure it out how to use it inside my script...

Or is there anything else i do not see?

Escape not quite right

The escaping code thinks that a colon ":" is a valid dot identifier when it isn't.

(fantastic library btw!)

dot2ruby: invalid option usage.

hi,

I was trying to convert a dot file into a Graphviz graph object using Graphviz.parse(file).

this error was thrown:

RuntimeError: Error from -f /Library/Ruby/Gems/1.8/gems/ruby-graphviz-0.9.20/lib/ext/gvpr/dot2ruby.g -a "-" /Users/dana/Desktop/trial.dot: sh: - : invalid option Usage: sh [GNU long option] [option] ... sh [GNU long option] [option] script-file ... GNU long options: --debug --debugger --dump-po-strings --dump-strings --help --init-file --login --noediting --noprofile --norc --posix --protected --rcfile --restricted --verbose --version --wordexp Shell options: -irsD or -c command or -O shopt_option (invocation only) -abefhkmnptuvxBCHP or -o option

method output_from_command in utils.rb at line 74
method eval in dot2ruby.rb at line 46
method parse in graphviz.rb at line 681

tests are failing to run in a chroot environment

Even though the dot command succeeds, tests treat pango warning as error and makes the tests to fail. I thin pango warning should not be treated as an error. Probably it is just doing a pattern match for "error" keyword.

  1. Failure:
    test_sample69(GraphVizTest)
    [./test/test_examples.rb:125:in assert_sample_file_has_no_output' ./test/test_examples.rb:97:intest_sample69']:
    got exception on sample69.rb: Error from "/usr/bin/dot" -q1 -Tpng
    -o./test/output/sample69.rb.png
    /tmp/graphviz.rb20121026-14167-gb2xpp-0:

(process:14361): Pango-WARNING **: error opening config file
'/root/.pangorc': Permission denied

.
is not true.
Ref http://bugs.debian.org/cgi-bin/bugreport.cgi?bug=676393#24

HTML-like labels supported

graphviz doc says:
http://www.graphviz.org/doc/info/shapes.html#html

When using this in ruby-graphviz, so setting an edge.label to something like "<some <b>label</b>>"
I just get a "some label" without the markup.

Am I doing something wrong or is this not supported in the current version?
I see some note in the changelog of version 1.0.0 regarding to html labels, but i cant figure out how to use it. Is there an example around?

man pages for the commandline programs

Debian policy requires every program in /usr/bin to have a man page, so I wrote man pages for these executables. You can see them at http://anonscm.debian.org/gitweb/?p=pkg-ruby-extras/ruby-graphviz.git;a=tree;f=debian;h=131d5d236f5eab223cd98bf07e906aa8d071f318;hb=HEAD

You can convert these to man page by running pod2man. pod2man options I used can be seen at http://anonscm.debian.org/gitweb/?p=pkg-ruby-extras/ruby-graphviz.git;a=blob;f=debian/rules;h=36d91ce6dda36509991107690b03964b3098f64d;hb=HEAD

If you like it, feel free to include it in your gem so that everyone using the gem benefits.

Can't assign nil to node attributes

require 'rubygems'
require 'graphviz'

# Create a new graph                                                                                                                                                                                        
g = GraphViz.new( :G, :type => :digraph )

# Create two nodes                                                                                                                                                                                          
hello = g.add_node( "Hello" )
hello.color = nil
world = g.add_node( "World" )

# Create an edge between the two nodes                                                                                                                                                                      
g.add_edge( hello, world )

# Generate output image                                                                                                                                                                                     
g.output( :png => "hello_world.png" )

With 0.9.21, this works; with 1.0.4, this raises an exception:

graphviz/attrs.rb:62:in `[]=': Invalide value `` for attribute `color` : undefined method `empty?' for nil:NilClass (AttributeException)

This breaks backward compatibility.

On Windows, the 'dot' (or other progs) command fails

This is due to a limitation where when run via backquote or execute strings a command should have its complete name with extension. so running dot -Tpng will fail on windows. Instead dot.exe -Tpng will work.

Here is a patched find_executable() method that should work on *NIX and Windows (grab it here also: http://gist.github.com/252527 )

def find_executable(bin = @prog, *paths) #:nodoc:
  paths = ENV['PATH'].split(File::PATH_SEPARATOR) if paths.empty?
  paths.each do |path|
    file = File.join(path,bin)
    if File.executable?(file) then
      return file
    elsif RUBY_PLATFORM =~ /mswin|mingw/
      found_ext = (ENV['PATHEXT'] || '.exe;.bat;.com').split(";").find {|ext| File.executable?(file + ext) }
      return file + found_ext if found_ext
    end
  end
  return nil
end

fixed positions and neato

Is it possible to create graphs with fixed positions and using neato?

If i create nodes and set the pos attribute with values like "10,10!" and in addition pin=true, then the output doesnt use these coordinates except for the canon format.

Is there a way to append the -n value to the call of neato? That would use no layout engine then.

Node image loading problems with Apache2 (passenger) due to environment variables

When switching to passenger, we noticed, that our referenced node image paths where empty (white). Strange is, when running that same function via IRB, the images where included into the diagram correctly.

After hours of search, we found out, that Graphviz reads 2 environment variables SERVER_NAME and GV_FILE_PATH.
http://www.graphviz.org/doc/info/command.html#d:GV_FILE_PATH

If SERVER_NAME is present (which apache sets automatically), than graphviz will not load any image from standard path. ->

            Warning: file loading is disabled because the environment contains:
            and there is no GV_FILE_PATH variable.
            Warning: "/tmp/pp-4.png" was not found as a file or as a shape library member
            Warning: No or improper image="/tmp/pp-4.png" for node "user1"

We "fixed" that by using a custom shell-out function (instead of using Graphviz#output)

        tempfile = Tempfile.new(["graph",".dot"])
        tempfile.write graph.to_s
        tempfile.close

        pngfile = Tempfile.new(["graph",".png"])
        pngfile.binmode

        cmd = "unset SERVER_NAME; circo #{tempfile.path} -Tpng  > #{pngfile.path}"
        `#{cmd}`

        blob = File.open(pngfile,"rb").read

if there is an option to remove that env var via another switch in Graphviz#output that would be great.

Otherwise, this issue description might save other people some time. :)

Avoid autoload

Autoload will be removed from Ruby. Also, it is causing problems with Bundler:

$ rake dm:doc:graphviz --trace
** Invoke dm:doc:graphviz (first_time)
** Invoke dm:doc:graphviz:relational (first_time)
** Invoke dm:doc:graphviz:relational:png (first_time)
** Execute dm:doc:graphviz:relational:png
rake aborted!
cannot load such file -- graphviz/utils/colors
/home/hal/.rvm/gems/ruby-1.9.3-p194/gems/ruby-graphviz-1.0.8/lib/graphviz/types/color.rb:1:in `require'
/home/hal/.rvm/gems/ruby-1.9.3-p194/gems/ruby-graphviz-1.0.8/lib/graphviz/types/color.rb:1:in `'
/home/hal/.rvm/gems/ruby-1.9.3-p194/gems/ruby-graphviz-1.0.8/lib/graphviz/types/color_list.rb:8:in `block in check'
/home/hal/.rvm/gems/ruby-1.9.3-p194/gems/ruby-graphviz-1.0.8/lib/graphviz/types/color_list.rb:8:in `map'
/home/hal/.rvm/gems/ruby-1.9.3-p194/gems/ruby-graphviz-1.0.8/lib/graphviz/types/color_list.rb:8:in `check'
/home/hal/.rvm/gems/ruby-1.9.3-p194/gems/ruby-graphviz-1.0.8/lib/graphviz/types.rb:5:in `initialize'
/home/hal/.rvm/gems/ruby-1.9.3-p194/gems/ruby-graphviz-1.0.8/lib/graphviz/attrs.rb:62:in `new'
/home/hal/.rvm/gems/ruby-1.9.3-p194/gems/ruby-graphviz-1.0.8/lib/graphviz/attrs.rb:62:in `[]='
/home/hal/.rvm/gems/ruby-1.9.3-p194/gems/ruby-graphviz-1.0.8/lib/graphviz/edge.rb:77:in `[]='
/home/hal/.rvm/gems/ruby-1.9.3-p194/gems/ruby-graphviz-1.0.8/lib/graphviz.rb:210:in `block in add_edges'
/home/hal/.rvm/gems/ruby-1.9.3-p194/gems/ruby-graphviz-1.0.8/lib/graphviz.rb:209:in `each'
/home/hal/.rvm/gems/ruby-1.9.3-p194/gems/ruby-graphviz-1.0.8/lib/graphviz.rb:209:in `add_edges'

some tests fail because it cannot find 'dot'

  1. Failure:
    test_sample43(GraphVizTest)
    [./test/test_examples.rb:125:in assert_sample_file_has_no_output' ./test/test_examples.rb:97:intest_sample43']:
    got exception on sample43.rb: GraphViz not installed or dot not in PATH. Install GraphViz or use the 'path' option.
    is not true.

84 tests, 221 assertions, 11 failures, 1 errors

Even though dot is already in PATH. Please fix these tests.

$ which dot
/usr/bin/dot

Changes in 1.0.9 breaks functionality

When outputting my graph (using graphviz-dot, output as svg) dot crashes and doesn't produce a graph.
Everything works in 1.0.8.

Using windows 32-bit ruby 2.0.0. Graphviz 2.30.1

edit:

Here is an example of the code that creates an incorrect graph:

graph.add_edges(graph_reference_table[src_path + condition], graph_reference_table[statement_home + "()"], :lhead=>graph_reference_table[statement_home], :color=>"purple", :style=>"dashed", :constraint=>"false")

The two nodes are references to two nodes. The lhead is a reference to a cluster graph from which to start the head of the edge.
This works in 1.0.8, and I think this was the suggested way of drawing edges from node to a cluster/graph.

If I remove the lhead attribute this is drawn in in 1.0.9 also.

I should add, the graph in question has compound=true set

why deprecate add_node() and add_edge()?

They're perfectly reasonable names for the (original) special case. Please remove the nagging warnings.

Also, it's considered bad style for a library routine to write to standard output or standard error. Indicate an error with a return value or an exception, but you shouldn't assume that output streams are available for your use.

Trouble with dot2ruby

Calling:

graph = GraphViz.parse_string("")

produces the following error in ubuntu 13.04 with rvm installed ruby 2.0.0. This was called from irb. I also tried it in a rake task

2.0.0p195 :004 >   require 'graphviz'
 => true 
2.0.0p195 :005 > GraphViz.parse_string("")
RuntimeError: Error from  -f /home/me/.rvm/gems/ruby-2.0.0-p195/gems/ruby-graphviz-1.0.9/lib/ext/gvpr/dot2ruby.g -a "-" /tmp/dot2ruby.rb20130626-9878-1xsi51p:
sh: 1: -f: not found

    from /home/me/.rvm/gems/ruby-2.0.0-p195/gems/ruby-graphviz-1.0.9/lib/graphviz/utils.rb:77:in `output_from_command'
    from /home/me/.rvm/gems/ruby-2.0.0-p195/gems/ruby-graphviz-1.0.9/lib/graphviz/dot2ruby.rb:46:in `eval'
    from /home/me/.rvm/gems/ruby-2.0.0-p195/gems/ruby-graphviz-1.0.9/lib/graphviz/dot2ruby.rb:55:in `eval_string'
    from /home/me/.rvm/gems/ruby-2.0.0-p195/gems/ruby-graphviz-1.0.9/lib/graphviz.rb:754:in `parse_string'
    from (irb):5

Making an edge between a node and a subgraph

Making an edge between a note and a subgraph doesn't seem to work. Instead a new node is generated with the name of the subgraph.

c0 = g.add_graph( "cluster0", "label" => "cluster #1"  )
a0 = c0.add_nodes( "a0" )

c1 = g.add_graph( "cluster1", "label" => "cluster #2" )
b0 = c1.add_nodes( "b0" )

g.add_edges(c0,c1)
g.add_edges(c0,b0)

is generated to

digraph G {
subgraph cluster0 {
  label = "cluster #1";
  a0 [label = "a0"];
}
subgraph cluster1 {
  label = "cluster #2";
  b0 [label = "b0"];
}
  cluster0 [label = "cluster0"];
  cluster1 [label = "cluster1"];
  cluster0 -> cluster1
  cluster0 -> b0
}

I was trying something like this

add_graph fails when passed a GraphViz object

require "graphviz"

# ok
master = GraphViz::new(:G)
cl1 = master.add_graph('cluster_cl1')
puts master.inspect
# digraph G {
# subgraph cluster_cl1 {
# }
# }

# add_graph fails when passed a GraphViz object
master = GraphViz::new(:G)
cl1 = GraphViz::new('cluster_cl1')
master.add_graph cl1
puts master.inspect
# digraph G {
# digraph cluster_cl1 {
# }
# }

I believe that the output of the two parts should be equivalent, i.e. cluster_cl1 should be subgraph instead of digraph.

generated empty pngs

Git cloned. Went to examples/. Ran ruby sample01.rb but generated empty sample01.rb.png (no bytes). Same with 02. Did not try the rest. Suggestions?

Cygwin PATH (by Anton Ivanov)

find I need the following modification in order to run on cygwin. Please consider including it.

--- /usr/lib/ruby/gems/1.8/gems/ruby-graphviz-0.9.10/lib/graphviz.rb.orig 2010-03-20 21:54:09.281250000 -0700

+++ /usr/lib/ruby/gems/1.8/gems/ruby-graphviz-0.9.10/lib/graphviz.rb 2010-03-20 22:09:51.109375000 -0700

@@ -470,7 +470,12 @@

if IS_JRUBY

xCmd = "#{cmd} -q#{@errors} #{xExternalLibraries} #{xOutputWithFile} #{xOutputWithoutFile} #{t.path}"

else

  • xCmd = ""#{cmd}" -q#{@errors} #{xExternalLibraries} #{xOutputWithFile} #{xOutputWithoutFile} #{t.path}"
  • tmp_path = case RUBY_PLATFORM
  • when /cygwin/: "'" + cygpath -w #{t.path}.chomp + "'"
  • else
  • t.path
  • end
  • xCmd = ""#{cmd}" -q#{@errors} #{xExternalLibraries} #{xOutputWithFile} #{xOutputWithoutFile} #{tmp_path}"

end

output_from_command( xCmd )

========end patch

parse_string graph object does not accept global settings

I have a dot output string that I would like to parse into a Ruby GraphViz object and then set graph/node/edge properties on it and add more nodes.

hello_goodnight = GraphViz::new( "" )

hello_goodnight.node[:style] = "rounded"
hello_goodnight.node[:shape] = "box"

hello_world = hello_goodnight.add_graph("hello_world")
hello = hello_world.add_nodes("Hello")
world = hello_world.add_nodes("World")
hello_world.add_edges(hello, world)

goodnight_all = hello_goodnight.add_graph("goodnight_all")
goodnight = goodnight_all.add_nodes("Goodnight")
all = goodnight_all.add_nodes("All")
goodnight_all.add_edges(goodnight, all)

#This gives an output with the style and shape in the global node section
puts hello_goodnight.output( :xdot => String )


#This does not bring in the style and shape
g = GraphViz.parse_string( hello_goodnight.output( :dot => String ) )
#Try setting it again
g.node[:style] = "rounded"
g.node[:shape] = "box"
hello_world = g.get_graph("hello_world")
foo = hello_world.add_nodes('Foo')
bar = hello_world.add_nodes('Bar')
hello_world.add_edges(foo, bar)

# The style and shape are not added to the global node section..
# the style/shape is listed inside the each previously created node
# Hello, World, Goodnight, All are still rounded box style
puts g.output( :xdot => String )

Foo and Bar do not have the rounded box style.

This, however, does work (by putting in the updated subgraph node settings):

g = GraphViz.parse_string( hello_goodnight.output( :dot => String ) )
hello_world = g.get_graph("hello_world")
hello_world.node[:style] = "rounded"
hello_world.node[:shape] = "box"
foo = hello_world.add_nodes('Foo')
bar = hello_world.add_nodes('Bar')
hello_world.add_edges(foo, bar)
puts g.output( :xdot => String )

But I would rather not set rounded box on every single subgraph. I'd rather set it globally.

Any ideas on how to get these properties to show up in the global node section?

cannot load such file -- xml/xslt

Hi.

When I try to run git2gv inside a git repository I get the following output:

GraphViz#add_node is deprecated, please use GraphViz#add_nodes
GraphViz#add_node is deprecated, please use GraphViz#add_nodes
GraphViz#add_node is deprecated, please use GraphViz#add_nodes
GraphViz#add_node is deprecated, please use GraphViz#add_nodes
fatal: ambiguous argument 'master': unknown revision or path not in the working tree.
Use '--' to separate paths from revisions
GraphViz#add_edge is deprecated, please use GraphViz#add_edges
GraphViz#add_edge is deprecated, please use GraphViz#add_edges
GraphViz#add_edge is deprecated, please use GraphViz#add_edges
/home/<username>/.rvm/rubies/ruby-1.9.3-p0/lib/ruby/site_ruby/1.9.1/rubygems/custom_require.rb:36:in `require': cannot load such file -- xml/xslt (LoadError)
        from /home/<username>/.rvm/rubies/ruby-1.9.3-p0/lib/ruby/site_ruby/1.9.1/rubygems/custom_require.rb:36:in `require'
        from /home/<username>/.rvm/gems/ruby-1.9.3-p0@global/gems/ruby-graphviz-1.0.4/lib/graphviz/nothugly.rb:11:in `<top (required)>'
        from /home/<username>/.rvm/rubies/ruby-1.9.3-p0/lib/ruby/site_ruby/1.9.1/rubygems/custom_require.rb:36:in `require'
        from /home/<username>/.rvm/rubies/ruby-1.9.3-p0/lib/ruby/site_ruby/1.9.1/rubygems/custom_require.rb:36:in `require'
        from /home/<username>/.rvm/gems/ruby-1.9.3-p0@global/gems/ruby-graphviz-1.0.4/lib/graphviz.rb:550:in `block in output'
        from /home/<username>/.rvm/gems/ruby-1.9.3-p0@global/gems/ruby-graphviz-1.0.4/lib/graphviz.rb:504:in `each'
        from /home/<username>/.rvm/gems/ruby-1.9.3-p0@global/gems/ruby-graphviz-1.0.4/lib/graphviz.rb:504:in `output'
        from /home/<username>/.rvm/gems/ruby-1.9.3-p0@global/gems/ruby-graphviz-1.0.4/bin/git2gv:53:in `run'
        from /home/<username>/.rvm/gems/ruby-1.9.3-p0@global/gems/ruby-graphviz-1.0.4/bin/git2gv:168:in `<top (required)>'
        from /home/<username>/.rvm/gems/ruby-1.9.3-p0@global/bin/git2gv:19:in `load'
        from /home/<username>/.rvm/gems/ruby-1.9.3-p0@global/bin/git2gv:19:in `<main>'

What is the reason of this issue? How can I force ruby-graphviz to work correctly?

Thanks.

Debian GNU/Linux 6.0.3;

Ruby 1.9.3-p0;

Graphviz 2.26.3;

Ruby-graphviz 1.0.4.

(undefined local variable or method `file' )

hello, i've got a problem with the following method: find_executable(bin, custom_paths) in Ruby-Graphviz / lib / graphviz / utils.rb.

I saw in the file history(change 2 days ago) that the variable declaration was deleted. I think you must have the problem too or I did something wrong.

Thanks for your great work.

dots in href are escaped with backslash, which corrupts the URL

When I add a node to my graph with a :href attribute like this:
g.add_node(site, :label => "N", :href => "http://www.website.com", :tooltip => site, :shape => "ellipse", :color => "#FF0000")

This will result in a link like this in the SVG output:

I tested it via the DOT language syntax directly like this and there it works, so this makes me think that it is a problem in Ruby-Graphviz
b [label="N",href="http://www.website.com"]

The same problem applies for the :tooltip I believe.

Any ideas?

How can I add named edges?

I want to add a to an edge, so the string will appear next to the edge, but the documentation does not explain how to do this. The code shows that you can pass in a hash of edge attributes, but I am not sure of how to name those attributes.

path option is never being used to find the executable

If you set the path option, the supplied path is never being parsed as a possible location. The find_executable is being called empty, and the *paths hash doesn't exist anywhere, so it's ALWAYS empty.
Replacing line graphviz.rb:383 with fix below the issue for me, but will likely need to be checked and generalized.

FIX
cmd = find_executable( @prog, @path )

EXISTING
cmd = find_executable( )
if cmd == nil
raise StandardError, "GraphViz not installed or #{@prog} not in PATH. Install GraphViz or use the 'path' option"
end

def find_executable(bin = @prog, *paths) #:nodoc:
  paths = ENV['PATH'].split(File::PATH_SEPARATOR) if paths.empty?
  paths.each do |path|
    file = File.join(path,bin)
    if File.executable?(file) then
      return file
    elsif RUBY_PLATFORM =~ /mswin|mingw/
      found_ext = (ENV['PATHEXT'] || '.exe;.bat;.com').split(";").find {|ext| File.executable?(file + ext) }
      return file + found_ext if found_ext
    end
  end
  return nil
end

Can't convert Fixnum to String (TypeError)

Adding an edge with a numeric label fails with the following error:

ruby-graphviz-1.0.8/lib/graphviz/types/lbl_string.rb:9:in match': can't convert Fixnum to String (TypeError)`

The last line causes the error in irb:

graph = GraphViz.digraph(:G)
a = graph.add_nodes('a')
b = graph.add_nodes('b')
graph.add_edges(a, b, label: 5)

ruby-graphviz breaks autoloading of ActiveSupport::Concerns

I've already created an issue in rails for this so creating one here as well to link them together somewhat. Also copying the main body from my initial issue post below.
rails/rails#9355

If ruby-graphviz is in the Gemfile, autoloading of generic ActiveSupport::Concerns fails. By generic I mean ones that aren't namespaced within a class.

I have an example application with instructions on how to exhibit the problem below.
https://github.com/brocktimus/rails_graphviz_example

This shows that with or without ruby-graphviz ActiveSupport::Concerns within a class are fine.

# app/model/post/extras.rb
module Post::Extras
  extends ActiveSupport::Concern
end

If they have been required manually first generic ones work (such as in an initializer).

# app/model/concerns/constants.rb
module Constants
  extends ActiveSupport::Concern
end

If they have not been required and ruby-graphviz is in the bundle everything explodes when the model is used.

I tried to look into what ruby-graphviz was doing that could cause this, but I couldn't see anything obvious.

"rank" tag example

Could you give a hint on how rank tag shall be used - Id like to declare equivalent to dot expression
{ rank = same; "node1"; "node2"; }

RGB color list - supported?

Hi

I was experimenting a bit with colors and colorlist and was wondering if it is possible to define a color list using rgb colors??

e.g.:

node[:color] = "red:white"  # works
node[:color] = "#FF0000:#FFFFFF"  # raises error
node[:color] = "#FFFFFF:FFFFFF"  # raises error

I think according to the documentation of colorlist, the second one should work. Did I misinterpreted the docs (http://www.graphviz.org/doc/info/attrs.html#k:colorlist) or is it not yet supported/bug in ruby-graphviz?

Outputting to a String on Windows fails

Because pipes are opened in text mode by default, the output for binary types like PNG is mangled.
To fix this issue simply call the following line in the output_and_errors_from_command method:
stdin.binmode
Do this for both ways (Open3#popen3 and IO#popen). Note that it will also affect text types but should really not be an issue because \n is a valid newline for SVG and other text formats.

Regards,

Pascal

File::ALT_SEPARATOR nil

In the .../1.8/gems/ruby-graphviz-0.9.6/lib/graphviz.rb method escape_path_containing_blanks
line 714
def escape_path_containing_blanks(path)
path.gsub!(File::ALT_SEPARATOR, File::SEPARATOR)
throws an Exception on my machine since File::ALT_SEPARATOR
A simple workaround is:
def escape_path_containing_blanks(path)
path.gsub!(File::ALT_SEPARATOR, File::SEPARATOR) if File::ALT_SEPARATOR

I'm using ubuntu 9.10, JRuby 1.4.0

How to combine graphviz instances?

Hi,

I was wondering if and how I can combine several graphs.

My usecase is the following:
I have several graphs that are visualized apart from each other.
I now want to show the structure between these graphs by having an 'overview' graph, showing each individual graph inside a cluster

Can I convert them to dot, save them to a file, and then parse them again inside the 'subgraph' of the 'overview' model, or is there an easier way to do this?

Thanks in advance

UTF8 (by Anton Ivanov)

I seem to have a problem with utf-8 labels. The following renders fine: a [label="Ξ΅"]; however when I pass {:label=>'Ξ΅'} to add_node, the output has
[label="\316\265"] which renders as a decimal value.

About the acquisition of graphml <data> tags with ruby 1.9.2p290, ruby-graphviz 1.0.3

Using ruby 1.9.2p290 and ruby-graphviz 1.0.3, I noticed that ruby-graphviz
presented the content of graphml tags within square brackets, and with new, escaped quotes.
So

'text'

in graphml became

'["text"]'

in dot and hence

'["text"]'

in final formats, as it can be seen working out a simple graphml file like

ab.graphml

<node id="n0">
  <data key="nm">a</data>
</node>

<node id="n1">
  <data key="nm">b</data>
</node>

<edge source="n0" target="n1"/>
##

This behaviour can easily be corrected by redefining the method graphml_graph_node_data in
GraphViz::GraphML.

This can be done - Γ  la Ruby - just in programs, like this

class GraphViz
class GraphML

def graphml_graph_node_data( node ) 

  # drop this
  #@current_node[@attributs[:nodes][node.attributes['key']][:name]] = node.texts().to_s

  # add this
  @current_node[@attributs[:nodes][node.attributes['key']][:name]] = node.texts().join(sep='\n',)

end

end

end

Bye

Ernesto Torresin (EWK)

PS I like this library. Thank you for it.

Feature Request: Enable Cluster to Cluster edges

I am working on generating Statecharts using ruby. One of the important features of these graphs is that sets of nodes can be connected to other sets of nodes with edges. The sets of nodes are themselves drawn in a box (called a superstate sometimes).

Graphviz can be coaxed to accomplish this. This stack overflow article shows the solution: http://stackoverflow.com/questions/2012036/graphviz-how-to-connect-subgraphs

My request is that if the ruby-graphviz user creates subgraphs that are clusters, and connects them together with an edge, the little hack above in the stackoverflow article is used to draw directly from one cluster to another. The ltail and lhead attributes would be generated automatically by ruby-graphviz.

initial = g.subgraph("cluster initial startup")
show_toggle_prompt = initial.add_node( "show_toggle_prompt" )
blink_info = initial.add_node( "blink_info" )
initial.add_edge(show_toggle_prompt, blink_info)

select_prompts = g.subgraph("cluster selector prompts")

g.add_edge(initial, select_prompts) # this creates an edge between the two subgraphs

What do you think?

Best,
John

ruby2gv is failing

$ ruby2gv -Tpng -
oruby2gv.png lib/ruby-graphviz.rb
/usr/bin/ruby2gv:119:in parseFile': undefined methodeach' for "require 'graphviz'\n":String (NoMethodError)
from /usr/bin/ruby2gv:43:in parse' from /usr/bin/ruby2gv:235:in

'

Version: ruby-graphviz-1.0.8

Documentation for the node/edge attributes?

What exactly do they all do? I kind of want to dynamically change an edge type from undirected to directed, yet it isn't immediately obvious how to do this, or which attribute I should fiddle around with.

Thin server ?

Hi,

I'm using thin as server. I got this error when using graphviz with it.
is it a way to change the default tmp file ?

RuntimeError (Error from "/usr/bin/dot" -q1  -Tpng -o/home/www/prog/public/images/graph.png   /tmp/thin server (10.1.1.83:10204)20100624-12443-grpl3f-0:
sh: -c: line 0: syntax error near unexpected token `('
sh: -c: line 0: `"/usr/bin/dot" -q1  -Tpng -o/home/www/prog/public/images/graph.png   /tmp/thin server (10.1.1.83:10204)20100624-12443-grpl3f-0'
):
  ruby-graphviz (0.9.11) lib/graphviz.rb:533:in `output_from_command'
  ruby-graphviz (0.9.11) lib/graphviz.rb:493:in `output'

Regards,

Teuf

escaped dot in label, backslash showing up

Related:
#8
b2204d9

Having problem with labels that contain dot, did you ever find out why the escaping was added? Dot should be a valid character in label.

Parsing back generated dot file chokes too:

$ cat sample.rb 
require 'graphviz'
g = GraphViz.new(:G, :type => :graph)
g.add_nodes("Hello World.")
puts g.to_s
GraphViz.parse_string(g.to_s)

$ RUBYLIB=lib ruby sample.rb
graph G {
  "Hello World\." [label = "Hello World."];
}
./lib/graphviz/dot2ruby.rb:47:in `eval': (eval):8:in `eval': compile error (SyntaxError)
(eval):6: syntax error, unexpected $undefined, expecting '}'
  node_hello__world\ = graph_g.add_nodes( "Hello W...
                    ^
    from ./lib/graphviz/dot2ruby.rb:55:in `eval_string'
    from ./lib/graphviz.rb:784:in `parse_string'
    from sample.rb:5

And, sample29 which has a dot in the label is generating:

$ grep '<g.*title' ./test/output/sample29.rb.svg
<g id="node1" class="node"><title>&quot;Hello\.&quot;\nHow are you ?</title>

Thanks.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    πŸ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. πŸ“ŠπŸ“ˆπŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❀️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.