Skip to content

Commit b4a0ae5

Browse files
committed
Implement additional parameter table
as proposed in #222
1 parent 1f86c97 commit b4a0ae5

File tree

3 files changed

+21
-3
lines changed

3 files changed

+21
-3
lines changed

src/wireviz/DataClasses.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
#!/usr/bin/env python3
22
# -*- coding: utf-8 -*-
33

4-
from typing import Optional, List, Tuple, Union
4+
from typing import Optional, List, Dict, Tuple, Union
55
from dataclasses import dataclass, field, InitVar
66
from pathlib import Path
77

@@ -94,6 +94,7 @@ class Connector:
9494
type: Optional[MultilineHypertext] = None
9595
subtype: Optional[MultilineHypertext] = None
9696
pincount: Optional[int] = None
97+
additional_parameters: Optional[Dict] = None
9798
image: Optional[Image] = None
9899
notes: Optional[MultilineHypertext] = None
99100
pinlabels: List[Pin] = field(default_factory=list)
@@ -182,6 +183,7 @@ class Cable:
182183
color: Optional[Color] = None
183184
wirecount: Optional[int] = None
184185
shield: Union[bool, Color] = False
186+
additional_parameters: Optional[Dict] = None
185187
image: Optional[Image] = None
186188
notes: Optional[MultilineHypertext] = None
187189
colors: List[Colors] = field(default_factory=list)

src/wireviz/Harness.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
from wireviz.DataClasses import Connector, Cable
1313
from wireviz.wv_colors import get_color_hex
1414
from wireviz.wv_gv_html import nested_html_table, html_colorbar, html_image, \
15-
html_caption, remove_links, html_line_breaks, bom_bubble
15+
html_caption, remove_links, html_line_breaks, bom_bubble, nested_html_table_dict
1616
from wireviz.wv_bom import manufacturer_info_field, \
1717
get_additional_component_table, bom_list, generate_bom
1818
from wireviz.wv_html import generate_html_output
@@ -122,11 +122,13 @@ def create_graph(self) -> Graph:
122122
connector.color, html_colorbar(connector.color)],
123123
[f'P/N: {remove_links(connector.pn)}' if connector.pn else None,
124124
html_line_breaks(manufacturer_info_field(connector.manufacturer, connector.mpn))] if self.show_part_numbers else None,
125+
nested_html_table_dict(connector.additional_parameters),
125126
'<!-- connector table -->' if connector.style != 'simple' else None,
126127
[html_image(connector.image)],
127128
[html_caption(connector.image)]]
128129
rows.append(get_additional_component_table(self, connector))
129130
rows.append([html_line_breaks(connector.notes)])
131+
130132
html.extend(nested_html_table(rows))
131133

132134
if connector.style != 'simple':
@@ -208,6 +210,7 @@ def create_graph(self) -> Graph:
208210
html_line_breaks(manufacturer_info_field(
209211
cable.manufacturer if not isinstance(cable.manufacturer, list) else None,
210212
cable.mpn if not isinstance(cable.mpn, list) else None))],
213+
nested_html_table_dict(cable.additional_parameters),
211214
'<!-- wire table -->',
212215
[html_image(cable.image)],
213216
[html_caption(cable.image)]]

src/wireviz/wv_gv_html.py

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,25 @@
11
#!/usr/bin/env python
22
# -*- coding: utf-8 -*-
33

4-
from typing import List, Union
4+
from typing import List, Dict, Union
55
import re
66

77
from wireviz.wv_colors import translate_color
88
from wireviz.wv_helper import remove_links
99

10+
def nested_html_table_dict(rows):
11+
if isinstance(rows, Dict):
12+
html = []
13+
html.append('<table border="0" cellspacing="0" cellpadding="3" cellborder="1">')
14+
for (key, value) in rows.items():
15+
html.append(f' <tr><td align="left" balign="left">{key}</td>')
16+
html.append(f' <td align="left" balign="left">{value}</td></tr>')
17+
html.append(' </table>')
18+
out = '\n'.join(html)
19+
else:
20+
out = None
21+
return out
22+
1023
def nested_html_table(rows):
1124
# input: list, each item may be scalar or list
1225
# output: a parent table with one child table per parent item that is list, and one cell per parent item that is scalar

0 commit comments

Comments
 (0)