Skip to content

Commit 3fdf24f

Browse files
committed
fix: preserve long labels in drawio output
Signed-off-by: 1cbyc <isaacnsisong@gmail.com>
1 parent 553c6f6 commit 3fdf24f

2 files changed

Lines changed: 46 additions & 25 deletions

File tree

src/ibmdiagrams/ibmbase/common.py

Lines changed: 2 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -40,31 +40,8 @@ def compress(self, string):
4040
return hash.hexdigest()
4141

4242
def truncateText(self, text, size, linebreak):
43-
if text.find(linebreak) == -1:
44-
if len(text) > size:
45-
return text[0 : size - 1] + "..."
46-
else:
47-
return text
48-
else:
49-
textsplit = text.split(linebreak)
50-
newtext = ""
51-
count = 0
52-
for name in textsplit:
53-
count = count + 1
54-
if len(name) == 0:
55-
continue
56-
elif len(name) > size:
57-
if count == 1:
58-
newtext = name[0 : size - 1] + "..."
59-
else:
60-
newtext = newtext + linebreak + name[0 : size - 1] + "..."
61-
else:
62-
newtext = name if count == 1 else newtext + linebreak + name
63-
64-
if len(newtext) > 0:
65-
return newtext
66-
else:
67-
return text
43+
# Preserve labels as authored; draw.io handles wrapping/overflow.
44+
return text
6845

6946
# Options
7047

tests/test_release_stabilization.py

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,50 @@ def test_shape_builder_returns_drawio_cell_without_undefined_header():
8080
assert shape["props"] == {"owner": "test"}
8181

8282

83+
def test_shape_builder_preserves_long_labels_without_truncation():
84+
"""Long shape labels are preserved instead of shortened with ellipses."""
85+
types = Types(Common())
86+
long_label = "My Production VPC with a long name"
87+
node = {
88+
"shape": "gploc",
89+
"label": long_label,
90+
"sublabel": "",
91+
"genname": "VPC",
92+
"linecolor": Colors.lines["network"],
93+
"fillcolor": Colors.fills["network"],
94+
"parentid": None,
95+
"image": "",
96+
"icon": "",
97+
}
98+
99+
shape = types.buildShape("shape-long-label", node, 10, 20, 200, 120, {}, False)
100+
101+
assert long_label in shape["cell"]["value"]
102+
assert "..." not in shape["cell"]["value"]
103+
104+
105+
def test_python_api_preserves_long_group_labels_in_drawio_output(tmp_path: Path):
106+
"""Diagram-as-code output keeps full group labels in the generated DrawIO file."""
107+
from ibmdiagrams.ibmcloud.compute import VirtualServer
108+
from ibmdiagrams.ibmcloud.diagram import Diagram
109+
from ibmdiagrams.ibmcloud.groups import VPC, IBMCloud, Region, Subnet, Zone
110+
111+
with Diagram("long-labels", output=str(tmp_path)):
112+
with IBMCloud("IBM Cloud with a long name"):
113+
with Region("Dallas"):
114+
with VPC("My Production VPC with a long name"):
115+
with Zone("Zone 1", "10.10.0.0/18"):
116+
with Subnet("App Subnet", "10.10.10.0/24"):
117+
VirtualServer("Web Server", "10.10.10.4")
118+
119+
drawio = (tmp_path / "long-labels.drawio").read_text()
120+
121+
assert "IBM Cloud with a long name" in drawio
122+
assert "My Production VPC with a long name" in drawio
123+
assert "IBM Cloud with..." not in drawio
124+
assert "My Production ..." not in drawio
125+
126+
83127
def test_value_builder_uses_text_style_without_undefined_shape_map():
84128
"""Value builder uses the built-in text style instead of an undefined shape map."""
85129
types = Types(Common())

0 commit comments

Comments
 (0)