# HG changeset patch # User Jeff Hammel # Date 1293583656 28800 # Node ID 30d03e83035479ce17bfde661f570b116bde3295 # Parent 084088505eeaea664875b908d1b44fa34a8a5a59 compute line widths diff -r 084088505eea -r 30d03e830354 example/example.py --- 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 = '%s' body = '
'.join([link % (i,i) for i in range(30)]) - body = '%s' % body + body = 'map
%s' % 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__': diff -r 084088505eea -r 30d03e830354 svgsitemap/middleware.py --- 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