pygraphvizfactory.py
Go to the documentation of this file.
1 #
2 # License: Yujin
3 #
4 ##############################################################################
5 # Description
6 ##############################################################################
7 
8 """
9 .. module:: pygraphvizfactory
10  :platform: Unix
11  :synopsis: Repackaging of the limiting ROS qt_dotgraph.pygraphvizfactory module.
12 
13 Oh my spaghettified magnificence,
14 Bless my noggin with a tickle from your noodly appendages!
15 
16 """
17 
18 ##############################################################################
19 # Imports
20 ##############################################################################
21 
22 import pygraphviz
23 
24 ##############################################################################
25 # Classes
26 ##############################################################################
27 
28 
29 # Reference implementation for a dotcode factory
31 
32  def __init__(self):
33  pass
34 
35  def get_graph(self, graph_type='digraph', rank='same', simplify=True, rankdir='TB', ranksep=0.2, compound=True):
36  graph = pygraphviz.AGraph(directed=(graph_type == 'digraph'), ranksep=ranksep, rankdir=rankdir, rank=rank, compound=True, simplify=simplify)
37  return graph
38 
39  def add_node_to_graph(self,
40  graph,
41  nodename,
42  nodelabel=None,
43  shape='box',
44  color=None,
45  url=None,
46  tooltip=None):
47  """
48  creates a node item for this factory, adds it to the graph.
49  Node name can vary from label but must always be same for the same node label
50  """
51  if nodename is None or nodename == '':
52  raise ValueError('Empty Node name')
53  if nodelabel is None:
54  nodelabel = nodename
55 
56  kwargs = {}
57  if tooltip is not None:
58  kwargs['tooltip'] = tooltip
59  if color is not None:
60  kwargs['color'] = color
61 
62  graph.add_node(nodename, label=str(nodelabel), shape=shape, url=url, **kwargs)
63 
64  def add_subgraph_to_graph(self,
65  graph,
66  subgraphlabel,
67  rank='same',
68  simplify=True,
69  rankdir='TB',
70  ranksep=0.2,
71  compound=True,
72  color=None,
73  shape='box',
74  style='bold'):
75  """
76  creates a cluster subgraph item for this factory, adds it to the graph.
77  cluster name can vary from label but must always be same for the same node label.
78  Most layouters require cluster names to start with cluster.
79  """
80  if subgraphlabel is None or subgraphlabel == '':
81  raise ValueError('Empty subgraph label')
82 
83  sg = graph.add_subgraph(name="cluster_%s" % subgraphlabel, ranksep=ranksep, rankdir=rankdir, rank=rank, compound=compound, label=str(subgraphlabel), style=style, color=color)
84 
85  return sg
86 
87  def add_edge_to_graph(self, graph, nodename1, nodename2, label=None, url=None, simplify=True, style=None, penwidth=1, color=None):
88  kwargs = {'url': url}
89  if label is not None:
90  kwargs['label'] = label
91  if style is not None:
92  kwargs['style'] = style
93  kwargs['penwidth'] = str(penwidth)
94  if color is not None:
95  kwargs['colorR'] = str(color[0])
96  kwargs['colorG'] = str(color[1])
97  kwargs['colorB'] = str(color[2])
98  graph.add_edge(nodename1, nodename2, **kwargs)
99 
100  def create_dot(self, graph):
101  graph.layout('dot')
102  # sadly pygraphviz generates line wraps cutting between numbers
103  return graph.string().replace("\\\n", "")
def add_subgraph_to_graph(self, graph, subgraphlabel, rank='same', simplify=True, rankdir='TB', ranksep=0.2, compound=True, color=None, shape='box', style='bold')
def get_graph(self, graph_type='digraph', rank='same', simplify=True, rankdir='TB', ranksep=0.2, compound=True)
def add_edge_to_graph(self, graph, nodename1, nodename2, label=None, url=None, simplify=True, style=None, penwidth=1, color=None)
def add_node_to_graph(self, graph, nodename, nodelabel=None, shape='box', color=None, url=None, tooltip=None)


rqt_py_trees
Author(s): Thibault Kruse, Michal Staniaszek, Daniel Stonier, Naveed Usmani
autogenerated on Mon Jun 10 2019 14:55:56