Skip to content

Commit bd8c4b8

Browse files
committed
filter: build target category list before applying filter fn
1 parent 5da21cb commit bd8c4b8

File tree

2 files changed

+37
-1
lines changed

2 files changed

+37
-1
lines changed

src/transforms/filter.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -184,7 +184,13 @@ function getDataToCoordFunc(gd, trace, target) {
184184
type: autoType(target),
185185
_categories: []
186186
};
187+
187188
setConvert(ax);
189+
190+
// build up ax._categories (usually done during ax.makeCalcdata()
191+
for(var i = 0; i < target.length; i++) {
192+
ax.d2c(target[i]);
193+
}
188194
}
189195
else {
190196
ax = axisIds.getFromTrace(gd, trace, target);

test/jasmine/tests/transform_filter_test.js

Lines changed: 31 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -638,7 +638,7 @@ describe('filter transforms calc:', function() {
638638
expect(out[0].transforms[0].target).toEqual([0, 0, 0]);
639639
});
640640

641-
it('with categorical items', function() {
641+
it('with categorical items and *{}*', function() {
642642
var out = _transform([Lib.extendDeep({}, _base, {
643643
transforms: [{
644644
target: ['a', 'a', 'b', 'b', 'a', 'b', 'a'],
@@ -651,6 +651,36 @@ describe('filter transforms calc:', function() {
651651
expect(out[0].transforms[0].target).toEqual(['b', 'b', 'b']);
652652
});
653653

654+
it('with categorical items and *<* & *>=*', function() {
655+
var out = _transform([{
656+
x: [1, 2, 3],
657+
y: [10, 20, 30],
658+
transforms: [{
659+
type: 'filter',
660+
operation: '<',
661+
target: ['a', 'b', 'c'],
662+
value: 'c'
663+
}]
664+
}, {
665+
x: [1, 2, 3],
666+
y: [30, 20, 10],
667+
transforms: [{
668+
type: 'filter',
669+
operation: '>=',
670+
target: ['a', 'b', 'c'],
671+
value: 'b'
672+
}]
673+
}]);
674+
675+
expect(out[0].x).toEqual([1, 2]);
676+
expect(out[0].y).toEqual([10, 20]);
677+
expect(out[0].transforms[0].target).toEqual(['a', 'b']);
678+
679+
expect(out[1].x).toEqual([2, 3]);
680+
expect(out[1].y).toEqual([20, 10]);
681+
expect(out[1].transforms[0].target).toEqual(['b', 'c']);
682+
});
683+
654684
it('with dates items', function() {
655685
var out = _transform([Lib.extendDeep({}, _base, {
656686
transforms: [{

0 commit comments

Comments
 (0)