Mercurial > hg > svgsitemap
comparison svgsitemap/middleware.py @ 2:30d03e830354
compute line widths
author | Jeff Hammel <jhammel@mozilla.com> |
---|---|
date | Tue, 28 Dec 2010 16:47:36 -0800 |
parents | 084088505eea |
children | 84344f9ed3f8 |
comparison
equal
deleted
inserted
replaced
1:084088505eea | 2:30d03e830354 |
---|---|
32 | 32 |
33 ### class level variables | 33 ### class level variables |
34 defaults = { 'name': '', | 34 defaults = { 'name': '', |
35 'hosts': '', | 35 'hosts': '', |
36 'external_referers': True, | 36 'external_referers': True, |
37 'maxwidth': 20 | 37 'maxwidth': 5, |
38 'minwidth': '0.01', | |
38 | 39 |
39 # input/output | 40 # input/output |
40 'file': None, # .ini file | 41 'file': None, # .ini file |
41 'output': None, # .svg file | 42 'output': None, # .svg file |
42 | 43 |
64 setattr(self, key, kw.get(key, self.defaults[key])) | 65 setattr(self, key, kw.get(key, self.defaults[key])) |
65 | 66 |
66 # sanity checks + data fixing | 67 # sanity checks + data fixing |
67 assert self.output, "Please give an output file" | 68 assert self.output, "Please give an output file" |
68 assert self.file, "Cannot save file!" | 69 assert self.file, "Cannot save file!" |
70 self.maxwidth = float(self.maxwidth) | |
69 if self.hosts: | 71 if self.hosts: |
70 self.hosts = self.hosts.split() | 72 self.hosts = self.hosts.split() |
71 else: | 73 else: |
72 self.hosts = [] | 74 self.hosts = [] |
73 if isinstance(self.external_referers, basestring): | 75 if isinstance(self.external_referers, basestring): |
83 self.max = count | 85 self.max = count |
84 else: | 86 else: |
85 self.graph = AGraph(name=self.name, splines=False, directed=True) | 87 self.graph = AGraph(name=self.name, splines=False, directed=True) |
86 | 88 |
87 # make it pretty | 89 # make it pretty |
90 self.graph.graph_attr['name'] = self.name | |
88 self.graph.graph_attr['label'] = self.name | 91 self.graph.graph_attr['label'] = self.name |
89 self.graph.graph_attr['fontname'] = self.fontname | 92 self.graph.graph_attr['fontname'] = self.fontname |
90 self.graph.graph_attr['fontcolor'] = self.fontcolor | 93 self.graph.graph_attr['fontcolor'] = self.fontcolor |
91 self.graph.graph_attr['bgcolor'] = self.bgcolor | 94 self.graph.graph_attr['bgcolor'] = self.bgcolor |
92 self.graph.node_attr['color'] = self.nodecolor | 95 self.graph.node_attr['color'] = self.nodecolor |
142 if count > self.max: | 145 if count > self.max: |
143 self.max = count | 146 self.max = count |
144 self.edges[(from_url, to_url)] = count | 147 self.edges[(from_url, to_url)] = count |
145 edge = self.graph.get_edge(from_url, to_url) | 148 edge = self.graph.get_edge(from_url, to_url) |
146 edge.attr['label'] = str(count) | 149 edge.attr['label'] = str(count) |
147 width = self.maxwidth * (count / self.max) | |
148 if not width: | |
149 width = 1 | |
150 edge.attr['style'] = 'setlinewidth(%d)' % width | |
151 else: | 150 else: |
152 self.edges[(from_url, to_url)] = 1 | 151 self.edges[(from_url, to_url)] = 1 |
153 self.graph.add_edge(from_url, to_url, label='1') | 152 self.graph.add_edge(from_url, to_url, label='1') |
153 | |
154 for edge in self.graph.edges(): | |
155 count = self.edges[(edge[0], edge[1])] | |
156 width = self.maxwidth * count / self.max | |
157 if not width: | |
158 width = self.minwidth | |
159 edge.attr['style'] = 'setlinewidth(%s)' % width | |
154 | 160 |
155 for url in from_url, to_url: | 161 for url in from_url, to_url: |
156 node = self.graph.get_node(url) | 162 node = self.graph.get_node(url) |
157 node.attr['label'] = url | 163 node.attr['label'] = url |
158 node.attr['href'] = url | 164 node.attr['href'] = url |