Skip to content

Commit

Permalink
Added alignment option to the connector images
Browse files Browse the repository at this point in the history
  • Loading branch information
martonmiklos committed Aug 19, 2024
1 parent 1c4fd68 commit 00716d0
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 7 deletions.
2 changes: 2 additions & 0 deletions src/wireviz/DataClasses.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
PlainText # = Literal['wirecount', 'terminations', 'length', 'total_length']
)
ImageScale = PlainText # = Literal['false', 'true', 'width', 'height', 'both']
ImageAlignment = PlainText # = Literal['under', 'above', 'left', 'right']

# Type combinations
Pin = Union[int, PlainText] # Pin identifier
Expand Down Expand Up @@ -86,6 +87,7 @@ class Image:
height: Optional[int] = None
fixedsize: Optional[bool] = None
bgcolor: Optional[Color] = None
alignment: Optional[ImageAlignment] = None
# Contents of the text cell <td> just below the image cell:
caption: Optional[MultilineHypertext] = None
# See also HTML doc at https://graphviz.org/doc/info/shapes.html#html
Expand Down
42 changes: 35 additions & 7 deletions src/wireviz/Harness.py
Original file line number Diff line number Diff line change
Expand Up @@ -191,6 +191,12 @@ def create_graph(self) -> Graph:
connector.ports_left = True # Use left side pins.

html = []

image_rows = []
if connector.image:
image_rows = [[html_image(connector.image)],
[html_caption(connector.image)]]

# fmt: off
rows = [[f'{html_bgcolor(connector.bgcolor_title)}{remove_links(connector.name)}'
if connector.show_name else None],
Expand All @@ -202,13 +208,20 @@ def create_graph(self) -> Graph:
f'{connector.pincount}-pin' if connector.show_pincount else None,
translate_color(connector.color, self.options.color_mode) if connector.color else None,
html_colorbar(connector.color)],
'<!-- connector table -->' if connector.style != 'simple' else None,
[html_image(connector.image)],
[html_caption(connector.image)]]
'<!-- connector table -->' if connector.style != 'simple' else None]
# fmt: on
imagetable=''
if connector.image:
if connector.image.alignment == 'under' or connector.image.alignment is None:
rows += image_rows
elif connector.image.alignment == 'above':
rows = image_rows + rows
else:
imagetable = ''.join(nested_html_table(image_rows, html_bgcolor_attr(connector.bgcolor)))

rows.extend(get_additional_component_table(self, connector))
rows.append([html_line_breaks(connector.notes)])

html.extend(nested_html_table(rows, html_bgcolor_attr(connector.bgcolor)))

if connector.style != "simple":
Expand All @@ -217,18 +230,28 @@ def create_graph(self) -> Graph:
'<table border="0" cellspacing="0" cellpadding="3" cellborder="1">'
)

for pinindex, (pinname, pinlabel, pincolor) in enumerate(
zip_longest(
firstpin = True
pincount = len(connector.pins)
if len(connector.pinlabels) > pincount:
pincount = len(connector.pinlabels)
if len(connector.pincolors) > pincount:
pincount = len(connector.pincolors)

for pinindex, (pinname, pinlabel, pincolor) in enumerate(zip_longest(
connector.pins, connector.pinlabels, connector.pincolors
)
):
)):
if (
connector.hide_disconnected_pins
and not connector.visible_pins.get(pinname, False)
):
continue

pinhtml.append(" <tr>")

if firstpin and connector.image and connector.image.alignment == 'left':
firstpin = False
pinhtml.append(f'<td rowspan="{pincount}">{imagetable}</td>')

if connector.ports_left:
pinhtml.append(f' <td port="p{pinindex+1}l">{pinname}</td>')
if pinlabel:
Expand All @@ -248,6 +271,11 @@ def create_graph(self) -> Graph:

if connector.ports_right:
pinhtml.append(f' <td port="p{pinindex+1}r">{pinname}</td>')

if firstpin and connector.image and connector.image.alignment == 'right':
firstpin = False
pinhtml.append(
f'<td rowspan="{pincount}">{imagetable}</td>')
pinhtml.append(" </tr>")

pinhtml.append(" </table>")
Expand Down

0 comments on commit 00716d0

Please sign in to comment.