Skip to content

Commit

Permalink
max_table_str_len
Browse files Browse the repository at this point in the history
  • Loading branch information
abrichr committed Jun 25, 2023
1 parent 27b89b7 commit 4051804
Showing 1 changed file with 9 additions and 1 deletion.
10 changes: 9 additions & 1 deletion openadapt/visualize.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
LOG_LEVEL = "INFO"
MAX_EVENTS = None
MAX_TABLE_CHILDREN = 5
MAX_TABLE_STR_LEN = 1024
PROCESS_EVENTS = True
IMG_WIDTH_PCT = 60
CSS = string.Template(
Expand Down Expand Up @@ -114,7 +115,7 @@ def indicate_missing(some, every, indicator):
return rval


def dict2html(obj, max_children=MAX_TABLE_CHILDREN):
def dict2html(obj, max_children=MAX_TABLE_CHILDREN, max_len=MAX_TABLE_STR_LEN):
if isinstance(obj, list):
children = [dict2html(value, max_children) for value in obj]
if max_children is not None and len(children) > max_children:
Expand All @@ -138,6 +139,13 @@ def dict2html(obj, max_children=MAX_TABLE_CHILDREN):
html_str = f"<table>{rows_html}</table>"
else:
html_str = html.escape(str(obj))
if len(html_str) > max_len:
n = max_len // 2
head = html_str[:n]
tail = html_str[-n:]
snipped = html_str[n:-n]
middle = f"<br/>...<i>(snipped {len(snipped):,})...</i><br/>"
html_str = head + middle + tail
return html_str


Expand Down

0 comments on commit 4051804

Please sign in to comment.