CartoDB / turbo-carto

CartoCSS preprocessor
BSD 3-Clause "New" or "Revised" License
28 stars 7 forks source link

TurboCARTO not recognizing CartoCSS conditional statements #61

Open makella opened 7 years ago

makella commented 7 years ago

@rochoa @saleiva

It looks like TurboCARTO is not respecting conditional CartoCSS statements.

Building on this issue: https://github.com/CartoDB/turbo-carto/issues/60

To make the election map described, we need to add two conditional statements. One for county_winner='gop' and another for county_winner='dem'. What we would expect is that within the condition, that only the polygons requested are considered in the classification.

CartoCSS

For example, in traditional CartoCSS that would be written like this:

#layer {
 //republican styling
  [county_winner="gop"] {
    [pct_gop>0.5]{polygon-fill: #FBD0D0;}
    [pct_gop>0.6]{polygon-fill: #E99D99;}
    [pct_gop>0.8]{polygon-fill: #CF615D;}  
  }

 //democratic styling
  [county_winner="dem"] {
    [pct_dem>0.5]{polygon-fill: #9CC0E3;}
    [pct_dem>0.6]{polygon-fill: #6193C7;}
    [pct_dem>0.8]{polygon-fill: #006AAB;}  
  }
}

So the logic here is first considering only counties won by a candidate and then second, splitting the class breaks only between the values of the requested polygons.

TurboCARTO

With TurboCARTO, whether you are doing manual classification or using one of our built-in classification methods (like equal), all polygons in the dataset are being considered.

For example, if we assigned this TurboCARTO to the elections results:

#layer {
  [county_winner="gop"] {
    polygon-fill: ramp([pct_gop],(#FBD0D0,#E99D99,#CF615D),equal);
  }
  [county_winner="dem"]{  
     polygon-fill: ramp([pct_dem],(#9CC0E3,#6193C7,#006AAB),equal);
  }
}

The output CartoCSS is:

#layer {
  [county_winner="gop"] {
    polygon-fill: #FBD0D0;
    [ pct_gop > 0.35085033740544175 ] {polygon-fill: #E99D99}
    [ pct_gop > 0.6591914024689549 ] {polygon-fill: #CF615D}
  }
  [county_winner="dem"] {
    polygon-fill: #9CC0E3;
    [ pct_dem > 0.3408085975310453 ] {polygon-fill: #6193C7}
    [ pct_dem > 0.6491496625945582 ] {polygon-fill: #006AAB}
  }
}

The reason I can tell that the output CartoCSS is not right and that TurboCARTO is not only respecting the requested polygons is because if a candidate won a county, there pct_ would be >50.

In addition to not respecting the conditions, we are encountering the same issue we are here with only two classes being colored for each candidate.

Autostyling is doing it properly when using something like a category widget. Basically, a widget treats a filter like a traditional CartoCSS condition, first, filtering on the condition and second, applying the TurboCARTO ramp.

.carto with TurboCARTO from above applied

Elections_ TurboCARTO with Condition (on 2016-12-23 at 03.14.06).carto.zip

saleiva commented 7 years ago

@rochoa, any update on this?