Skip to content

Commit

Permalink
Support bgcolor of additional components
Browse files Browse the repository at this point in the history
Maybe not needed that much, but mainly for consistency, to support
bgcolor in all dataclasses that represent boxes in the diagram.
  • Loading branch information
kvid committed Mar 29, 2021
1 parent edb1a18 commit 7bb3bc3
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 5 deletions.
1 change: 1 addition & 0 deletions docs/syntax.md
Original file line number Diff line number Diff line change
Expand Up @@ -260,6 +260,7 @@ Parts can be added to a connector or cable in the section `<additional-component
pn: <str> # [internal] part number
mpn: <str> # manufacturer part number
manufacturer: <str> # manufacturer name
bgcolor: <color> # Background color of entry in diagram component box
```
Alternatively items can be added to just the BOM by putting them in the section `<bom-item>` above.
Expand Down
1 change: 1 addition & 0 deletions src/wireviz/DataClasses.py
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@ class AdditionalComponent:
qty: float = 1
unit: Optional[str] = None
qty_multiplier: Union[ConnectorMultiplier, CableMultiplier, None] = None
bgcolor: Optional[Color] = None

@property
def description(self) -> str:
Expand Down
10 changes: 5 additions & 5 deletions src/wireviz/wv_bom.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
from collections import Counter

from wireviz.DataClasses import Connector, Cable
from wireviz.wv_gv_html import html_line_breaks
from wireviz.wv_gv_html import html_bgcolor_attr, html_line_breaks
from wireviz.wv_helper import clean_whitespace

def get_additional_component_table(harness, component: Union[Connector, Cable]) -> List[str]:
Expand All @@ -16,9 +16,9 @@ def get_additional_component_table(harness, component: Union[Connector, Cable])
qty = extra.qty * component.get_qty_multiplier(extra.qty_multiplier)
if harness.mini_bom_mode:
id = get_bom_index(harness, extra.description, extra.unit, extra.manufacturer, extra.mpn, extra.pn)
rows.append(component_table_entry(f'#{id} ({extra.type.rstrip()})', qty, extra.unit))
rows.append(component_table_entry(f'#{id} ({extra.type.rstrip()})', qty, extra.unit, extra.bgcolor))
else:
rows.append(component_table_entry(extra.description, qty, extra.unit, extra.pn, extra.manufacturer, extra.mpn))
rows.append(component_table_entry(extra.description, qty, extra.unit, extra.bgcolor, extra.pn, extra.manufacturer, extra.mpn))
return(rows)

def get_additional_component_bom(component: Union[Connector, Cable]) -> List[dict]:
Expand Down Expand Up @@ -145,7 +145,7 @@ def bom_list(bom):
bom_list.append(item_list)
return bom_list

def component_table_entry(type, qty, unit=None, pn=None, manufacturer=None, mpn=None):
def component_table_entry(type, qty, unit=None, bgcolor=None, pn=None, manufacturer=None, mpn=None):
output = f'{qty}'
if unit:
output += f' {unit}'
Expand All @@ -163,7 +163,7 @@ def component_table_entry(type, qty, unit=None, pn=None, manufacturer=None, mpn=
output = html_line_breaks(output)
# format the above output as left aligned text in a single visible cell
# indent is set to two to match the indent in the generated html table
return f'''<table border="0" cellspacing="0" cellpadding="3" cellborder="1"><tr>
return f'''<table border="0" cellspacing="0" cellpadding="3" cellborder="1"{html_bgcolor_attr(bgcolor)}><tr>
<td align="left" balign="left">{output}</td>
</tr></table>'''

Expand Down

0 comments on commit 7bb3bc3

Please sign in to comment.