2 # NEPI, a framework to manage network experiments
3 # Copyright (C) 2013 INRIA
5 # This program is free software: you can redistribute it and/or modify
6 # it under the terms of the GNU General Public License as published by
7 # the Free Software Foundation, either version 3 of the License, or
8 # (at your option) any later version.
10 # This program is distributed in the hope that it will be useful,
11 # but WITHOUT ANY WARRANTY; without even the implied warranty of
12 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 # GNU General Public License for more details.
15 # You should have received a copy of the GNU General Public License
16 # along with this program. If not, see <http://www.gnu.org/licenses/>.
18 # Author: Alina Quereilhac <alina.quereilhac@inria.fr>
23 class Plotter(object):
24 def __init__(self, box):
25 self._graph = networkx.Graph(graph = dict(overlap = "false"))
28 self._traverse_boxes(traversed, box)
30 def _traverse_boxes(self, traversed, box):
31 traversed.add(box.guid)
33 self._graph.add_node(box.label,
34 width = 50/72.0, # 1 inch = 72 points
38 for b in box.connections:
39 self._graph.add_edge(box.label, b.label)
40 if b.guid not in traversed:
41 self._traverse_boxes(traversed, b)
44 f = tempfile.NamedTemporaryFile(delete=False)
45 networkx.draw_graphviz(self._graph)
46 networkx.write_dot(self._graph, f.name)