PlotlyJS.jl
PlotlyJS.jl copied to clipboard
kaleido/savefig for any objects outside PlotlyJS.jl
It appears (https://github.com/JuliaComputing/PlotlyLight.jl/issues/8) that PlotlyJS.savefig
works out of the box for PlotlyLight.Plot
s if you simply remove the type annotations in the savefig
code.
How would ya'll feel about one of these options?
- Put the
savefig
code in its own package. Then PlotlyJS wouldn't need to depend on Kaliedo_jll. - Remove the type annotations in the
savefig
code, so other Plotly packages could take advantage of it.
I’d be happy to get this working. Perhaps it belongs in Kaliedo package?
can you elaborate more on what you were thinking with (1)
can you elaborate more on what you were thinking with (1)
Please correct me if I'm mistaken, but I think we can leave off the ::Plot
type annotation
https://github.com/JuliaPlots/PlotlyJS.jl/blob/562082f9a584a22bd9bda42dc0402640b5e8f611/src/kaleido.jl#L73-L79
Then as long as p
gets JSON.json
-ed into the right format, everything should "just work".
https://github.com/JuliaPlots/PlotlyJS.jl/blob/562082f9a584a22bd9bda42dc0402640b5e8f611/src/kaleido.jl#L86-L92
(as it happens, a PlotlyLight.Plot
gets JSON.json
-ed into the right format)
I could also imagine a savefig
method that accepts the JSON string, e.g.
fig_string = """{"data": ...}"""
savefigfromjson(fig_string)
and then the yet-to-be-created Kaleido package wouldn't need to depend on JSON/JSON3. It's more verbose though, so it depends on what you want with that tradeoff.
savefigfromjson(JSON.json(myplot))
savefigfromjson(JSON3.write(myplot))
Somehow related to https://github.com/JuliaPlots/PlotlyJS.jl/issues/428
I'm much in favor of having a seperate package for saving plotly plots to different output formats.
Soft-pinning PlotlyBase to 0.7 in Plots is beginning to hurt and I'd rather avoid having Kaleido_jll
as a direct dependency.
@BeastyBlacksmith happy to consider something here. What would you propose?
I'm with @joshday here to create a Kaleido.jl package that takes a json-string and the desired output format and a target path and then creates a file.
Any volunteers to create it? I'll get to it next week (probably) if there are no takers.
I don't know much about the package, but if its just copying the stuff from src/kaleido.jl
in a seperate package, I could also do that
Yeah I think all the code is out there. Copy/paste to move it to a separate package should be the way forward.
The only potential issue is deciding how dependencies flow. Will PlotlyJS.jl depend on Kaleido.jl? If so, what types will be used for the savefig
methods in the Kaleido.jl source (if you look at src/kaledio.jl
you see we are using types from both PlotlyJS.jl and PlotlyBase.jl)
Will PlotlyJS.jl depend on Kaleido.jl? If so, what types will be used for the
savefig
methods in the Kaleido.jl source (if you look atsrc/kaledio.jl
you see we are using types from both PlotlyJS.jl and PlotlyBase.jl)
I'd say Kaleido.jl should be agnostic to any types and just work on the string representation of the plot. So I'd change that and then PlotlyJS.jl would convert its Plot objects to string before passing it to Kaleido.jl.
I made a first version here: https://github.com/JuliaPlots/Kaleido.jl