-
-
Notifications
You must be signed in to change notification settings - Fork 2.6k
Animations/Frames in Python API #584
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
Changes from 2 commits
cb4552c
b4c3953
54c1386
d19c6ca
efa390e
eb57218
5482b53
b2b8451
a156503
d173cbb
d17a222
49bdc97
4fbdc99
dbb386f
bd2132b
26c3714
0c7bb1c
4acc146
c195e78
6f12ba8
253228f
405e71d
c1727d8
fca8fed
587dfa5
495b015
dd20177
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -162,8 +162,15 @@ def init_notebook_mode(connected=False): | |
|
||
def _plot_html(figure_or_data, show_link, link_text, validate, | ||
default_width, default_height, global_requirejs): | ||
|
||
figure = tools.return_figure_from_figure_or_data(figure_or_data, validate) | ||
# force no validation if frames is in the call | ||
if 'frames' in figure_or_data: | ||
figure = tools.return_figure_from_figure_or_data( | ||
figure_or_data, False | ||
) | ||
else: | ||
figure = tools.return_figure_from_figure_or_data( | ||
figure_or_data, validate | ||
) | ||
|
||
width = figure.get('layout', {}).get('width', default_width) | ||
height = figure.get('layout', {}).get('height', default_height) | ||
|
@@ -185,6 +192,8 @@ def _plot_html(figure_or_data, show_link, link_text, validate, | |
plotdivid = uuid.uuid4() | ||
jdata = json.dumps(figure.get('data', []), cls=utils.PlotlyJSONEncoder) | ||
jlayout = json.dumps(figure.get('layout', {}), cls=utils.PlotlyJSONEncoder) | ||
if 'frames' in figure_or_data: | ||
jframes = json.dumps(figure.get('frames', {}), cls=utils.PlotlyJSONEncoder) | ||
|
||
config = {} | ||
config['showLink'] = show_link | ||
|
@@ -204,11 +213,30 @@ def _plot_html(figure_or_data, show_link, link_text, validate, | |
link_text = link_text.replace('plot.ly', link_domain) | ||
config['linkText'] = link_text | ||
|
||
script = 'Plotly.newPlot("{id}", {data}, {layout}, {config})'.format( | ||
id=plotdivid, | ||
data=jdata, | ||
layout=jlayout, | ||
config=jconfig) | ||
if 'frames' in figure_or_data: | ||
script = ''' | ||
Plotly.plot( | ||
'{id}', | ||
{data}, | ||
{layout}, | ||
{config} | ||
).then(function () {add_frames}).then(function(){animate}) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. That PR has been merged and is on plotly.js/master (unreleased, but coming very soon?) and makes the syntax somewhat simpler. I'd elaborate here, but the PR description explains it fairly clearly. Calling There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Okay, fantastic. I think Chris mentioned that I'd have to do some rewriting when that gets added. I'll leave it for now, but does that mean There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yeah, should just be a simplification. Long story short, given
I'm not 100% sure what that means for validation, but on a strictly abstract level, it's conceptually simple. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Oh, sorry, unless you were referring to python arguments instead of data validation… That PR just changes the call signature. Not 100% sure the other concerns, but feel free to ask whatever questions you need and I'll do my best to get you what you need. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yeah, I'm referring to this
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ah, got it. Yeah, it should permit frames. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I am still receiving the error. Anything I can do to fix? I There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Hmm… not sure. It seems like that's a whitelisting issue on the plotly (not js) side. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Okay, so after playing |
||
'''.format( | ||
id=plotdivid, | ||
data=jdata, | ||
layout=jlayout, | ||
config=jconfig, | ||
add_frames="{" + "return Plotly.addFrames('{id}',{frames}".format( | ||
id=plotdivid, frames=jframes | ||
) + ");}", | ||
animate="{" + "Plotly.animate('{id}');".format(id=plotdivid) + "}" | ||
) | ||
else: | ||
script = 'Plotly.newPlot("{id}", {data}, {layout}, {config})'.format( | ||
id=plotdivid, | ||
data=jdata, | ||
layout=jlayout, | ||
config=jconfig) | ||
|
||
optional_line1 = ('require(["plotly"], function(Plotly) {{ ' | ||
if global_requirejs else '') | ||
|
@@ -232,6 +260,7 @@ def _plot_html(figure_or_data, show_link, link_text, validate, | |
|
||
return plotly_html_div, plotdivid, width, height | ||
|
||
|
||
def iplot(figure_or_data, show_link=True, link_text='Export to plot.ly', | ||
validate=True, image=None, filename='plot_image', image_width=800, | ||
image_height=600): | ||
|
@@ -301,10 +330,10 @@ def iplot(figure_or_data, show_link=True, link_text='Export to plot.ly', | |
) | ||
# if image is given, and is a valid format, we will download the image | ||
script = get_image_download_script('iplot').format(format=image, | ||
width=image_width, | ||
height=image_height, | ||
filename=filename, | ||
plot_id=plotdivid) | ||
width=image_width, | ||
height=image_height, | ||
filename=filename, | ||
plot_id=plotdivid) | ||
# allow time for the plot to draw | ||
time.sleep(1) | ||
# inject code to download an image of the plot | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
TODO
this and link to some issue pls :)