Skip to content

Commit

Permalink
Add bgcolor attribute to connectors and cables
Browse files Browse the repository at this point in the history
This solves the wireviz#210 suggestion to render the title row of
the graph nodes with this bgcolor.
  • Loading branch information
kvid committed Aug 24, 2021
1 parent e212fc9 commit c2cc851
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 6 deletions.
2 changes: 2 additions & 0 deletions docs/syntax.md
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ additional_bom_items: # custom items to add to BOM
# no color marks will be added to remaining pins

# rendering information (all optional)
bgcolor: <color> # Background color of diagram connector box
style: <style> # may be set to simple for single pin connectors
show_name: <bool> # defaults to true for regular connectors,
# false for simple connectors
Expand Down Expand Up @@ -137,6 +138,7 @@ Since the auto-incremented and auto-assigned designator is not known to the user
wirelabels: <List> # optional; one label for each wire

# rendering information (all optional)
bgcolor: <color> # Background color of diagram cable box
show_name: <bool> # defaults to true
show_wirecount: <bool> # defaults to true
show_wirenumbers: <bool> # defaults to true for cables; false for bundles
Expand Down
2 changes: 2 additions & 0 deletions src/wireviz/DataClasses.py
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,7 @@ def description(self) -> str:
@dataclass
class Connector:
name: Designator
bgcolor: Optional[Color] = None
manufacturer: Optional[MultilineHypertext] = None
mpn: Optional[MultilineHypertext] = None
pn: Optional[Hypertext] = None
Expand Down Expand Up @@ -168,6 +169,7 @@ def get_qty_multiplier(self, qty_multiplier: Optional[ConnectorMultiplier]) -> i
@dataclass
class Cable:
name: Designator
bgcolor: Optional[Color] = None
manufacturer: Union[MultilineHypertext, List[MultilineHypertext], None] = None
mpn: Union[MultilineHypertext, List[MultilineHypertext], None] = None
pn: Union[Hypertext, List[Hypertext], None] = None
Expand Down
8 changes: 4 additions & 4 deletions src/wireviz/Harness.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@
from wireviz import wv_colors, __version__, APP_NAME, APP_URL
from wireviz.DataClasses import Connector, Cable
from wireviz.wv_colors import get_color_hex
from wireviz.wv_gv_html import nested_html_table, html_colorbar, html_image, \
html_caption, remove_links, html_line_breaks
from wireviz.wv_gv_html import nested_html_table, html_bgcolor, html_colorbar, \
html_image, html_caption, remove_links, html_line_breaks
from wireviz.wv_bom import manufacturer_info_field, component_table_entry, \
get_additional_component_table, bom_list, generate_bom
from wireviz.wv_html import generate_html_output
Expand Down Expand Up @@ -120,7 +120,7 @@ def create_graph(self) -> Graph:

html = []

rows = [[remove_links(connector.name) if connector.show_name else None],
rows = [[f'{html_bgcolor(connector.bgcolor)}{remove_links(connector.name)}' if connector.show_name else None],
[f'P/N: {remove_links(connector.pn)}' if connector.pn else None,
html_line_breaks(manufacturer_info_field(connector.manufacturer, connector.mpn))],
[html_line_breaks(connector.type),
Expand Down Expand Up @@ -201,7 +201,7 @@ def create_graph(self) -> Graph:
elif cable.gauge_unit.upper() == 'AWG':
awg_fmt = f' ({mm2_equiv(cable.gauge)} mm\u00B2)'

rows = [[remove_links(cable.name) if cable.show_name else None],
rows = [[f'{html_bgcolor(cable.bgcolor)}{remove_links(cable.name)}' if cable.show_name else None],
[f'P/N: {remove_links(cable.pn)}' if (cable.pn and not isinstance(cable.pn, list)) else None,
html_line_breaks(manufacturer_info_field(
cable.manufacturer if not isinstance(cable.manufacturer, list) else None,
Expand Down
10 changes: 8 additions & 2 deletions src/wireviz/wv_gv_html.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
from typing import List, Union
import re

from wireviz.DataClasses import Color
from wireviz.wv_colors import translate_color
from wireviz.wv_helper import remove_links

Expand Down Expand Up @@ -32,8 +33,13 @@ def nested_html_table(rows):
html.append('</table>')
return html

def html_colorbar(color):
return f'<tdX bgcolor="{translate_color(color, "HEX")}" width="4">' if color else None
def html_bgcolor(color: Color, _extra_attr: str = '') -> str:
"""Return <td> attributes prefix for bgcolor or '' if no color."""
return f'<tdX bgcolor="{translate_color(color, "HEX")}"{_extra_attr}>' if color else ''

def html_colorbar(color: Color) -> str:
"""Return <tdX> attributes prefix for bgcolor and minimum width or None if no color."""
return html_bgcolor(color, ' width="4"') if color else None

def html_image(image):
from wireviz.DataClasses import Image
Expand Down

0 comments on commit c2cc851

Please sign in to comment.