VEuPathDB / web-monorepo

A monorepo that contains all frontend code for VEuPathDB websites
Apache License 2.0
2 stars 0 forks source link

Add "Export to SVG" button to plots #793

Closed dmfalke closed 4 months ago

dmfalke commented 4 months ago

Closes #780

This PR adds a button to export plots as an SVG file. Plots made with plotly.js are using Plotly.toImage. Plots made with visx are using a custom function to export the SVG directly.

When exporting visx plots, the backgound is transparent. All of the elements are there, so it's possible to open the exported svg file in an editor and give it a white background. I think it would be better to make it white by default, but I'm not sure how to do that. Maybe @asizemore has some ideas?

The button is using coreui styling, and is positioned to the bottom-right of the plot:

image

It would be great to get some testing done with this. Specifically, does this meet the requirements for being able to modify the plot for other uses? Should we allow the user to choose other formats (png, jpeg, etc)? It might make sense to get this on qa soon, so that Dan Beiting, et al, can play with it.

asizemore commented 4 months ago

I've just tested so far, but the things ive tested (box, volcano, network) work great! I've been opening them in illustrator and they look really nice. The volcano opens with a black box over it, which is odd but once i deleted it the whole plot was there. This doesn't bother me, personally, because i'm used to weird objects showing up in svgs when i download them from places. In the same vein, it doesn't bother me at all that the background is not white. In fact the first thing i (again, just me personally) do when i would download an svg like this is to immediately delete the background. When these are going into figures or presentations, the background rectangle just gets in the way.

The one question i had was it looks like the bipartite network has the Export button within the plot div. Was that intentional? All the others, even the visx volcano, are just below the bottom of the plot panel.

asizemore commented 4 months ago

I'll check out the code tomorrow!

dmfalke commented 4 months ago

I've just tested so far, but the things ive tested (box, volcano, network) work great! I've been opening them in illustrator and they look really nice. The volcano opens with a black box over it, which is odd but once i deleted it the whole plot was there. This doesn't bother me, personally, because i'm used to weird objects showing up in svgs when i download them from places. In the same vein, it doesn't bother me at all that the background is not white. In fact the first thing i (again, just me personally) do when i would download an svg like this is to immediately delete the background. When these are going into figures or presentations, the background rectangle just gets in the way.

Thanks, this is very useful feedback! :smile:

The one question i had was it looks like the bipartite network has the Export button within the plot div. Was that intentional? All the others, even the visx volcano, are just below the bottom of the plot panel.

This was an oversight. I will fix it up.

dmfalke commented 4 months ago

This was an oversight. I will fix it up.

Upon further investigation, the styling for bpnet viz looks a little different than volcano viz. I'll try to fix it up in a bit.

asizemore commented 4 months ago

I forgot to say, another thing i like about the button and its placement is that it makes expanding download options easy. For example if we also had a button for download png, and one for download data, etc., it's obvious where those all go.

dmfalke commented 4 months ago

I forgot to say, another thing i like about the button and its placement is that it makes expanding download options easy. For example if we also had a button for download png, and one for download data, etc., it's obvious where those all go.

I was envisioning a dropdown with a "Download" or "Export" label. Thoughts?

asizemore commented 4 months ago

I was envisioning a dropdown with a "Download" or "Export" label. Thoughts?

That works for me!

dmfalke commented 4 months ago

I pushed a change to allow the user to choose their export format:

image

asizemore commented 4 months ago

Looking good! Testing now:

Some screenshots:

Screen Shot 2024-01-31 at 6 56 52 AM Screen Shot 2024-01-31 at 7 00 00 AM

I think at this point just the button placement and png output for the bipartite network are the only things that are worth updating if you don't mind! I'm still not worried about the black box on the volcano plot, since the underlying plot is still there.

I'm sorry for the slowness in review!

dmfalke commented 4 months ago

Thanks for the review!

Regarding button placement for bipartite, this is what I see:

image

I still don't know how to get a bipartite graph, so I didn't look at the output images. Maybe you can share an analysis that has a good bipartite viz?

asizemore commented 4 months ago

I should have also mentioned, to get the Generate Results button to show up, just modify any of those Prefilter Inputs. We introduced a bug in those prefilter inputs and i haven't had a chance to fix it yet

dmfalke commented 4 months ago

Oh, I misread what you said about the button placement for bipartite. I thought you said "way up on the right", but now I see it says "way on the right". I will try to fix!

dmfalke commented 4 months ago

I have made the following changes, which I hope address the immediate issues:


Screenshots

Facet plots image

Error image

dmfalke commented 4 months ago

I made an issue to look into PNG issues: https://github.com/VEuPathDB/web-monorepo/issues/818

dmfalke commented 4 months ago

I wonder if the issue with scatter is that we're using webgl to render the points.

I'm not sure what changes would have impacted the layout for bipartite. I'll take a quick look.

Also, I forgot that I was going to look at changing dimensions for bipartite.

I will spend a little bit of time trying to address these issues. I'll post an update by this afternoon.

dmfalke commented 4 months ago

Okay, I pushed fixed for the issues you mentioned:

Let me know what you think :crossed_fingers:

asizemore commented 4 months ago

Thanks @dmfalke !

Scatterplots: check! Points are just an image for plots with more than 1000 points, and they are svg objects when plots have < 1000 points.

Bipartite network button placement: check! Looks good!

Bipartite network png: check! Also looks great!

lgtm! 🎸

dmfalke commented 4 months ago

Thanks! Let's rock and roll 🎸 🤘