Merge pull request #41 from CartoDB/carto-40
Ignore zoom for the filtered field when the value is the default one.
This commit is contained in:
commit
a48ba58cae
6
dist/carto.js
vendored
6
dist/carto.js
vendored
File diff suppressed because one or more lines are too long
72
dist/carto.uncompressed.js
vendored
72
dist/carto.uncompressed.js
vendored
@ -268,7 +268,7 @@ var carto = {
|
|||||||
if (typeof(extract[2]) === 'string') {
|
if (typeof(extract[2]) === 'string') {
|
||||||
error.push(stylize((ctx.line + 1) + ' ' + extract[2], 'grey'));
|
error.push(stylize((ctx.line + 1) + ' ' + extract[2], 'grey'));
|
||||||
}
|
}
|
||||||
error = options.indent + error.join('\n' + options.indent) + '\033[0m\n';
|
error = options.indent + error.join('\n' + options.indent) + '\x1B[0m\n';
|
||||||
|
|
||||||
message = options.indent + message + stylize(ctx.message, 'red');
|
message = options.indent + message + stylize(ctx.message, 'red');
|
||||||
if (ctx.filename) (message += stylize(' in ', 'red') + ctx.filename);
|
if (ctx.filename) (message += stylize(' in ', 'red') + ctx.filename);
|
||||||
@ -326,8 +326,8 @@ function stylize(str, style) {
|
|||||||
'red' : [31, 39],
|
'red' : [31, 39],
|
||||||
'grey' : [90, 39]
|
'grey' : [90, 39]
|
||||||
};
|
};
|
||||||
return '\033[' + styles[style][0] + 'm' + str +
|
return '\x1B[' + styles[style][0] + 'm' + str +
|
||||||
'\033[' + styles[style][1] + 'm';
|
'\x1B[' + styles[style][1] + 'm';
|
||||||
}
|
}
|
||||||
|
|
||||||
}).call(this,require('_process'),"/lib/carto")
|
}).call(this,require('_process'),"/lib/carto")
|
||||||
@ -1769,6 +1769,8 @@ CartoCSS.prototype = {
|
|||||||
// serach the max index to know rendering order
|
// serach the max index to know rendering order
|
||||||
lyr.index = _.max(props[v].map(function(a) { return a.index; }).concat(lyr.index));
|
lyr.index = _.max(props[v].map(function(a) { return a.index; }).concat(lyr.index));
|
||||||
lyr.constant = !_.any(props[v].map(function(a) { return !a.constant; }));
|
lyr.constant = !_.any(props[v].map(function(a) { return !a.constant; }));
|
||||||
|
// True when the property is filtered.
|
||||||
|
lyr.filtered = props[v][0].filtered;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -4229,48 +4231,37 @@ tree.Definition.prototype.toXML = function(env, existing) {
|
|||||||
|
|
||||||
tree.Definition.prototype.toJS = function(env) {
|
tree.Definition.prototype.toJS = function(env) {
|
||||||
var shaderAttrs = {};
|
var shaderAttrs = {};
|
||||||
|
|
||||||
// merge conditions from filters with zoom condition of the
|
|
||||||
// definition
|
|
||||||
var zoom = "(" + this.zoom + " & (1 << ctx.zoom))";
|
|
||||||
var frame_offset = this.frame_offset;
|
var frame_offset = this.frame_offset;
|
||||||
var _if = this.filters.toJS(env);
|
var zoomFilter = "(" + this.zoom + " & (1 << ctx.zoom))";
|
||||||
var filters = [zoom];
|
var filters = [zoomFilter];
|
||||||
if(_if) filters.push(_if);
|
var originalFilters = this.filters.toJS(env);
|
||||||
if(frame_offset) filters.push('ctx["frame-offset"] === ' + frame_offset);
|
// Ignore default zoom for filtering (https://github.com/CartoDB/carto/issues/40)
|
||||||
_if = filters.join(" && ");
|
var zoomFiltered = this.zoom !== tree.Zoom.all;
|
||||||
|
|
||||||
|
if (originalFilters) {
|
||||||
|
filters.push(originalFilters);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (frame_offset) {
|
||||||
|
filters.push('ctx["frame-offset"] === ' + frame_offset);
|
||||||
|
}
|
||||||
|
|
||||||
_.each(this.rules, function (rule) {
|
_.each(this.rules, function (rule) {
|
||||||
if(rule instanceof tree.Rule) {
|
var exportedRule = {};
|
||||||
shaderAttrs[rule.name] = shaderAttrs[rule.name] || [];
|
|
||||||
|
|
||||||
var r = {
|
if (!rule instanceof tree.Rule) {
|
||||||
index: rule.index,
|
|
||||||
symbolizer: rule.symbolizer
|
|
||||||
};
|
|
||||||
|
|
||||||
if (_if) {
|
|
||||||
r.js = "if(" + _if + "){" + rule.value.toJS(env) + "}"
|
|
||||||
} else {
|
|
||||||
r.js = rule.value.toJS(env);
|
|
||||||
}
|
|
||||||
|
|
||||||
r.constant = rule.value.ev(env).is !== 'field';
|
|
||||||
r.filtered = !!_if;
|
|
||||||
|
|
||||||
shaderAttrs[rule.name].push(r);
|
|
||||||
} else {
|
|
||||||
throw new Error("Ruleset not supported");
|
throw new Error("Ruleset not supported");
|
||||||
//if (rule instanceof tree.Ruleset) {
|
|
||||||
//var sh = rule.toJS(env);
|
|
||||||
//for(var v in sh) {
|
|
||||||
//shaderAttrs[v] = shaderAttrs[v] || [];
|
|
||||||
//for(var attr in sh[v]) {
|
|
||||||
//shaderAttrs[v].push(sh[v][attr]);
|
|
||||||
//}
|
|
||||||
//}
|
|
||||||
//}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
exportedRule.index = rule.index;
|
||||||
|
exportedRule.symbolizer = rule.symbolizer;
|
||||||
|
exportedRule.js = "if(" + filters.join(" && ") + "){" + rule.value.toJS(env) + "}";
|
||||||
|
exportedRule.constant = rule.value.ev(env).is !== 'field';
|
||||||
|
exportedRule.filtered = zoomFiltered || (originalFilters !== '');
|
||||||
|
shaderAttrs[rule.name] = shaderAttrs[rule.name] || [];
|
||||||
|
shaderAttrs[rule.name].push(exportedRule);
|
||||||
});
|
});
|
||||||
|
|
||||||
return shaderAttrs;
|
return shaderAttrs;
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -7322,7 +7313,7 @@ function hasOwnProperty(obj, prop) {
|
|||||||
},{"./support/isBuffer":42,"_process":40,"inherits":41}],44:[function(require,module,exports){
|
},{"./support/isBuffer":42,"_process":40,"inherits":41}],44:[function(require,module,exports){
|
||||||
module.exports={
|
module.exports={
|
||||||
"name": "carto",
|
"name": "carto",
|
||||||
"version": "0.15.1-cdb3",
|
"version": "0.15.1-cdb4",
|
||||||
"description": "CartoCSS Stylesheet Compiler",
|
"description": "CartoCSS Stylesheet Compiler",
|
||||||
"url": "https://github.com/cartodb/carto",
|
"url": "https://github.com/cartodb/carto",
|
||||||
"repository": {
|
"repository": {
|
||||||
@ -7375,6 +7366,7 @@ module.exports={
|
|||||||
"scripts": {
|
"scripts": {
|
||||||
"pretest": "npm install",
|
"pretest": "npm install",
|
||||||
"test": "mocha -R spec",
|
"test": "mocha -R spec",
|
||||||
|
"tdd" : "env HIDE_LOGS=true mocha -w -R spec",
|
||||||
"coverage": "istanbul cover ./node_modules/.bin/_mocha && coveralls < ./coverage/lcov.info"
|
"coverage": "istanbul cover ./node_modules/.bin/_mocha && coveralls < ./coverage/lcov.info"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -214,7 +214,8 @@ tree.Definition.prototype.toJS = function(env) {
|
|||||||
var zoomFilter = "(" + this.zoom + " & (1 << ctx.zoom))";
|
var zoomFilter = "(" + this.zoom + " & (1 << ctx.zoom))";
|
||||||
var filters = [zoomFilter];
|
var filters = [zoomFilter];
|
||||||
var originalFilters = this.filters.toJS(env);
|
var originalFilters = this.filters.toJS(env);
|
||||||
|
// Ignore default zoom for filtering (https://github.com/CartoDB/carto/issues/40)
|
||||||
|
var zoomFiltered = this.zoom !== tree.Zoom.all;
|
||||||
|
|
||||||
if (originalFilters) {
|
if (originalFilters) {
|
||||||
filters.push(originalFilters);
|
filters.push(originalFilters);
|
||||||
@ -235,8 +236,7 @@ tree.Definition.prototype.toJS = function(env) {
|
|||||||
exportedRule.symbolizer = rule.symbolizer;
|
exportedRule.symbolizer = rule.symbolizer;
|
||||||
exportedRule.js = "if(" + filters.join(" && ") + "){" + rule.value.toJS(env) + "}";
|
exportedRule.js = "if(" + filters.join(" && ") + "){" + rule.value.toJS(env) + "}";
|
||||||
exportedRule.constant = rule.value.ev(env).is !== 'field';
|
exportedRule.constant = rule.value.ev(env).is !== 'field';
|
||||||
exportedRule.filtered = originalFilters !== '';
|
exportedRule.filtered = zoomFiltered || (originalFilters !== '');
|
||||||
|
|
||||||
shaderAttrs[rule.name] = shaderAttrs[rule.name] || [];
|
shaderAttrs[rule.name] = shaderAttrs[rule.name] || [];
|
||||||
shaderAttrs[rule.name].push(exportedRule);
|
shaderAttrs[rule.name].push(exportedRule);
|
||||||
});
|
});
|
||||||
|
@ -7,21 +7,22 @@
|
|||||||
* This field gives information about whether a property is filtered or not.
|
* This field gives information about whether a property is filtered or not.
|
||||||
*
|
*
|
||||||
* A property is filtered if it was activated inside a filter. In the following cartocss
|
* A property is filtered if it was activated inside a filter. In the following cartocss
|
||||||
* code marker-color.filtered will be true because is inside a population filter.
|
* code marker-color.filtered will be true because it's inside a population filter.
|
||||||
*
|
*
|
||||||
* #layer {
|
* #layer {
|
||||||
* maker-width: 20;
|
* maker-width: 20;
|
||||||
* [population > 100] {
|
* [population > 100] {
|
||||||
* marker-color: red; //
|
* marker-color: red; // this property is filtered
|
||||||
* }
|
* }
|
||||||
* }
|
* }
|
||||||
|
*
|
||||||
|
* "zoom" is a special case, and it only should be considered when its value is not the default.
|
||||||
*/
|
*/
|
||||||
var assert = require('assert');
|
var assert = require('assert');
|
||||||
var Carto = require('../lib/carto/index.js');
|
var Carto = require('../lib/carto/index.js');
|
||||||
var renderer = new Carto.RendererJS({ strict: true });
|
var renderer = new Carto.RendererJS({ strict: true });
|
||||||
|
|
||||||
|
describe('property.filtered', function () {
|
||||||
describe('Field:filtered propery', function () {
|
|
||||||
it('should be false when the property is not filtered', function () {
|
it('should be false when the property is not filtered', function () {
|
||||||
var style = [
|
var style = [
|
||||||
'#layer {',
|
'#layer {',
|
||||||
@ -85,4 +86,17 @@ describe('Field:filtered propery', function () {
|
|||||||
|
|
||||||
assert(layers['marker-fill'].filtered);
|
assert(layers['marker-fill'].filtered);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it('should be true when filtering by zoom', function () {
|
||||||
|
var style = [
|
||||||
|
'#layer {',
|
||||||
|
' [zoom < 5]{',
|
||||||
|
' marker-fill: blue;',
|
||||||
|
' }',
|
||||||
|
'}`'
|
||||||
|
].join('\n');
|
||||||
|
var layers = renderer.render(style).layers[0].shader;
|
||||||
|
|
||||||
|
assert(layers['marker-fill'].filtered);
|
||||||
|
});
|
||||||
});
|
});
|
Loading…
Reference in New Issue
Block a user