Merge pull request #30 from CartoDB/support-multiple-values
Support multiple values/operands
This commit is contained in:
commit
decdcc5d46
@ -36,7 +36,9 @@ tree.Value.prototype = {
|
|||||||
v = "'" + v + "'";
|
v = "'" + v + "'";
|
||||||
} else if (val.is === 'field') {
|
} else if (val.is === 'field') {
|
||||||
// replace [variable] by ctx['variable']
|
// replace [variable] by ctx['variable']
|
||||||
v = v.replace(/\[(.*)\]/g, "data['$1']");
|
v = v.replace(/\[([^\]]*)\]/g, function(matched) {
|
||||||
|
return matched.replace(/\[(.*)\]/g, "data['$1']");
|
||||||
|
});
|
||||||
}else if (val.is === 'call') {
|
}else if (val.is === 'call') {
|
||||||
v = JSON.stringify({
|
v = JSON.stringify({
|
||||||
name: val.name,
|
name: val.name,
|
||||||
|
@ -4,19 +4,19 @@ var carto = require('../lib/carto');
|
|||||||
describe('RenderingJS', function() {
|
describe('RenderingJS', function() {
|
||||||
var shader;
|
var shader;
|
||||||
var style = [
|
var style = [
|
||||||
'#world {',
|
'#world {',
|
||||||
'line-width: 2;',
|
'line-width: 2;',
|
||||||
'line-color: #f00;',
|
'line-color: #f00;',
|
||||||
'[frame-offset = 1] {',
|
'[frame-offset = 1] {',
|
||||||
'line-width: 3;',
|
'line-width: 3;',
|
||||||
'}',
|
'}',
|
||||||
'[frame-offset = 2] {',
|
'[frame-offset = 2] {',
|
||||||
'line-width: 3;',
|
'line-width: 3;',
|
||||||
'}',
|
'}',
|
||||||
'}',
|
'}',
|
||||||
'',
|
'',
|
||||||
'#worls[frame-offset = 10] {',
|
'#worls[frame-offset = 10] {',
|
||||||
'line-width: 4;',
|
'line-width: 4;',
|
||||||
'}'
|
'}'
|
||||||
].join('\n');
|
].join('\n');
|
||||||
|
|
||||||
@ -183,6 +183,18 @@ describe('RenderingJS', function() {
|
|||||||
assert.equal(st.args[2].args[0].value, 10);
|
assert.equal(st.args[2].args[0].value, 10);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it("should work with multiple operands", function(){
|
||||||
|
var css = [
|
||||||
|
'#layer {',
|
||||||
|
' marker-width: [value] * [value] * 0.5;',
|
||||||
|
'}'
|
||||||
|
].join('\n');
|
||||||
|
var shader = (new carto.RendererJS({ debug: false })).render(css);
|
||||||
|
var layer = shader.getLayers()[0];
|
||||||
|
var width = layer.shader['marker-width'].style({value: 4}, {zoom: 1});
|
||||||
|
assert.equal(width, 8);
|
||||||
|
});
|
||||||
|
|
||||||
it("should not throw `ReferenceError` with `=~` operator", function(){
|
it("should not throw `ReferenceError` with `=~` operator", function(){
|
||||||
var css = [
|
var css = [
|
||||||
'#layer[name=~".*wadus*"] {',
|
'#layer[name=~".*wadus*"] {',
|
||||||
@ -197,7 +209,7 @@ describe('RenderingJS', function() {
|
|||||||
assert.equal(value, 14);
|
assert.equal(value, 14);
|
||||||
}, ReferenceError);
|
}, ReferenceError);
|
||||||
});
|
});
|
||||||
|
|
||||||
it("`=~` operator should support numbers", function(){
|
it("`=~` operator should support numbers", function(){
|
||||||
var css = [
|
var css = [
|
||||||
'#layer[value=~"^10"] {',
|
'#layer[value=~"^10"] {',
|
||||||
|
Loading…
Reference in New Issue
Block a user