pyparsing 3.0.0铁路图软件包产生垂直排列

问题描述

在使用pyparsing 3.0.0a2生成一些铁路图时,我遇到了一些图形错误。下面的示例(图片和相关的SVG文件)是使用以下代码示例生成的:

from pyparsing import *
a = Literal('HJ').setName('a')
b = Literal('AB').setName('b')
c = Literal('KL').setName('c')
ALL = (a[4] ^ b[5] + c).setName('ALL')
if __name__ == '__main__':
    if '3.0.0' in __version__:
        from pyparsing.diagram import to_railroad,railroad_to_html
        with open('test.html','w') as fp:
            rr = to_railroad(ALL)
            fp.write(railroad_to_html(rr))

如您所见,存在三个问题:

  • 当有4个以上的元素彼此相邻放置时,生成器将垂直表示它们
  • 内容相比,大小设置有误(上面的第一点似乎不会影响图片的大小)
  • 这种垂直排列与应该位于下方的其他图对象重叠

如果正确计算SVG大小,我不介意进行垂直排列。

但是,是否有一种方法可以禁用此“功能”,以便保持连续元素的水平排列?



<svg class="railroad-diagram" height="218" width="516" xmlns="http://www.w3.org/2000/svg" style="background-color:#f5f2f0"><g transform="translate(.5 .5)"><style>svg.railroad-diagram path,svg.railroad-diagram rect{stroke-width:3;stroke:#000;fill:transparent}svg.railroad-diagram text{font:700 14px monospace;text-anchor:middle}svg.railroad-diagram text.comment{font:italic 12px monospace}svg.railroad-diagram rect{fill:#cfc}svg.railroad-diagram rect.group-Box{stroke:gray;stroke-dasharray:10 5;fill:none}</style><path d="M20 45v20m10-20v20M20 55h20M40 55h20M60 55h20M154 55"/><rect class="group-Box" height="38" rx="10" ry="10" width="74" x="80" y="36"/><g class="terminal"><path d="M80 55h10M144 55h10"/><rect height="22" rx="10" ry="10" width="54" x="90" y="44"/><text x="117" y="59">&apos;HJ&apos;</text></g><g class="non-terminal"><path d="M97 28"/><text class="comment" x="88.5" y="33">a</text></g><path d="M154 55h10M164 55h10M248 55"/><rect class="group-Box" height="38" rx="10" ry="10" width="74" x="174" y="36"/><g class="terminal"><path d="M174 55h10M238 55h10"/><rect height="22" rx="10" ry="10" width="54" x="184" y="44"/><text x="211" y="59">&apos;HJ&apos;</text></g><g class="non-terminal"><path d="M191 28"/><text class="comment" x="182.5" y="33">a</text></g><path d="M248 55h10M258 55h10"/><g><path d="M342 55"/><rect class="group-Box" height="38" rx="10" ry="10" width="74" x="268" y="36"/><g class="terminal"><path d="M268 55h10M332 55h10"/><rect height="22" rx="10" ry="10" width="54" x="278" y="44"/><text x="305" y="59">&apos;HJ&apos;</text></g><g class="non-terminal"><path d="M285 28"/><text class="comment" x="276.5" y="33">a</text></g></g><path d="M342 55h10M352 55h10"/><g><path d="M436 55"/><rect class="group-Box" height="38" rx="10" ry="10" width="74" x="362" y="36"/><g class="terminal"><path d="M362 55h10M426 55h10"/><rect height="22" rx="10" ry="10" width="54" x="372" y="44"/><text x="399" y="59">&apos;HJ&apos;</text></g><g class="non-terminal"><path d="M379 28"/><text class="comment" x="370.5" y="33">a</text></g></g><path d="M436 55h20M60 55a10 10 0 0110 10v42a10 10 0 0010 10"/><g><path d="M80 117h121M201 117h10M211 117h10M295 117h10"/><rect class="group-Box" height="38" rx="10" ry="10" width="74" x="221" y="98"/><g class="terminal"><path d="M221 117h10M285 117h10"/><rect height="22" rx="10" ry="10" width="54" x="231" y="106"/><text x="258" y="121">&apos;AB&apos;</text></g><g class="non-terminal"><path d="M238 90"/><text class="comment" x="229.5" y="95">b</text></g><path d="M305 117a10 10 0 0110 10v7a10 10 0 01-10 10h-94a10 10 0 00-10 10v23a10 10 0 0010 10M211 187h10M295 187h10"/><rect class="group-Box" height="38" rx="10" ry="10" width="74" x="221" y="168"/><g class="terminal"><path d="M221 187h10M285 187h10"/><rect height="22" rx="10" ry="10" width="54" x="231" y="176"/><text x="258" y="191">&apos;AB&apos;</text></g><g class="non-terminal"><path d="M238 160"/><text class="comment" x="229.5" y="165">b</text></g><path d="M305 187a10 10 0 0110 10v7a10 10 0 01-10 10h-94a10 10 0 00-10 10v23a10 10 0 0010 10"/><g><path d="M211 257h10M295 257h10"/><rect class="group-Box" height="38" rx="10" ry="10" width="74" x="221" y="238"/><g class="terminal"><path d="M221 257h10M285 257h10"/><rect height="22" rx="10" ry="10" width="54" x="231" y="246"/><text x="258" y="261">&apos;AB&apos;</text></g><g class="non-terminal"><path d="M238 230"/><text class="comment" x="229.5" y="235">b</text></g></g><path d="M305 257a10 10 0 0110 10v7a10 10 0 01-10 10h-94a10 10 0 00-10 10v23a10 10 0 0010 10"/><g><path d="M211 327h10M295 327h10"/><rect class="group-Box" height="38" rx="10" ry="10" width="74" x="221" y="308"/><g class="terminal"><path d="M221 327h10M285 327h10"/><rect height="22" rx="10" ry="10" width="54" x="231" y="316"/><text x="258" y="331">&apos;AB&apos;</text></g><g class="non-terminal"><path d="M238 300"/><text class="comment" x="229.5" y="305">b</text></g></g><path d="M305 327a10 10 0 0110 10v7a10 10 0 01-10 10h-94a10 10 0 00-10 10v23a10 10 0 0010 10"/><g><path d="M211 397h10M295 397h10"/><rect class="group-Box" height="38" rx="10" ry="10" width="74" x="221" y="378"/><g class="terminal"><path d="M221 397h10M285 397h10"/><rect height="22" rx="10" ry="10" width="54" x="231" y="386"/><text x="258" y="401">&apos;AB&apos;</text></g><g class="non-terminal"><path d="M238 370"/><text class="comment" x="229.5" y="375">b</text></g></g><path d="M305 397h10M315 397h121"/></g><path d="M436 397a10 10 0 0010-10V65a10 10 0 0110-10M456 55h20M40 55a10 10 0 0110 10v104a10 10 0 0010 10"/><g><path d="M60 179h161M295 179h161"/><rect class="group-Box" height="38" rx="10" ry="10" width="74" x="221" y="160"/><g class="terminal"><path d="M221 179h10M285 179h10"/><rect height="22" rx="10" ry="10" width="54" x="231" y="168"/><text x="258" y="183">&apos;KL&apos;</text></g><g class="non-terminal"><path d="M238 152"/><text class="comment" x="229.5" y="157">c</text></g></g><path d="M456 179a10 10 0 0010-10V65a10 10 0 0110-10M476 55h20m-10-10v20m10-20v20"/></g></svg>

Picture with errors

Picture with a more correct size



3.0.0b1与3.0.0a2的附录

pyparsing==3.0.0b1

pyparsing==3.0.0a2

一个小的校正序列应该是: ALL = (a[4] ^ b[5] ^ c).setName('ALL')以与图表相对应。

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)