Skip to content

Commit

Permalink
Implement additional parameter table
Browse files Browse the repository at this point in the history
as proposed in #222
  • Loading branch information
formatc1702 committed Mar 23, 2021
1 parent 1f86c97 commit b4a0ae5
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 3 deletions.
4 changes: 3 additions & 1 deletion src/wireviz/DataClasses.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#!/usr/bin/env python3
# -*- coding: utf-8 -*-

from typing import Optional, List, Tuple, Union
from typing import Optional, List, Dict, Tuple, Union
from dataclasses import dataclass, field, InitVar
from pathlib import Path

Expand Down Expand Up @@ -94,6 +94,7 @@ class Connector:
type: Optional[MultilineHypertext] = None
subtype: Optional[MultilineHypertext] = None
pincount: Optional[int] = None
additional_parameters: Optional[Dict] = None
image: Optional[Image] = None
notes: Optional[MultilineHypertext] = None
pinlabels: List[Pin] = field(default_factory=list)
Expand Down Expand Up @@ -182,6 +183,7 @@ class Cable:
color: Optional[Color] = None
wirecount: Optional[int] = None
shield: Union[bool, Color] = False
additional_parameters: Optional[Dict] = None
image: Optional[Image] = None
notes: Optional[MultilineHypertext] = None
colors: List[Colors] = field(default_factory=list)
Expand Down
5 changes: 4 additions & 1 deletion src/wireviz/Harness.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
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, bom_bubble
html_caption, remove_links, html_line_breaks, bom_bubble, nested_html_table_dict
from wireviz.wv_bom import manufacturer_info_field, \
get_additional_component_table, bom_list, generate_bom
from wireviz.wv_html import generate_html_output
Expand Down Expand Up @@ -122,11 +122,13 @@ def create_graph(self) -> Graph:
connector.color, html_colorbar(connector.color)],
[f'P/N: {remove_links(connector.pn)}' if connector.pn else None,
html_line_breaks(manufacturer_info_field(connector.manufacturer, connector.mpn))] if self.show_part_numbers else None,
nested_html_table_dict(connector.additional_parameters),
'<!-- connector table -->' if connector.style != 'simple' else None,
[html_image(connector.image)],
[html_caption(connector.image)]]
rows.append(get_additional_component_table(self, connector))
rows.append([html_line_breaks(connector.notes)])

html.extend(nested_html_table(rows))

if connector.style != 'simple':
Expand Down Expand Up @@ -208,6 +210,7 @@ def create_graph(self) -> Graph:
html_line_breaks(manufacturer_info_field(
cable.manufacturer if not isinstance(cable.manufacturer, list) else None,
cable.mpn if not isinstance(cable.mpn, list) else None))],
nested_html_table_dict(cable.additional_parameters),
'<!-- wire table -->',
[html_image(cable.image)],
[html_caption(cable.image)]]
Expand Down
15 changes: 14 additions & 1 deletion src/wireviz/wv_gv_html.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,25 @@
#!/usr/bin/env python
# -*- coding: utf-8 -*-

from typing import List, Union
from typing import List, Dict, Union
import re

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

def nested_html_table_dict(rows):
if isinstance(rows, Dict):
html = []
html.append('<table border="0" cellspacing="0" cellpadding="3" cellborder="1">')
for (key, value) in rows.items():
html.append(f' <tr><td align="left" balign="left">{key}</td>')
html.append(f' <td align="left" balign="left">{value}</td></tr>')
html.append(' </table>')
out = '\n'.join(html)
else:
out = None
return out

def nested_html_table(rows):
# input: list, each item may be scalar or list
# output: a parent table with one child table per parent item that is list, and one cell per parent item that is scalar
Expand Down

0 comments on commit b4a0ae5

Please sign in to comment.