a.t.
a.t.

Reputation: 2808

Increase graph size in plantUML from python?

MWE

To generate PlantUML diagrams in (sub)folder: /Diagrams/ I use the following python script:

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}'))

It is used to generate for example the following test.txt file:

@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

Expected behavior

Because I set the PLANTUML_LIMIT_SIZE variable to 16384 (pixels) as the FAQ suggests, I would expect this to fill up the picture of the diagram with all the blocks connected side by side up to a max width of 4096 * 4 pixels.

To test whether perhaps setting it from the python script was implemented incorrectly I also tried to set it manually with: set PLANTUML_LIMIT_SIZE=16384 to expect the same behavior as explained in the above paragraph (a picture filled up till 16384 pixels).

Observed behavior

Instead PlantUML cuts off the picture at 2000 horizontal pictures as shown in the figure below:

Question

How can I ensure the PlantUML does not cut off the blocks of the diagrams of n pixels (height or width), from a python script?

Upvotes: 2

Views: 4351

Answers (2)

a.t.
a.t.

Reputation: 2808

Approach 1:

To prevent the diagram from being cut off I followed the following steps:

  1. Downloaded the plantuml.jar from this location http://sourceforge.net/projects/plantuml/files/plantuml.jar/download
  2. Put the diagram which I wrote in a someLargeDiagram.txt file, in the same directory as the plantuml.jar file.
  3. Opened terminal on Ubuntu 20.04 in that same directory and ran:
java -jar plantuml.jar -verbose someLargeDiagram.txt

That successfully generated the diagram as .png file, which was not cut off.

Approach 2:

After creating even larger graphs, they got cut-off again, and it gave the message to increase the PLANTUML_LIMIT_SIZE. I tried passing the size as an argument in the commandline using: java -jar plantuml.jar -verbose -PLANTUML_LIMIT_SIZE=8192 Diagrams/latest.uml however that did not work, nor did ..-PLANTUML_LIMIT_SIZE 8192... This link suggested one could set it as an environment variable, so I did that in Ubuntu 20.04 using command: export PLANTUML_LIMIT_SIZE 8192, after which I successfully created a larger diagram that was not cut-off with command:

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

Upvotes: 1

The best way I've found to prevent diagrams from being cut off, without trying to guess at the size or picking some arbitrarily large limit, is to select SVG output.

Note that setting PLANTUML_LIMIT_SIZE is only going to have an effect if you're running PlantUML locally, but it appears the Python interface you're using sends the diagram to the online service. I don't know the internals of that interface, but per the documentation you should be able to get SVG output by using http://www.plantuml.com/plantuml/svg/ as the service URL.

If you need the final image in PNG format, you will need to convert it with another tool.

Upvotes: 2

Related Questions