pygraphvizfactory.py
Go to the documentation of this file.
1 # Software License Agreement (BSD License)
2 #
3 # Copyright (c) 2008, Willow Garage, Inc.
4 # All rights reserved.
5 #
6 # Redistribution and use in source and binary forms, with or without
7 # modification, are permitted provided that the following conditions
8 # are met:
9 #
10 # * Redistributions of source code must retain the above copyright
11 # notice, this list of conditions and the following disclaimer.
12 # * Redistributions in binary form must reproduce the above
13 # copyright notice, this list of conditions and the following
14 # disclaimer in the documentation and/or other materials provided
15 # with the distribution.
16 # * Neither the name of Willow Garage, Inc. nor the names of its
17 # contributors may be used to endorse or promote products derived
18 # from this software without specific prior written permission.
19 #
20 # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
21 # "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
22 # LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
23 # FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
24 # COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
25 # INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
26 # BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
27 # LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
28 # CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
29 # LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
30 # ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
31 # POSSIBILITY OF SUCH DAMAGE.
32 
33 import pygraphviz
34 
35 
36 # Reference implementation for a dotcode factory
38 
39  def __init__(self):
40  pass
41 
42  def get_graph(
43  self, graph_type='digraph', rank='same',
44  simplify=True, rankdir='TB', ranksep=0.2, compound=True):
45  graph = pygraphviz.AGraph(
46  directed=(graph_type == 'digraph'), ranksep=ranksep, rankdir=rankdir,
47  rank=rank, compound=True, simplify=simplify)
48  return graph
49 
50  def add_node_to_graph(self,
51  graph,
52  nodename,
53  nodelabel=None,
54  shape='box',
55  color=None,
56  url=None,
57  tooltip=None):
58  """
59  Create a node item for this factory, adds it to the graph.
60 
61  Node name can vary from label but must always be same for the same node label
62  """
63  if nodename is None or nodename == '':
64  raise ValueError('Empty Node name')
65  if nodelabel is None:
66  nodelabel = nodename
67 
68  kwargs = {}
69  if tooltip is not None:
70  kwargs['tooltip'] = tooltip
71  if color is not None:
72  kwargs['color'] = color
73 
74  graph.add_node(nodename, label=str(nodelabel), shape=shape, url=url, **kwargs)
75 
76  def add_subgraph_to_graph(self,
77  graph,
78  subgraphlabel,
79  rank='same',
80  simplify=True,
81  rankdir='TB',
82  ranksep=0.2,
83  compound=True,
84  color=None,
85  shape='box',
86  style='bold'):
87  """
88  Create a cluster subgraph item for this factory, adds it to the graph.
89 
90  Cluster name can vary from label but must always be same for the same node label.
91  Most layouters require cluster names to start with cluster.
92  """
93  if subgraphlabel is None or subgraphlabel == '':
94  raise ValueError('Empty subgraph label')
95 
96  sg = graph.add_subgraph(
97  name='cluster_%s' % subgraphlabel, ranksep=ranksep, rankdir=rankdir,
98  rank=rank, compound=compound, label=str(subgraphlabel), style=style, color=color)
99 
100  return sg
101 
102  def add_edge_to_graph(
103  self, graph, nodename1, nodename2, label=None, url=None, simplify=True, style=None):
104  kwargs = {'url': url}
105  if label is not None:
106  kwargs['label'] = label
107  if style is not None:
108  kwargs['style'] = style
109  graph.add_edge(nodename1, nodename2, **kwargs)
110 
111  def create_dot(self, graph):
112  graph.layout('dot')
113  # sadly pygraphviz generates line wraps cutting between numbers
114  return graph.string().replace('\\\n', '')
def add_edge_to_graph(self, graph, nodename1, nodename2, label=None, url=None, simplify=True, style=None)
def add_node_to_graph(self, graph, nodename, nodelabel=None, shape='box', color=None, url=None, tooltip=None)
def get_graph(self, graph_type='digraph', rank='same', simplify=True, rankdir='TB', ranksep=0.2, compound=True)
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')


qt_dotgraph
Author(s): Thibault Kruse, Dirk Thomas
autogenerated on Tue Apr 13 2021 03:03:12