Implement multiple colors for components, improve multicolor table rendering
This commit is contained in:
parent
2fc132bdb9
commit
1b6030c1a3
@ -33,7 +33,7 @@ def gv_node_component(component: Component) -> Table:
|
|||||||
# generate all rows to be shown in the node
|
# generate all rows to be shown in the node
|
||||||
if component.show_name:
|
if component.show_name:
|
||||||
str_name = f"{remove_links(component.designator)}"
|
str_name = f"{remove_links(component.designator)}"
|
||||||
line_name = colored_cell(str_name, component.bgcolor_title)
|
line_name = Td(str_name, bgcolor=component.bgcolor_title.html)
|
||||||
else:
|
else:
|
||||||
line_name = None
|
line_name = None
|
||||||
|
|
||||||
@ -50,7 +50,6 @@ def gv_node_component(component: Component) -> Table:
|
|||||||
html_line_breaks(component.subtype),
|
html_line_breaks(component.subtype),
|
||||||
f"{component.pincount}-pin" if component.show_pincount else None,
|
f"{component.pincount}-pin" if component.show_pincount else None,
|
||||||
str(component.color) if component.color else None,
|
str(component.color) if component.color else None,
|
||||||
colorbar_cell(component.color) if component.color else None,
|
|
||||||
]
|
]
|
||||||
elif isinstance(component, Cable):
|
elif isinstance(component, Cable):
|
||||||
line_info = [
|
line_info = [
|
||||||
@ -61,10 +60,10 @@ def gv_node_component(component: Component) -> Table:
|
|||||||
"+ S" if component.shield else None,
|
"+ S" if component.shield else None,
|
||||||
component.length_str,
|
component.length_str,
|
||||||
str(component.color) if component.color else None,
|
str(component.color) if component.color else None,
|
||||||
colorbar_cell(component.color) if component.color else None,
|
|
||||||
]
|
]
|
||||||
|
|
||||||
x = colorbar_cell(component.color) if component.color else None
|
if component.color:
|
||||||
|
line_info.extend(colorbar_cells(component.color))
|
||||||
|
|
||||||
line_image, line_image_caption = image_and_caption_cells(component)
|
line_image, line_image_caption = image_and_caption_cells(component)
|
||||||
line_additional_component_table = gv_additional_component_table(component)
|
line_additional_component_table = gv_additional_component_table(component)
|
||||||
@ -445,40 +444,27 @@ def gv_edge_mate(mate) -> (str, str, str, str):
|
|||||||
return color, dir, code_from, code_to
|
return color, dir, code_from, code_to
|
||||||
|
|
||||||
|
|
||||||
def colored_cell(contents, bgcolor) -> Td:
|
def colorbar_cells(color, mini=False) -> List[Td]:
|
||||||
return Td(contents, bgcolor=bgcolor.html)
|
cells = []
|
||||||
|
mini = {height: 8, width: 8, fixedsize: "true"} if mini else {}
|
||||||
|
for index, subcolor in enumerate(color.colors):
|
||||||
def colorbar_cell(color) -> Td:
|
sides_l = "L" if index == 0 else ""
|
||||||
# return Td("", bgcolor=color.html, width=4)
|
sides_r = "R" if index == len(color.colors) - 1 else ""
|
||||||
cells = [
|
sides = "TB" + sides_l + sides_r
|
||||||
Td(
|
cells.append(Td("", bgcolor=subcolor.html, sides=sides, **mini))
|
||||||
"",
|
return cells
|
||||||
bgcolor=subcolor.html,
|
|
||||||
width=8,
|
|
||||||
)
|
|
||||||
for subcolor in color.colors
|
|
||||||
]
|
|
||||||
return Td(Table(Tr(cells), border=0, cellspacing=0), cellspacing=0, cellpadding=0)
|
|
||||||
|
|
||||||
|
|
||||||
def color_minitable(color: Optional[MultiColor]) -> Union[Table, str]:
|
def color_minitable(color: Optional[MultiColor]) -> Union[Table, str]:
|
||||||
if color is None or len(color) == 0:
|
if color is None or len(color) == 0:
|
||||||
return ""
|
return ""
|
||||||
cells = [
|
|
||||||
Td(
|
cells = colorbar_cells(color)
|
||||||
"",
|
|
||||||
bgcolor=subcolor.html,
|
|
||||||
height=8,
|
|
||||||
width=8,
|
|
||||||
fixedsize="true",
|
|
||||||
)
|
|
||||||
for subcolor in color.colors
|
|
||||||
]
|
|
||||||
return Table(
|
return Table(
|
||||||
Tr(cells),
|
Tr(cells),
|
||||||
border=1,
|
border=0,
|
||||||
cellborder=0,
|
cellborder=1,
|
||||||
cellspacing=0,
|
cellspacing=0,
|
||||||
height=8,
|
height=8,
|
||||||
width=8 * len(cells) + 2,
|
width=8 * len(cells) + 2,
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user