Good good progress
This commit is contained in:
@@ -1465,67 +1465,60 @@ class GraphGenerator:
|
||||
Args:
|
||||
data: List of rows (each row is a list of values)
|
||||
columns: List of column headers (Zone 1-5)
|
||||
cell_colors: Optional matrix of cell colors
|
||||
cell_colors: Optional matrix of cell colors (IGNORED - using notebook colors)
|
||||
save_as_base64: If True, return base64 string
|
||||
|
||||
Returns:
|
||||
Base64 string or file path
|
||||
"""
|
||||
import io
|
||||
import textwrap
|
||||
|
||||
# Optimal sizing for HR Zones table (5 columns, 8 rows)
|
||||
fig, ax = plt.subplots(figsize=(14, 8))
|
||||
# Optimal sizing for HR Zones table (5 columns, 8 rows) - match notebook exactly
|
||||
fig, ax = plt.subplots(figsize=(12, 8))
|
||||
ax.axis("off")
|
||||
|
||||
# Column widths - slightly wider for first column which has longer text
|
||||
# col_widths = [0.24, 0.19, 0.19, 0.19, 0.19]
|
||||
# Data comes pre-formatted with newlines from context_generator - use as-is
|
||||
# No text wrapping needed
|
||||
|
||||
# Wrap text in cells for better readability
|
||||
wrapped_data = []
|
||||
for row in data:
|
||||
wrapped_row = []
|
||||
for i, cell in enumerate(row):
|
||||
cell_text = str(cell)
|
||||
# First column needs more wrapping space
|
||||
wrap_width = 35 if i == 0 else 25
|
||||
wrapped_text = "\n".join(textwrap.wrap(cell_text, width=wrap_width))
|
||||
wrapped_row.append(wrapped_text)
|
||||
wrapped_data.append(wrapped_row)
|
||||
|
||||
# Create table
|
||||
# Create table without rowLabels - match notebook exactly
|
||||
table = ax.table(
|
||||
cellText=wrapped_data,
|
||||
cellText=data,
|
||||
colLabels=columns,
|
||||
cellLoc="center",
|
||||
loc="center",
|
||||
colColours=["#4dd0e1"] * len(columns),
|
||||
# colWidths=col_widths,
|
||||
cellLoc="center",
|
||||
)
|
||||
|
||||
# Style the table
|
||||
# Style the table - match notebook exactly
|
||||
table.auto_set_font_size(False)
|
||||
table.set_fontsize(11)
|
||||
table.scale(1, 2.0)
|
||||
table.set_fontsize(10)
|
||||
table.scale(1, 3.5) # Increased vertical scale for multi-line text
|
||||
|
||||
# Apply cell colors
|
||||
if cell_colors:
|
||||
for i, row_colors in enumerate(cell_colors):
|
||||
for j, color in enumerate(row_colors):
|
||||
if color and j < len(columns):
|
||||
cell = table[(i + 1, j)]
|
||||
cell.set_facecolor(color)
|
||||
# Header row styling
|
||||
for j, label in enumerate(columns):
|
||||
cell = table[(0, j)]
|
||||
cell.set_facecolor("#7dd3fc") # cyan-300
|
||||
cell.set_text_props(weight="bold")
|
||||
|
||||
# Style all cells
|
||||
for (row, col), cell in table.get_celld().items():
|
||||
if row == 0:
|
||||
cell.set_text_props(weight="bold", fontsize=13)
|
||||
cell.set_edgecolor("#333333")
|
||||
cell.set_linewidth(1.5)
|
||||
else:
|
||||
cell.set_edgecolor("#666666")
|
||||
cell.set_linewidth(0.8)
|
||||
cell.set_text_props(fontsize=10)
|
||||
# Row specific styling - match notebook colors exactly
|
||||
colors = ["#fecaca", "#fecaca", "#fef08a", "#bbf7d0", "#bbf7d0"]
|
||||
|
||||
# HR BPM row is at index 2 (0-based in data) -> row 3 in table (0 is header)
|
||||
for j in range(len(columns)):
|
||||
cell = table[(3, j)]
|
||||
cell.set_facecolor(colors[j])
|
||||
cell.set_text_props(weight="bold")
|
||||
|
||||
# Breathing row is at index 7 -> row 8 in table
|
||||
for j in range(len(columns)):
|
||||
cell = table[(8, j)]
|
||||
cell.set_facecolor(colors[j])
|
||||
cell.set_text_props(weight="bold")
|
||||
|
||||
# Add title matching notebook
|
||||
plt.title(
|
||||
"Personalized Heart Rate Zones", fontsize=16, fontweight="bold", pad=5
|
||||
)
|
||||
plt.tight_layout()
|
||||
|
||||
if save_as_base64:
|
||||
buf = io.BytesIO()
|
||||
@@ -1535,7 +1528,6 @@ class GraphGenerator:
|
||||
bbox_inches="tight",
|
||||
dpi=300,
|
||||
facecolor="white",
|
||||
pad_inches=0.1,
|
||||
)
|
||||
plt.close(fig)
|
||||
buf.seek(0)
|
||||
@@ -1549,7 +1541,6 @@ class GraphGenerator:
|
||||
bbox_inches="tight",
|
||||
dpi=300,
|
||||
facecolor="white",
|
||||
pad_inches=0.1,
|
||||
)
|
||||
plt.close(fig)
|
||||
return str(output_path)
|
||||
|
||||
Reference in New Issue
Block a user