-
-
Notifications
You must be signed in to change notification settings - Fork 1.9k
Filter transform '!=' operation and 'preservegaps' option #1589
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
Changes from 4 commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
52e9e4d
resolves #1177 - add '!=' filter operation
etpinard 3f15c73
resolves #1178 - add preservegaps filter options
etpinard bb34df2
Merge branch 'master' into filter-preservegaps
etpinard 1e0fe2f
AJ-proof filter preservegaps
etpinard 2146bdd
merge INEQUALITY_OPS with COMPARISON_OPS
etpinard File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -30,6 +30,7 @@ describe('filter transforms defaults:', function() { | |
expect(traceOut.transforms).toEqual([{ | ||
type: 'filter', | ||
enabled: true, | ||
preservegaps: false, | ||
operation: '=', | ||
value: 0, | ||
target: 'x', | ||
|
@@ -320,6 +321,120 @@ describe('filter transforms calc:', function() { | |
expect(out[0].y).toEqual([1]); | ||
}); | ||
|
||
it('should preserve gaps in data when `preservegaps` is turned on', function() { | ||
var out = _transform([Lib.extendDeep({}, base, { | ||
transforms: [{ | ||
type: 'filter', | ||
preservegaps: true, | ||
operation: '>', | ||
value: 0, | ||
target: 'x' | ||
}] | ||
})]); | ||
|
||
expect(out[0].x).toEqual([undefined, undefined, undefined, undefined, 1, 2, 3]); | ||
expect(out[0].y).toEqual([undefined, undefined, undefined, undefined, 2, 3, 1]); | ||
expect(out[0].marker.color).toEqual([undefined, undefined, undefined, undefined, 0.2, 0.3, 0.4]); | ||
}); | ||
|
||
it('two filter transforms with `preservegaps: true` should commute', function() { | ||
var transform0 = { | ||
type: 'filter', | ||
preservegaps: true, | ||
operation: '>', | ||
value: -1, | ||
target: 'x' | ||
}; | ||
|
||
var transform1 = { | ||
type: 'filter', | ||
preservegaps: true, | ||
operation: '<', | ||
value: 2, | ||
target: 'x' | ||
}; | ||
|
||
var out0 = _transform([Lib.extendDeep({}, base, { | ||
transforms: [transform0, transform1] | ||
})]); | ||
|
||
var out1 = _transform([Lib.extendDeep({}, base, { | ||
transforms: [transform1, transform0] | ||
})]); | ||
|
||
['x', 'y', 'ids', 'marker.color', 'marker.size'].forEach(function(k) { | ||
var v0 = Lib.nestedProperty(out0[0], k).get(); | ||
var v1 = Lib.nestedProperty(out1[0], k).get(); | ||
expect(v0).toEqual(v1); | ||
}); | ||
}); | ||
|
||
it('two filter transforms with `preservegaps: false` should commute', function() { | ||
var transform0 = { | ||
type: 'filter', | ||
preservegaps: false, | ||
operation: '>', | ||
value: -1, | ||
target: 'x' | ||
}; | ||
|
||
var transform1 = { | ||
type: 'filter', | ||
preservegaps: false, | ||
operation: '<', | ||
value: 2, | ||
target: 'x' | ||
}; | ||
|
||
var out0 = _transform([Lib.extendDeep({}, base, { | ||
transforms: [transform0, transform1] | ||
})]); | ||
|
||
var out1 = _transform([Lib.extendDeep({}, base, { | ||
transforms: [transform1, transform0] | ||
})]); | ||
|
||
['x', 'y', 'ids', 'marker.color', 'marker.size'].forEach(function(k) { | ||
var v0 = Lib.nestedProperty(out0[0], k).get(); | ||
var v1 = Lib.nestedProperty(out1[0], k).get(); | ||
expect(v0).toEqual(v1); | ||
}); | ||
}); | ||
|
||
it('two filter transforms with different `preservegaps` values should not necessary commute', function() { | ||
var transform0 = { | ||
type: 'filter', | ||
preservegaps: true, | ||
operation: '>', | ||
value: -1, | ||
target: 'x' | ||
}; | ||
|
||
var transform1 = { | ||
type: 'filter', | ||
preservegaps: false, | ||
operation: '<', | ||
value: 2, | ||
target: 'x' | ||
}; | ||
|
||
var out0 = _transform([Lib.extendDeep({}, base, { | ||
transforms: [transform0, transform1] | ||
})]); | ||
|
||
expect(out0[0].x).toEqual([0, 1]); | ||
expect(out0[0].y).toEqual([1, 2]); | ||
expect(out0[0].marker.color).toEqual([0.1, 0.2]); | ||
|
||
var out1 = _transform([Lib.extendDeep({}, base, { | ||
transforms: [transform1, transform0] | ||
})]); | ||
|
||
expect(out1[0].x).toEqual([undefined, undefined, undefined, 0, 1]); | ||
expect(out1[0].y).toEqual([undefined, undefined, undefined, 1, 2]); | ||
expect(out1[0].marker.color).toEqual([undefined, undefined, undefined, 0.1, 0.2]); | ||
}); | ||
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. Awesome, thanks for those tests. |
||
|
||
describe('filters should handle numeric values', function() { | ||
var _base = Lib.extendDeep({}, base); | ||
|
||
|
@@ -595,6 +710,23 @@ describe('filter transforms calc:', function() { | |
_assert(out, ['2015-07-20'], [1], [0.1]); | ||
}); | ||
|
||
it('with operation *!=*', function() { | ||
var out = _transform([Lib.extendDeep({}, _base, { | ||
transforms: [{ | ||
operation: '!=', | ||
value: '2015-07-20', | ||
target: 'x' | ||
}] | ||
})]); | ||
|
||
_assert( | ||
out, | ||
['2016-08-01', '2016-09-01', '2016-10-21', '2016-12-02'], | ||
[2, 3, 1, 5], | ||
[0.2, 0.3, 0.1, 0.2] | ||
); | ||
}); | ||
|
||
it('with operation *<*', function() { | ||
var out = _transform([Lib.extendDeep({}, _base, { | ||
transforms: [{ | ||
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -31,6 +31,7 @@ describe('general transforms:', function() { | |
operation: '=', | ||
value: 0, | ||
target: 'x', | ||
preservegaps: false, | ||
_module: Filter | ||
}]); | ||
}); | ||
|
@@ -66,23 +67,23 @@ describe('general transforms:', function() { | |
|
||
traceOut = Plots.supplyTraceDefaults(traceIn, 0, layout); | ||
|
||
expect(traceOut.transforms[0]).toEqual({ | ||
expect(traceOut.transforms[0]).toEqual(jasmine.objectContaining({ | ||
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, didn't know about that one, cool! |
||
type: 'filter', | ||
enabled: true, | ||
operation: '=', | ||
value: 0, | ||
target: 'x', | ||
_module: Filter | ||
}, '- global first'); | ||
}), '- global first'); | ||
|
||
expect(traceOut.transforms[1]).toEqual({ | ||
expect(traceOut.transforms[1]).toEqual(jasmine.objectContaining({ | ||
type: 'filter', | ||
enabled: true, | ||
operation: '>', | ||
value: 0, | ||
target: 'x', | ||
_module: Filter | ||
}, '- trace second'); | ||
}), '- trace second'); | ||
|
||
expect(layout._transformModules).toEqual([Filter]); | ||
}); | ||
|
@@ -118,14 +119,14 @@ describe('general transforms:', function() { | |
}], msg); | ||
|
||
msg = 'supplying the transform defaults'; | ||
expect(dataOut[1].transforms[0]).toEqual({ | ||
expect(dataOut[1].transforms[0]).toEqual(jasmine.objectContaining({ | ||
type: 'filter', | ||
enabled: true, | ||
operation: '>', | ||
value: 0, | ||
target: 'x', | ||
_module: Filter | ||
}, msg); | ||
}), msg); | ||
|
||
msg = 'keeping refs to user data'; | ||
expect(dataOut[1]._input.x).toEqual([-2, -1, -2, 0, 1, 2, 3], msg); | ||
|
@@ -144,6 +145,7 @@ describe('general transforms:', function() { | |
operation: '>', | ||
value: 0, | ||
target: 'x', | ||
preservegaps: false, | ||
_module: Filter | ||
}], msg); | ||
|
||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
Are there any interesting cases to test with two filters applied in sequence having different
preservegaps
values?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.
Not yet. I'll add one in a future commit 🚀