turbo-carto
Advanced tools
Comparing version 0.20.2 to 0.20.3
# Changelog | ||
## Version 0.20.3 | ||
Released 2017-07-08 | ||
- Fix ramp result when number of buckets equals 2 #14075 | ||
- Move .catch() before .then() when calling postcss.process() #78 | ||
## Version 0.20.2 | ||
@@ -4,0 +9,0 @@ Released 2017-11-29 |
{ | ||
"name": "turbo-carto", | ||
"version": "0.20.2", | ||
"version": "0.20.3", | ||
"description": "CartoCSS preprocessor", | ||
@@ -5,0 +5,0 @@ "main": "src/index.js", |
@@ -225,3 +225,3 @@ 'use strict'; | ||
} | ||
var lastIndex = 0; | ||
var lastIndex = null; | ||
metadataRule.buckets = filters.slice(range.start, range.end).map(function (filterRaw, index) { | ||
@@ -243,3 +243,4 @@ var bucket = { | ||
var lastElementIndex = lastIndex === 0 ? 0 : (lastIndex + 1); | ||
var lastElementIndex = (lastIndex === null) ? 0 : (lastIndex + 1); | ||
metadataRule.buckets.push({ | ||
@@ -292,3 +293,3 @@ filter: { | ||
} | ||
var lastIndex = 0; | ||
var lastIndex = null; | ||
metadataRule.buckets = filters.slice(range.start, range.end).map(function (filterRaw, index) { | ||
@@ -310,3 +311,3 @@ var bucket = { | ||
var lastElementIndex = lastIndex === 0 ? 0 : (lastIndex + 1); | ||
var lastElementIndex = (lastIndex === null) ? 0 : (lastIndex + 1); | ||
metadataRule.buckets.push({ | ||
@@ -313,0 +314,0 @@ filter: { |
@@ -20,6 +20,6 @@ 'use strict'; | ||
.process(this.cartocss) | ||
.catch(callback) | ||
.then(function (result) { | ||
callback(null, result.css, self.metadataHolder); | ||
}) | ||
.catch(callback); | ||
}); | ||
}; | ||
@@ -26,0 +26,0 @@ |
@@ -7,38 +7,38 @@ 'use strict'; | ||
var scenarios = [ | ||
{ | ||
desc: '">" strategy', | ||
datasource: new DummyDatasource(function () { | ||
return [1]; | ||
}), | ||
turboCartocss: [ | ||
'#layer{', | ||
' marker-fill: ramp([cartodb_id], cartocolor(SunsetDark, 10), jenks);', | ||
'}' | ||
].join('\n'), | ||
expectedCartocss: [ | ||
'#layer{', | ||
' marker-fill: #fcde9c;', | ||
'}' | ||
].join('\n') | ||
}, | ||
{ | ||
desc: '"<" strategy', | ||
datasource: new DummyDatasource(function () { | ||
return [1]; | ||
}), | ||
turboCartocss: [ | ||
'#layer{', | ||
' marker-fill: ramp([cartodb_id], cartocolor(SunsetDark, 10), headtails(1));', | ||
'}' | ||
].join('\n'), | ||
expectedCartocss: [ | ||
'#layer{', | ||
' marker-fill: #7c1d6f;', | ||
'}' | ||
].join('\n') | ||
} | ||
]; | ||
describe('conditional ramp-buckets', function () { | ||
var scenarios = [ | ||
{ | ||
desc: '">" strategy', | ||
datasource: new DummyDatasource(function () { | ||
return [1]; | ||
}), | ||
turboCartocss: [ | ||
'#layer{', | ||
' marker-fill: ramp([cartodb_id], cartocolor(SunsetDark, 10), jenks);', | ||
'}' | ||
].join('\n'), | ||
expectedCartocss: [ | ||
'#layer{', | ||
' marker-fill: #fcde9c;', | ||
'}' | ||
].join('\n') | ||
}, | ||
{ | ||
desc: '"<" strategy', | ||
datasource: new DummyDatasource(function () { | ||
return [1]; | ||
}), | ||
turboCartocss: [ | ||
'#layer{', | ||
' marker-fill: ramp([cartodb_id], cartocolor(SunsetDark, 10), headtails(1));', | ||
'}' | ||
].join('\n'), | ||
expectedCartocss: [ | ||
'#layer{', | ||
' marker-fill: #7c1d6f;', | ||
'}' | ||
].join('\n') | ||
} | ||
]; | ||
describe('conditional ramp-buckets', function () { | ||
scenarios.forEach(function (scenario) { | ||
@@ -57,1 +57,120 @@ it('should generate a valid cartocss for a ramp with only one bucket/value and ' + scenario.desc, function (done) { | ||
}); | ||
describe('Buckets calculation', function () { | ||
function createCartoCSS (numBuckets) { | ||
return [ | ||
'#layer {', | ||
' marker-width: ramp([population], range(1, 100), quantiles(' + numBuckets + '));', | ||
' marker-fill: #EE4D5A;\n marker-fill-opacity: 0.9;\n', | ||
' marker-allow-overlap: true; \n marker-line-width: 1; \n', | ||
' marker-line-color: #FFFFFF; \n marker-line-opacity: 1; \n', | ||
'}' | ||
].join('\n'); | ||
} | ||
var scenarios = [ | ||
{ | ||
desc: 'Buckets: 1', | ||
numBuckets: 1, | ||
dataSourceStats: { min_val: 1, max_val: 100, avg_val: 50 }, | ||
ramp: [1], | ||
expectedBuckets: [ | ||
{ | ||
'filter': { | ||
'type': 'range', | ||
'start': 1, | ||
'end': 100 | ||
}, | ||
'value': 1 | ||
} | ||
], | ||
expectedStats: { | ||
filter_avg: 50 | ||
} | ||
}, | ||
{ | ||
desc: 'Buckets: 2', | ||
numBuckets: 2, | ||
dataSourceStats: { min_val: 1, max_val: 100, avg_val: 50 }, | ||
ramp: [1, 2], | ||
expectedBuckets: [ | ||
{ | ||
'filter': { | ||
'type': 'range', | ||
'start': 1, | ||
'end': 1 | ||
}, | ||
'value': 1 | ||
}, | ||
{ | ||
'filter': { | ||
'type': 'range', | ||
'start': 1, | ||
'end': 100 | ||
}, | ||
'value': 100 | ||
} | ||
], | ||
expectedStats: { | ||
filter_avg: 50 | ||
} | ||
}, | ||
{ | ||
desc: 'Buckets: 3', | ||
numBuckets: 3, | ||
dataSourceStats: { min_val: 1, max_val: 100, avg_val: 50 }, | ||
ramp: [1, 2, 3], | ||
expectedBuckets: [ | ||
{ | ||
'filter': { | ||
'type': 'range', | ||
'start': 1, | ||
'end': 1 | ||
}, | ||
'value': 1 | ||
}, | ||
{ | ||
'filter': { | ||
'type': 'range', | ||
'start': 1, | ||
'end': 2 | ||
}, | ||
'value': 50.5 | ||
}, | ||
{ | ||
'filter': { | ||
'type': 'range', | ||
'start': 2, | ||
'end': 100 | ||
}, | ||
'value': 100 | ||
} | ||
], | ||
expectedStats: { | ||
filter_avg: 50 | ||
} | ||
} | ||
]; | ||
scenarios.forEach(function (scenario) { | ||
it(scenario.desc, function (done) { | ||
var datasource = new DummyDatasource(function () { | ||
return { | ||
ramp: scenario.ramp, | ||
strategy: '>', | ||
stats: scenario.dataSourceStats | ||
}; | ||
}); | ||
var cartocss = createCartoCSS(scenario.numBuckets); | ||
turbocarto(cartocss, datasource, function (err, result, metadata) { | ||
assert.ifError(err); | ||
assert.equal(metadata.rules[0].buckets.length, scenario.numBuckets); | ||
assert.deepEqual(metadata.rules[0].buckets, scenario.expectedBuckets); | ||
done(); | ||
}); | ||
}); | ||
}); | ||
}); |
New author
Supply chain riskA new npm collaborator published a version of the package for the first time. New collaborators are usually benign additions to a project, but do indicate a change to the security surface area of a package.
Found 1 instance in 1 package
109037
2853
1