Merge pull request #7 from Lightsockie/main
Allow Single-Axis Annotations
This commit is contained in:
@@ -26,12 +26,8 @@ class GridAnnotationNode(BaseNode):
|
||||
font_size: int,
|
||||
) -> tuple[Annotation]:
|
||||
font = ImageFont.truetype(str(STATIC_PATH / "Roboto-Regular.ttf"), size=font_size)
|
||||
column_texts_list = self._set_value_to_texts_list(
|
||||
self._get_texts_from_string(column_texts),
|
||||
)
|
||||
row_texts_list = self._set_value_to_texts_list(
|
||||
self._get_texts_from_string(row_texts),
|
||||
)
|
||||
column_texts_list = self._get_texts_from_string(column_texts)
|
||||
row_texts_list = self._get_texts_from_string(row_texts)
|
||||
|
||||
result = Annotation(column_texts=column_texts_list, row_texts=row_texts_list, font=font)
|
||||
return (result,)
|
||||
@@ -42,8 +38,3 @@ class GridAnnotationNode(BaseNode):
|
||||
for i in string.split(";")
|
||||
if (result := i.strip()) != ""
|
||||
]
|
||||
|
||||
def _set_value_to_texts_list(self, texts_list: list[str]) -> list[str]:
|
||||
if not texts_list:
|
||||
return ["None"]
|
||||
return texts_list
|
||||
|
||||
@@ -92,10 +92,14 @@ def _create_grid_annotation(
|
||||
row_texts: list[str],
|
||||
font: ImageFont.FreeTypeFont,
|
||||
) -> Image.Image:
|
||||
if not column_texts or not row_texts:
|
||||
raise ValueError("Column text or row text is empty")
|
||||
if not column_texts and not row_texts:
|
||||
raise ValueError("Column text and row text is empty")
|
||||
|
||||
grid = grid_info.image
|
||||
left_padding = 0
|
||||
top_padding = 0
|
||||
|
||||
if row_texts:
|
||||
left_padding = int(
|
||||
max(
|
||||
font.getlength(splitted_text)
|
||||
@@ -104,6 +108,7 @@ def _create_grid_annotation(
|
||||
)
|
||||
+ font.getlength(WIDEST_LETTER)*2
|
||||
)
|
||||
if column_texts:
|
||||
top_padding = int(font.size * 2)
|
||||
|
||||
image = Image.new(
|
||||
@@ -116,6 +121,7 @@ def _create_grid_annotation(
|
||||
draw.font = font # type: ignore
|
||||
|
||||
_paste_image_to_lower_left_corner(image, grid)
|
||||
if column_texts:
|
||||
_draw_column_text(
|
||||
draw=draw,
|
||||
texts=column_texts,
|
||||
@@ -123,6 +129,7 @@ def _create_grid_annotation(
|
||||
left_padding=left_padding,
|
||||
top_padding=top_padding,
|
||||
)
|
||||
if row_texts:
|
||||
_draw_row_text(
|
||||
draw=draw,
|
||||
texts=row_texts,
|
||||
|
||||
Reference in New Issue
Block a user