Mercurial > hg > svgsitemap
comparison svgsitemap/middleware.py @ 15:61038b4e7425
initial version with acceptable formatting
author | Jeff Hammel <jhammel@mozilla.com> |
---|---|
date | Sun, 02 Jan 2011 13:55:49 -0800 |
parents | 6cf3539cfa9c |
children | f50b4e4ad764 |
comparison
equal
deleted
inserted
replaced
14:2916206a6807 | 15:61038b4e7425 |
---|---|
35 defaults = { 'name': '', | 35 defaults = { 'name': '', |
36 'hosts': '', | 36 'hosts': '', |
37 'external_referers': True, | 37 'external_referers': True, |
38 'maxwidth': 5, | 38 'maxwidth': 5, |
39 'minwidth': '0.1', | 39 'minwidth': '0.1', |
40 'maxlength': 80, | 40 'maxlength': 60, |
41 'excluded': '*.css *.js */static/* /css/* *.ico /backgrounds/* *.png *.jpg', | 41 'excluded': '*.css *.js */static/* /css/* *.ico /backgrounds/* *.png *.jpg', |
42 | 42 |
43 # input/output | 43 # input/output |
44 'file': None, # graphviz file | 44 'file': None, # graphviz file |
45 'output': None, # .svg file | 45 'output': None, # .svg file |
46 | 46 |
47 # graph attributes | 47 # graph attributes |
48 'bgcolor': 'black', | 48 'bgcolor': 'black', |
49 'fontcolor': 'white', | 49 'fontcolor': 'white', |
50 'fontname': 'Helvetica', | 50 'fontname': 'Helvetica', |
51 'fontsize': '10.0', | 51 'fontsize': '80.0', |
52 'nodecolor': 'aqua', | 52 'nodecolor': 'aqua', |
53 'edgecolor': 'lime', | 53 'edgecolor': 'lime', |
54 'shape': 'plaintext', | 54 'shape': 'plaintext', |
55 'len': '1.3', | 55 'len': '1.0', |
56 'arrowsize': '0.5', | 56 'arrowsize': '0.5', |
57 } | 57 } |
58 | 58 |
59 def __init__(self, app, **kw): | 59 def __init__(self, app, **kw): |
60 | 60 |
85 self.graph = AGraph(self.file, name=self.name, splines=False, directed=True) | 85 self.graph = AGraph(self.file, name=self.name, splines=False, directed=True) |
86 for edge in self.graph.edges(): | 86 for edge in self.graph.edges(): |
87 if self.exclude(edge[0], edge[1]): | 87 if self.exclude(edge[0], edge[1]): |
88 self.graph.remove_edge(edge[0], edge[1]) | 88 self.graph.remove_edge(edge[0], edge[1]) |
89 continue | 89 continue |
90 label = edge.attr['label'] | 90 if edge.attr['tooltip']: |
91 count = int(label) | 91 count = int(edge.attr['tooltip'].split(':', 1)[0].strip()) |
92 else: | |
93 label = edge.attr['label'] | |
94 count = int(label) | |
95 self.label(edge, count) | |
92 self.edges[(edge[0], edge[1])] = count | 96 self.edges[(edge[0], edge[1])] = count |
93 if count > self.max: | 97 if count > self.max: |
94 self.max = count | 98 self.max = count |
95 self.remove_orphans() | 99 self.remove_orphans() |
96 self.set_widths() | 100 self.set_widths() |
101 self.graph.graph_attr['name'] = self.name | 105 self.graph.graph_attr['name'] = self.name |
102 self.graph.graph_attr['label'] = self.name | 106 self.graph.graph_attr['label'] = self.name |
103 self.graph.graph_attr['fontname'] = self.fontname | 107 self.graph.graph_attr['fontname'] = self.fontname |
104 self.graph.graph_attr['fontcolor'] = self.fontcolor | 108 self.graph.graph_attr['fontcolor'] = self.fontcolor |
105 self.graph.graph_attr['bgcolor'] = self.bgcolor | 109 self.graph.graph_attr['bgcolor'] = self.bgcolor |
110 self.graph.graph_attr['overlap'] = 'compress' | |
111 self.graph.graph_attr['sep'] = '0.01' | |
106 self.graph.node_attr['color'] = self.nodecolor | 112 self.graph.node_attr['color'] = self.nodecolor |
107 self.graph.node_attr['fontcolor'] = self.fontcolor | 113 self.graph.node_attr['fontcolor'] = self.fontcolor |
108 self.graph.node_attr['fontname'] = self.fontname | 114 self.graph.node_attr['fontname'] = self.fontname |
109 self.graph.node_attr['fontsize'] = self.fontsize | 115 self.graph.node_attr['fontsize'] = self.fontsize |
110 self.graph.node_attr['shape'] = self.shape | 116 self.graph.node_attr['shape'] = self.shape |
158 count += 1 | 164 count += 1 |
159 if count > self.max: | 165 if count > self.max: |
160 self.max = count | 166 self.max = count |
161 self.edges[(from_url, to_url)] = count | 167 self.edges[(from_url, to_url)] = count |
162 edge = self.graph.get_edge(from_url, to_url) | 168 edge = self.graph.get_edge(from_url, to_url) |
163 edge.attr['label'] = str(count) | 169 self.label(edge, count) |
164 else: | 170 else: |
165 self.edges[(from_url, to_url)] = 1 | 171 self.edges[(from_url, to_url)] = 1 |
166 self.max = 1 | 172 self.max = 1 |
167 self.graph.add_edge(from_url, to_url, label='1') | 173 labeltooltip = '1: %s -> %s' % (from_url, to_url) |
174 self.graph.add_edge(from_url, to_url, label='', tooltip=labeltooltip, href='#') | |
168 | 175 |
169 if self.maxwidth: | 176 if self.maxwidth: |
170 self.set_widths() | 177 self.set_widths() |
171 | 178 |
172 for url in from_url, to_url: | 179 for url in from_url, to_url: |
173 node = self.graph.get_node(url) | 180 node = self.graph.get_node(url) |
174 node.attr['label'] = url | 181 node.attr['label'] = url |
175 node.attr['href'] = url | 182 node.attr['href'] = url |
176 | 183 |
177 self.save() | 184 self.save() |
185 | |
186 def label(self, edge, count): | |
187 edge.attr['label'] = '' | |
188 edge.attr['tooltip'] = '%d: %s -> %s' % (count, edge[0], edge[1]) | |
189 edge.attr['labeltooltip'] = edge.attr['tooltip'] | |
190 edge.attr['href'] = '#' | |
178 | 191 |
179 def exclude(self, *urls): | 192 def exclude(self, *urls): |
180 """tell whether the edge is excluded""" | 193 """tell whether the edge is excluded""" |
181 for pattern in self.excluded: | 194 for pattern in self.excluded: |
182 for url in urls: | 195 for url in urls: |