JetBrains / lets-plot

Multiplatform plotting library based on the Grammar of Graphics
https://lets-plot.org
MIT License
1.5k stars 47 forks source link

Auto width API #488

Closed agusakow closed 2 years ago

agusakow commented 2 years ago

It would be great to provide API for rendering plot with auto-detected width adopted to the container width. Right now it's possible to set only fixed sizes, which leads to unnecessary scrollbars on publishing.

Possible scenario:

(see example at https://datalore.jetbrains.com/view/notebook/wB6Vq1oKU3GniCi1i05l2X)

In general, we couldn't solve this problem at the Datalore side, as we don't know if this html output was produced by Lets plot or not. Even if we will make hacks and provide this information from kernel, we will need some Lets plot js API to interact with, and this will require customizing exporting notebooks and rendering at publishing side for Lets plot. Also, it's will not fix rendering exported notebooks at other viewers (nbviewer for example).

Proposal:

Provide Lets plot API to specify rendering dimensions strategy, it could be fixed (using ggsize) or auto-detected. This will allow user to control rendered plot dimensions and as a bonus automatically supported by all viewers, not only Datalore.

alshan commented 2 years ago

We can have a flag to scale plots down proportionally (keeping its aspect ratio) in case a plot's width exceeds the container width.

Yet IMO it will often have adverse effect on Datalore publications as a published container there is so dramatically narrower then one in notebook.

alshan commented 2 years ago

@agusakow In the recent Lets-Plot release v2.3.0 plot automatically adjust size in case its width exceeds the width of container. This should prevent unnecessary scrollbars to appear. We didn't introduce any new API for configuring plots behavior regarding their size but we can do it later if needed.

Please check if this is working well with Datalore reports.