Skip to content

Commit

Permalink
Add some additional debugging
Browse files Browse the repository at this point in the history
  • Loading branch information
agriyakhetarpal committed Dec 10, 2024
1 parent 09abbb4 commit 334d6d1
Showing 1 changed file with 33 additions and 0 deletions.
33 changes: 33 additions & 0 deletions matplotlib_pyodide/html5_canvas_backend.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
"html5_canvas_backend is only supported in the browser in the main thread"
) from err
from pyodide.ffi import create_proxy
from pyodide.ffi.wrappers import set_timeout

_capstyle_d = {"projecting": "square", "butt": "butt", "round": "round"}

Expand Down Expand Up @@ -311,14 +312,28 @@ def _draw_math_text_path(self, gc, x, y, s, prop, angle):
angle : float
The rotation angle in degrees
"""
import sys

print(f"Drawing math text: '{s}' at ({x}, {y})", file=sys.stderr) # noqa: B907

# Parse the math text to get paths and metrics
width, height, depth, glyphs, rects = self.mathtext_parser.parse(
s, dpi=self.dpi, prop=prop
)

print(
f"Parsed text dimensions: {width}x{height} (depth: {depth})",
file=sys.stderr,
)
print(f"Number of glyphs: {len(glyphs)}", file=sys.stderr)
print(f"Number of rectangles: {len(rects)}", file=sys.stderr)

# Save the canvas state
self.ctx.save()

baseline_y = self.height - y + depth
self.ctx.translate(x, baseline_y)

# Move to text position and apply rotation if needed
self.ctx.translate(x, self.height - y)
if angle != 0:
Expand Down Expand Up @@ -377,6 +392,24 @@ def _draw_math_text(self, gc, x, y, s, prop, angle):
angle : float
The rotation angle in degrees
"""

def check_fonts_loaded():
for url in self.fonts_loading:
if url in self.fonts_loading:
return False
return True

if not check_fonts_loaded():
# if fonts aren't loaded, we shall schedule a redraw
def redraw_when_ready():
if check_fonts_loaded():
self.fig.draw()
else:
set_timeout(redraw_when_ready, 50)

set_timeout(redraw_when_ready, 50)
return

try:
# Try rendering directly with paths first
self._draw_math_text_path(gc, x, y, s, prop, angle)
Expand Down

0 comments on commit 334d6d1

Please sign in to comment.