Attributes
==========

>>> from pygraphviz import *

Graph Defaults
--------------

>>> A=AGraph()
>>> A.graph_attr['label']='test'
>>> A.graph_attr['spam']='eggs'
>>> 'label' in A.graph_attr
True
>>> A.graph_attr['label']
u'test'
>>> A.graph_attr.keys()
[u'label', u'spam']
>>> sorted(list(A.graph_attr.iteritems()))
[(u'label', u'test'), (u'spam', u'eggs')]
>>> print A.string().expandtabs(2)
strict graph {
  graph [label=test,
    spam=eggs
  ];
}
<BLANKLINE>
>>> A.graph_attr['label']=''
>>> A.graph_attr['spam']=''
>>> print A.string().expandtabs(2)
strict graph {
}
<BLANKLINE>

>>> A.graph_attr['label']='test'
>>> del A.graph_attr['label']
>>> print A.string().expandtabs(2)
strict graph {
}
<BLANKLINE>

>>> A=AGraph(rankdir='LR',pack='true')
>>> print A.string().expandtabs(2)
strict graph {
  graph [pack=true,
    rankdir=LR
  ];
}
<BLANKLINE>

Node Defaults
--------------

>>> A=AGraph()
>>> A.node_attr['label']='test'
>>> 'label' in A.node_attr
True
>>> A.node_attr['label']
u'test'
>>> A.node_attr.keys()
[u'label']
>>> A.node_attr
{u'label': u'test'}
>>> list(A.node_attr.iteritems())
[(u'label', u'test')]
>>> print A.string().expandtabs(2)
strict graph {
  node [label=test];
}
<BLANKLINE>
>>> A.node_attr['label']=''
>>> print A.string().expandtabs(2)
strict graph {
}
<BLANKLINE>

>>> A.node_attr['label']='test'
>>> del A.node_attr['label']
>>> print A.string().expandtabs(2)
strict graph {
}
<BLANKLINE>

>>> A.graph_attr['fontname'] = 'graph font'
>>> A.node_attr['fontname'] = 'node font'
>>> A.edge_attr['fontname'] = 'edge font'
>>> print A.string().expandtabs(2)
strict graph {
  graph [fontname="graph font"];
  node [fontname="node font"];
  edge [fontname="edge font"];
}
<BLANKLINE>

Edge Defaults
--------------

>>> A=AGraph()
>>> A.edge_attr['label']='test'
>>> 'label' in A.edge_attr
True
>>> A.edge_attr['label']
u'test'
>>> A.edge_attr.keys()
[u'label']
>>> A.edge_attr
{u'label': u'test'}
>>> list(A.edge_attr.iteritems())
[(u'label', u'test')]
>>> print A.string().expandtabs(2)
strict graph {
  edge [label=test];
}
<BLANKLINE>
>>> A.edge_attr['label']=''
>>> print A.string().expandtabs(2)
strict graph {
}
<BLANKLINE>
>>> A.edge_attr['label']='test'
>>> del A.edge_attr['label']
>>> print A.string().expandtabs(2)
strict graph {
}
<BLANKLINE>

Individual node attributes
--------------------------

>>> A=AGraph()
>>> A.add_node(1,label='test',spam='eggs')
>>> print A.string().expandtabs(2)
strict graph {
  node [label="\N"];
  1  [label=test,
    spam=eggs];
}
<BLANKLINE>

>>> A=AGraph()
>>> A.add_node(1)
>>> one=A.get_node(1)
>>> one.attr['label']='test'
>>> one.attr['spam']='eggs'
>>> 'label' in one.attr
True
>>> one.attr['label']
u'test'
>>> sorted(one.attr.keys())
[u'label', u'spam']
>>> print A.string().expandtabs(2)
strict graph {
  node [label="\N"];
  1  [label=test,
    spam=eggs];
}
<BLANKLINE>
>>> one.attr['label']=''
>>> one.attr['spam']=''
>>> print A.string().expandtabs(2)
strict graph {
  node [label="\N"];
  1  [label=""];
}
<BLANKLINE>
>>> one.attr['label']='test'
>>> del one.attr['label']
>>> print A.string().expandtabs(2)
strict graph {
  node [label="\N"];
  1  [label=""];
}
<BLANKLINE>

Individual edge attributes
--------------------------

>>> A=AGraph()
>>> A.add_edge(1,2,label='test',spam='eggs')
>>> print A.string().expandtabs(2)
strict graph {
  1 -- 2   [label=test,
    spam=eggs];
}
<BLANKLINE>
>>> A=AGraph()
>>> A.add_edge(1,2)
>>> one=A.get_edge(1,2)
>>> one.attr['label']='test'
>>> one.attr['spam']='eggs'
>>> 'label' in one.attr
True
>>> one.attr['label']
u'test'
>>> sorted(one.attr.keys())
[u'label', u'spam']
>>> print A.string().expandtabs(2)
strict graph {
  1 -- 2   [label=test,
    spam=eggs];
}
<BLANKLINE>
>>> one.attr['label']=''
>>> one.attr['spam']=''
>>> print A.string().expandtabs(2)
strict graph {
  1 -- 2;
}
<BLANKLINE>
>>> one.attr['label']='test'
>>> del one.attr['label']
>>> print A.string().expandtabs(2)
strict graph {
  1 -- 2;
}
<BLANKLINE>

Anonymous edges and attributes
------------------------------
>>> d="""graph test {\n a -- b [label="edge1"];\n a -- b [label="edge2"];\n }"""
>>> import os,tempfile
>>> (fd,fname)=tempfile.mkstemp()
>>> fh=open(fname,'w')
>>> fh.write(d)
>>> fh.close()
>>> A=AGraph(fname)
>>> print A.string().expandtabs(2)
graph test {
  a -- b   [label=edge1];
  a -- b   [label=edge2];
}
<BLANKLINE>

HTML
----
>>> G = AGraph(label='<Hello<BR/>Graph>')
>>> G.add_node('a', label='<Hello<BR/>Node>')
>>> s = G.add_subgraph('b', label='<Hello<BR/>Subgraph>')
>>> s.add_node('sa', label='<Hello<BR/>Subgraph Node b>')
>>> G.add_edge('a','b', label='<Hello<BR/>Edge>')
>>> print G.string().expandtabs(2)
strict graph {
  graph [label=<Hello<BR/>Graph>];
  node [label="\N"];
  {
    graph [label=<Hello<BR/>Subgraph>];
    sa     [label=<Hello<BR/>Subgraph Node b>];
  }
  a  [label=<Hello<BR/>Node>];
  a -- b   [label=<Hello<BR/>Edge>];
}
<BLANKLINE>


Subgraphs
---------
>>> G = AGraph(label='foo')
>>> s = G.subgraph('cluster_a', label='<Hello<BR/>World>')
>>> s.add_node('sa')
>>> G.add_node('a')
>>> print G.string().expandtabs(2)
strict graph {
  graph [label=foo];
  {
    graph [label=<Hello<BR/>World>];
    sa;
  }
  a;
}
<BLANKLINE>
>>> G = AGraph()
>>> s = G.subgraph(name='cluster_a')
>>> s.node_attr['foo']='bar'
>>> G.add_node('a')
>>> G.node_attr['foo']='baz'
>>> print G.string().expandtabs(2)
strict graph {
  node [foo=baz];
  subgraph cluster_a {
    graph [foo=bar];
  }
  a;
}
<BLANKLINE>
