Skip to content

Improved animation merging for layout and traces #1041

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 9 commits into from
Oct 17, 2016

Conversation

rreusser
Copy link
Contributor

@rreusser rreusser commented Oct 14, 2016

This PR adds some nuance to extendDeepNoArrays with Lib.extendTrace and Lib.extendLayout. It manually dives into container arrays to allow more animation compatibility. Specifically, it removes the blocker for transform animations:

Plotly.animate(gd, {'transforms[0].value': 7})

To do:

  • Make expandObjectPaths handle a couple more array corner cases. This functionality is unused at the moment, but it should be correct.
  • Test that it also works in Plotly.animate (arises in both Plots.transition and Plotly.animate)
  • Confirm existing tests pass

@rreusser rreusser added bug something broken feature something new status: in progress labels Oct 14, 2016
@rreusser
Copy link
Contributor Author

rreusser commented Oct 14, 2016

@etpinard A brief explanation of how merging frames works and why this exists.

  1. It copies the input frame with extendDeepNoArrays so that the original frame definitions don't get mangled.
  2. It expands paths in the copied input. That is, a frame with {'line.color': 'red'} gets expanded into {line: {color: 'red'}}
  3. It merges those changes into the destination trace using extendDeepNoArrays.

The reason for this PR: To get this process working with container arrays, it was not enough to simply recurse into container objects. expandObjectPaths did not previously know about array notation so that it was unable to expand things like {transforms[0].operation: '='}. Step 2 now expands arrays.

In case you're wondering, yes, it uses objectFromPath so it's not entirely duplicating functionality. I could have used objectFromPath to recurse slightly differently, but I think the result would be the same.

@etpinard etpinard added this to the v1.19.0 milestone Oct 17, 2016
// scoping vs. recompilation tradeoff, but at least it's not just inlining it into
// the inner loop.
var dottedPropertyRegex = /^([^\[\.]+)\.(.+)?/;
var indexedPropertyRegex = /^([^\.]+)\[([0-9]+)\](\.)?(.+)?/;

lib.expandObjectPaths = function(data) {
Copy link
Contributor

Choose a reason for hiding this comment

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

thanks for reusing this method 🎉

plots.extendLayout = function(destLayout, srcLayout) {
return plots.extendObjectWithContainers(destLayout, srcLayout, [
'annotations',
'shapes'
Copy link
Contributor

Choose a reason for hiding this comment

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

you're missing a few items here:

  • images
  • updatemenus
  • sliders

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ah, thanks! I didn't have a full list on hand, but yeah, designed it so should be trivial to add as needed. Will add.

plots.extendLayout = function(destLayout, srcLayout) {
return plots.extendObjectWithContainers(destLayout, srcLayout, [
'annotations',
'shapes'
Copy link
Contributor

@etpinard etpinard Oct 17, 2016

Choose a reason for hiding this comment

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

More generally, I've been thinking about adding a preprocess step that would crawl through the plot schema and output this list of array container (as determined by _isLinkedToArray) to a json file in build/. That build/ file would then be required in the relevant plotly.js src file(s).

But, that will be for a different PR ...

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Sounds good. 👍


// TODO: This test is unimplemented since it's a currently-unused corner case.
// Getting the test to pass requires some extension (pun?) to extendDeepNoArrays
// that's intelligent enough to only selectively merge *some* arrays, in particular
Copy link
Contributor

Choose a reason for hiding this comment

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

those arrays are declared as info_array e.g. pie domain.

Copy link
Contributor

Choose a reason for hiding this comment

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

Does

var input = {'marker[1].range': [4, 5] };
Lib.expandObjectPaths(input);

// => {marker: [undefined, {range: [4, 5]}]}

??

Copy link
Contributor Author

@rreusser rreusser Oct 17, 2016

Choose a reason for hiding this comment

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

Yes, that one works. It's fairly robust when there's just one property. It's the merging of arrays that doesn't currently work.

On that note, found a simpler case that might not be okay:

Lib.expandObjectPaths({'marker.range[0]': 5, 'marker.range[1]': 2})

// => {marker: {range: [null, 2]}}

This happens because there's not a way for it to tell how deeply it should merge, i.e. whether range is an data_array or not.

Note that this case does work because the array merge is not deep:

Lib.expandObjectPaths({'range[0]': 5, 'range[1]': 2}

// => {range: [5, 2]}

Copy link
Contributor Author

Choose a reason for hiding this comment

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

My best guess at a workaround was to flag arrays that have been expanded by this routine with {_extendDeepArrays: true}, and then modify the extendDeepNoArrays to optionally extend deep if that override is set.

Copy link
Contributor Author

@rreusser rreusser Oct 17, 2016

Choose a reason for hiding this comment

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

@etpinard I added these examples to test comments so that when we regroup and come up with a more complete solution, the cases that work vs. do not work should be readily apparent. There's no regression in functionality here (the opposite, in fact), so it doesn't bother me to consider this mergable even though it's not as complete a solution as I'd like.

Side note: I've still debated just making this a deep merge with arrays since the cost of iterating through ~500 array contents is still probably an order of magnitude or two less than the cost of SVG rendering ~500 elements, which kinda gets up to the limit of what you can animate nicely with SVG anyway.

* The result is the original object reference with the new contents merged in.
*/
plots.extendTrace = function(destTrace, srcTrace) {
return plots.extendObjectWithContainers(destTrace, srcTrace, ['transforms']);
Copy link
Contributor

@etpinard etpinard Oct 17, 2016

Choose a reason for hiding this comment

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

For completeness, transforms is currently the only array containers found in data traces until perhaps #1031

👍

Copy link
Contributor

@etpinard etpinard left a comment

Choose a reason for hiding this comment

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

@etpinard etpinard removed this from the v1.19.0 milestone Oct 17, 2016
Copy link
Contributor

@etpinard etpinard left a comment

Choose a reason for hiding this comment

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

Great work 💃

'shapes',
'images',
'sliders',
'updatemenus'
Copy link
Contributor

Choose a reason for hiding this comment

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

👍

// Lib.expandObjectPaths({'marker.range[1]': 2})
//
// // => {marker: {range: [null, 2]}}
//
Copy link
Contributor

Choose a reason for hiding this comment

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

very nice 👍

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

Successfully merging this pull request may close these issues.

2 participants