From 1067cf50db2547560164a747df8af15bfad7a26e Mon Sep 17 00:00:00 2001 From: Bruno Meneguello <1322552+bkmeneguello@users.noreply.github.com> Date: Wed, 30 Dec 2020 16:14:56 -0300 Subject: [PATCH] Allow multiline labels be defined as a sequence --- diagrams/__init__.py | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/diagrams/__init__.py b/diagrams/__init__.py index cd8b89bf..62614419 100644 --- a/diagrams/__init__.py +++ b/diagrams/__init__.py @@ -3,7 +3,7 @@ import html import os import uuid from pathlib import Path -from typing import List, Union, Dict +from typing import List, Union, Dict, Sequence from graphviz import Digraph @@ -310,7 +310,12 @@ class Node(_Cluster): """ # Generates an ID for identifying a node. self._id = self._rand_id() - self.label = label + if isinstance(label, str): + self.label = label + elif isinstance(label, Sequence): + self.label = "\n".join(label) + else: + self.label = str(label) super().__init__() @@ -329,7 +334,7 @@ class Node(_Cluster): # If a node has an icon, increase the height slightly to avoid # that label being spanned between icon image and white space. # Increase the height by the number of new lines included in the label. - padding = 0.4 * (label.count('\n')) + padding = 0.4 * (self.label.count('\n')) icon_path = self._load_icon() self._attrs = { "shape": "none",