-
Notifications
You must be signed in to change notification settings - Fork 0
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
Add fancy clipboard/download plot functionality #32
Conversation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Codecov ReportAttention:
Additional details and impacted files@@ Coverage Diff @@
## main #32 +/- ##
==========================================
+ Coverage 87.37% 88.80% +1.42%
==========================================
Files 11 12 +1
Lines 206 250 +44
==========================================
+ Hits 180 222 +42
- Misses 26 28 +2
☔ View full report in Codecov by Sentry. |
Also fix some other stuff
respect config when popping out
disberd
changed the title
Add a button to copy the plot as image to the clipboard
Add fancy clipboard/download plot functionality
Oct 29, 2023
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This PR adds a button by default to allow copying the plot image to the clipboard.
The following fixes/changes have been included in this PR:
PLOT
object is now embedded inside anotherCONTAINER
div (while before it was directly sent as output). This allows use to have better control on the display, and to use this container for creating a floating re-sizeable window to customize the plot appearance before copying to clipboardplutoplotly_paste_receiver
can be used to create a small floating div that will receive and store an the PNG that is copied when pressing the clipboard icon on any PlutoPlotly plot. This is will always hold the latest copied plot and is useful for browsers like Firefox which by default disable access from javascript to the system clipboard. This effectively prevent to send the PNG directly to the clipboard in firefox and so it must be manually copied (with right-click on the image).default_plotly_template
was added to change package-wise the template used by default for plots. I personally prefer to remove the default template from PlotlyBase so this allow one to specify it once at the beginning of the notebookCheck below for a pasted example snapshot of a copied image, and further down for a video example of the feature in action (INCEPTION!)
When pressed, this make the plot a floating window that can be moved around an re-sized to customize its appearance. When the desired size is obtained, one can change ths
scale
factor (which creates higher resolution images) and can get a copy of the plot image as png on the clipboard. Clicking anywhere outside of the plot window will put back the plot inside the cell. The copied image will be a snapshot of what is currently visualized on the screenNew Copy/Download image options
Clipboard Container
The plots always have a clipboard icon on the modebar which will copy the current version of the plot as PNG on the clipboard. Upon double click, the plot container will pop out with resizable borders and fields to view/set the width, height and scale of the plot (the scale is only impacting the DPI in the generated png).
parameters of the container can be set, so that the copy (or download) button will respect the selected value of height/width/scale.
To fix a given value, it is sufficient to click on the value name and the color of the name will turn green.
Black color represent value which are not set, and red colors represent values that are set but are different from the current size of the container (clicking the clipboard icon with a red colored parameter will used the stored value of the parameter, not the current view of the plot).
An example of the popped out plot container is shown below:
Once the desired aspect ratio of the plot has been chosen, the plot can be copied with the current settings by pressing once on the clipboard icon.
Here is an example of a pasted plot obtained with this functionality and the video showing how to generate this plot below (INCEPTION!):
e675617c-8e37-4182-9cda-6c6b2c547b67.mp4
plutoplotly_paste_receiver
Unfortunately direct access to the system clipboard from Javascript is only enabled by default on chromium browsers.
On firefox for example, write access to the system clipboard is not allowed by javascript, so there needs to be some additional manual user intervention for this.
The
plutoplotly_paste_receiver
function was created for this reason, and it will insert a floating clipboard icon on the top right of the screen. This will store a copy of the last image that has been copied to the clipboard by PlutoPlotly, and it can be expanded by clicking on the icon to manually copy the image as shown below:91919e69-fe89-43a8-b082-8df3c58da4db.mp4
Download Image button
The camer icon on the modebar, used or downloading an image, is also enhanced in PlutoPlotly with similar functionality to the clipboard icon.
Once double clicking on the download image button, two additional parameters are shown:
newplot
).Similar to the clipboard, size of the plot can be adapted either by resizing the container or by setting the values in the fields of the respective parameter, and the actual download can be started by clicking once on the camera icon.
This is the container look when it is popped using the camera icon rather than the clipboard icon: