Skip to content
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

Save static image #51

Closed
wronk opened this issue Aug 26, 2015 · 7 comments
Closed

Save static image #51

wronk opened this issue Aug 26, 2015 · 7 comments

Comments

@wronk
Copy link

wronk commented Aug 26, 2015

I dabble in some graph theory, and it would be great to have a way to save your visualizations to a image and/or vector format for non-web formats. Something like matplotlib's img.savefig('my_path') would be awesome (even though it throws away all the interactive functionality).

@mathisonian
Copy link
Member

hey @wronk,

We currently have an endpoint that exposes the visualizations as images, with the following URL structure:

/visualizations/<visualization-id>/screenshot/?width=<width-in-pixels>&height=<height-in-pixels>

e.g. running locally:

http://localhost:3000/visualizations/34cc6441-5078-4d7a-b29f-2032e0e39071/screenshot/?width=1024&height=768

there's a shortcut to this link that can be accessed from the "actions dropdown" on the server:
screen shot 2015-08-31 at 4 11 52 pm

@wronk
Copy link
Author

wronk commented Aug 31, 2015

Awesome, thanks. Is there any way to do that within a script?

@mathisonian
Copy link
Member

(assuming you are in the python client)

There's no builtin method in the client right now, but you could do it like this:

# imports and initialize client
import urllib
from lightning import Lightning
lgn = Lighting()

data = [1, 2, 3, 4, 5]
viz = lgn.line(data)

image_url = viz.get_perma_link() + '/screenshot'
# or with size parameters
# image_url = viz.get_perma_link() + '/screenshot?width=100&height=100'

# save it locally
# referenced from http://stackoverflow.com/questions/8286352/how-to-save-an-image-locally-using-python-whose-url-address-i-already-know
urllib.urlretrieve(image_url, "local-filename.png")

I would be happy to accept a PR encapsulating this functionality into the python client. If you want to take a shot it can be as straightforward as adding an additional method to the visualization class here

@freeman-lab
Copy link
Member

Yup I think that's what we're missing. Two things would probably be good to have:

  1. A save_png method in the client when running against a server that can use the route @mathisonian pointed to

  2. A way to do the same in the server-less mode, which will most likely need to work slightly differently.

We can start by adding (1) to the Python client, and then try to tackle (2).

---------------------------jeremyfreeman.net

@thefreemanlab

On Mon, Aug 31, 2015 at 2:58 PM, wronk [email protected] wrote:

Awesome, thanks. Is there any way to do that within a script?

Reply to this email directly or view it on GitHub:
#51 (comment)

@mathisonian
Copy link
Member

yeah, (2) is going to need to use something like http://html2canvas.hertzen.com/ or a similar approach

@wronk
Copy link
Author

wronk commented Sep 5, 2015

@mathisonian, I probably won't get to it anytime soon, but I'll let you guys know on this thread the moment it moves up on my priority list :)

@mathisonian
Copy link
Member

sounds good @wronk, let us know if you run into anything else.

I've created an issue on the python client: lightning-viz/lightning-python#29, going to close this in favor of that one

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants