g2nb / igv-jupyter

Extension for Jupyter which integrates igv.js
MIT License
154 stars 13 forks source link

Add image output API #15

Closed jrobinso closed 5 years ago

jrobinso commented 5 years ago

Add a method to output a png and/or svg file. See issue #1

a-slide commented 5 years ago

Hi Jim, Thanks a lot for this new version. I gave it a try this morning and it is much better than the previous one. Regarding the image output the rendering is great but for svg the picture extends outside of the image frame (when opening with inkscape for example). A nice feature would also be to have a output of the entire widget and not only the selected track.

Thanks again Adrien

jrobinso commented 5 years ago

@a-slide There is a function on igv.js browser to create an svg document for the entire browser (widget). The object of this ticket is to expose it, something like

b.to_svg()

However, where should the output go? Probably a file, not in cell output. We could open a file dialog from the browser to "download" it as we do now in the popup menus, or return it to python using a Comms message and deal with it there. Any thoughts on the right mechanism?

jrobinso commented 5 years ago

@a-slide Actually maybe cell output would be useful, then it could be saved. I suffer from having zero experience using a notebook myself and don't really have a feel for how people would use this.

a-slide commented 5 years ago

Yes I was about to suggest cell output ;) At the end of the day, the idea is to be able to share the notebook with collaborators.

Thanks.

jrobinso commented 5 years ago

OK, makes sense. Without resorting to hacks it looks like the only legit way to export cell output is from the server (python). So this might entail sending SVG to the server via a Comms message, only for the server to send it back to the client (via whatever mechanism they use) to be inserted in the DOM. I can't find any documentation on manipulating the DOM from an nbextension. If running client and server on the same machine, which I think is how most people run notebooks, this really won't matter.

On Sat, Jan 5, 2019 at 5:21 AM Adrien Leger notifications@github.com wrote:

Yes I was about to suggest cell output ;) At the end of the day, the idea is to be able to share the notebook with collaborators.

Thanks.

— You are receiving this because you were assigned. Reply to this email directly, view it on GitHub https://github.com/igvteam/igv.js-jupyter/issues/15#issuecomment-451654866, or mute the thread https://github.com/notifications/unsubscribe-auth/AA49HK3uYZFEGd50YCpaqb8nZUmNwDmyks5vAKbbgaJpZM4ZnYcA .

jrobinso commented 5 years ago

I've implemented this but it requires 2 function calls (1) browser.get_svg() (2) browser.display_svg()

The first sends a message to the front end to create an SVG image representing the current view. The SVG is then sent to the server (python) via a message and stored on the "Browser" object. The second call displays the browser in the cell. 2 calls are necessary because the messages are 1-way and asynchronous. If anyone knows a way to do this with a single call I would welcome a PR.