Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

support html5_canvas_backend in worker #24

Closed
bugzpodder opened this issue Aug 31, 2023 · 5 comments
Closed

support html5_canvas_backend in worker #24

bugzpodder opened this issue Aug 31, 2023 · 5 comments

Comments

@bugzpodder
Copy link
Contributor

WebR uses OffscreenCanvas to support canvas renderings. Polyscript's worker doesn't do this so not sure what can be done here:
https://github.com/pyodide/matplotlib-pyodide/

import matplotlib
import numpy as np
matplotlib.use("module://matplotlib_pyodide.html5_canvas_backend")
import matplotlib.cm as cm
from matplotlib import pyplot as plt
delta = 0.025
x = y = np.arange(-3.0, 3.0, delta)
X, Y = np.meshgrid(x, y)
Z1 = np.exp(-(X**2) - Y**2)
Z2 = np.exp(-((X - 1) ** 2) - (Y - 1) ** 2)
Z = (Z1 - Z2) * 2
plt.figure()
plt.imshow(
Z,
interpolation="bilinear",
cmap=cm.RdYlGn,
origin="lower",
extent=[-3, 3, -3, 3],
vmax=abs(Z).max(),
vmin=-abs(Z).max(),
)
print("showing")
plt.show()
@WebReflection
Copy link
Contributor

polyscript supports real-main canvas out of real-main references ... not sure what you are asking here

@bugzpodder
Copy link
Contributor Author

polyscript supports real-main canvas out of real-main references ... not sure what you are asking here

ok I'll test it.

@bugzpodder
Copy link
Contributor Author

bugzpodder commented Aug 31, 2023

Here is an repo:

https://bugzpodder.pyscriptapps.com/polyscript-worker-copy-19536/latest/ [worker version]
https://pyscript.com/@bugzpodder/polyscript-worker-copy-19536/latest [non-worker version]
There is an error in the worker but seems to work on the main thread.
However something did happen and you can see a "Figure 1" in the worker demo

No big deal, this is experimental feature anyway but I thought I'd just raise this issue since I was trying it out.

related issue: pyodide/matplotlib-pyodide#6

@WebReflection
Copy link
Contributor

if the error is about that lib using from js import document you can patch the global env with js.document = xworker.window.document and hopefully call it a day.

@bugzpodder
Copy link
Contributor Author

Given this is an experimental feature https://pyodide.org/en/stable/usage/sdl.html I will close this and can revisit

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants