mic3333 commited on
Commit
6d82cbd
·
verified ·
1 Parent(s): 86e4e85

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +30 -14
app.py CHANGED
@@ -117,34 +117,50 @@ def create_pyodide_interface():
117
  import json
118
  from js import renderPlotWithDebug
119
 
120
- def show_plot_debug(fig):
121
  try:
122
- print("=== PLOT DEBUG INFO ===")
123
 
124
- # Convert to dict and inspect
125
  fig_dict = fig.to_dict()
126
- print(f"Figure has {len(fig_dict.get('data', []))} traces")
127
 
128
- # Debug each trace
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
129
  for i, trace in enumerate(fig_dict.get('data', [])):
130
- print(f"Trace {i}: type={trace.get('type', 'unknown')}")
131
- print(f" x data: {trace.get('x', 'missing')}")
132
- print(f" y data: {trace.get('y', 'missing')}")
133
- print(f" mode: {trace.get('mode', 'default')}")
134
 
135
- # Convert to JSON for JavaScript
136
  fig_json = json.dumps(fig_dict)
137
- print(f"JSON length: {len(fig_json)} characters")
138
 
139
  # Send to JavaScript
140
  success = renderPlotWithDebug(fig_json)
141
 
142
  if success:
143
- print("✅ Plot rendered successfully!")
144
  else:
145
- print("❌ Plot rendering failed")
146
 
147
- print("=== END DEBUG INFO ===")
148
  return success
149
 
150
  except Exception as e:
 
117
  import json
118
  from js import renderPlotWithDebug
119
 
120
+ def show_plot_fixed(fig):
121
  try:
122
+ print("=== CONVERTING NUMPY TO LISTS ===")
123
 
124
+ # Get figure dict
125
  fig_dict = fig.to_dict()
 
126
 
127
+ # Fix NumPy array serialization issue
128
+ for trace in fig_dict.get('data', []):
129
+ # Convert x data if it's a NumPy array
130
+ if isinstance(trace.get('x'), dict) and 'bdata' in trace.get('x', {}):
131
+ print("Converting x data from NumPy binary to list...")
132
+ # Get the original data from the figure object
133
+ for fig_trace in fig.data:
134
+ if hasattr(fig_trace, 'x') and hasattr(fig_trace.x, 'tolist'):
135
+ trace['x'] = fig_trace.x.tolist()
136
+ print(f"X converted: {trace['x']}")
137
+ break
138
+
139
+ # Convert y data if it's a NumPy array
140
+ if isinstance(trace.get('y'), dict) and 'bdata' in trace.get('y', {}):
141
+ print("Converting y data from NumPy binary to list...")
142
+ for fig_trace in fig.data:
143
+ if hasattr(fig_trace, 'y') and hasattr(fig_trace.y, 'tolist'):
144
+ trace['y'] = fig_trace.y.tolist()
145
+ print(f"Y converted: {trace['y']}")
146
+ break
147
+
148
+ # Now the data should be proper lists
149
+ print(f"Figure has {len(fig_dict.get('data', []))} traces")
150
  for i, trace in enumerate(fig_dict.get('data', [])):
151
+ print(f"Trace {i}: x={trace.get('x')}, y={trace.get('y')}")
 
 
 
152
 
153
+ # Convert to JSON
154
  fig_json = json.dumps(fig_dict)
 
155
 
156
  # Send to JavaScript
157
  success = renderPlotWithDebug(fig_json)
158
 
159
  if success:
160
+ print("✅ Plot with converted data rendered!")
161
  else:
162
+ print("❌ Plot rendering still failed")
163
 
 
164
  return success
165
 
166
  except Exception as e: