vega-lite
Advanced tools
Comparing version 0.7.17 to 0.7.18
{ | ||
"name": "vega-lite", | ||
"main": "vega-lite.js", | ||
"version": "0.7.17", | ||
"version": "0.7.18", | ||
"homepage": "https://github.com/vega/vega-lite", | ||
@@ -6,0 +6,0 @@ "authors": [ |
{ | ||
"name": "vega-lite", | ||
"author": "Jeffrey Heer, Dominik Moritz, Kanit \"Ham\" Wongsuphasawat", | ||
"version": "0.7.17", | ||
"version": "0.7.18", | ||
"collaborators": [ | ||
@@ -6,0 +6,0 @@ "Kanit Wongsuphasawat <kanitw@gmail.com> (http://kanitw.yellowpigz.com)", |
@@ -78,6 +78,4 @@ 'use strict'; | ||
data.raw.transform = function(encoding) { | ||
// null filter comes first so transforms are not performed on null values | ||
// time and bin should come before filter so we can filter by time and bin | ||
return data.raw.transform.nullFilter(encoding).concat( | ||
data.raw.transform.time(encoding), | ||
return data.raw.transform.time(encoding).concat( | ||
data.raw.transform.bin(encoding), | ||
@@ -126,29 +124,2 @@ data.raw.transform.filter(encoding) | ||
/** | ||
* @return {Object} An array that might contain a filter transform for filtering null value based on filterNul config | ||
*/ | ||
data.raw.transform.nullFilter = function(encoding) { | ||
var filteredFields = util.reduce(encoding.fields(), | ||
function(filteredFields, fieldList, fieldName) { | ||
if (fieldName === '*') return filteredFields; //count | ||
// TODO(#597) revise how filterNull is structured. | ||
if ((encoding.config('filterNull').Q && fieldList.containsType[Q]) || | ||
(encoding.config('filterNull').T && fieldList.containsType[T]) || | ||
(encoding.config('filterNull').O && fieldList.containsType[O]) || | ||
(encoding.config('filterNull').N && fieldList.containsType[N])) { | ||
filteredFields.push(fieldName); | ||
} | ||
return filteredFields; | ||
}, []); | ||
return filteredFields.length > 0 ? | ||
[{ | ||
type: 'filter', | ||
test: filteredFields.map(function(fieldName) { | ||
return fieldName + '!==null'; | ||
}).join(' && ') | ||
}] : []; | ||
}; | ||
data.raw.transform.filter = function(encoding) { | ||
@@ -171,2 +142,10 @@ var filters = encoding.filter().reduce(function(f, filter) { | ||
condition = d + op1 + ' ' + operator + ' ' + op2; | ||
} else if (operator === 'notNull') { | ||
// expects a number of fields | ||
for (var j=0; j<operands.length; j++) { | ||
condition += d + operands[j] + '!==null'; | ||
if (j < operands.length - 1) { | ||
condition += ' && '; | ||
} | ||
} | ||
} else { | ||
@@ -173,0 +152,0 @@ util.warn('Unsupported operator: ', operator); |
@@ -103,3 +103,21 @@ 'use strict'; | ||
proto.filter = function() { | ||
return this._filter; | ||
var filterNull = [], | ||
fields = this.fields(), | ||
self = this; | ||
util.forEach(fields, function(fieldList, fieldName) { | ||
if (fieldName === '*') return; //count | ||
if ((self.config('filterNull').Q && fieldList.containsType[Q]) || | ||
(self.config('filterNull').T && fieldList.containsType[T]) || | ||
(self.config('filterNull').O && fieldList.containsType[O]) || | ||
(self.config('filterNull').N && fieldList.containsType[N])) { | ||
filterNull.push({ | ||
operands: [fieldName], | ||
operator: 'notNull' | ||
}); | ||
} | ||
}); | ||
return filterNull.concat(this._filter); | ||
}; | ||
@@ -106,0 +124,0 @@ |
@@ -617,3 +617,2 @@ // Package of defining Vega-lite Specification's json schema | ||
properties: { | ||
N: {type:'boolean', default: false}, | ||
O: {type:'boolean', default: false}, | ||
@@ -620,0 +619,0 @@ Q: {type:'boolean', default: true}, |
@@ -132,45 +132,13 @@ 'use strict'; | ||
describe('nullFilter', function() { | ||
var spec = { | ||
marktype: 'point', | ||
encoding: { | ||
y: {name: 'Q', type:'Q'}, | ||
x: {name: 'T', type:'T'}, | ||
color: {name: 'O', type:'O'} | ||
} | ||
}; | ||
describe('filter', function () { | ||
it('should return filter transform that include filter null', function () { | ||
var transform = data.raw.transform.filter(encoding); | ||
it('should add filterNull for Q and T by default', function () { | ||
var encoding = Encoding.fromSpec(spec); | ||
expect(data.raw.transform.nullFilter(encoding)) | ||
.to.eql([{ | ||
type: 'filter', | ||
test: 'T!==null && Q!==null' | ||
}]); | ||
}); | ||
it('should add filterNull for O when specified', function () { | ||
var encoding = Encoding.fromSpec(spec, { | ||
config: { | ||
filterNull: {O: true} | ||
} | ||
expect(transform[0]).to.eql({ | ||
type: 'filter', | ||
test: '(d.data.a!==null) && (d.data.Acceleration!==null)' + | ||
' && (d.data.a > b) && (d.data.c == d)' | ||
}); | ||
expect(data.raw.transform.nullFilter(encoding)) | ||
.to.eql([{ | ||
type: 'filter', | ||
test:'T!==null && Q!==null && O!==null' | ||
}]); | ||
}); | ||
// }); | ||
}); | ||
describe('filter', function () { | ||
it('should return array that contains a filter transform', function () { | ||
expect(data.raw.transform.filter(encoding)) | ||
.to.eql([{ | ||
type: 'filter', | ||
test: '(d.data.a > b) && (d.data.c == d)' | ||
}]); | ||
}); | ||
it('should exclude unsupported operator', function () { | ||
@@ -201,8 +169,7 @@ var badEncoding = Encoding.fromSpec({ | ||
it('should have null filter, timeUnit, bin then filter', function () { | ||
it('should time and bin before filter', function () { | ||
var transform = data.raw.transform(encoding); | ||
expect(transform[0].type).to.eql('filter'); | ||
expect(transform[1].type).to.eql('formula'); | ||
expect(transform[2].type).to.eql('bin'); | ||
expect(transform[3].type).to.eql('filter'); | ||
expect(transform[0].type).to.eql('formula'); | ||
expect(transform[1].type).to.eql('bin'); | ||
expect(transform[2].type).to.eql('filter'); | ||
}); | ||
@@ -209,0 +176,0 @@ |
@@ -17,1 +17,27 @@ 'use strict'; | ||
describe('encoding.filter()', function () { | ||
var spec = { | ||
marktype: 'point', | ||
encoding: { | ||
y: {name: 'Q', type:'Q'}, | ||
x: {name: 'T', type:'T'}, | ||
color: {name: 'O', type:'O'} | ||
} | ||
}; | ||
it('should add filterNull for Q and T by default', function () { | ||
var encoding = Encoding.fromSpec(spec), | ||
filter = encoding.filter(); | ||
expect(filter.length).to.equal(2); | ||
expect(filter.indexOf({name: 'O', type:'O'})).to.equal(-1); | ||
}); | ||
it('should add filterNull for O when specified', function () { | ||
var encoding = Encoding.fromSpec(spec, { | ||
config: { | ||
filterNull: {O: true} | ||
} | ||
}); | ||
var filter = encoding.filter(); | ||
expect(filter.length).to.equal(3); | ||
}); | ||
}); |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
7539086
120656