Code Monkey home page Code Monkey logo

Comments (10)

benbovy avatar benbovy commented on May 14, 2024

To reproduce the issue: https://github.com/fastscape-lem/gilbert-board

from ipycanvas.

martinRenou avatar martinRenou commented on May 14, 2024

Thanks for filling this issue! I'll give it a try. Are you running voila with --enable_nbextensions=True?

from ipycanvas.

benbovy avatar benbovy commented on May 14, 2024

Are you running voila with --enable_nbextensions=True

Just tried it but no apparent effect.

from ipycanvas.

martinRenou avatar martinRenou commented on May 14, 2024

It seems like the first commands are lost in the void... Never received by the Canvas. I will investigate a bit.

from ipycanvas.

martinRenou avatar martinRenou commented on May 14, 2024

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.

martinRenou avatar martinRenou commented on May 14, 2024

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.

benbovy avatar benbovy commented on May 14, 2024

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.

benbovy avatar benbovy commented on May 14, 2024

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.

martinRenou avatar martinRenou commented on May 14, 2024

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.

martinRenou avatar martinRenou commented on May 14, 2024

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)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.