Skip to content

Commit 9c933d1

Browse files
committed
Simplify colorbar using the same technique as html_image()
Moving common code into html_colorbar() helper function.
1 parent 6081bf5 commit 9c933d1

2 files changed

Lines changed: 7 additions & 11 deletions

File tree

src/wireviz/Harness.py

Lines changed: 3 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
from wireviz.wv_helper import awg_equiv, mm2_equiv, tuplelist2tsv, \
99
nested_html_table, flatten2d, index_if_list, html_line_breaks, \
1010
graphviz_line_breaks, remove_line_breaks, open_file_read, open_file_write, \
11-
html_image, html_caption, manufacturer_info_field
11+
html_colorbar, html_image, html_caption, manufacturer_info_field
1212
from collections import Counter
1313
from typing import List
1414
from pathlib import Path
@@ -96,17 +96,13 @@ def create_graph(self) -> Graph:
9696
[html_line_breaks(connector.type),
9797
html_line_breaks(connector.subtype),
9898
f'{connector.pincount}-pin' if connector.show_pincount else None,
99-
connector.color, '<!-- colorbar -->' if connector.color else None],
99+
connector.color, html_colorbar(connector.color)],
100100
'<!-- connector table -->' if connector.style != 'simple' else None,
101101
[html_image(connector)],
102102
[html_caption(connector)],
103103
[html_line_breaks(connector.notes)]]
104104
html.extend(nested_html_table(rows))
105105

106-
if connector.color: # add color bar next to color info, if present
107-
colorbar = f' bgcolor="{wv_colors.translate_color(connector.color, "HEX")}" width="4"></td>' # leave out '<td' from string to preserve any existing attributes of the <td> tag
108-
html = [row.replace('><!-- colorbar --></td>', colorbar) for row in html]
109-
110106
if connector.style != 'simple':
111107
pinhtml = []
112108
pinhtml.append('<table border="0" cellspacing="0" cellpadding="3" cellborder="1">')
@@ -173,17 +169,13 @@ def create_graph(self) -> Graph:
173169
f'{cable.gauge} {cable.gauge_unit}{awg_fmt}' if cable.gauge else None,
174170
'+ S' if cable.shield else None,
175171
f'{cable.length} m' if cable.length > 0 else None,
176-
cable.color, '<!-- colorbar -->' if cable.color else None],
172+
cable.color, html_colorbar(cable.color)],
177173
'<!-- wire table -->',
178174
[html_image(cable)],
179175
[html_caption(cable)],
180176
[html_line_breaks(cable.notes)]]
181177
html.extend(nested_html_table(rows))
182178

183-
if cable.color: # add color bar next to color info, if present
184-
colorbar = f' bgcolor="{wv_colors.translate_color(cable.color, "HEX")}" width="4"></td>' # leave out '<td' from string to preserve any existing attributes of the <td> tag
185-
html = [row.replace('><!-- colorbar --></td>', colorbar) for row in html]
186-
187179
wirehtml = []
188180
wirehtml.append('<table border="0" cellspacing="0" cellborder="0">') # conductor table
189181
wirehtml.append('<tr><td>&nbsp;</td></tr>')

src/wireviz/wv_helper.py

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

4+
from wireviz import wv_colors
45
from typing import List
56

67
awg_equiv_table = {
@@ -55,6 +56,9 @@ def nested_html_table(rows):
5556
html.append('</table>')
5657
return html
5758

59+
def html_colorbar(color):
60+
return f'<tdX bgcolor="{wv_colors.translate_color(color, "HEX")}" width="4">' if color else None
61+
5862
def html_image(node):
5963
if not node.image:
6064
return None

0 commit comments

Comments
 (0)