Skip to content

Commit

Permalink
et_visualizer: Escape labels for graph rendering
Browse files Browse the repository at this point in the history
  • Loading branch information
TaekyungHeo committed Feb 6, 2024
1 parent d61b00c commit 650f276
Showing 1 changed file with 19 additions and 1 deletion.
20 changes: 19 additions & 1 deletion et_visualizer/et_visualizer.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import argparse
import graphviz
import networkx as nx
import re

from chakra.third_party.utils.protolib import (
openFileRd as open_file_rd,
Expand All @@ -14,6 +15,22 @@
)


def escape_label(label: str) -> str:
"""
Escapes special characters in labels for graph rendering.
Args:
label (str): The original label string.
Returns:
str: The escaped label string.
"""
# Define special characters to escape
special_chars = "{}()<>\[\]|&-"
# Escape special characters
return re.sub(f"([{special_chars}])", r"\\\1", label)


def main() -> None:
parser = argparse.ArgumentParser(
description="Execution Trace Visualizer"
Expand Down Expand Up @@ -43,8 +60,9 @@ def main() -> None:
f = graphviz.Digraph()
decode_message(et, gm)
while decode_message(et, node):
escaped_label = escape_label(node.name)
f.node(name=f"{node.id}",
label=f"{node.name}",
label=escaped_label,
id=str(node.id),
shape="record")

Expand Down

0 comments on commit 650f276

Please sign in to comment.