1

I am stuck with the BGL trying to read nodes default attributes. I managed to read nodes, edges and even graph attributes. But not the default attributes (color, fontname, shape) as in the graph below:

digraph G {
node [color = black, fontname = courier, shape = plaintext];
0[id=0, label=start];
1[id=1, label="0x00007ff7ca001358"];
2[id=2, label="0x00007ff7ca001969"];
0->1;
1->2;
}

Here is my code, to start with:

class Node {
    public:
        std::string label, id;
};
class Branch {
    public:
        bool path;
};

typedef boost::adjacency_list<boost::listS, boost::vecS, boost::directedS,Node,Branch> DAG;

std::istream & operator>>(std::istream & i, DAG & g)
{
    boost::dynamic_properties dp;        
    dp.property("id",get(&Node::id,g));
    dp.property("label",get(&Node::label,g));
    dp.property("path", get(&Branch::path, g));
    /* ??? dp.property("color", get(&????, g)); <= what to put here ? ref_property_map ? */
    read_graphviz(i,g,dp,"index");
    return i;
}
Heyji
  • 1,113
  • 8
  • 26
  • Can you clarify what you mean by default attributes? For example if I would change your input graph like this: https://pastebin.com/jsv9RNTn When rendering the graph with graphviz, the first two nodes would be black and the third node would be red. You could of course add a color attribute to your `Node` class and read the color for each node as a dynamic property. But my understanding is that this is not what you want to do, rather you want to get a kind of global attribute value. Do you simply want to fetch the last attribute value that was declared, so in my example "red"? – f9c69e9781fa194211448473495534 May 25 '20 at 16:50
  • Hi, I wasn't planning to use dot the way you did in your example. For me, you specify the default attributes in a "node clause" (i.e. node [color = red]) and that is what I call the default attribute as it Apply to all nodes, except if you specify another color in the node itself (i.e. 2 [ id=2, label="blablabla", color=red];) which I call this a "specific attribute". The example you showed let me think there is no solution to my problem (DOT grammar does not allow this) – Heyji May 27 '20 at 20:46
  • The DOT grammar allows multiple node clauses (https://www.graphviz.org/doc/info/lang.html), here is the quote: "If a default attribute is defined using a node, edge, or graph statement, or by an attribute assignment not attached to a node or edge, any object of the appropriate type defined **afterwards** will inherit this attribute value. This holds until the default attribute is set to a new value, from which point the new value is used. Objects defined before a default attribute is set will have an empty string value attached to the attribute once the default attribute definition is made." – f9c69e9781fa194211448473495534 May 27 '20 at 20:51
  • So I conclude that there is no such "default attributes" that could be red by read_graphviz() and captured without being overwritten each time a new value is defined. In which case saving only the last node default attribute would not be satisfactory as it would not render exactly what is described by the DOT script. When I said "DOT grammar does not allow this" I meant DOT grammar is too permissive and thus there is no point of reading nodes default attributes with read_graphviz() as it is designed. – Heyji May 28 '20 at 21:38

0 Answers0