Skip to content
Snippets Groups Projects
Commit 5b6a23f3 authored by mhocke's avatar mhocke
Browse files

Abbreviate long texts in rendering

parent 46fc793f
No related branches found
No related tags found
1 merge request!28Draft: Update show_text render option + fix grid points
Pipeline #49071 passed
...@@ -902,8 +902,12 @@ class File(h5py.File): ...@@ -902,8 +902,12 @@ class File(h5py.File):
points = [grid_points, goal_point, target_line] points = [grid_points, goal_point, target_line]
if options["show_text"]: if options["show_text"]:
label_top_right = ax_text.text(0, 0.95, "", fontsize=10) label_top_right = ax_text.text(
label_bottom_right = ax_text.text(0, 0, "", fontsize=10) 0, 0.90, "", fontsize=9, fontfamily="monospace"
)
label_bottom_right = ax_text.text(
0, 0.1, "", fontsize=9, fontfamily="monospace"
)
labels = [label_top_right, label_bottom_right] labels = [label_top_right, label_bottom_right]
else: else:
labels = [] labels = []
...@@ -935,20 +939,25 @@ class File(h5py.File): ...@@ -935,20 +939,25 @@ class File(h5py.File):
def get_attributes_as_text() -> str: def get_attributes_as_text() -> str:
attrs = {} attrs = {}
width = 92
for key, val in self.attrs.items(): for key, val in self.attrs.items():
if key == "experiment_setup": if key == "experiment_setup":
continue continue
attrs[key] = val attrs[key] = val
separator = "-" * 130 + "\n" separator = "\u2500" * width + "\n"
text = "" text = ""
text += separator text += separator
text += "experiment_setup:\n%s\n" % utils.wrap_newline( text += "experiment_setup:\n"
self.attrs["experiment_setup"], 60 text += utils.wrap_newline(
text=self.attrs["experiment_setup"],
width=width,
justify=True,
maxlines=10,
) )
text += separator text += "\n" + separator
text += "\n".join( text += "\n".join(
[ [
"%s: %s" % (key, utils.wrap_newline(val, 60)) f"{key}: {utils.wrap_newline(text=val, width=width-len(key)-2, justify=True, maxlines=3)}"
for key, val in attrs.items() for key, val in attrs.items()
] ]
) )
......
import robofish.io import robofish.io
import numpy as np import numpy as np
from typing import Union, Iterable from typing import Union, Iterable, Optional
from pathlib import Path from pathlib import Path
from tqdm import tqdm from tqdm import tqdm
import textwrap import textwrap
...@@ -123,5 +123,14 @@ def get_all_data_from_paths( ...@@ -123,5 +123,14 @@ def get_all_data_from_paths(
return all_data, expected_settings return all_data, expected_settings
def wrap_newline(text, width=60): def wrap_newline(
return "\n".join(textwrap.wrap(str(text), width)) text: str, width: int = 60, justify: bool = False, maxlines: Optional[int] = None
) -> str:
text = str(text).strip()
if justify:
text = text.replace("\n", " ")
lines = textwrap.wrap(text, width)
if maxlines and len(lines) > maxlines:
lines = lines[:maxlines]
lines[-1] = lines[-1][: width - 3] + "..."
return "\n".join(lines)
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment