#!/usr/bin/env python # -*- coding: utf-8 -*- from typing import List, Union import re from wireviz.wv_colors import translate_color from wireviz.wv_helper import remove_links 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 # purpose: create the appearance of one table, where cell widths are independent between rows # attributes in any leading inside a list are injected into to the preceeding tag html = [] html.append('') for row in rows: if isinstance(row, List): if len(row) > 0 and any(row): html.append(' ') elif row is not None: html.append(' ') html.append('
') html.append(' ') for cell in row: if cell is not None: # Inject attributes to the preceeding '.replace('>
tag where needed html.append(f' {cell}
') html.append('
') html.append(f' {row}') html.append('
') return html def html_colorbar(color): return f'' if color else None def html_image(image): from wireviz.DataClasses import Image if not image: return None # The leading attributes belong to the preceeding tag. See where used below. html = f'{html_size_attr(image)}>' if image.fixedsize: # Close the preceeding tag and enclose the image cell in a table without # borders to avoid narrow borders when the fixed width < the node width. html = f'''>
''' return f'''{html_line_breaks(image.caption)}' if image and image.caption else None def html_size_attr(image): from wireviz.DataClasses import Image # Return Graphviz HTML attributes to specify minimum or fixed size of a TABLE or TD object return ((f' width="{image.width}"' if image.width else '') + (f' height="{image.height}"' if image.height else '') + ( ' fixedsize="true"' if image.fixedsize else '')) if image else '' def html_line_breaks(inp): return remove_links(inp).replace('\n', '
') if isinstance(inp, str) else inp