-
-
Notifications
You must be signed in to change notification settings - Fork 1.9k
Filter-groupby interaction #1892
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 8 commits
84164e3
9373680
9b44b4b
464b18a
7ebee7d
c742487
5668830
695ad68
1544e71
9f0600a
364f8f7
88b5673
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 |
---|---|---|
|
@@ -137,8 +137,22 @@ function pasteArray(newTrace, trace, j, a) { | |
); | ||
} | ||
|
||
// In order for groups to apply correctly to other transform data (e.g. | ||
// a filter transform), we have to break the connection and clone the | ||
// transforms so that each group writes grouped values into a different | ||
// destination. This function does not break the array reference | ||
// connection between the split transforms it creates. That's handled in | ||
// initialize, which creates a new empty array for each arrayAttr. | ||
function cloneTransforms(newTrace) { | ||
var transforms = newTrace.transforms; | ||
newTrace.transforms = []; | ||
for(var j = 0; j < transforms.length; j++) { | ||
newTrace.transforms[j] = Lib.extendDeepNoArrays({}, transforms[j]); | ||
} | ||
} | ||
|
||
function transformOne(trace, state) { | ||
var i; | ||
var i, j; | ||
var opts = state.transform; | ||
var groups = trace.transforms[state.transformIndex].groups; | ||
|
||
|
@@ -163,12 +177,14 @@ function transformOne(trace, state) { | |
|
||
var newTrace = newData[i] = Lib.extendDeepNoArrays({}, trace); | ||
|
||
cloneTransforms(newTrace); | ||
|
||
arrayAttrs.forEach(initializeArray.bind(null, newTrace)); | ||
|
||
for(var j = 0; j < len; j++) { | ||
for(j = 0; j < len; j++) { | ||
if(groups[j] !== groupName) continue; | ||
|
||
arrayAttrs.forEach(pasteArray.bind(0, newTrace, trace, j)); | ||
arrayAttrs.forEach(pasteArray.bind(null, newTrace, trace, j)); | ||
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. This isn't new here - except that the change you made reminded me how 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. 🎉 🎉 🎉 Glad to change 😄 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. @alexcjohnson @etpinard I've refactored… actually a fair amount of groupby. It was mostly trivial reordering and inlining in order to cut down on function calls and Oh, and also it was iterating over all points for each group, which is unnecessary. Now it just iterates over all points once and uses an index to pick the right expanded trace destination. |
||
} | ||
|
||
newTrace.name = groupName; | ||
|
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.
Interesting fix 👍
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 is that something we should do for all 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.
Oh hah - of course, because the original
Lib.extendDeepNoArrays({}, trace)
doesn't dive into thetransforms
array. Do we need aLib.extendDeepOnlyTheseArrays({}, trace, ['transforms'])
? 🙈This only applies to transforms that generate multiple traces, right? I do kind of like the idea of recursive transforms, but until we do something like that, that might be more inherently robust, I think we should manage this case-by-case.
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.
So…
arrayAttrs
does pick up on data_array arrays nested inside transforms. The particular challenge is executing a transform after another has created expanded traces. Because if the first transform splits it into multiple traces, then each expanded trace needs its own copy of the other transforms since they, for example, have different splittarget
orgroups
data. By expanding deep with no arrays and then cloning the data arrays (which are inarrayAttrs
, they all have their own copy that can be filtered appropriately.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.
Oh, I missed a bit of subtlety. Let me check on the identity of the split
transforms
. Unless I'm mistaken, something somewhere is cloning those… Let me dig that up.Uh oh!
There was an error while loading. Please reload this page.
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 wondered the same. The downfall of transforms at the moment is that there are too many corner cases and different things transforms might need to do to lock them down to a completely airtight state such that they can only do what they need to do. The result is that there are some patterns like this that should not be a concern of individual transforms at all but which might need to be applied to them all separately. Or if a clear pattern arises, then it can be abstracted. At the moment, the sample size is just a bit to small for me to see overarching patterns.
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 good answer. Thanks!
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.
@alexcjohnson Never mind. I read my code more carefully. I'm just manually transferring the transforms. 👍