-
Notifications
You must be signed in to change notification settings - Fork 227
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[WIP]Add connector image alignment #420
base: master
Are you sure you want to change the base?
[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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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 Large scale refactoring #251 changes before a merge-in
- Fixing a few bugs (see details in each comment)
- Minor simplifications
- Black formatting (remember running
isort *.py
andblack *.py
before committing your changes) - Please add an entry to
docs/syntax.md
that lists the alternative attribute values and briefly explains that they relate to the pin list of connectors. - Left/right images for
simple
connectors are still not implemented, and I suggest for now to only allowimage.position==below
forsimple
connectors and all cables, and raiseValueError
otherwise 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'"
)
@@ -86,6 +87,7 @@ class Image: | |||
height: Optional[int] = None | |||
fixedsize: Optional[bool] = None | |||
bgcolor: Optional[Color] = None | |||
position: Optional[ImagePosition] = None |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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
if
test - Black formatting
# fmt: on | ||
imagetable='' |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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
above
image present). - When
above
image 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
above
image 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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
if connector.image.position == 'below' or connector.image.position is None: | |
if connector.image.position == "below": |
- Simplify because
None
is 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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
if connector.hide_disconnected_pins: | |
pincount = sum(connector.visible_pins.values()) | |
Bug:
rowspan
becomes 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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
)): | |
) | |
): |
- 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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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: