adds parser support for arrays and also updates reference to add "ramp" function
This commit is contained in:
parent
72d005a082
commit
cf5886579f
@ -477,6 +477,7 @@ carto.Parser = function Parser(env) {
|
|||||||
return new tree.Dimension(value[1], value[2], memo);
|
return new tree.Dimension(value[1], value[2], memo);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
},
|
},
|
||||||
|
|
||||||
// The variable part of a variable definition.
|
// The variable part of a variable definition.
|
||||||
@ -725,10 +726,22 @@ carto.Parser = function Parser(env) {
|
|||||||
},
|
},
|
||||||
// A sub-expression, contained by parenthensis
|
// A sub-expression, contained by parenthensis
|
||||||
sub: function() {
|
sub: function() {
|
||||||
var e;
|
var e, expressions = [];
|
||||||
|
|
||||||
if ($('(') && (e = $(this.expression)) && $(')')) {
|
if ($('(')) {
|
||||||
return e;
|
while (e = $(this.expression)) {
|
||||||
|
expressions.push(e);
|
||||||
|
if (! $(',')) { break; }
|
||||||
|
}
|
||||||
|
$(')');
|
||||||
|
}
|
||||||
|
|
||||||
|
if (expressions.length > 1) {
|
||||||
|
return new tree.Value(expressions.map(function(e) {
|
||||||
|
return e.value[0];
|
||||||
|
}));
|
||||||
|
} else if (expressions.length === 1) {
|
||||||
|
return new tree.Value(expressions);
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
// This is a misnomer because it actually handles multiplication
|
// This is a misnomer because it actually handles multiplication
|
||||||
|
@ -166,7 +166,8 @@ var _mapnik_reference_latest = {
|
|||||||
["sharpen", 0],
|
["sharpen", 0],
|
||||||
["colorize-alpha", -1],
|
["colorize-alpha", -1],
|
||||||
["color-to-alpha", 1],
|
["color-to-alpha", 1],
|
||||||
["scale-hsla", 8]
|
["scale-hsla", 8],
|
||||||
|
["ramp", -1]
|
||||||
],
|
],
|
||||||
"doc": "A list of image filters."
|
"doc": "A list of image filters."
|
||||||
},
|
},
|
||||||
|
@ -54,7 +54,8 @@ var _mapnik_reference_latest = {
|
|||||||
["x-gradient", 0],
|
["x-gradient", 0],
|
||||||
["y-gradient", 0],
|
["y-gradient", 0],
|
||||||
["invert", 0],
|
["invert", 0],
|
||||||
["sharpen", 0]
|
["sharpen", 0],
|
||||||
|
["ramp", 0]
|
||||||
],
|
],
|
||||||
"doc": "A list of image filters."
|
"doc": "A list of image filters."
|
||||||
},
|
},
|
||||||
|
@ -149,4 +149,21 @@ describe('RenderingJS', function() {
|
|||||||
assert.equal(emptyFilterProps['marker-width'], null);
|
assert.equal(emptyFilterProps['marker-width'], null);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it ("should parse turbocarto", function(){
|
||||||
|
var css = [
|
||||||
|
'#layer {',
|
||||||
|
' marker-width: ramp([cartodb_id], (#fff, #bbb), jenks);',
|
||||||
|
'}'
|
||||||
|
].join('\n');
|
||||||
|
var shader = (new carto.RendererJS({ debug: true })).render(css);
|
||||||
|
var layer = shader.getLayers()[0];
|
||||||
|
var st = layer.shader['marker-width'].style({}, {zoom: 1})
|
||||||
|
assert.equal(st.name, "ramp")
|
||||||
|
assert.equal(st.args.length, 3);
|
||||||
|
assert.equal(st.args[1].value[0].rgb[0], 255);
|
||||||
|
assert.equal(st.args[1].value[0].rgb[1], 255);
|
||||||
|
assert.equal(st.args[1].value[0].rgb[2], 255);
|
||||||
|
assert.equal(st.args[2].value, 'jenks');
|
||||||
|
})
|
||||||
|
|
||||||
});
|
});
|
||||||
|
1605
test/underscore.js
1605
test/underscore.js
File diff suppressed because it is too large
Load Diff
Loading…
Reference in New Issue
Block a user