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 Sep 24, 2021
1 parent 9d64194 commit cf01502
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 3 deletions.
1 change: 1 addition & 0 deletions docs/syntax.md
Original file line number Diff line number Diff line change
Expand Up @@ -323,6 +323,7 @@ Parts can be added to a connector or cable in the section `<additional-component
mpn: <str> # manufacturer part number
supplier: <str> # supplier name
spn: <str> # supplier part number
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 @@ -114,6 +114,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
8 changes: 5 additions & 3 deletions src/wireviz/wv_bom.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@
from itertools import groupby
from typing import Any, Dict, List, Optional, Tuple, Union

from wireviz.DataClasses import AdditionalComponent, Connector, Cable
from wireviz.DataClasses import AdditionalComponent, Cable, Color, Connector
from wireviz.wv_colors import translate_color
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

BOM_COLUMNS_ALWAYS = ('id', 'description', 'qty', 'unit', 'designators')
Expand Down Expand Up @@ -36,6 +36,7 @@ def get_additional_component_table(harness: "Harness", component: Union[Connecto
common_args = {
'qty': part.qty * component.get_qty_multiplier(part.qty_multiplier),
'unit': part.unit,
'bgcolor': part.bgcolor,
}
if harness.options.mini_bom_mode:
id = get_bom_index(harness.bom(), bom_entry_key({**asdict(part), 'description': part.description}))
Expand Down Expand Up @@ -158,6 +159,7 @@ def component_table_entry(
type: str,
qty: Union[int, float],
unit: Optional[str] = None,
bgcolor: Optional[Color] = None,
pn: Optional[str] = None,
manufacturer: Optional[str] = None,
mpn: Optional[str] = None,
Expand All @@ -177,7 +179,7 @@ def component_table_entry(
+ (', '.join([pn for pn in part_number_list if pn])))
# 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">{html_line_breaks(output)}</td>
</tr></table>'''

Expand Down

0 comments on commit cf01502

Please sign in to comment.