python - 从python增加plantUML中的图形大小?
问题描述
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
预期行为
因为我按照常见问题解答PLANTUML_LIMIT_SIZE
的建议将变量设置为 16384(像素),所以我希望这会填充图表的图片,所有块并排连接,最大宽度为 4096 * 4 像素。
为了测试是否从 python 脚本设置它是否被错误地实现,我还尝试手动设置它:set PLANTUML_LIMIT_SIZE=16384
期望与上一段中解释的相同行为(一张图片填充到 16384 像素)。
观察到的行为
取而代之的是PlantUML在2000张水平图片处截取图片如下图所示:
问题
如何确保 PlantUML 不会n
从 python 脚本中截断像素图块(高度或宽度)?
解决方案
我发现防止图表被截断的最佳方法是选择 SVG 输出,而不是尝试猜测大小或选择任意大的限制。
请注意,PLANTUML_LIMIT_SIZE
只有在本地运行 PlantUML 时,设置才会生效,但您使用的 Python 接口似乎会将图表发送到在线服务。我不知道该接口的内部结构,但根据文档,您应该能够通过将http://www.plantuml.com/plantuml/svg/
其用作服务 URL 来获得 SVG 输出。
如果您需要 PNG 格式的最终图像,则需要使用其他工具对其进行转换。
推荐阅读
- microsoft-graph-api - 代表来宾用户访问共享点文件
- c++ - 如何加载 XCTest 以与 iOS 应用程序一起处理内存(堆损坏问题)?
- java - 致命异常:java.lang.NoSuchMethodError
- firebase - 如何在发送重置电子邮件之前检查用户是否存在于firebase中?
- php - 仅显示具有任何产品或其子类别具有任何产品的根级别类别
- javascript - 从 Google 表格中删除行,基于多个列值作为标准
- python - 如何使用 Python 将媒体流从 SocketSever 传输到 Falcon API
- python - PySpark - 用于查找 URL 和正确地址的正则表达式
- scala - 一个测试容器用于多个测试
- spring-boot - 通过数据库进行spring rbac身份验证