Repository navigation
Make svg, jpeg and png images resizable in notebook. - #1832
Conversation
|
Do we really want to allow resizing raster images? Zooming looks pretty horrible. |
|
While I agree it's not perfect, I still think it's a useful capability: say giving a talk you may need to quickly resize an image so it fits on the projector... |
|
Fair point. I would at least add the |
|
And I think the svg issue does need to be fixed before we can merge this. It also doesn't work for me... |
|
I agree that rezooming matplotlib figures with the default dpi looks On Fri, Jun 1, 2012 at 10:41 AM, Fernando Perez
Brian E. Granger |
In that case, you should set maxHeight/Width to the natural height/width. Aside from preventing ugliness, this lets gives a mechanism for restoring to 'no-zoom', which this currently lacks (and I think is critical). |
|
I think I have fixed the svg problem and will push soon. |
|
What a crazy pain. I thought I had the svg resizing working properly now in FF+Webkit, but that was an illusion. I have pushed it anyways. The reason is rather subtle:
The current version works fine with svg tags that have their from IPython.core.display import SVG
SVG("""<svg>
<circle cx="100" cy="50" r="40" stroke="black"
stroke-width="2" fill="red"/>
</svg>""")I see two options:
|
|
That's rough. I think 3. is right out, because we don't want to be changing the sizes of SVGs from their natural defaults unnecessarily. |
|
Yes, 3 is bad because we would have to guess at what the correct aspect ratio was - and we would most often be wrong. |
|
Do you think we could add an option to set the curent matplotlib rc figwidth and figheight to the current size of the resized image, so that you could choose your size and rerun the plotting cell to have a nice image ? Or maybe this would be better as a plotting function decorator. |
|
Ultimately I'd like a matplotlib backend that will redraw the image |
|
The other option is that we could just remove this ability for SVG images for now. |
|
My vote would be for not having the svg resizing unless it can work well. I prefer not having a feature than having a half-broken one. It's a bummer that you've put so much effort into it without a satisfactory solution, but it just seems that life in the SVG garden is still not a very pleasant one... |
|
OK, I will pull out the svg code and leave the logic there for png and jpeg. |
|
I just tried this in combination with my SVG patch #1881. The result is that figures are much larger than the browser window, because I cranked up the Perhaps instead we can use |
|
Let's do the following. I am going to remove the svg code handling from this branch and why don't you add it to yours. It probably makes sense to do all of the svg stuff in one place. That way, this branch can be merged to get the resizable jpeg/png in place. |
|
Ok. I can't figure out how to get the width of the enclosing output area, to set the initial svg width/height. Any suggestions? element.parent.offsetWidth etc don't seem to work. |
|
This might be a bit subtle. But in general you should use the jQuery Probably On Fri, Jun 8, 2012 at 10:15 AM, Bob McElrath
Brian E. Granger |
|
Here is the code I removed for resizing SVG in case we need it later: https://gist.github.com/2897174 |
|
I think this is ready to merge now. The SVG work will be continued in #1881. |
|
The most important part of this UI for me for raster images is that there be an easy mechanism for restoring to zero-zoom. What do you have for that? |
|
Rebased. |
Make svg, jpeg and png images resizable in notebook.
|
This merge after rebase made invalid javascript syntax, rendering the notebook as a totally empty page. It was just a missing comma, so I fixed it in the online GitHub editor. I see no mechanism for restoring zero zoom. Any ideas on that? 99%/101% raster images look quite a lot worse than 100%, so this seems pretty important. |
|
This appears to have caused an additional problem: some fraction of the time (seems ~10%), plots do not appear at all when loading from a file. I would guess this is due to resize() being called while the element is invisible, and thus starting with an initial height of 0. |
|
Crap, sorry about the rebase problem Thanks for fixing it. I will On Fri, Jun 8, 2012 at 11:10 AM, Min RK
Brian E. Granger |
|
Can you clarify what you mean by "loading from a file"? On Fri, Jun 8, 2012 at 11:16 AM, Min RK
Brian E. Granger |
Opening a saved notebook with figures. |
|
Ah, crap I know what is going on. On load, we build the notebook On Fri, Jun 8, 2012 at 11:17 AM, Min RK
Brian E. Granger |
|
I just need some measurement (any measurement) upon which I can base the svg $(this).{parent()}^n.innerWidth() are all zero when append_svg is called. Cheers, Bob McElrath "The individual has always had to struggle to keep from being overwhelmed by |
|
Ahh, this is because the call to append_svg is done before the On Fri, Jun 8, 2012 at 11:23 AM, Bob McElrath
Brian E. Granger |
|
I've tried up to 6 parents up, all are zero. I think this is the same problem Brian E. Granger [[email protected]] wrote:
"The individual has always had to struggle to keep from being overwhelmed by |
|
Hmm, can you see what those parents actually are (console.log them). On Fri, Jun 8, 2012 at 11:31 AM, Bob McElrath
Brian E. Granger |
|
I moved the SVG resize code to my branch #1881, fixed some things, and added doubleclick-to-restore-size as requested by Min. You may want to copy that for png/jpeg too. I'm quite happy with the result. |
Make svg, jpeg and png images resizable in notebook.
This addresses #1193. All images are now resizable in the notebook by dragging handle in the lower R corner of the image. I am having problems with svg images not working properly, but I don't know enough about svg to fix this this second. Wondering if any of the matplotlib devs could help on this.