changeset 2:30d03e830354

compute line widths
author Jeff Hammel <jhammel@mozilla.com>
date Tue, 28 Dec 2010 16:47:36 -0800
parents 084088505eea
children fc09a7ffb767
files example/example.py svgsitemap/middleware.py
diffstat 2 files changed, 13 insertions(+), 7 deletions(-) [+]
line wrap: on
line diff
--- a/example/example.py	Tue Dec 28 16:23:07 2010 -0800
+++ b/example/example.py	Tue Dec 28 16:47:36 2010 -0800
@@ -5,7 +5,7 @@
 def example(environ, start_response):
     link = '<a href="/%s">%s</a>'
     body = '<br/>'.join([link % (i,i) for i in range(30)])
-    body = '<html><body>%s</body></html>' % body
+    body = '<html><body><a href="/map">map</a><br/>%s</body></html>' % body
     response = Response(content_type='text/html', body=body)
     return response(environ, start_response)
 
@@ -14,7 +14,7 @@
     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)
+    app = SVGSiteMap(app, file=inifile, output=svgfile, name='foo.com')
     return app
 
 if __name__ == '__main__':
--- a/svgsitemap/middleware.py	Tue Dec 28 16:23:07 2010 -0800
+++ b/svgsitemap/middleware.py	Tue Dec 28 16:47:36 2010 -0800
@@ -34,7 +34,8 @@
     defaults = { 'name': '',
                  'hosts': '',
                  'external_referers': True,
-                 'maxwidth': 20
+                 'maxwidth': 5,
+                 'minwidth': '0.01',
 
                  # input/output
                  'file': None, # .ini file
@@ -66,6 +67,7 @@
         # sanity checks + data fixing
         assert self.output, "Please give an output file"
         assert self.file, "Cannot save file!"
+        self.maxwidth = float(self.maxwidth)
         if self.hosts:
             self.hosts = self.hosts.split()
         else:
@@ -85,6 +87,7 @@
             self.graph = AGraph(name=self.name, splines=False, directed=True)
 
         # make it pretty
+        self.graph.graph_attr['name'] = self.name
         self.graph.graph_attr['label'] = self.name
         self.graph.graph_attr['fontname'] = self.fontname
         self.graph.graph_attr['fontcolor'] = self.fontcolor
@@ -144,14 +147,17 @@
             self.edges[(from_url, to_url)] = count
             edge = self.graph.get_edge(from_url, to_url)
             edge.attr['label'] =  str(count)
-            width = self.maxwidth * (count / self.max)
-            if not width:
-                width = 1
-            edge.attr['style'] = 'setlinewidth(%d)' % width
         else:
             self.edges[(from_url, to_url)] = 1
             self.graph.add_edge(from_url, to_url, label='1')
 
+        for edge in self.graph.edges():
+            count = self.edges[(edge[0], edge[1])]
+            width = self.maxwidth * count / self.max
+            if not width:
+                width = self.minwidth
+            edge.attr['style'] = 'setlinewidth(%s)' % width
+
         for url in from_url, to_url:
             node = self.graph.get_node(url)
             node.attr['label'] = url