From b4a0ae50b84ab7d23a84247d440382b1944ecdb6 Mon Sep 17 00:00:00 2001 From: Daniel Rojas Date: Tue, 23 Mar 2021 15:57:38 +0100 Subject: [PATCH] Implement additional parameter table as proposed in #222 --- src/wireviz/DataClasses.py | 4 +++- src/wireviz/Harness.py | 5 ++++- src/wireviz/wv_gv_html.py | 15 ++++++++++++++- 3 files changed, 21 insertions(+), 3 deletions(-) diff --git a/src/wireviz/DataClasses.py b/src/wireviz/DataClasses.py index 87dfe6cd..6aa9e662 100644 --- a/src/wireviz/DataClasses.py +++ b/src/wireviz/DataClasses.py @@ -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 @@ -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) @@ -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) diff --git a/src/wireviz/Harness.py b/src/wireviz/Harness.py index 14f96b06..486dfdd9 100644 --- a/src/wireviz/Harness.py +++ b/src/wireviz/Harness.py @@ -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 @@ -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), '' 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': @@ -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), '', [html_image(cable.image)], [html_caption(cable.image)]] diff --git a/src/wireviz/wv_gv_html.py b/src/wireviz/wv_gv_html.py index 87b24962..a54f0020 100644 --- a/src/wireviz/wv_gv_html.py +++ b/src/wireviz/wv_gv_html.py @@ -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('') + for (key, value) in rows.items(): + html.append(f' ') + html.append(f' ') + html.append('
{key}{value}
') + 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