Re: [boost] Reading DOT files with Boost.Graph

On Jun 20, 2007, at 4:44 PM, Marshall Clow wrote:
How do I keep "global settings" when reading and writing a graphviz file?
For example, consider the following file:
digraph G { node [ color=blue ]; rankDir=LR
a0 [ label = "//depot/path/to/file_1#4" ]; a1 [ label = "//depot/path/to/file_2#9" ];
a0 -> a1 [ color=gray ]; }
when read and written (with no changes) becomes:
digraph G { a0 [ color="blue" , label = "//depot/path/to/file_1#4" ]; a1 [ color="blue" , label = "//depot/path/to/file_2#9" ]; a0 -> a1 [ color="gray" ]; }
As you can see, the global property "node [ color=blue ];" has been set in each individual node, and the "rankdir=LR" has been completely lost. The first one doesn't change how the graph gets rendered, but the second one certainly does.
Any way to preserve either of these?
Because of the way the graphviz language works, the node and edge settings are associated directly with the nodes and edges of the graph. Node and edge settings are only global until another setting is put in place. It's legal to write: digraph G { node [color=blue]; a0 a1 node [color=gray]; a2 } and that is semantically equivalent to digraph G { a0 [color=blue] a1 [color=blue] a2 [color=gray]; } As for the graph properties, the reader in CVS supports graph properties. For an example use, look at libs/boost/graph/test/ graphviz_test.cpp. Cheers, ron

At 11:36 AM -0400 6/21/07, Ronald Garcia wrote:
On Jun 20, 2007, at 4:44 PM, Marshall Clow wrote:
How do I keep "global settings" when reading and writing a graphviz file?
For example, consider the following file:
digraph G { node [ color=blue ]; rankDir=LR
a0 [ label = "//depot/path/to/file_1#4" ]; a1 [ label = "//depot/path/to/file_2#9" ];
a0 -> a1 [ color=gray ]; }
when read and written (with no changes) becomes:
digraph G { a0 [ color="blue" , label = "//depot/path/to/file_1#4" ]; a1 [ color="blue" , label = "//depot/path/to/file_2#9" ]; a0 -> a1 [ color="gray" ]; }
As you can see, the global property "node [ color=blue ];" has been set in each individual node, and the "rankdir=LR" has been completely lost. The first one doesn't change how the graph gets rendered, but the second one certainly does.
Any way to preserve either of these?
Because of the way the graphviz language works, the node and edge settings are associated directly with the nodes and edges of the graph. Node and edge settings are only global until another setting is put in place. It's legal to write:
digraph G { node [color=blue]; a0 a1 node [color=gray]; a2 }
and that is semantically equivalent to
digraph G { a0 [color=blue] a1 [color=blue] a2 [color=gray]; }
Ok. That's what I figured - it is unfortunate, but I can live with that.
As for the graph properties, the reader in CVS supports graph properties. For an example use, look at libs/boost/graph/test/graphviz_test.cpp.
Do you mean boost/libs/graph/test/graphviz_test.cpp? I looked in the file, and the only graph properties that I can see are the types of the node and edge properties. Am I missing something? I have two goals here, one short term, and one long term. The short term goal is to read and write a Graphviz file successfully (which I am mostly doing, thanks in large part to your answers and bug fixes!), and the long term one is to understand what the graph library is doing so that I can use it better. The short term problem that I am trying to solve is that when I read and then write a Graphviz file, I don't get all the information back. In particular, I get results like this: Input: digraph G { rankDir=LR a0 [ label = "//depot/path/to/file_1#4" ]; a1 [ label = "//depot/path/to/file_2#9" ]; a0 -> a1 [ color=gray ]; } Output: digraph G { a0 [ label = "//depot/path/to/file_1#4" ]; a1 [ label = "//depot/path/to/file_2#9" ]; a0 -> a1 [ color="gray" ]; } The line: rankDir=LR has been lost, and Graphviz renders the file quite differently in the absence of this line. I called this a "graph property" in my earlier email, which may not have been the right term. Is there an easy way to convince the Graphviz reader and writer to preserve that command? -- -- Marshall Marshall Clow Idio Software <mailto:marshall@idio.com> It is by caffeine alone I set my mind in motion. It is by the beans of Java that thoughts acquire speed, the hands acquire shaking, the shaking becomes a warning. It is by caffeine alone I set my mind in motion.

On Jun 21, 2007, at 12:20 PM, Marshall Clow wrote:
As for the graph properties, the reader in CVS supports graph properties. For an example use, look at libs/boost/graph/test/ graphviz_test.cpp.
Do you mean boost/libs/graph/test/graphviz_test.cpp?
I looked in the file, and the only graph properties that I can see are the types of the node and edge properties. Am I missing something? In particular, notice the use of the ref_property map to represent
Yes, sorry about that. the graph name property: boost::ref_property_map<graph_t*,std::string> gname( get_property(graph,graph_name)); dp.property("name",gname); One of the tests is marked with a comment "Graph Property Test". It has a graph of the form: digraph { graph [name="foo"] a c e [mass = 6.66] } The name ends up getting stored in the string referenced by graph_name. HTH, ron

At 12:33 PM -0400 6/21/07, Ronald Garcia wrote:
On Jun 21, 2007, at 12:20 PM, Marshall Clow wrote:
As for the graph properties, the reader in CVS supports graph properties. For an example use, look at libs/boost/graph/test/graphviz_test.cpp.
Do you mean boost/libs/graph/test/graphviz_test.cpp?
Yes, sorry about that.
We are in a small maze of twisty directory names, all different ;-)
I looked in the file, and the only graph properties that I can see are the types of the node and edge properties. Am I missing something? In particular, notice the use of the ref_property map to represent the graph name property:
boost::ref_property_map<graph_t*,std::string> gname( get_property(graph,graph_name)); dp.property("name",gname);
One of the tests is marked with a comment "Graph Property Test". It has a graph of the form: digraph { graph [name="foo"] a c e [mass = 6.66] }
The name ends up getting stored in the string referenced by graph_name.
Ah - I see my problem. I was looking at the 1.34 version of the file, not HEAD. -- -- Marshall Marshall Clow Idio Software <mailto:marshall@idio.com> It is by caffeine alone I set my mind in motion. It is by the beans of Java that thoughts acquire speed, the hands acquire shaking, the shaking becomes a warning. It is by caffeine alone I set my mind in motion.
participants (2)
-
Marshall Clow
-
Ronald Garcia