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

Easier figure support (Plots and Makie)

Open matthijscox-asml opened this issue 2 years ago • 7 comments

We're still thinking about easier figure support.

Right now you'd have to

  • load your favorite plotting package, let's assume either Plots.jl or Makie.jl.
  • Then make a plot
  • Find and use the savefig() function of your favorite plotting package.
  • Wrap the saved figure path into a Picture() type and add it to a Slide.

Ideally this is simplified into:

fig = plot(1:5,1:5)
pic = Picture(fig)

Or even just push the figure into a Slide directly.

Most difficult technical challenge is that we ideally want to avoid including Plots and Makie as a dependency. These are rather large dependencies that we do not want to force onto the user, as some will not want to include figures into their generated slide decks.

matthijscox-asml avatar Feb 01 '23 08:02 matthijscox-asml

I believe that Plots.jl defines the Plot type in RecipesBase.jl, which is a very lightweight package. Makie does not define its top-level type in MakieCore, its equivalent of RecipesBase, so I'm not 100% sure what you could do there, but will have a look.

Another consideration is that the dimensions of the plot could be determined by PPTX.jl, the user, or some combination of both. One would also want higher resolution figures so that they look good in a presentation or on a projector. Some sort of feedback mechanism might be required.

asinghvi17 avatar Feb 02 '23 08:02 asinghvi17

Cool, thanks for the suggestions!

Is the savefig function also defined inside RecipesBase.jl? I don't think so. And what would be a good way to include the savefig functionality then?

matthijscox-asml avatar Feb 02 '23 09:02 matthijscox-asml

I suspect not. Neither is Makie's saving functionality (using FileIO) defined in MakieCore.

You could use https://github.com/JuliaPackaging/Requires.jl to add some code which will load only when the respective library (Plots/Makie) is loaded, which overrides the Picture method with Plots.Plot or Makie.FigureLike.

Out of curiosity, what's your end goal for this package?

asinghvi17 avatar Feb 02 '23 10:02 asinghvi17

Thanks, I'll look into Requires.jl. I'd prefer to not use such trickery, but it might be the only way.

The end goal of the package is to make fancy PowerPoints easily with a few Julia commands. In the corporate world, at least at my employer, PowerPoints are often used as a kind of static portable dashboards, automatically generated by analysis scripts. People have been complaining they cannot do this from Julia.

Personally, I think if we can make tables, plots and text boxes we have a good foundation. And layout those easily on slides, maybe with a relative grid layout (I like the Makie grid layout approach). If you have ideas for other functionality, feel free to open an issue.

matthijscox-asml avatar Feb 02 '23 15:02 matthijscox-asml

Aha! I thought it was something like that. Yes, Makie has some good stuff - grid layouts are made using https://github.com/jkrumbiegel/GridLayoutBase.jl which is not too well documented but shouldn't be too hard to dive into, and basically uses the same layout syntax as Makie does. You'd just have to hook up the PowerPoint object types you currently have into the layout using something like this:

https://github.com/MakieOrg/Makie.jl/blob/156e651ffd1b20eed3f511f925c1e8ac4eed1474/src/makielayout/blocks.jl#L295-L433

Another interesting approach is https://github.com/fatteneder/MakieSlides.jl which is basically rendering presentations in Makie - either as PDFs or display them using Makie's interactive backends. This allows you to also add animations, interactive features, etc as desired which can interact with your actual data on demand.

asinghvi17 avatar Feb 02 '23 15:02 asinghvi17

I think it would be the easiest to do this via package extensions, since the user has to load the plotting library anyways

BeastyBlacksmith avatar Jul 26 '23 19:07 BeastyBlacksmith

I think it would be the easiest to do this via package extensions, since the user has to load the plotting library anyways

True, this would be a good solution, except we will break compatibility with older Julia version. Decisions, decisions...

matthijscox-asml avatar Aug 15 '23 12:08 matthijscox-asml