turbo-carto
Advanced tools
Comparing version 0.19.2 to 0.20.0
# Changelog | ||
## Version 0.20.0 | ||
Released 2017-09-25 | ||
- Allow to override filters' column name via metadata from datasource #72. | ||
## Version 0.19.2 | ||
@@ -4,0 +10,0 @@ Released 2017-07-20 |
{ | ||
"name": "turbo-carto", | ||
"version": "0.19.2", | ||
"version": "0.20.0", | ||
"description": "CartoCSS preprocessor", | ||
@@ -5,0 +5,0 @@ "main": "src/index.js", |
@@ -96,3 +96,3 @@ # Turbo-Carto | ||
#selector { | ||
marker-width: ramp([room_type], (green, red), ("Private room"), =); | ||
marker-fill: ramp([room_type], (green, red), ("Private room"), =); | ||
} | ||
@@ -146,5 +146,5 @@ ``` | ||
#### Color ramps | ||
#### Color schemes | ||
For color ramps, there are a couple of handy functions to retrieve color palettes: `cartocolor` and `colorbrewer`. | ||
For color schemes, there are a couple of handy functions to retrieve color palettes: `cartocolor` and `colorbrewer`. | ||
@@ -167,2 +167,4 @@ You can create a choropleth map using Reds color palette from colorbrewer (see [examples/readme/example-6.css](./examples/readme/example-6.css)): | ||
Go to [CARTOcolors](https://carto.com/carto-colors) website to discover the wide diversity of color schemes that are available. | ||
#### Numeric ramps | ||
@@ -169,0 +171,0 @@ |
@@ -29,8 +29,10 @@ 'use strict'; | ||
var stats = {}; | ||
var meta = {}; | ||
if (!Array.isArray(filters)) { | ||
strategy = filters.strategy || 'max'; | ||
stats = filters.stats; | ||
meta = filters.meta || {}; | ||
filters = filters.ramp; | ||
} | ||
resolve(new FiltersResult(filters, strategy, stats)); | ||
resolve(new FiltersResult(filters, strategy, stats, meta)); | ||
}); | ||
@@ -37,0 +39,0 @@ }); |
@@ -16,3 +16,3 @@ 'use strict'; | ||
function createSplitStrategy (mapping) { | ||
return function splitStrategy (column, rampResult, stats, decl, metadataHolder) { | ||
return function splitStrategy (column, rampResult, stats, meta, decl, metadataHolder) { | ||
var allFilters = rampResult.filter(evenIndex); | ||
@@ -25,3 +25,3 @@ var values = rampResult.filter(reverse(evenIndex)); | ||
filters = filters.filter(reverse(isNull)); | ||
var ramp = new RampResult(new ValuesResult(values), new FiltersResult(filters, null, stats), mapping); | ||
var ramp = new RampResult(new ValuesResult(values), new FiltersResult(filters, null, stats, meta), mapping); | ||
return ramp.process(column, decl, metadataHolder); | ||
@@ -46,6 +46,6 @@ }; | ||
var strategy = { | ||
max: function maxStrategy (column, rampResult, stats, decl, metadataHolder) { | ||
max: function maxStrategy (column, rampResult, stats, meta, decl, metadataHolder) { | ||
var values = rampResult.filter(reverse(evenIndex)); | ||
var filters = rampResult.filter(evenIndex).filter(reverse(isNull)); | ||
var ramp = new RampResult(new ValuesResult(values), new FiltersResult(filters, null, stats), '>'); | ||
var ramp = new RampResult(new ValuesResult(values), new FiltersResult(filters, null, stats, meta), '>'); | ||
return ramp.process(column, decl, metadataHolder); | ||
@@ -74,3 +74,5 @@ }, | ||
var strategyFn = strategy.hasOwnProperty(rampResult.strategy) ? strategy[rampResult.strategy] : strategy.max; | ||
return strategyFn(columnName(column), rampResult.ramp, rampResult.stats, decl, metadataHolder); | ||
return strategyFn( | ||
columnName(column), rampResult.ramp, rampResult.stats, rampResult.meta, decl, metadataHolder | ||
); | ||
}) | ||
@@ -269,8 +271,10 @@ .catch(function (err) { | ||
var stats = {}; | ||
var meta = {}; | ||
if (!Array.isArray(filters)) { | ||
strategy = filters.strategy || 'max'; | ||
stats = filters.stats; | ||
meta = filters.meta || {}; | ||
filters = filters.ramp; | ||
} | ||
resolve(new FiltersResult(filters, strategy, stats)); | ||
resolve(new FiltersResult(filters, strategy, stats, meta)); | ||
}); | ||
@@ -299,3 +303,8 @@ }); | ||
return { ramp: rampResult, strategy: filtersResult.getStrategy(), stats: filtersResult.stats }; | ||
return { | ||
ramp: rampResult, | ||
strategy: filtersResult.getStrategy(), | ||
stats: filtersResult.stats, | ||
meta: filtersResult.meta | ||
}; | ||
}; | ||
@@ -327,3 +336,8 @@ } | ||
return { ramp: rampResult, strategy: filtersResult.getStrategy(), stats: filtersResult.stats }; | ||
return { | ||
ramp: rampResult, | ||
strategy: filtersResult.getStrategy(), | ||
stats: filtersResult.stats, | ||
meta: filtersResult.meta | ||
}; | ||
}; | ||
@@ -330,0 +344,0 @@ } |
@@ -6,6 +6,7 @@ 'use strict'; | ||
function FiltersResult (result, strategy, stats) { | ||
function FiltersResult (result, strategy, stats, meta) { | ||
ValuesResult.call(this, result, result.length); | ||
this.strategy = strategy; | ||
this.stats = stats; | ||
this.meta = meta || {}; | ||
} | ||
@@ -12,0 +13,0 @@ |
@@ -327,4 +327,5 @@ 'use strict'; | ||
var filter = processFilterValue(filterRaw); | ||
var columnName = this.filters.meta.columnName || column; | ||
var rule = postcss.rule({ | ||
selector: '[ ' + column + ' ' + this.mapping + ' ' + filter + ' ]' | ||
selector: '[ ' + columnName + ' ' + this.mapping + ' ' + filter + ' ]' | ||
}); | ||
@@ -331,0 +332,0 @@ rule.append(postcss.decl({ prop: decl.prop, value: values[index + indexOffset] })); |
103547
2679
222