-
-
Notifications
You must be signed in to change notification settings - Fork 104
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
jupyter_tools: fix out of order display of multiple shapes in static html #829
Conversation
Can you explain how to view this issue? All I see is just the notebook cells with no 3D view. Perhaps a screenshot would be more appropriate?
As noted in It might be a few days or longer until we get back to this, the build123d codebase is in the middle of a major refactor. |
|
I've also pushed a new commit to update the test in |
GitHub won’t show interactive output cells. Need to use nbviewer.org To see the problem more clearly, here is an example (any notebook on gist or github can be viewed on nbviewer.org, including The source code for the example |
Here is the desired result The source code used to produce the above thanks to the pull request is in a slightly different form to pull request because I'm not using the _repr_javascript/_repr_html, but using the shape_to_html function directly. |
@victorpoughon can you rebase this PR? I believe the major refactor is now complete. Also FYI, we have static type checking (mypy) passing on the codebase, so this PR will need to keep that working as well. FYI |
@jdegenstein Sure! I'll take a look, give me a few days. |
36eb3ae
to
f67c54d
Compare
I've rebased the branch. Nothing special besides reporting the old If you want to test it with the test notebook on your side:
|
After some testing, I found a bug in my code :) Using I've pushed a new commit that should fix it. The unique id is now made with |
Can you instead try |
That would work too if shape is hashable, except in the edge case where the same object is displayed more than once in the same notebook. Then div id's aren't unique. |
Codecov ReportAll modified and coverable lines are covered by tests ✅
Additional details and impacted files@@ Coverage Diff @@
## dev #829 +/- ##
==========================================
+ Coverage 96.62% 96.65% +0.03%
==========================================
Files 31 31
Lines 9142 9177 +35
==========================================
+ Hits 8833 8870 +37
+ Misses 309 307 -2 ☔ View full report in Codecov by Sentry. |
Unfortunately this change has been messed up by yet another build123d change - this time the |
fd52978
to
edf1dbd
Compare
No problem, I just rebased it moving the test to I haven't changed the div id generation as discussed by @jdegenstein though. It's still using uuid4. I think that's a better solution than hash but I'm open to changing it if you prefer. |
That is fine with me, it can always be changed later if needed., |
Thank you! |
Hello! I know we talked on discord about how you're thinking of removing the jupyter display support, but I found a bug in it and fixed it 😁
The problem
When using IPython display from jupyter_tools, there is currently an issue when exporting a notebook to static html. If the notebook contains multiple calls to
display(part)
displaying multiple parts, the parts will be all displayed at the end of the notebook, instead of after the cell that calls the code.This is because the javascript code that displays the shape is only executed after the full html is loaded, and it dynamically appends a new div to the end of the notebook container when it runs. Therefore, when viewing the static html, all parts 3D models are at the end of the document. This does not happen interactively because the javascript is executed right away.
Here is a jupyter notebook that show the issue: https://gist.github.com/fouronnes/c6bee77d9895003935a83ff5db11d8ca
Interactively, it works fine. But if you convert the notebook to html with:
and open the html in firefox, all 3D widgets are at the end, which is not the intended order.
The fix
First I moved the template JS code to its own
.js
file for lisibility. I also switch to usingstring.Template
instead for f-strings, because escaping{
makes the JS code very un-canny. Subsitution with$
is more suited in this case, I think.Then in the second commit, I fix the issue by immediately returning a div with a unique ID. This creates a HTML DOM element that the javascript code can them fill with its data later.
Here is a screenshot of a side by side compare of 0.7.0 (the left) and this branch (the right). Each html page is rendered with
jupyter nbconvert ~/Downloads/build123d_fix_async_display.ipynb --execute --to html
The unknown
The only thing I'm not sure about is this piece of code (currently in dev branch):
I don't understand what this else branch is for. As far as I can tell it should never be executed, and it's producing invalid html anyway. I removed it, but I'm not sure why it was there.