Skip to content

Commit 4f2abeb

Browse files
committed
Merge branch 'master' into gh-pages
2 parents 30e43d4 + 19a3399 commit 4f2abeb

File tree

7 files changed

+67
-78
lines changed

7 files changed

+67
-78
lines changed

bower.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "vega-lite",
33
"main": "vega-lite.js",
4-
"version": "0.7.17",
4+
"version": "0.7.18",
55
"homepage": "https://github.com/vega/vega-lite",
66
"authors": [
77
"Kanit Wongsuphasawat <[email protected]> (http://kanitw.yellowpigz.com)",

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "vega-lite",
33
"author": "Jeffrey Heer, Dominik Moritz, Kanit \"Ham\" Wongsuphasawat",
4-
"version": "0.7.17",
4+
"version": "0.7.18",
55
"collaborators": [
66
"Kanit Wongsuphasawat <[email protected]> (http://kanitw.yellowpigz.com)",
77
"Dominik Moritz <[email protected]> (http://domoritz.de)",

src/Encoding.js

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,25 @@ module.exports = (function() {
100100
};
101101

102102
proto.filter = function() {
103-
return this._filter;
103+
var filterNull = [],
104+
fields = this.fields(),
105+
self = this;
106+
107+
util.forEach(fields, function(fieldList, fieldName) {
108+
if (fieldName === '*') return; //count
109+
110+
if ((self.config('filterNull').Q && fieldList.containsType[Q]) ||
111+
(self.config('filterNull').T && fieldList.containsType[T]) ||
112+
(self.config('filterNull').O && fieldList.containsType[O]) ||
113+
(self.config('filterNull').N && fieldList.containsType[N])) {
114+
filterNull.push({
115+
operands: [fieldName],
116+
operator: 'notNull'
117+
});
118+
}
119+
});
120+
121+
return filterNull.concat(this._filter);
104122
};
105123

106124
// get "field" reference for vega

src/compiler/data.js

Lines changed: 9 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -75,10 +75,8 @@ data.raw.formatParse = function(encoding) {
7575
* transforms for time unit, binning and filtering.
7676
*/
7777
data.raw.transform = function(encoding) {
78-
// null filter comes first so transforms are not performed on null values
7978
// time and bin should come before filter so we can filter by time and bin
80-
return data.raw.transform.nullFilter(encoding).concat(
81-
data.raw.transform.time(encoding),
79+
return data.raw.transform.time(encoding).concat(
8280
data.raw.transform.bin(encoding),
8381
data.raw.transform.filter(encoding)
8482
);
@@ -122,33 +120,6 @@ data.raw.transform.bin = function(encoding) {
122120
}, []);
123121
};
124122

125-
/**
126-
* @return {Object} An array that might contain a filter transform for filtering null value based on filterNul config
127-
*/
128-
data.raw.transform.nullFilter = function(encoding) {
129-
var filteredFields = util.reduce(encoding.fields(),
130-
function(filteredFields, fieldList, fieldName) {
131-
if (fieldName === '*') return filteredFields; //count
132-
133-
// TODO(#597) revise how filterNull is structured.
134-
if ((encoding.config('filterNull').Q && fieldList.containsType[Q]) ||
135-
(encoding.config('filterNull').T && fieldList.containsType[T]) ||
136-
(encoding.config('filterNull').O && fieldList.containsType[O]) ||
137-
(encoding.config('filterNull').N && fieldList.containsType[N])) {
138-
filteredFields.push(fieldName);
139-
}
140-
return filteredFields;
141-
}, []);
142-
143-
return filteredFields.length > 0 ?
144-
[{
145-
type: 'filter',
146-
test: filteredFields.map(function(fieldName) {
147-
return fieldName + '!==null';
148-
}).join(' && ')
149-
}] : [];
150-
};
151-
152123
data.raw.transform.filter = function(encoding) {
153124
var filters = encoding.filter().reduce(function(f, filter) {
154125
var condition = '';
@@ -166,6 +137,14 @@ data.raw.transform.filter = function(encoding) {
166137
var op1 = operands[0];
167138
var op2 = operands[1];
168139
condition = d + op1 + ' ' + operator + ' ' + op2;
140+
} else if (operator === 'notNull') {
141+
// expects a number of fields
142+
for (var j=0; j<operands.length; j++) {
143+
condition += d + operands[j] + '!==null';
144+
if (j < operands.length - 1) {
145+
condition += ' && ';
146+
}
147+
}
169148
} else {
170149
util.warn('Unsupported operator: ', operator);
171150
return f;

src/schema/schema.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -614,7 +614,6 @@ var config = {
614614
filterNull: {
615615
type: 'object',
616616
properties: {
617-
N: {type:'boolean', default: false},
618617
O: {type:'boolean', default: false},
619618
Q: {type:'boolean', default: true},
620619
T: {type:'boolean', default: true}

test/Encoding.spec.js

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,3 +14,29 @@ describe('Encoding.fromShorthand()', function () {
1414
});
1515
});
1616

17+
describe('encoding.filter()', function () {
18+
var spec = {
19+
marktype: 'point',
20+
encoding: {
21+
y: {name: 'Q', type:'Q'},
22+
x: {name: 'T', type:'T'},
23+
color: {name: 'O', type:'O'}
24+
}
25+
};
26+
it('should add filterNull for Q and T by default', function () {
27+
var encoding = Encoding.fromSpec(spec),
28+
filter = encoding.filter();
29+
expect(filter.length).to.equal(2);
30+
expect(filter.indexOf({name: 'O', type:'O'})).to.equal(-1);
31+
});
32+
33+
it('should add filterNull for O when specified', function () {
34+
var encoding = Encoding.fromSpec(spec, {
35+
config: {
36+
filterNull: {O: true}
37+
}
38+
});
39+
var filter = encoding.filter();
40+
expect(filter.length).to.equal(3);
41+
});
42+
});

test/compiler/data.spec.js

Lines changed: 11 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -129,47 +129,15 @@ describe('data.raw', function() {
129129
});
130130
});
131131

132-
describe('nullFilter', function() {
133-
var spec = {
134-
marktype: 'point',
135-
encoding: {
136-
y: {name: 'Q', type:'Q'},
137-
x: {name: 'T', type:'T'},
138-
color: {name: 'O', type:'O'}
139-
}
140-
};
141-
142-
it('should add filterNull for Q and T by default', function () {
143-
var encoding = Encoding.fromSpec(spec);
144-
expect(data.raw.transform.nullFilter(encoding))
145-
.to.eql([{
146-
type: 'filter',
147-
test: 'T!==null && Q!==null'
148-
}]);
149-
});
132+
describe('filter', function () {
133+
it('should return filter transform that include filter null', function () {
134+
var transform = data.raw.transform.filter(encoding);
150135

151-
it('should add filterNull for O when specified', function () {
152-
var encoding = Encoding.fromSpec(spec, {
153-
config: {
154-
filterNull: {O: true}
155-
}
136+
expect(transform[0]).to.eql({
137+
type: 'filter',
138+
test: '(d.data.a!==null) && (d.data.Acceleration!==null)' +
139+
' && (d.data.a > b) && (d.data.c == d)'
156140
});
157-
expect(data.raw.transform.nullFilter(encoding))
158-
.to.eql([{
159-
type: 'filter',
160-
test:'T!==null && Q!==null && O!==null'
161-
}]);
162-
});
163-
// });
164-
});
165-
166-
describe('filter', function () {
167-
it('should return array that contains a filter transform', function () {
168-
expect(data.raw.transform.filter(encoding))
169-
.to.eql([{
170-
type: 'filter',
171-
test: '(d.data.a > b) && (d.data.c == d)'
172-
}]);
173141
});
174142

175143
it('should exclude unsupported operator', function () {
@@ -197,12 +165,11 @@ describe('data.raw', function() {
197165
});
198166
});
199167

200-
it('should have null filter, timeUnit, bin then filter', function () {
168+
it('should time and bin before filter', function () {
201169
var transform = data.raw.transform(encoding);
202-
expect(transform[0].type).to.eql('filter');
203-
expect(transform[1].type).to.eql('formula');
204-
expect(transform[2].type).to.eql('bin');
205-
expect(transform[3].type).to.eql('filter');
170+
expect(transform[0].type).to.eql('formula');
171+
expect(transform[1].type).to.eql('bin');
172+
expect(transform[2].type).to.eql('filter');
206173
});
207174

208175
});

0 commit comments

Comments
 (0)