Browse Source

Better handling of multiline Cluster labels

pull/407/head^2
Bruno Meneguello 3 years ago
parent
commit
070308c254
1 changed files with 6 additions and 4 deletions
  1. +6
    -4
      diagrams/__init__.py

+ 6
- 4
diagrams/__init__.py View File

@@ -346,10 +346,12 @@ class Node(_Cluster):

icon = self._load_icon()
if icon:
self.dot.graph_attr["label"] = '<<TABLE border="0"><TR>'\
'<TD fixedsize="true" width="' + str(self._icon_size) + '" height="' + str(self._icon_size) + '">'\
'<IMG SRC="' + icon + '"></IMG></TD>'\
'<TD>' + html.escape(self.label) + '</TD></TR></TABLE>>'
lines = iter(html.escape(self.label).split("\n"))
self.dot.graph_attr["label"] = '<<TABLE border="0"><TR>' +\
f'<TD fixedsize="true" width="{self._icon_size}" height="{self._icon_size}"><IMG SRC="{icon}"></IMG></TD>' +\
f'<TD align="left">{next(lines)}</TD></TR>' +\
''.join(f'<TR><TD colspan="2" align="left">{line}</TD></TR>' for line in lines) +\
'</TABLE>>'

if not self._validate_direction(self._direction):
raise ValueError(f'"{self._direction}" is not a valid direction')


Loading…
Cancel
Save