Skip to content

Emit plotly_animatingframe event on animated frames #953

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

Merged
merged 5 commits into from
Sep 20, 2016

Conversation

rreusser
Copy link
Contributor

This PR emits an event called plotly_animatingframe at the beginning of each frame animation. The data argument contains the name of the frame.

Together with the internal event emitter, this is a prerequisite for hooking up the slider so that there's an event to listen to to know which frame is being animated.

Plus, it just seems like a reasonable thing to implement.

@@ -2274,6 +2274,8 @@ Plotly.animate = function(gd, frameOrGroupNameOrFrameList, animationOpts) {
var newFrame = trans._currentFrame = trans._frameQueue.shift();

if(newFrame) {
gd.emit('plotly_animatingframe', newFrame.name);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Have you thought about adding more fields to the event data?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah. I have nothing against that since there's not another way to query frames by name short of looking it up yourself in the input data. What other fields do you think are relevant? I see:

transitionOpts, frameOpts, frame (the data itself), name.

Maybe all of them? They're just references, so not really any extra cost. Could pass as an object.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Making the event data an object seems like the way to go in case we want to add more stuff in their at some point.

@@ -2219,7 +2219,7 @@ Plotly.animate = function(gd, frameOrGroupNameOrFrameList, animationOpts) {

var nextFrame = {
frame: computedFrame,
name: frameList[i].name,
name: frameList[i].name || computedFrame.name,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why do need a fallback here?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's not a bad point. I can move that elsewhere (being careful not to mutate the user input itself) for this particular case. (It's the case when a plain object is provided instead of the name of a frame.)

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No need to move it. I was just curious.

How hard would it to be to add a test for that case? If not so hard, then let's add one,

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good catch. Moved. I added an extra container for frames internally so that I'm not cramming any extra properties together that could conceivably conflict.

@rreusser
Copy link
Contributor Author

Okay, fixed my broken tests. Once circleci is happy, that's all I have here.

@etpinard etpinard added this to the v1.18.0 milestone Sep 20, 2016
@etpinard
Copy link
Contributor

Looks good 💃

@rreusser rreusser merged commit de6a183 into master Sep 20, 2016
@rreusser rreusser deleted the animation-frame-events branch September 20, 2016 21:21
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature something new
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants