changeset 9:aa4eab6dc994

* dont set node width, height; * move save() to its own function
author Jeff Hammel <jhammel@mozilla.com>
date Sun, 02 Jan 2011 11:39:45 -0800
parents 1d16bde33eee
children 1329127709de
files example/example.py svgsitemap/middleware.py
diffstat 2 files changed, 11 insertions(+), 7 deletions(-) [+]
line wrap: on
line diff
--- a/example/example.py
+++ b/example/example.py
@@ -9,15 +9,15 @@ def example(environ, start_response):
     response = Response(content_type='text/html', body=body)
     return response(environ, start_response)
 
 def factory():
     dirname = os.path.dirname(os.path.abspath(__file__))
     inifile = os.path.join(dirname, 'example.gv.txt')
     svgfile = os.path.join(dirname, 'example.svg')
     app = MapserverMiddleware(example, svgfile)
-    app = SVGSiteMap(app, file=inifile, output=svgfile, name='foo.com')
+    app = SVGSiteMap(app, file=inifile, output=svgfile)
     return app
 
 if __name__ == '__main__':
     from wsgiref import simple_server
     server = simple_server.make_server(host='0.0.0.0', port=int(54321), app=factory())
     server.serve_forever() 
--- a/svgsitemap/middleware.py
+++ b/svgsitemap/middleware.py
@@ -106,24 +106,25 @@ class SVGSiteMap(object):
         self.graph.graph_attr['fontname'] = self.fontname
         self.graph.graph_attr['fontcolor'] = self.fontcolor
         self.graph.graph_attr['bgcolor'] = self.bgcolor
         self.graph.node_attr['color'] = self.nodecolor
         self.graph.node_attr['fontcolor'] = self.fontcolor
         self.graph.node_attr['fontname'] = self.fontname
         self.graph.node_attr['fontsize'] = self.fontsize
         self.graph.node_attr['shape'] = self.shape
-        self.graph.node_attr['width'] = '0.1'
-        self.graph.node_attr['height'] = '0.1'
         self.graph.edge_attr['color'] = self.edgecolor
         self.graph.edge_attr['fontcolor'] = self.fontcolor
         self.graph.edge_attr['fontname'] = self.fontname
         self.graph.edge_attr['fontsize'] = self.fontsize
         self.graph.edge_attr['len'] = self.len
         self.graph.edge_attr['arrowsize'] = self.arrowsize
+
+        if self.edges:
+            self.save()
         
     def __call__(self, environ, start_response):
         request = Request(environ)
         if request.referer:
 
             # parse the URLs
             parsed_referer = urlparse.urlsplit(request.referer)
             parsed_referee = urlparse.urlsplit(request.url)
@@ -171,20 +172,17 @@ class SVGSiteMap(object):
         if self.maxwidth:
             self.set_widths()
 
         for url in from_url, to_url:
             node = self.graph.get_node(url)
             node.attr['label'] = url
             node.attr['href'] = url
 
-        if self.file:
-            self.graph.write(self.file)
-        if self.output:
-            self.graph.draw(self.output, prog='neato')
+        self.save()
 
     def exclude(self, *urls):
         """tell whether the edge is excluded"""
         for pattern in self.excluded:
             for url in urls:
                 if fnmatch(url, pattern):
                     return True
         for url in urls:
@@ -199,8 +197,14 @@ class SVGSiteMap(object):
                 width = self.maxwidth * count / self.max
                 if not width:
                     width = self.minwidth
                 edge.attr['style'] = 'setlinewidth(%s)' % width
 
         else:
             for edge in self.graph.edges():
                 edge.attr['style'] = ''
+
+    def save(self):
+        if self.file:
+            self.graph.write(self.file)
+        if self.output:
+            self.graph.draw(self.output, prog='neato')