diff options
author | 2013-07-24 18:21:37 +0200 | |
---|---|---|
committer | 2013-07-24 18:21:37 +0200 | |
commit | 94296f8fbcfbad0620ef69e44eb53ff16b9f1fa6 (patch) | |
tree | 97a465181b14aaa8792efb0ed355429e0eb7fe40 /dotviewer | |
parent | Add comments (diff) | |
download | pypy-94296f8fbcfbad0620ef69e44eb53ff16b9f1fa6.tar.gz pypy-94296f8fbcfbad0620ef69e44eb53ff16b9f1fa6.tar.bz2 pypy-94296f8fbcfbad0620ef69e44eb53ff16b9f1fa6.zip |
Add linewidth attribute to dotviewer
note that due to 'plain'-format restrictions, only the
older 'style="setlinewidth(...)"' style is supported.
Diffstat (limited to 'dotviewer')
-rw-r--r-- | dotviewer/drawgraph.py | 12 | ||||
-rw-r--r-- | dotviewer/test/test_interactive.py | 24 |
2 files changed, 34 insertions, 2 deletions
diff --git a/dotviewer/drawgraph.py b/dotviewer/drawgraph.py index 04fbc6c52e..8f394c5c47 100644 --- a/dotviewer/drawgraph.py +++ b/dotviewer/drawgraph.py @@ -22,6 +22,7 @@ COLOR = { 'yellow': (255,255,0), } re_nonword=re.compile(r'([^0-9a-zA-Z_.]+)') +re_linewidth=re.compile(r'setlinewidth\((\d+(\.\d*)?|\.\d+)\)') def combine(color1, color2, alpha): r1, g1, b1 = color1 @@ -138,6 +139,13 @@ class Edge: self.yl = float(yl) rest = rest[3:] self.style, self.color = rest + linematch = re_linewidth.match(self.style) + if linematch: + num = linematch.group(1) + self.linewidth = int(round(float(num))) + self.style = self.style[linematch.end(0):] + else: + self.linewidth = 1 self.highlight = False self.cachedbezierpoints = None self.cachedarrowhead = None @@ -520,8 +528,8 @@ class GraphRenderer: fgcolor = highlight_color(fgcolor) points = [self.map(*xy) for xy in edge.bezierpoints()] - def drawedgebody(points=points, fgcolor=fgcolor): - pygame.draw.lines(self.screen, fgcolor, False, points) + def drawedgebody(points=points, fgcolor=fgcolor, width=edge.linewidth): + pygame.draw.lines(self.screen, fgcolor, False, points, width) edgebodycmd.append(drawedgebody) points = [self.map(*xy) for xy in edge.arrowhead()] diff --git a/dotviewer/test/test_interactive.py b/dotviewer/test/test_interactive.py index 2948ca3aca..0f116856b3 100644 --- a/dotviewer/test/test_interactive.py +++ b/dotviewer/test/test_interactive.py @@ -34,6 +34,23 @@ _generated____4 -> _generated____7 } ''' +SOURCE2=r'''digraph f { + a; d; e; f; g; h; i; j; k; l; + a -> d [penwidth=1, style="setlinewidth(1)"]; + d -> e [penwidth=2, style="setlinewidth(2)"]; + e -> f [penwidth=4, style="setlinewidth(4)"]; + f -> g [penwidth=8, style="setlinewidth(8)"]; + g -> h [penwidth=16, style="setlinewidth(16)"]; + h -> i [penwidth=32, style="setlinewidth(32)"]; + i -> j [penwidth=64, style="setlinewidth(64)"]; + j -> k [penwidth=128, style="setlinewidth(128)"]; + k -> l [penwidth=256, style="setlinewidth(256)"]; +}''' + + + + + def setup_module(mod): if not option.pygame: py.test.skip("--pygame not enabled") @@ -161,3 +178,10 @@ def test_fixedfont(): page = MyPage(str(dotfile)) page.fixedfont = True graphclient.display_page(page) + +def test_linewidth(): + udir.join("graph2.dot").write(SOURCE2) + from dotviewer import graphpage, graphclient + dotfile = udir.join('graph2.dot') + page = graphpage.DotFileGraphPage(str(dotfile)) + graphclient.display_page(page) |