blockdiag / seqdiag

Apache License 2.0
66 stars 13 forks source link

seqdiag cannot handle diagrams with 'note' inclusions in node labels #19

Open tk0miya opened 6 years ago

tk0miya commented 6 years ago

With the latest version of blockdiag/seqdiag in combination, seqdiag now crashes with 'note' inclusions in node labels. This slight change to the simple sample demonstrates:

#!seqdiag

seqdiag {
  browser  -> webserver [label = "GET /index.html", note="foo"];
  browser <-- webserver;
  browser  -> webserver [label = "POST /blog/comment"];
              webserver  -> database [label = "INSERT comment"];
              webserver <-- database;
  browser <-- webserver;
}

with seqdiag --debug simpleseq.txt, produces this traceback:

Traceback (most recent call last):
  File "/usr/local/lib/python2.7/site-packages/blockdiag/utils/bootstrap.py", line 37, in run
    return self.build_diagram(parsed)
  File "/usr/local/lib/python2.7/site-packages/blockdiag/utils/bootstrap.py", line 76, in build_diagram
    transparency=self.options.transparency)
  File "/usr/local/lib/python2.7/site-packages/blockdiag/drawer.py", line 46, in __init__
    fontmap=kwargs.get('fontmap'))
  File "/usr/local/lib/python2.7/site-packages/seqdiag/drawer.py", line 23, in create_metrics
    return DiagramMetrics(*args, **kwargs)
  File "/usr/local/lib/python2.7/site-packages/seqdiag/metrics.py", line 66, in __init__
    self.expand_pagesize_for_note(edge)
  File "/usr/local/lib/python2.7/site-packages/seqdiag/metrics.py", line 215, in expand_pagesize_for_note
    width = self.pagesize().x - cell.center.x - self.cellsize * 3
AttributeError: 'Size' object has no attribute 'x'

Looking at seqdiag/metrics.py, we see that line 215 has this:

        if edge.rightnote:
            cell = self.cell(edge.right_node)
            if edge.direction == 'self':
                right = self.edge(edge).right
                width = self.pagesize().x - right - self.cellsize * 3
            else:
                width = self.pagesize().x - cell.center.x - self.cellsize * 3

Some tracing back shows that blockdiag\utils__init__.py's definition of the Size(tuple) class shows that it no longer has an x (or y) property, but rather a width and height property.

This change to the code seems to provide a fix for the tested sample diagram(s):

        if edge.rightnote:
            cell = self.cell(edge.right_node)
            if edge.direction == 'self':
                right = self.edge(edge).right
                width = self.pagesize().width - right - self.cellsize * 3
            else:
                width = self.pagesize().width - cell.center.x - self.cellsize * 3

Pull request #3 goes with this issue.


tk0miya commented 6 years ago

From Takeshi KOMIYA on 2012-03-15 06:25:11+00:00

At this present, node.colheight attribute (and colwidth) is internal use only.

In another case, you'll get edges across large nodes: {{{ { A -> B -> C; A -> C; B [colheight = 3]; } }}}

this problem will be fixed after replacing layout-engine of blockdiag.

So I change this issue to enhancement type.

tk0miya commented 6 years ago

From ViktorHaag on 2014-07-02 19:15:35+00:00

Added cross-reference to pull request #3