Comments (10)
To reproduce the issue: https://github.com/fastscape-lem/gilbert-board
from ipycanvas.
Thanks for filling this issue! I'll give it a try. Are you running voila with --enable_nbextensions=True
?
from ipycanvas.
Are you running voila with --enable_nbextensions=True
Just tried it but no apparent effect.
from ipycanvas.
It seems like the first commands are lost in the void... Never received by the Canvas. I will investigate a bit.
from ipycanvas.
I think I've got a workaround for your scaled image. Every time you redraw the image, you should do something like:
canvas.save()
canvas.scale(scale)
canvas.put_image_data(data, 0, 0)
canvas.restore()
EDIT: You would also need to remove the scale
call in the board constructor
And it should work.
But it does not fix the first render... I've got the feeling it can be a bug in the Voila widget manager, some comm messages that are not handled correctly when the widget is displayed.
from ipycanvas.
The problem is actually that ipycanvas
is almost stateless. And between the execution of the Notebook and the front-end initialization, some messages are sent and there is no Canvas view for receiving those messages...
I cannot think of a good way to tackle this issue right now. I can only think of ugly workarounds...
from ipycanvas.
I cannot think of a good way to tackle this issue right now. I can only think of ugly workarounds...
Thanks for investigating anyway!
Regarding the 1st render, I guess I could add a code cell in the notebook (below the one that outputs the canvas) that triggers redrawing the canvas (that will be executed but hidden in the voila
rendered dashboard).
from ipycanvas.
Regarding the 1st render, I guess I could add a code cell in the notebook (below the one that outputs the canvas) that triggers redrawing the canvas (that will be executed but hidden in the voila rendered dashboard).
Mmm it doesn't work. I guess a message has to come from the front-end then?!
from ipycanvas.
No, it cannot work... Voila waits for the entire Notebook to be executed before creating any widget view. It will eventually be fixed when Voila will support progressive widget rendering (It's on the roadmap).
What you could eventually do is execute this redraw in a separate thread in the last cell.
Something like: (disclaimer: this is not the final solution, this is very ugly)
from time import sleep
from threading import Thread
class Redraw(Thread):
def __init__(self, canvas):
self.canvas = canvas
super(Redraw, self).__init__()
def run(self):
sleep(1) # wait one or two seconds and hope that the frontend has time to initialize
# redraw here
# ...
Redraw(canvas).start()
from ipycanvas.
I'm thinking of adding an event on the Canvas that will be triggered when the front-end is ready, so you know when you need to redraw the Canvas. It would allow you to do that more properly.
from ipycanvas.
Related Issues (20)
- How to get the new path HOT 7
- add width, height support to put_image_data HOT 1
- How to add transform to Path2D HOT 6
- voila fails to load ipycanvas.js from localhost HOT 2
- how to drag an image around on the canvas? HOT 2
- bundle text and shape into one object HOT 4
- ipycanvas does not work with JupyterLab 4 HOT 4
- debug_output only works if calling display(canvas) HOT 1
- ipycanvas 0.13.1 does not work with google colab. 0.13 works. HOT 1
- Take a screenshot of a drawing/canvas and save it? HOT 2
- current canvas out of sync after page reload
- Commands JSON content mangled HOT 3
- Error displaying widget: model not found HOT 1
- is there no call to remove a shape? HOT 1
- bug on canvas.clear() HOT 1
- any way to pause animation? HOT 2
- feature request for mouse drag HOT 2
- Using Path2D for stroke
- Error with fresh jupyterlab 3 install - "Failed to load model class" / "Error: No version of module ipycanvas is registered" HOT 3
- The docs link to github needs updating HOT 5
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from ipycanvas.