Skip to content

Commit 52e9e4d

Browse files
committed
resolves #1177 - add '!=' filter operation
1 parent 00355fb commit 52e9e4d

File tree

2 files changed

+22
-1
lines changed

2 files changed

+22
-1
lines changed

src/transforms/filter.js

+5-1
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ var axisIds = require('../plots/cartesian/axis_ids');
1515
var autoType = require('../plots/cartesian/axis_autotype');
1616
var setConvert = require('../plots/cartesian/set_convert');
1717

18-
var INEQUALITY_OPS = ['=', '<', '>=', '>', '<='];
18+
var INEQUALITY_OPS = ['=', '!=', '<', '>=', '>', '<='];
1919
var INTERVAL_OPS = ['[]', '()', '[)', '(]', '][', ')(', '](', ')['];
2020
var SET_OPS = ['{}', '}{'];
2121

@@ -57,6 +57,7 @@ exports.attributes = {
5757
'Sets the filter operation.',
5858

5959
'*=* keeps items equal to `value`',
60+
'*!=* keeps items not equal to `value`',
6061

6162
'*<* keeps items less than `value`',
6263
'*<=* keeps items less than or equal to `value`',
@@ -262,6 +263,9 @@ function getFilterFunc(opts, d2c, targetCalendar) {
262263
case '=':
263264
return function(v) { return d2cTarget(v) === coercedValue; };
264265

266+
case '!=':
267+
return function(v) { return d2cTarget(v) !== coercedValue; };
268+
265269
case '<':
266270
return function(v) { return d2cTarget(v) < coercedValue; };
267271

test/jasmine/tests/transform_filter_test.js

+17
Original file line numberDiff line numberDiff line change
@@ -595,6 +595,23 @@ describe('filter transforms calc:', function() {
595595
_assert(out, ['2015-07-20'], [1], [0.1]);
596596
});
597597

598+
it('with operation *!=*', function() {
599+
var out = _transform([Lib.extendDeep({}, _base, {
600+
transforms: [{
601+
operation: '!=',
602+
value: '2015-07-20',
603+
target: 'x'
604+
}]
605+
})]);
606+
607+
_assert(
608+
out,
609+
['2016-08-01', '2016-09-01', '2016-10-21', '2016-12-02'],
610+
[2, 3, 1, 5],
611+
[0.2, 0.3, 0.1, 0.2]
612+
);
613+
});
614+
598615
it('with operation *<*', function() {
599616
var out = _transform([Lib.extendDeep({}, _base, {
600617
transforms: [{

0 commit comments

Comments
 (0)