Add an image_size attribute to both Connectors and Cables

It is a list containing minimum width and minimum height of the
image cell. To obtain more available space in the image cell,
this size must be set greater than the natural size of the image.
This commit is contained in:
KV 2020-08-06 20:01:26 +02:00
parent 335f42112c
commit b1173a0a50
2 changed files with 14 additions and 1 deletions

View File

@ -20,6 +20,7 @@ class Connector:
pincount: Optional[int] = None
image: Optional[str] = None
image_scale: Optional[str] = "FALSE"
image_size: List[Any] = field(default_factory=list)
caption: Optional[str] = None
notes: Optional[str] = None
pinlabels: List[Any] = field(default_factory=list)
@ -96,6 +97,7 @@ class Cable:
shield: bool = False
image: Optional[str] = None
image_scale: Optional[str] = "FALSE"
image_size: List[Any] = field(default_factory=list)
caption: Optional[str] = None
notes: Optional[str] = None
colors: List[Any] = field(default_factory=list)

View File

@ -58,11 +58,22 @@ def nested_html_table(rows):
def html_image(node):
if not node.image:
return None
return f'''<tdX{' sides="TLR"' if node.caption else ''}><img scale="{node.image_scale}" src="{node.image}"/>'''
return f'''<tdX{' sides="TLR"' if node.caption else ''}{html_size_attr(node.image_size)}>''' \
f'''<img scale="{node.image_scale}" src="{node.image}"/>'''
def html_caption(node):
return f'''<tdX{' sides="LRB"' if node.image else ''}>{html_line_breaks(node.caption)}''' if node.caption else None
def html_size_attr(size):
# Return Graphviz HTML attributes to specify minimum size of a TABLE or TD object
# size: List of values where only these are used:
# - First value is minimum width of object in points, an int value in the range 1-65535. (Default 0 = none)
# - Second value is minimum height of the object in points, an int value in the range 1-65535. (Default 0 = none)
if not size or not isinstance(size, list):
return ''
return ((f' width="{size[0]}"' if len(size) > 0 and size[0] else '')
+ (f' height="{size[1]}"' if len(size) > 1 and size[1] else ''))
def expand(yaml_data):
# yaml_data can be: