米维
要在(子)文件夹中生成PlantUML图:/Diagrams/
,我使用以下python:
from plantuml import PlantUML
import os
from os.path import abspath
from shutil import copyfile
os.environ['PLANTUML_LIMIT_SIZE'] = str(4096 * 4) # set max with to 4 times the default (16,384)
server = PlantUML(url='http://www.plantuml.com/plantuml/img/',
basic_auth={},
form_auth={}, http_opts={}, request_opts={})
diagram_dir = "./Diagrams"
#directory = os.fsencode()
for file in os.listdir(diagram_dir):
filename = os.fsdecode(file)
if filename.endswith(".txt"):
server.processes_file(abspath(f'./Diagrams/{filename}'))
例如,它用于生成以下test.txt
文件:
@startuml
'Enforce straight lines
skinparam linetype ortho
' Set direction of graph hierarchy
Left to Right direction
' create work package data
rectangle "something something something" as ffd0
rectangle "something something something" as ffd1
rectangle "something something something something something" as ffd2
rectangle "something something something something" as ffd3
rectangle "something something somethingsomethingsomething" as ffd4
rectangle "something something something something something something" as ffd5
rectangle "something something something something" as ffd6
rectangle "something something something " as ffd7
' Implement graph hierarchy
ffd0-->ffd1
ffd1-->ffd2
ffd2-->ffd3
ffd3-->ffd4
ffd4-->ffd5
ffd5-->ffd6
ffd6-->ffd7
@enduml
预期行为
因为我将PLANTUML_LIMIT_SIZE
变量设置为常见问题建议的16384 (像素),所以我希望这将填充图的图片,所有块并排连接到最大宽度为4096 *4像素。
为了测试从python脚本中设置它是否不正确,我还尝试用:set PLANTUML_LIMIT_SIZE=16384
手动设置它,以期待与上面段落中解释的相同行为(图片填充到16384像素)。
观察行为
相反,PlantUML在2000年水平图片上切断图片,如下图所示:
问题
如何确保PlantUML不从python脚本中切断n
像素图的块(高度或宽度)?
发布于 2020-08-07 14:38:02
我发现的防止图被切断的最佳方法是选择SVG输出,而不试图猜测大小或选择任意大的限制。
请注意,只有在本地运行PLANTUML_LIMIT_SIZE
时,设置PlantUML才会产生效果,但是您使用的Python接口似乎会将图表发送给在线服务。我不知道该接口的内部结构,但是每个文献资料都应该能够使用http://www.plantuml.com/plantuml/svg/
作为服务URL来获得SVG输出。
如果您需要PNG格式的最终图像,则需要使用另一个工具来转换它。
发布于 2020-11-16 20:26:16
方法1:
为了防止图被切断,我执行了以下步骤:
plantuml.jar
http://sourceforge.net/projects/plantuml/files/plantuml.jar/downloadsomeLargeDiagram.txt
文件中编写的图表放在与plantuml.jar
文件相同的目录中。java -jar plantuml.jar -verbose someLargeDiagram.txt
它成功地生成了未被切断的.png
文件的关系图。
办法2:
在创建了更大的图表之后,它们又被切断了,这给出了增加PLANTUML_LIMIT_SIZE
的信息。我尝试使用:java -jar plantuml.jar -verbose -PLANTUML_LIMIT_SIZE=8192 Diagrams/latest.uml
将这个大小作为参数在命令行中传递,但是这不起作用,..-PLANTUML_LIMIT_SIZE 8192..
也不起作用。这个链接建议将其设置为一个环境变量,因此我在Ubuntu20.04中使用命令:export PLANTUML_LIMIT_SIZE 8192
完成了这一操作,之后我成功地创建了一个更大的关系图,没有与命令断线:
java -jar plantuml.jar -verbose Diagrams/latest.uml
https://stackoverflow.com/questions/63111593
复制相似问题