From 41b3f3acfedb42dacf600f81985ef67547b58e37 Mon Sep 17 00:00:00 2001 From: KV Date: Thu, 6 Aug 2020 20:01:26 +0200 Subject: [PATCH] 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. --- src/wireviz/DataClasses.py | 2 ++ src/wireviz/wv_helper.py | 13 ++++++++++++- 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/src/wireviz/DataClasses.py b/src/wireviz/DataClasses.py index 89bff69..6b9c42c 100644 --- a/src/wireviz/DataClasses.py +++ b/src/wireviz/DataClasses.py @@ -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) diff --git a/src/wireviz/wv_helper.py b/src/wireviz/wv_helper.py index a91737e..8992ba5 100644 --- a/src/wireviz/wv_helper.py +++ b/src/wireviz/wv_helper.py @@ -58,11 +58,22 @@ def nested_html_table(rows): def html_image(node): if not node.image: return None - return f'''''' + return f'''''' \ + f'''''' def html_caption(node): return f'''{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: