从 python 增加 plantUML 中的图形大小?

Increase graph size in plantUML from python?

MWE

要在(子)文件夹中生成 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

预期行为

因为我按照 FAQ 的建议将 PLANTUML_LIMIT_SIZE 变量设置为 16384(像素),所以我希望这会填满所有块并排连接的图表图片最大宽度为 4096 * 4 像素。

为了测试 python 脚本中的设置是否实施不正确,我还尝试手动设置它: set PLANTUML_LIMIT_SIZE=16384 以期待与上一段中解释的相同的行为(图片填充到 16384 像素)。

观察到的行为

改为PlantUML在2000张水平图片处裁剪图片如下图所示:

问题

如何确保 PlantUML 不会从 python 脚本中截断 n 像素(高度或宽度)的图表块?

我发现防止图表被截断的最好方法是 select SVG 输出,而不是尝试猜测大小或选择任意大的限制。

请注意,设置 PLANTUML_LIMIT_SIZE 仅当您在本地 运行 PlantUML 时才会生效,但您正在使用的 Python 界面似乎将图表发送至在线服务。我不知道该接口的内部结构,但根据 the documentation,您应该能够通过使用 http://www.plantuml.com/plantuml/svg/ 作为服务 URL.

来获取 SVG 输出

如果您需要 PNG 格式的最终​​图像,则需要使用其他工具进行转换。

方法一:

为了防止图表被截断,我按照以下步骤操作:

  1. 从这个位置 http://sourceforge.net/projects/plantuml/files/plantuml.jar/download
  2. 下载了 plantuml.jar
  3. 将我写的图表放在someLargeDiagram.txt文件中,与plantuml.jar文件在同一目录中。
  4. 在同一目录中的 Ubuntu 20.04 和 运行:
  5. 上打开了终端
java -jar plantuml.jar -verbose someLargeDiagram.txt

成功生成图为 .png 文件,未被截断。

方法二:

在创建更大的图形后,它们再次被截断,并给出了增加 PLANTUML_LIMIT_SIZE 的消息。我尝试使用以下命令在命令行中将大小作为参数传递:java -jar plantuml.jar -verbose -PLANTUML_LIMIT_SIZE=8192 Diagrams/latest.uml 但这没有用,..-PLANTUML_LIMIT_SIZE 8192.. 也没有用。 This link 建议可以将其设置为环境变量,所以我在 Ubuntu 20.04 中使用命令:export PLANTUML_LIMIT_SIZE 8192 做到了这一点,之后我成功创建了一个更大的图表,该图表没有被切断命令:

java -jar plantuml.jar -verbose Diagrams/latest.uml