Skip to content
This repository has been archived by the owner on Jan 12, 2024. It is now read-only.

Commit

Permalink
let filters accept expressions, ref #121
Browse files Browse the repository at this point in the history
  • Loading branch information
nebulon42 committed Dec 24, 2016
1 parent e7c4d2b commit 4590bfd
Show file tree
Hide file tree
Showing 7 changed files with 101 additions and 1 deletion.
3 changes: 2 additions & 1 deletion lib/carto/parser.js
Original file line number Diff line number Diff line change
Expand Up @@ -588,7 +588,8 @@ carto.Parser = function Parser(env) {
key = new tree.Field(key.toString());
}
if ((op = $(this.entities.comparison)) &&
(val = $(this.entities.quoted) ||
(val = $(this.expression) ||
$(this.entities.quoted) ||
$(this.entities.variable) ||
$(this.entities.dimension) ||
$(this.entities.keyword) ||
Expand Down
4 changes: 4 additions & 0 deletions lib/carto/tree/operation.js
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,10 @@ tree.Operation.prototype.ev = function(env) {
return a.operate(env, this.op, b);
};

tree.Operation.prototype.toString = function () {
return this.operands[0].toString() + this.op + this.operands[1].toString();
};

tree.operate = function(op, a, b) {
switch (op) {
case '+': return a + b;
Expand Down
3 changes: 3 additions & 0 deletions test/rendering-mss/issue_121.mss
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
#data {
[[dem] > [rep]] { marker-fill: #00f;}
}
6 changes: 6 additions & 0 deletions test/rendering-mss/issue_121.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
<Style name="style" filter-mode="first">
<Rule>
<Filter>([dem] &gt; [rep])</Filter>
<MarkersSymbolizer fill="#0000ff" />
</Rule>
</Style>
36 changes: 36 additions & 0 deletions test/rendering/issue_121.mml
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
{
"bounds": [
-180,
-85.05112877980659,
180,
85.05112877980659
],
"center": [
0,
0,
2
],
"format": "png",
"interactivity": false,
"minzoom": 0,
"maxzoom": 22,
"srs": "+proj=merc +a=6378137 +b=6378137 +lat_ts=0.0 +lon_0=0.0 +x_0=0.0 +y_0=0.0 +k=1.0 +units=m +nadgrids=@null +wktext +no_defs +over",
"Stylesheet": [
"issue_121.mss"
],
"Layer": [
{
"id": "filtertest",
"srs": "+proj=merc +a=6378137 +b=6378137 +lat_ts=0.0 +lon_0=0.0 +x_0=0.0 +y_0=0.0 +k=1.0 +units=m +nadgrids=@null +wktext +no_defs +over",
"geometry": "polygon",
"Datasource": {
"file": "http://mapbox-geodata.s3.amazonaws.com/natural-earth-1.4.0/cultural/10m-admin-0-countries.zip",
"type": "shape"
}
}
],
"scale": 1,
"metatile": 2,
"name": "",
"description": ""
}
11 changes: 11 additions & 0 deletions test/rendering/issue_121.mss
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
#filtertest[[a] > [b]] {
marker-fill: #ff0000;
}

#filtertest[[a] > [b] * 2] {
marker-fill: #00ff00;
}

#filtertest[[a] > 10 * 2] {
marker-fill: #0000ff;
}
39 changes: 39 additions & 0 deletions test/rendering/issue_121.result
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE Map[]>
<Map srs="+proj=merc +a=6378137 +b=6378137 +lat_ts=0.0 +lon_0=0.0 +x_0=0.0 +y_0=0.0 +k=1.0 +units=m +nadgrids=@null +wktext +no_defs +over">

<Parameters>
<Parameter name="bounds">-180,-85.05112877980659,180,85.05112877980659</Parameter>
<Parameter name="center">0,0,2</Parameter>
<Parameter name="format">png</Parameter>
<Parameter name="minzoom">0</Parameter>
<Parameter name="maxzoom">22</Parameter>
<Parameter name="scale">1</Parameter>
<Parameter name="metatile">2</Parameter>
</Parameters>


<Style name="filtertest" filter-mode="first" >
<Rule>
<Filter>([a] &gt; 20)</Filter>
<MarkersSymbolizer fill="#0000ff" />
</Rule>
<Rule>
<Filter>([a] &gt; [b]*2)</Filter>
<MarkersSymbolizer fill="#00ff00" />
</Rule>
<Rule>
<Filter>([a] &gt; [b])</Filter>
<MarkersSymbolizer fill="#ff0000" />
</Rule>
</Style>
<Layer name="filtertest"
srs="+proj=merc +a=6378137 +b=6378137 +lat_ts=0.0 +lon_0=0.0 +x_0=0.0 +y_0=0.0 +k=1.0 +units=m +nadgrids=@null +wktext +no_defs +over">
<StyleName>filtertest</StyleName>
<Datasource>
<Parameter name="file">[absolute path]</Parameter>
<Parameter name="type"><![CDATA[shape]]></Parameter>
</Datasource>
</Layer>

</Map>

0 comments on commit 4590bfd

Please sign in to comment.