From 0629734a6a395930d20e78cf3a32e49255575911 Mon Sep 17 00:00:00 2001 From: "sandipsamal117@gmail.com" Date: Tue, 27 Feb 2024 17:41:10 -0500 Subject: [PATCH] Bug Fix to reposition additional text at the bottom --- markimg/markimg.py | 27 ++++++++++++++++++--------- 1 file changed, 18 insertions(+), 9 deletions(-) diff --git a/markimg/markimg.py b/markimg/markimg.py index 1f84963..4ac2da0 100644 --- a/markimg/markimg.py +++ b/markimg/markimg.py @@ -534,7 +534,8 @@ def run(self, options): x_pos = x_pos + line_gap plt.text(x_pos, y_pos, totalRightInfo, color='white', fontsize=options.textSize, rotation=90) - totalLeftInfo = 'Total left: ' + str(self.getSum(d_lengths['Left femur'], d_lengths['Left tibia'])) + f' {unit}' + totalLeftInfo = 'Total left: ' + str( + self.getSum(d_lengths['Left femur'], d_lengths['Left tibia'])) + f' {unit}' d_total['Total left'] = str(self.getSum(d_lengths['Left femur'], d_lengths['Left tibia'])) + f' {unit}' x_pos = x_pos + line_gap plt.text(x_pos, y_pos, totalLeftInfo, color='white', fontsize=options.textSize, rotation=90) @@ -551,11 +552,16 @@ def run(self, options): plt.text(x_pos, y_pos, totalDiffText, color='white', fontsize=options.textSize, rotation=90) # Print some blank lines - for i in range(0, 3): + for i in range(0, 2): x_pos = x_pos + line_gap plt.text(x_pos, y_pos, '', color='white', fontsize=options.textSize, rotation=90) rotation = 0 plt.text(x_pos, y_pos, msg, color='cyan', fontsize=options.textSize, rotation=90) + for i in range(0, 2): + x_pos = x_pos + line_gap + plt.text(x_pos, y_pos, '', color='white', fontsize=options.textSize, rotation=90) + plt.text(x_pos, y_pos, options.addText, color=options.addTextColor, fontsize=options.addTextSize, + rotation=90) """ Need to rewrite logic for directions. @@ -584,8 +590,8 @@ def run(self, options): # y_pos = y_pos - line_gap - plt.text(x_pos, y_pos, options.addText, color=options.addTextColor, fontsize=options.addTextSize, - rotation=rotation) + # plt.text(x_pos, y_pos, options.addText, color=options.addTextColor, fontsize=options.addTextSize, + # rotation=rotation) # Clean up all matplotlib stuff and save as PNG plt.tick_params(left=False, right=False, labelleft=False, @@ -654,10 +660,13 @@ def getSum(self, val1, val2): def compareLength(self, left, right): compareText = "equal" - if left > right: - compareText = f'left longer ({round(((left-right)/right)*100, 1)}%)' - elif right > left: - compareText = f'right longer ({round(((right-left)/left)*100, 1)}%)' + try: + if left > right: + compareText = f'left longer ({round(((left - right) / right) * 100, 1)}%)' + elif right > left: + compareText = f'right longer ({round(((right - left) / left) * 100, 1)}%)' + except ZeroDivisionError: + compareText = "Error: ZeroDivisionError" return compareText + ' ' @@ -666,7 +675,7 @@ def measureXDist(self, line, color, size, max_y, scale, unit='cm'): P2 = line[1] pixel_distance = round(abs(P1[0] - P2[0])) actual_distance = round((pixel_distance * scale) / 10, 1) - if scale==0: + if scale == 0: return pixel_distance, pixel_distance return pixel_distance, actual_distance