[WIP]Add connector image alignment#420
Conversation
- Rename image alignment to position - Rename under to below - Display the above positioned images right above the pins list Fixes wireviz#418
5a273fc to
f19fafb
Compare
|
The left and right option need also to be considered in #404😊 |
There was a problem hiding this comment.
Thank you for accepting and implementing my preliminary suggestions in #418 (comment) - and here follows my promised detailed comments/suggestions to your code changes:
- Remember that most HTML generation code changes must later be adapted to #251 changes before a merge-in
- Fixing a few bugs (see details in each comment)
- Minor simplifications
- Black formatting (remember running
isort *.pyandblack *.pybefore committing your changes) - Please add an entry to
docs/syntax.mdthat lists the alternative attribute values and briefly explains that they relate to the pin list of connectors. - Left/right images for
simpleconnectors are still not implemented, and I suggest for now to only allowimage.position==belowforsimpleconnectors and all cables, and raiseValueErrorotherwise inConnector.__post_init__()andCable.__post_init__()
Github only allow me in this review to add code suggestions close to your code changes, but as an example to my latter point above, this could be added at the bottom of the existing if self.style == "simple": statement body in Connector.__post_init__():
if self.image and self.image.position != "below":
raise ValueError(
f"{self.name}.image.position='{self.image.position}', but simple connectors (with no pin table) only support the default 'below'"
)| height: Optional[int] = None | ||
| fixedsize: Optional[bool] = None | ||
| bgcolor: Optional[Color] = None | ||
| position: Optional[ImagePosition] = None |
There was a problem hiding this comment.
| position: Optional[ImagePosition] = None | |
| position: ImagePosition = "below" |
I see no need for allowing a None value here. When a None value always should be treated equally as a "below" value, then it's better to use the latter as the default value explicitly.
|
|
||
| image_rows = [] | ||
| if connector.image and connector.image.position != 'above': | ||
| image_rows = [[html_image(connector.image)], | ||
| [html_caption(connector.image)]] | ||
|
|
There was a problem hiding this comment.
| image_rows = [] | |
| if connector.image and connector.image.position != 'above': | |
| image_rows = [[html_image(connector.image)], | |
| [html_caption(connector.image)]] | |
| image_rows = [ | |
| [html_image(connector.image)], | |
| [html_caption(connector.image)], | |
| ] |
- No need for the
iftest - Black formatting
| [html_caption(connector.image)]] | ||
| '<!-- connector table -->' if connector.style != 'simple' else None] | ||
| # fmt: on | ||
| imagetable='' |
There was a problem hiding this comment.
| imagetable='' | |
| image_table = "" |
- Suggest a name similar to other image variables
- Black formatted
| f'{connector.pincount}-pin' if connector.show_pincount else None], | ||
| [html_caption(connector.image) if connector.image and connector.image.position == 'above' else None, | ||
| html_image(connector.image) if connector.image and connector.image.position == 'above' else None, | ||
| translate_color(connector.color, self.options.color_mode) if connector.color else None, | ||
| html_colorbar(connector.color)], |
There was a problem hiding this comment.
| f'{connector.pincount}-pin' if connector.show_pincount else None], | |
| [html_caption(connector.image) if connector.image and connector.image.position == 'above' else None, | |
| html_image(connector.image) if connector.image and connector.image.position == 'above' else None, | |
| translate_color(connector.color, self.options.color_mode) if connector.color else None, | |
| html_colorbar(connector.color)], | |
| 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)], | |
| *(image_rows if connector.image and connector.image.position == 'above' else []), |
Bugs:
- The row containing type, subtype, pincount, and color was broken into two rows (even if no
aboveimage present). - When
aboveimage present, it had caption to the left and color to the right - all 3 at the same row. I assume this was a mistake, and not intended.
Fix:
- Reverse breaking the existing row.
- Insert any
aboveimage rows just above the connector table.
| # fmt: on | ||
| imagetable='' | ||
| if connector.image: | ||
| if connector.image.position == 'below' or connector.image.position is None: |
There was a problem hiding this comment.
| if connector.image.position == 'below' or connector.image.position is None: | |
| if connector.image.position == "below": |
- Simplify because
Noneis no longer allowed - Black formatted
| pincount = len(connector.pinlabels) | ||
| if len(connector.pincolors) > pincount: | ||
| pincount = len(connector.pincolors) | ||
|
|
There was a problem hiding this comment.
| if connector.hide_disconnected_pins: | |
| pincount = sum(connector.visible_pins.values()) | |
Bug:
rowspanbecomes too large when hiding disconnected pins
Fix:
- Count only visible pins in that case
| if len(connector.pincolors) > pincount: | ||
| pincount = len(connector.pincolors) | ||
|
|
||
| for pinindex, (pinname, pinlabel, pincolor) in enumerate(zip_longest( |
There was a problem hiding this comment.
| for pinindex, (pinname, pinlabel, pincolor) in enumerate(zip_longest( | |
| for pinindex, (pinname, pinlabel, pincolor) in enumerate( | |
| zip_longest( |
- Black formatting reversed your change
| connector.pins, connector.pinlabels, connector.pincolors | ||
| ) | ||
| ): | ||
| )): |
There was a problem hiding this comment.
| )): | |
| ) | |
| ): |
- Black formatting reversed your change
|
|
||
| if firstpin and connector.image and connector.image.position == '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>') |
There was a problem hiding this comment.
| if firstpin and connector.image and connector.image.position == '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 connector.ports_left: | |
| pinhtml.append(f' <td port="p{pinindex+1}l">{pinname}</td>') | |
| if ( | |
| firstpin | |
| and connector.image | |
| and connector.image.position == "left" | |
| ): | |
| firstpin = False | |
| pinhtml.append( | |
| f' <td rowspan="{pincount}">{image_table}</td>' | |
| ) |
- Any left column with connected port cells MUST be the leftmost column for drawing the wire splines correctly
- Add indent for readable HTML
- Black formatted
| if connector.ports_right: | ||
| pinhtml.append(f' <td port="p{pinindex+1}r">{pinname}</td>') | ||
|
|
||
| if firstpin and connector.image and connector.image.position == 'right': | ||
| firstpin = False | ||
| pinhtml.append( | ||
| f'<td rowspan="{pincount}">{imagetable}</td>') |
There was a problem hiding this comment.
| if connector.ports_right: | |
| pinhtml.append(f' <td port="p{pinindex+1}r">{pinname}</td>') | |
| if firstpin and connector.image and connector.image.position == 'right': | |
| firstpin = False | |
| pinhtml.append( | |
| f'<td rowspan="{pincount}">{imagetable}</td>') | |
| if ( | |
| firstpin | |
| and connector.image | |
| and connector.image.position == "right" | |
| ): | |
| firstpin = False | |
| pinhtml.append( | |
| f' <td rowspan="{pincount}">{image_table}</td>' | |
| ) | |
| if connector.ports_right: | |
| pinhtml.append(f' <td port="p{pinindex+1}r">{pinname}</td>') |
- Any right column with connected port cells MUST be the rightmost column for drawing the wire splines correctly
- Add indent for readable HTML
- Black formatted
Added a new 'position' property to connector images which can be used to position images above/right/left of the connector tables:
Above:



Left:
Right: