-
-
Notifications
You must be signed in to change notification settings - Fork 1.9k
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
Conversation
@etpinard A brief explanation of how merging frames works and why this exists.
The reason for this PR: To get this process working with container arrays, it was not enough to simply recurse into container objects. In case you're wondering, yes, it uses |
// 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) { |
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.
thanks for reusing this method 🎉
plots.extendLayout = function(destLayout, srcLayout) { | ||
return plots.extendObjectWithContainers(destLayout, srcLayout, [ | ||
'annotations', | ||
'shapes' |
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.
you're missing a few items here:
images
updatemenus
sliders
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.
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' |
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.
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 ...
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.
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 |
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.
those arrays are declared as info_array
e.g. pie domain
.
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.
Does
var input = {'marker[1].range': [4, 5] };
Lib.expandObjectPaths(input);
// => {marker: [undefined, {range: [4, 5]}]}
??
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.
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]}
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.
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.
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.
@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']); |
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.
For completeness, transforms
is currently the only array containers found in data traces until perhaps #1031
👍
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.
@rreusser looking good
After review:
- 1 blocking comment: Improved animation merging for layout and traces #1041 (comment)
- 1 question: Improved animation merging for layout and traces #1041 (review)
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.
Great work 💃
'shapes', | ||
'images', | ||
'sliders', | ||
'updatemenus' |
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.
👍
// Lib.expandObjectPaths({'marker.range[1]': 2}) | ||
// | ||
// // => {marker: {range: [null, 2]}} | ||
// |
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.
very nice 👍
This PR adds some nuance to
extendDeepNoArrays
withLib.extendTrace
andLib.extendLayout
. It manually dives into container arrays to allow more animation compatibility. Specifically, it removes the blocker for transform animations:To do:
expandObjectPaths
handle a couple more array corner cases. This functionality is unused at the moment, but it should be correct.Plotly.animate
(arises in bothPlots.transition
andPlotly.animate
)