From 9a6522395913788c6583aeee96342203fe007cbe Mon Sep 17 00:00:00 2001 From: KV Date: Wed, 12 Aug 2020 18:15:04 +0200 Subject: [PATCH] Simplify colorbar using the same technique as html_image() Moving common code into html_colorbar() helper function. --- src/wireviz/Harness.py | 14 +++----------- src/wireviz/wv_helper.py | 4 ++++ 2 files changed, 7 insertions(+), 11 deletions(-) diff --git a/src/wireviz/Harness.py b/src/wireviz/Harness.py index 6077f08f..3178777a 100644 --- a/src/wireviz/Harness.py +++ b/src/wireviz/Harness.py @@ -8,7 +8,7 @@ from wireviz.wv_helper import awg_equiv, mm2_equiv, tuplelist2tsv, \ nested_html_table, flatten2d, index_if_list, html_line_breaks, \ graphviz_line_breaks, remove_line_breaks, open_file_read, open_file_write, \ - html_image, html_caption, manufacturer_info_field + html_colorbar, html_image, html_caption, manufacturer_info_field from collections import Counter from typing import List from pathlib import Path @@ -96,17 +96,13 @@ def create_graph(self) -> Graph: [html_line_breaks(connector.type), html_line_breaks(connector.subtype), f'{connector.pincount}-pin' if connector.show_pincount else None, - connector.color, '' if connector.color else None], + connector.color, html_colorbar(connector.color)], '' if connector.style != 'simple' else None, [html_image(connector)], [html_caption(connector)], [html_line_breaks(connector.notes)]] html.extend(nested_html_table(rows)) - if connector.color: # add color bar next to color info, if present - colorbar = f' bgcolor="{wv_colors.translate_color(connector.color, "HEX")}" width="4">' # leave out ' tag - html = [row.replace('>', colorbar) for row in html] - if connector.style != 'simple': pinhtml = [] pinhtml.append('') @@ -173,17 +169,13 @@ def create_graph(self) -> Graph: f'{cable.gauge} {cable.gauge_unit}{awg_fmt}' if cable.gauge else None, '+ S' if cable.shield else None, f'{cable.length} m' if cable.length > 0 else None, - cable.color, '' if cable.color else None], + cable.color, html_colorbar(cable.color)], '', [html_image(cable)], [html_caption(cable)], [html_line_breaks(cable.notes)]] html.extend(nested_html_table(rows)) - if cable.color: # add color bar next to color info, if present - colorbar = f' bgcolor="{wv_colors.translate_color(cable.color, "HEX")}" width="4">' # leave out ' tag - html = [row.replace('>', colorbar) for row in html] - wirehtml = [] wirehtml.append('
') # conductor table wirehtml.append(' ') diff --git a/src/wireviz/wv_helper.py b/src/wireviz/wv_helper.py index 8b31815f..680bf0c6 100644 --- a/src/wireviz/wv_helper.py +++ b/src/wireviz/wv_helper.py @@ -1,6 +1,7 @@ #!/usr/bin/env python3 # -*- coding: utf-8 -*- +from wireviz import wv_colors from typing import List awg_equiv_table = { @@ -55,6 +56,9 @@ def nested_html_table(rows): html.append('
 
') return html +def html_colorbar(color): + return f'' if color else None + def html_image(node): if not node.image: return None