niivue / ipyniivue

A WebGL-powered Jupyter Widget for Niivue based on anywidget
BSD 2-Clause "Simplified" License
25 stars 8 forks source link

Canvas doesn't render until after resize #3 #3

Closed AnthonyAndroulakis closed 1 year ago

AnthonyAndroulakis commented 1 year ago

When initializing a new Niivue widget using the following script

from ipyniivue import Niivue

w = Niivue()
w.load_volumes([])
w 

the canvas shows up as blank with a black background. The expected result would be to see red text on the black background saying "Waiting for images...". The expected result shows only after the window has been resized.

edit: mybinder (Binder) can be used to view the bug in jupyter online

hanayik commented 1 year ago

@AnthonyAndroulakis , not sure exactly what's happening here, but the most recent version of Niivue (0.30.0) has changed how it handles the name property here https://github.com/niivue/ipyniivue/blob/825834f04feebbf07f738b80711d884867f51455/src/widget.ts#L62. I would remove the name prop unless you need it for some reason (e.g. query strings in the URL, so you're not able to detect the file extension).

AnthonyAndroulakis commented 1 year ago

I'm working on moving to to the latest Niivue version. #4 details an issue I had when I last tried to move it over. edit: fixed issue #4

AnthonyAndroulakis commented 1 year ago

I was able to make a widget that just draws a point to a canvas with a webgl2 canvas (and get it to display without having to resize). I'm thinking perhaps the issue lies with not using await/async when using Niivue. For reference, I am using https://observablehq.com/@jozanza/webgl2-drawing-points to test the webgl2 context.

update: I tried using async/await and it did not fix the issue.

neurolabusc commented 11 months ago

@AnthonyAndroulakis I can not run your demo:

Looking for: ['jupyterlab=3', 'pip', 'ipyevents', 'ipywidgets', 'jupyter_ui_poll', 'traitlets']

Could not solve for environment specs
The following package could not be installed
└─ jupyter_ui_poll does not exist (perhaps a typo or a missing channel)

I do wonder if we need to await the canvas:

document.onreadystatechange = function () {
    if (document.readyState === "interactive") {
        // Your code.
    }
}
christian-oreilly commented 11 months ago

Check if jupyter-ui-poll works, instead of jupyter_ui_poll. I remember having an issue like that at some point. I think I probably fixed that in a PR that is currently stocked due to other issues presumably Java-side.

Best,

Christian

On Sun, Sep 24, 2023 at 4:40 PM Chris Rorden @.***> wrote:

@AnthonyAndroulakis https://github.com/AnthonyAndroulakis I can not run your demo:

Looking for: ['jupyterlab=3', 'pip', 'ipyevents', 'ipywidgets', 'jupyter_ui_poll', 'traitlets']

Could not solve for environment specs The following package could not be installed └─ jupyter_ui_poll does not exist (perhaps a typo or a missing channel)

I do wonder if we need to await the canvas https://stackoverflow.com/questions/49491139/canvas-sometimes-does-not-resize-to-width-and-height :

document.onreadystatechange = function () { if (document.readyState === "interactive") { // Your code. } }

— Reply to this email directly, view it on GitHub https://github.com/niivue/ipyniivue/issues/3#issuecomment-1732664534, or unsubscribe https://github.com/notifications/unsubscribe-auth/ABNIPGST3HBYP7MQVKHS47TX4CLDZANCNFSM6AAAAAAQ643S3Q . You are receiving this because you are subscribed to this thread.Message ID: @.***>