PlotlyJS.jl icon indicating copy to clipboard operation
PlotlyJS.jl copied to clipboard

kaleido/savefig for any objects outside PlotlyJS.jl

Open joshday opened this issue 2 years ago • 11 comments

It appears (https://github.com/JuliaComputing/PlotlyLight.jl/issues/8) that PlotlyJS.savefig works out of the box for PlotlyLight.Plots if you simply remove the type annotations in the savefig code.

How would ya'll feel about one of these options?

  1. Put the savefig code in its own package. Then PlotlyJS wouldn't need to depend on Kaliedo_jll.
  2. Remove the type annotations in the savefig code, so other Plotly packages could take advantage of it.

joshday avatar Apr 29 '22 15:04 joshday

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)

sglyon avatar May 03 '22 05:05 sglyon

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))

joshday avatar May 03 '22 21:05 joshday

Somehow related to https://github.com/JuliaPlots/PlotlyJS.jl/issues/428

disberd avatar May 13 '22 14:05 disberd

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 avatar Aug 24 '22 15:08 BeastyBlacksmith

@BeastyBlacksmith happy to consider something here. What would you propose?

sglyon avatar Aug 25 '22 02:08 sglyon

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.

BeastyBlacksmith avatar Aug 25 '22 07:08 BeastyBlacksmith

Any volunteers to create it? I'll get to it next week (probably) if there are no takers.

joshday avatar Aug 25 '22 13:08 joshday

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

BeastyBlacksmith avatar Aug 25 '22 14:08 BeastyBlacksmith

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)

sglyon avatar Aug 25 '22 19:08 sglyon

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)

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.

BeastyBlacksmith avatar Aug 26 '22 07:08 BeastyBlacksmith

I made a first version here: https://github.com/JuliaPlots/Kaleido.jl

BeastyBlacksmith avatar Aug 26 '22 12:08 BeastyBlacksmith