Skip to content
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

Display output in Juno Plot pane #18

Closed
cormullion opened this issue May 15, 2017 · 5 comments
Closed

Display output in Juno Plot pane #18

cormullion opened this issue May 15, 2017 · 5 comments

Comments

@cormullion
Copy link
Member

By loading this code:

using Juno, Hiccup

Media.media(Drawing, Media.Plot)

function Media.render(pane::Juno.PlotPane, img::Drawing)
    Media.render(pane, Hiccup.div(Hiccup.img(src=img.filename)))
end

it's sort of possible to display output in a Juno Plot pane:

screen shot 2017-05-15 at 11 08 34

However, this doesn't update when the file changes, so it's not yet working satisfactorily.

@cormullion
Copy link
Member Author

cormullion commented May 16, 2017

The code can be improved (JunoLab/Juno.jl#58) by adding a browser-fooling URL:

using Luxor
using Juno, Hiccup
Juno.media(MyType, Media.Plot)
Juno.media(MyType, Media.Graphical)

function Juno.render(pane::Juno.PlotPane, img::Drawing)
    Juno.render(pane, Hiccup.div(Hiccup.img(src=img.filename*"?$(time())")))
end

cd("/tmp")
Drawing("A6", "/tmp/t17.png")
background("grey20")
origin()
randomhue()
R = rand(30:63)
epitrochoid(R, rand(12:41), rand(5:137), :stroke)
fontsize(70)
sethue("white")
text(string(R))
finish()
display(currentdrawing)

screen shot 2017-05-16 at 10 37 46

This might be added to the Luxor package one day, perhaps when there are conditional dependencies (i.e. "load this code only if Juno is available".

@pfitzseb
Copy link

Okay, so our design idea here was that you'll only need to depend on Juno, which is super small and lightweight (because it and all it's dependecies are pure Julia) and can then call Juno.isactive() as a guard around your render definitions.
This approach shouldn't add much overhead, but still work around the conditional requirements issue. Still, it's of course up to you if you want to support native Juno plotting right now :)

@cormullion
Copy link
Member Author

Oh, it's easier than I thought... ! I'll have a crack at it today or tomorrow!

@cormullion cormullion reopened this May 16, 2017
@pfitzseb
Copy link

Great :)
Btw, you don't even need to save the svg to a file -- dumping the svg contents into the plot pane directly works too.

@cormullion
Copy link
Member Author

Added code to support Juno in this commit, see how it works...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants