Rgl can't produce disconnected graphs

[posted and mailed to package author]

Rubies:

I downloaded rgl-0.2.1 from http://sourceforge.net/projects/rgl/

Being a rather simple person, I decided to start by producing the simplest
graph I could possibly make; a graph with no vertices and no edges.

This proved trivial, so I decided to go to the next level: A graph with one
vertex and no edges:

    dg=RGL::DirectedAdjacencyGraph.new #[1,2 ,2,3 ,2,4, 4,5, 6,4, 1,6]
    dg.add_vertex('yo')
    dg.write_to_graphic_file('jpg')
    system('kview graph.jpg &')

This produces a graph containing a title, and nothing else. There is no
single vertex. (Graphviz, the back-end for ‘write_to_graphic_file’, knows
to produce a single vertex here.)

RGL either has a bug, or its author thinks single vertices are not graphs.
In the above example, if we uncomment the “[1,2 ,2,3 …” stuff and take
out the .new, we get a graph with 6 vertices. But the 7th is missing.

···


Phlip
http://www.greencheese.org/YaAw
– Proud victim of the dreaded boomerang effect –

Being a rather simple person, I decided to start by producing the simplest
graph I could possibly make; a graph with no vertices and no edges.

This proved trivial, so I decided to go to the next level: A graph with one
vertex and no edges:

    dg=RGL::DirectedAdjacencyGraph.new #[1,2 ,2,3 ,2,4, 4,5, 6,4, 1,6]
    dg.add_vertex('yo')
    dg.write_to_graphic_file('jpg')
    system('kview graph.jpg &')

This produces a graph containing a title, and nothing else. There is no
single vertex. (Graphviz, the back-end for ‘write_to_graphic_file’, knows
to produce a single vertex here.)

There is one vertex:

irb(main):073:0> dg.vertices
[“yo”]

write_to_graphic_file has a bug. It only shows edges. I fixed it in the latest CVS of rgl/dot.rb. By
the way: Support for dot is rather rudimentary. Debugging graph datastructures should better be done
using inspect or the graph accessors for vertices and edges.

RGL either has a bug, or its author thinks single vertices are not graphs.
In the above example, if we uncomment the “[1,2 ,2,3 …” stuff and take
out the .new, we get a graph with 6 vertices. But the 7th is missing.

A graph can have isolated vertices as the above example with the single vertex “yo” shows.

The expression

dg = RGL::DirectedAdjacencyGraph[1,2, 2,3, 2,4, 4,5, 6,4, 1,6]

creates a graph with edges (1-2) (2-3) (2-4) (4-5) (6-4) (1-6), one for each pair in the array given
as parameter for the singeleton method RGL::DirectedAdjacencyGraph.

dg.edges.sort.to_s => "(1-2)(1-6)(2-3)(2-4)(4-5)(6-4)"
dg.vertices.sort => [1, 2, 3, 4, 5, 6]

The constructor does not take vertices as parameter but edges. Vertices are created internally for
the source and target of each edge.

Horst

···

----- Original Message -----
From: “Phlip” phlip_cpp@yahoo.com

Horst Duchene wrote:

There is one vertex:

irb(main):073:0> dg.vertices
[“yo”]

Sorry - I tried to imply I knew there was a no bug in RGL proper - just its
path thru GraphViz’s Dot system.

write_to_graphic_file has a bug. It only shows edges. I fixed it in the
latest CVS of rgl/dot.rb. By the way: Support for dot is rather
rudimentary. Debugging graph datastructures should better be done using
inspect or the graph accessors for vertices and edges.

I’m not debugging graph accessors I’m writing a wrapper on Dot.

Here’s my outer intent:

One can create a very powerful user interface treating ‘dot’ essentially as
a geometry manager. Imagine if we had a “family tree” program. We could
click on a node to upgrade that person’s records, and we could use arrow
keys to travel between family members.

I can do this in <300 lines of code (plus test code, natch) using a
TkCanvas and a utility to convert a subset of SVG format into objects on
that canvas.

Writing that utility test-first requires me to start with the simplest
feature, which is one node. After posting the question I did this by
starting at the Graphviz layer.

So here’s my product, with [optional components]:

[RGL ->] GraphVis → SVG format → TkCanvas

The result is a truly sweet UI framework. I’l deliver it to RubyGarden very
soon; it’s almost done.

The only feature I could request is this: The TkCanvas layer works poorly
if the nodes are not filled-in. This is not mission-critical, but it
improves the odds an end-user programmer will opt to use the RGL layer
above GraphViz. Formatting ‘dot’ files in memory will be a pain in the nads.

The best feature for RGL (unless if I’m missing it) would be the ability to
add a string that the RGL::Dot layer will pass-thru to the Dot file. To
whit:

   aNode [label = "", style = filled, fillcolor = pink, color = green];
   bNode [label = "", style = filled, fillcolor = pink, color = green];

If the above is indeed possible via Ruby’s vaunted class extension
mechanics, please feel free to categorize me as the drooling newbie who
refuses to read the fine manual that I am, so long as source accompanies
the admonition!

···


Phlip
greencheese.org
– All sensors report Patti having a very good time –