Closed oxinabox closed 3 years ago
The reason I want this is that then FileIO.jl will work on figures and thus ReferenceTests.jl will work on them
Thanks for the suggestion. To be honest the way in which show
works for mime types different from text escapes my knowledge. For GRUtils, I just tried to replicate what GR does. Thus, for producing png files I also wrote a savefig
function just like in GR:
https://github.com/heliosdrm/GRUtils.jl/blob/f86dfc795eab4af029291b53ab83d02a1305e748/src/frontend.jl#L1437-L1449
Any hint about what should I do to make show(::IO, "image/png", ::Figure)
work as wanted will be welcome. :pray:
Any hint about what should I do to make show(::IO, "image/png", ::Figure) work as wanted will be welcome. 🙏
I think literally copying what Plots.jl does for GR and updating the types.
Roughly speaking the way the whole display stack works: As I understand it (which may not be perfect).
High level: display(object)
calls in and asked all current stack of displays to show an object, it finds one that can and then calls show
Breakdown:
AbstractDisplay
), they advertise what mimetypes they can display via displayable(this_display, mimetype
.
text/plain
(you actually have 2 but anyway, both are just text)InlineDisplay
that can do those inline bubblesPlotsDisplay
that can do various kinds of images.showable(mimetype, object)
showable
by this object and calls show(displays_own_io, best_mimetype, object)
@oxinabox: I'm not sure if #94 fixes the issue in all the relevant cases. Can you try it please? I've made the change only for png and svg, which are the image formats that I have more or less clear how GR deals with.
Probably I could extend this for video formats (MIME"video/mp4"
and `MIME"video/webm"). For other formats (pdf, ps...) this straightforward solution does not work.
@oxinabox : is this issue solved by #94?
sorry, testing this is in my TODO, but I haven't gotten around to it yet
Tested. Works well for me
If i run
show(::IO, "image/png", figure)
from the REPL it will do nothing. (andshowable
will return false) It would be useful if it actually did the thing. we have the technology in GR to save things as PNG In GR.jl: (for a filename) https://github.com/jheinen/GR.jl/blob/39d9cea254d4747ae7db55fdcbca38bc5a92bc17/src/jlgr.jl#L2495-L2501In Plots.jl (i think easier to apply since it is already a IO) https://github.com/JuliaPlots/Plots.jl/blob/514a7c4fffd05441cf2e3dd1d444f40def7ba7ad/src/backends/gr.jl#L1765-L1788
As I understand it, right now,
show(io, mimetype, ::Figure)
only works ifGR.mime_type
is set to the right thing. AFAICTGR.mime_type
is a weird global constant the GR sets at start time deoending on if it detect that it is in JuPyTer/Pluto or a bunch of other conditions. I don't get it, and I suspect it is evil, but it is out of scope here.