Support both bgcolor and bgcolor_title attributes

Solves #210 completely by supporting bgcolor of both the node title
and the whole node independently using separate attributes.
This commit is contained in:
KV 2021-02-20 00:21:22 +01:00 committed by Daniel Rojas
parent dbccb77b08
commit 45d7d03fe0
4 changed files with 20 additions and 9 deletions

View File

@ -122,6 +122,7 @@ tweak: # optional tweaking of .gv output
# rendering information (all optional) # rendering information (all optional)
bgcolor: <color> # Background color of diagram connector box bgcolor: <color> # Background color of diagram connector box
bgcolor_title: <color> # Background color of title in diagram connector box
style: <style> # may be set to simple for single pin connectors style: <style> # may be set to simple for single pin connectors
show_name: <bool> # defaults to true for regular connectors, show_name: <bool> # defaults to true for regular connectors,
# false for simple connectors # false for simple connectors
@ -200,6 +201,7 @@ Since the auto-incremented and auto-assigned designator is not known to the user
# rendering information (all optional) # rendering information (all optional)
bgcolor: <color> # Background color of diagram cable box bgcolor: <color> # Background color of diagram cable box
bgcolor_title: <color> # Background color of title in diagram cable box
show_name: <bool> # defaults to true show_name: <bool> # defaults to true
show_wirecount: <bool> # defaults to true show_wirecount: <bool> # defaults to true
show_wirenumbers: <bool> # defaults to true for cables; false for bundles show_wirenumbers: <bool> # defaults to true for cables; false for bundles

View File

@ -123,6 +123,7 @@ class AdditionalComponent:
class Connector: class Connector:
name: Designator name: Designator
bgcolor: Optional[Color] = None bgcolor: Optional[Color] = None
bgcolor_title: Optional[Color] = None
manufacturer: Optional[MultilineHypertext] = None manufacturer: Optional[MultilineHypertext] = None
mpn: Optional[MultilineHypertext] = None mpn: Optional[MultilineHypertext] = None
supplier: Optional[MultilineHypertext] = None supplier: Optional[MultilineHypertext] = None
@ -208,6 +209,7 @@ class Connector:
class Cable: class Cable:
name: Designator name: Designator
bgcolor: Optional[Color] = None bgcolor: Optional[Color] = None
bgcolor_title: Optional[Color] = None
manufacturer: Union[MultilineHypertext, List[MultilineHypertext], None] = None manufacturer: Union[MultilineHypertext, List[MultilineHypertext], None] = None
mpn: Union[MultilineHypertext, List[MultilineHypertext], None] = None mpn: Union[MultilineHypertext, List[MultilineHypertext], None] = None
supplier: Union[MultilineHypertext, List[MultilineHypertext], None] = None supplier: Union[MultilineHypertext, List[MultilineHypertext], None] = None

View File

@ -12,7 +12,8 @@ import re
from wireviz import wv_colors, __version__, APP_NAME, APP_URL from wireviz import wv_colors, __version__, APP_NAME, APP_URL
from wireviz.DataClasses import Metadata, Options, Tweak, Connector, Cable from wireviz.DataClasses import Metadata, Options, Tweak, Connector, Cable
from wireviz.wv_colors import get_color_hex, translate_color from wireviz.wv_colors import get_color_hex, translate_color
from wireviz.wv_gv_html import nested_html_table, html_bgcolor, html_colorbar, \ from wireviz.wv_gv_html import nested_html_table, \
html_bgcolor_attr, html_bgcolor, html_colorbar, \
html_image, html_caption, remove_links, html_line_breaks html_image, html_caption, remove_links, html_line_breaks
from wireviz.wv_bom import pn_info_string, component_table_entry, \ from wireviz.wv_bom import pn_info_string, component_table_entry, \
get_additional_component_table, bom_list, generate_bom, \ get_additional_component_table, bom_list, generate_bom, \
@ -125,7 +126,8 @@ class Harness:
html = [] html = []
rows = [[f'{html_bgcolor(connector.bgcolor)}{remove_links(connector.name)}' if connector.show_name else None], rows = [[f'{html_bgcolor(connector.bgcolor_title)}{remove_links(connector.name)}'
if connector.show_name else None],
[pn_info_string(HEADER_PN, None, remove_links(connector.pn)), [pn_info_string(HEADER_PN, None, remove_links(connector.pn)),
html_line_breaks(pn_info_string(HEADER_MPN, connector.manufacturer, connector.mpn)), html_line_breaks(pn_info_string(HEADER_MPN, connector.manufacturer, connector.mpn)),
html_line_breaks(pn_info_string(HEADER_SPN, connector.supplier, connector.spn))], html_line_breaks(pn_info_string(HEADER_SPN, connector.supplier, connector.spn))],
@ -139,7 +141,7 @@ class Harness:
[html_caption(connector.image)]] [html_caption(connector.image)]]
rows.extend(get_additional_component_table(self, connector)) rows.extend(get_additional_component_table(self, connector))
rows.append([html_line_breaks(connector.notes)]) rows.append([html_line_breaks(connector.notes)])
html.extend(nested_html_table(rows)) html.extend(nested_html_table(rows, html_bgcolor_attr(connector.bgcolor)))
if connector.style != 'simple': if connector.style != 'simple':
pinhtml = [] pinhtml = []
@ -209,7 +211,8 @@ class Harness:
elif cable.gauge_unit.upper() == 'AWG': elif cable.gauge_unit.upper() == 'AWG':
awg_fmt = f' ({mm2_equiv(cable.gauge)} mm\u00B2)' awg_fmt = f' ({mm2_equiv(cable.gauge)} mm\u00B2)'
rows = [[f'{html_bgcolor(cable.bgcolor)}{remove_links(cable.name)}' if cable.show_name else None], rows = [[f'{html_bgcolor(cable.bgcolor_title)}{remove_links(cable.name)}'
if cable.show_name else None],
[pn_info_string(HEADER_PN, None, [pn_info_string(HEADER_PN, None,
remove_links(cable.pn)) if not isinstance(cable.pn, list) else None, remove_links(cable.pn)) if not isinstance(cable.pn, list) else None,
html_line_breaks(pn_info_string(HEADER_MPN, html_line_breaks(pn_info_string(HEADER_MPN,
@ -231,7 +234,7 @@ class Harness:
rows.extend(get_additional_component_table(self, cable)) rows.extend(get_additional_component_table(self, cable))
rows.append([html_line_breaks(cable.notes)]) rows.append([html_line_breaks(cable.notes)])
html.extend(nested_html_table(rows)) html.extend(nested_html_table(rows, html_bgcolor_attr(cable.bgcolor)))
wirehtml = [] wirehtml = []
wirehtml.append('<table border="0" cellspacing="0" cellborder="0">') # conductor table wirehtml.append('<table border="0" cellspacing="0" cellborder="0">') # conductor table

View File

@ -1,20 +1,20 @@
#!/usr/bin/env python #!/usr/bin/env python
# -*- coding: utf-8 -*- # -*- coding: utf-8 -*-
from typing import List, Union from typing import List, Optional, Union
import re import re
from wireviz.DataClasses import Color from wireviz.DataClasses import Color
from wireviz.wv_colors import translate_color from wireviz.wv_colors import translate_color
from wireviz.wv_helper import remove_links from wireviz.wv_helper import remove_links
def nested_html_table(rows): def nested_html_table(rows: List[Union[str, List[Optional[str]], None]], table_attrs: str = '') -> str:
# input: list, each item may be scalar or list # 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 # output: a parent table with one child table per parent item that is list, and one cell per parent item that is scalar
# purpose: create the appearance of one table, where cell widths are independent between rows # purpose: create the appearance of one table, where cell widths are independent between rows
# attributes in any leading <tdX> inside a list are injected into to the preceeding <td> tag # attributes in any leading <tdX> inside a list are injected into to the preceeding <td> tag
html = [] html = []
html.append('<table border="0" cellspacing="0" cellpadding="0">') html.append(f'<table border="0" cellspacing="0" cellpadding="0"{table_attrs or ""}>')
for row in rows: for row in rows:
if isinstance(row, List): if isinstance(row, List):
if len(row) > 0 and any(row): if len(row) > 0 and any(row):
@ -33,9 +33,13 @@ def nested_html_table(rows):
html.append('</table>') html.append('</table>')
return html return html
def html_bgcolor_attr(color: Color) -> str:
"""Return attributes for bgcolor or '' if no color."""
return f' bgcolor="{translate_color(color, "HEX")}"' if color else ''
def html_bgcolor(color: Color, _extra_attr: str = '') -> str: def html_bgcolor(color: Color, _extra_attr: str = '') -> str:
"""Return <td> attributes prefix for bgcolor or '' if no color.""" """Return <td> attributes prefix for bgcolor or '' if no color."""
return f'<tdX bgcolor="{translate_color(color, "HEX")}"{_extra_attr}>' if color else '' return f'<tdX{html_bgcolor_attr(color)}{_extra_attr}>' if color else ''
def html_colorbar(color: Color) -> str: def html_colorbar(color: Color) -> str:
"""Return <tdX> attributes prefix for bgcolor and minimum width or None if no color.""" """Return <tdX> attributes prefix for bgcolor and minimum width or None if no color."""