Open MaximeBouton opened 6 years ago
I don't think there is a built-in way (which is a little frustrating). You can save it to a png and use imshow()
from Images.jl or save it as an svg and use the browser.
My only ideas to implement it are the ones in D3Trees.jl (blink()
and inchrome()
).
Thanks, I will look into it. I have not been able to render in Juno either.
There used to be some code for launching a GTK window.
With some help from the julia slack, here is a MWE:
using Gtk
using Cairo
using AutomotiveDrivingModels
using AutoViz
roadway = gen_stadium_roadway(4, length=100.0)
img = AutoViz.render(roadway) # cairo surface
c = @GtkCanvas()
win = GtkWindow(c, "Canvas")
@guarded draw(c) do widget
ctx = getgc(c)
h = height(c)
w = Gtk.width(c)
img_w = image.width;
img_h = image.height;
translate(ctx, w/2, h/2); # go to center
scale(ctx, w/img_w, h/img_h); # scale to image size
translate(ctx, -0.5*img_w, -0.5*img_h);
set_source_surface(ctx, img, 0, 0);
paint(ctx);
end
show(c)
@zsunberg do you have any recommendations on how to wrap that into a Base.show
method?
or is it better to have an AutoViz.gtk_render
function for triggering this rendering?
I think we implement this
show(io::IO, MIME"image/svg+xml", img::WhateverTypeIMGIs)
Then users can use whatever display they want, e.g.
julia> using ElectronDisplay
julia> display(img)
We should also probably implement it for other image types, e.g.
show(io::IO, MIME"image/png", img::WhateverTypeIMGIs)
The relevant documentation is here: https://docs.julialang.org/en/v1/base/io-network/index.html#Multimedia-I/O-1
Maybe we should make BrowserDisplay.jl
that just pops up html-y things in a browser when display
is called.
The output type returned by AutoViz is a CairoSurface
object, I was a little concerned about having a method show(io, MIME"image/png", img::CairoSurface)
within AutoViz as I thought it should belong to Cairo?
Shouldn't we implement a display
function rather than show
then?
e.g. display(::ElectronDisplay, x::CairoSurface)
, display(::GtkDisplay, x::CairoSurface)
From the documentation, display
chooses "the richest supported multimedia output". I don't understand how that works, let say I am in the REPL, how would it distinguish between using an electron vs Gtk window for example?
Oh, hmm...
Yeah, I think implementing either show
or display
in this case is piracy.
Is that show
method already implemented for CairoSurface
? If so, maybe display
will just work.
Ha, yes
julia> using AutomotiveDrivingModels, ElectronDisplay, AutoViz
julia> roadway = gen_stadium_roadway(4, length=100.0)
just works.
we should add this to the docs
let say I am in the REPL, how would it distinguish between using an electron vs Gtk window for example?
You can also specify the display explicitly, i.e. display(d, s)
where d
is a gtk window display or an electron display
Ha, yes
julia> using AutomotiveDrivingModels, ElectronDisplay, AutoViz julia> roadway = gen_stadium_roadway(4, length=100.0)
just works.
I guess this is a very reasonable solution, it makes sense that it works since the rendering in the vscode plot pane and juno works as well. There does not seem to be something as easy for Gtk unfortunately. Blink + Interact also works to have a slider and navigate through the simulation.
So far I have only used AutoViz in jupyter notebook but I was never able to render from the REPL. Is there an easy way to do so/ is it even possible?