Allow multiline labels be defined as a sequence

pull/823/head
Bruno Meneguello 5 years ago
parent d3ee0b66bc
commit 1067cf50db

@ -3,7 +3,7 @@ import html
import os import os
import uuid import uuid
from pathlib import Path from pathlib import Path
from typing import List, Union, Dict from typing import List, Union, Dict, Sequence
from graphviz import Digraph from graphviz import Digraph
@ -310,7 +310,12 @@ class Node(_Cluster):
""" """
# Generates an ID for identifying a node. # Generates an ID for identifying a node.
self._id = self._rand_id() self._id = self._rand_id()
if isinstance(label, str):
self.label = label self.label = label
elif isinstance(label, Sequence):
self.label = "\n".join(label)
else:
self.label = str(label)
super().__init__() super().__init__()
@ -329,7 +334,7 @@ class Node(_Cluster):
# If a node has an icon, increase the height slightly to avoid # If a node has an icon, increase the height slightly to avoid
# that label being spanned between icon image and white space. # that label being spanned between icon image and white space.
# Increase the height by the number of new lines included in the label. # 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() icon_path = self._load_icon()
self._attrs = { self._attrs = {
"shape": "none", "shape": "none",

Loading…
Cancel
Save