1

If you want to define manual class breaks with the ramp() function it seems you're out of luck; as far as I can tell this is not working as intended. For example, here I try to supply different colors for values that fall within user specified ranges

Code:

#layer{
           [dominant_origin = "Puerto-Rican"]{
             polygon-fill: ramp([relative_dom], (#004c6d, #3d708f, #6996b3, #94bed9, #c1e7ff), (.2, .4, .6, .8, 1), "<=");
           }
           [dominant_origin = "South American"]{
             polygon-fill: ramp([relative_dom], (#ff0000, #ff5d38, #ff8b67, #ffb297, #ffd8cb), (.2, .4, .6, .8, 1), "<=");
           }
           [dominant_origin = "Central American"]{
             polygon-fill: ramp([relative_dom], (#00ff00, #6cfb53, #97f67e, #b7f0a3, #d1eac7), (.2, .4, .6, .8, 1), "<=");
           }
           [dominant_origin = "Dominican"]{
             polygon-fill: ramp([relative_dom], (#ffff00, #fcf853, #f8f17b, #f1eb9d, #e9e4bd), (.2, .4, .6, .8, 1), "<=");
           }
           [dominant_origin = "Mexican"]{
             polygon-fill: ramp([relative_dom], (#7f00ff, #a451ff, #c181ff, #daaeff, #efdbff), (.2, .4, .6, .8, 1), "<=");
           }
           [dominant_origin = "Other"]{
             polygon-fill: ramp([relative_dom], (#000000, #363636, #6a6a6a, #a4a4a4, #e2e2e2), (.2, .4, .6, .8, 1), "<=");
           }
           [dominant_origin = "Cuban"]{
             polygon-fill: ramp([relative_dom], (#e6550d, #f17940, #f99a6b, #feba98, #ffd9c6), (.2, .4, .6, .8, 1), "<=");
           }
         }

if you console.log() the event on a metaDatachange you get this:

_buckets: Array(5)
0: {min: null, max: 0.2, value: "#004c6d"}
1: {min: 0.2, max: 0.4, value: "#3d708f"}
2: {min: 0.4, max: 0.6, value: "#6996b3"}
3: {min: 0.6, max: 0.8, value: "#94bed9"}
4: {min: 0.8, max: undefined, value: "#c1e7ff"}

If you console.log() bucket.min and bucket.max you'll get:

null
undefined

This is an issue for a few reasons. First you're getting nulls and undefined values for min and max in the first and last bins. Second, the class breaks are not explicit. Lastly, the last value supplied in the filter is ignored.

I know in a previous issue it was suggested to use the "<" mapping instead, but the result is exactly the same.

0

TurboCARTO, the CartoCSS preprocessor that works behind the scene everytime you run a ramp, does not support conditional styling. This was reported 3 years ago. So do not expect to be fixed.

  • oh lovely, between CARTO's lackluster documentation and little silly things like this; I am beginning to see why it's not used very frequently. – cvricella_sbu Nov 14 '19 at 21:26
  • The TurboCARTO project which is used by Builder UI and CARTO.js was kind of abandoned some months ago. It looks like CARTO tech team is focusing more on CARTOframes and integrations. You could also try CARTO VL is more powerful and dynamic than CartoCSS. – ramiroaznar Nov 15 '19 at 8:32
  • Whats the deal with CARTO VL? As I understand it, you can't use it iwth CARTO js. Does vector tiling lend itself to only specific use cases? Or can I pretty much do everything i do in CARTO js with VL ? – cvricella_sbu Nov 15 '19 at 14:55
  • I would give it a try. As far as I know, you can do more things with VL than with JS. – ramiroaznar Nov 15 '19 at 16:45
  • have any potential guide/resource that compares the two? Can't find anything googling around – cvricella_sbu Nov 15 '19 at 17:42

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.