2018-10-24 00:39:02 +08:00
|
|
|
'use strict';
|
|
|
|
|
2019-10-07 16:44:45 +08:00
|
|
|
require('../../support/test-helper');
|
2016-03-19 00:22:02 +08:00
|
|
|
|
|
|
|
var assert = require('../../support/assert');
|
|
|
|
var TestClient = require('../../support/test-client');
|
|
|
|
var dot = require('dot');
|
|
|
|
|
2019-10-22 01:07:24 +08:00
|
|
|
describe('analysis-layers-dataviews', function () {
|
2016-03-19 00:22:02 +08:00
|
|
|
var multitypeStyleTemplate = dot.template([
|
|
|
|
"#points['mapnik::geometry_type'=1] {",
|
2019-10-22 01:07:24 +08:00
|
|
|
' marker-fill-opacity: {{=it._opacity}};',
|
|
|
|
' marker-line-color: #FFF;',
|
|
|
|
' marker-line-width: 0.5;',
|
|
|
|
' marker-line-opacity: {{=it._opacity}};',
|
|
|
|
' marker-placement: point;',
|
|
|
|
' marker-type: ellipse;',
|
|
|
|
' marker-width: 8;',
|
|
|
|
' marker-fill: {{=it._color}};',
|
|
|
|
' marker-allow-overlap: true;',
|
|
|
|
'}',
|
2016-03-19 00:22:02 +08:00
|
|
|
"#lines['mapnik::geometry_type'=2] {",
|
2019-10-22 01:07:24 +08:00
|
|
|
' line-color: {{=it._color}};',
|
|
|
|
' line-width: 2;',
|
|
|
|
' line-opacity: {{=it._opacity}};',
|
|
|
|
'}',
|
2016-03-19 00:22:02 +08:00
|
|
|
"#polygons['mapnik::geometry_type'=3] {",
|
2019-10-22 01:07:24 +08:00
|
|
|
' polygon-fill: {{=it._color}};',
|
|
|
|
' polygon-opacity: {{=it._opacity}};',
|
|
|
|
' line-color: #FFF;',
|
|
|
|
' line-width: 0.5;',
|
|
|
|
' line-opacity: {{=it._opacity}};',
|
|
|
|
'}'
|
2016-03-19 00:22:02 +08:00
|
|
|
].join('\n'));
|
|
|
|
|
2019-10-22 01:07:24 +08:00
|
|
|
function cartocss (color, opacity) {
|
2016-03-19 00:22:02 +08:00
|
|
|
return multitypeStyleTemplate({
|
|
|
|
_color: color || '#F11810',
|
|
|
|
_opacity: Number.isFinite(opacity) ? opacity : 1
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2019-10-22 01:07:24 +08:00
|
|
|
function createMapConfig (layers, dataviews, analysis) {
|
2016-03-19 00:22:02 +08:00
|
|
|
return {
|
|
|
|
version: '1.5.0',
|
|
|
|
layers: layers,
|
|
|
|
dataviews: dataviews || {},
|
|
|
|
analyses: analysis || []
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
var DEFAULT_MULTITYPE_STYLE = cartocss();
|
|
|
|
|
|
|
|
var mapConfig = createMapConfig(
|
|
|
|
[
|
|
|
|
{
|
2019-10-22 01:07:24 +08:00
|
|
|
type: 'cartodb',
|
|
|
|
options: {
|
|
|
|
source: {
|
|
|
|
id: '2570e105-7b37-40d2-bdf4-1af889598745'
|
2016-03-19 00:22:02 +08:00
|
|
|
},
|
2019-10-22 01:07:24 +08:00
|
|
|
cartocss: DEFAULT_MULTITYPE_STYLE,
|
|
|
|
cartocss_version: '2.3.0'
|
2016-03-19 00:22:02 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
],
|
|
|
|
{
|
|
|
|
pop_max_histogram: {
|
|
|
|
source: {
|
|
|
|
id: '2570e105-7b37-40d2-bdf4-1af889598745'
|
|
|
|
},
|
|
|
|
type: 'histogram',
|
|
|
|
options: {
|
|
|
|
column: 'pop_max'
|
|
|
|
}
|
|
|
|
}
|
|
|
|
},
|
|
|
|
[
|
|
|
|
{
|
2019-10-22 01:07:24 +08:00
|
|
|
id: '2570e105-7b37-40d2-bdf4-1af889598745',
|
|
|
|
type: 'source',
|
|
|
|
params: {
|
|
|
|
query: 'select * from populated_places_simple_reduced'
|
2016-03-19 00:22:02 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
]
|
|
|
|
);
|
|
|
|
|
2019-10-22 01:07:24 +08:00
|
|
|
it('should get histogram dataview', function (done) {
|
2016-03-19 00:22:02 +08:00
|
|
|
var testClient = new TestClient(mapConfig, 1234);
|
|
|
|
|
2019-10-22 01:07:24 +08:00
|
|
|
testClient.getDataview('pop_max_histogram', function (err, dataview) {
|
2016-03-19 00:22:02 +08:00
|
|
|
assert.ok(!err, err);
|
|
|
|
|
2019-10-22 01:41:03 +08:00
|
|
|
assert.strictEqual(dataview.type, 'histogram');
|
|
|
|
assert.strictEqual(dataview.bins_start, 0);
|
2016-03-19 00:22:02 +08:00
|
|
|
|
|
|
|
testClient.drain(done);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2019-10-22 01:07:24 +08:00
|
|
|
it('should get a filtered histogram dataview', function (done) {
|
2016-03-19 00:22:02 +08:00
|
|
|
var testClient = new TestClient(mapConfig, 1234);
|
|
|
|
|
|
|
|
var params = {
|
|
|
|
filters: {
|
|
|
|
dataviews: {
|
|
|
|
pop_max_histogram: {
|
|
|
|
min: 2e6
|
|
|
|
}
|
|
|
|
}
|
2017-12-13 17:43:43 +08:00
|
|
|
},
|
|
|
|
own_filter: 1
|
2016-03-19 00:22:02 +08:00
|
|
|
};
|
|
|
|
|
2019-10-22 01:07:24 +08:00
|
|
|
testClient.getDataview('pop_max_histogram', params, function (err, dataview) {
|
2016-03-19 00:22:02 +08:00
|
|
|
assert.ok(!err, err);
|
|
|
|
|
2019-10-22 01:41:03 +08:00
|
|
|
assert.strictEqual(dataview.type, 'histogram');
|
|
|
|
assert.strictEqual(dataview.bins_start, 2008000);
|
2016-03-19 00:22:02 +08:00
|
|
|
|
|
|
|
testClient.drain(done);
|
|
|
|
});
|
|
|
|
});
|
2016-03-19 00:49:20 +08:00
|
|
|
|
2019-10-22 01:07:24 +08:00
|
|
|
it('should skip the filter when sending own_filter=0 for histogram dataview', function (done) {
|
2016-03-19 00:49:20 +08:00
|
|
|
var testClient = new TestClient(mapConfig, 1234);
|
|
|
|
|
|
|
|
var params = {
|
|
|
|
filters: {
|
|
|
|
dataviews: {
|
|
|
|
pop_max_histogram: {
|
|
|
|
min: 2e6
|
|
|
|
}
|
|
|
|
}
|
|
|
|
},
|
|
|
|
own_filter: 0
|
|
|
|
};
|
|
|
|
|
2019-10-22 01:07:24 +08:00
|
|
|
testClient.getDataview('pop_max_histogram', params, function (err, dataview) {
|
2016-03-19 00:49:20 +08:00
|
|
|
assert.ok(!err, err);
|
|
|
|
|
2019-10-22 01:41:03 +08:00
|
|
|
assert.strictEqual(dataview.type, 'histogram');
|
|
|
|
assert.strictEqual(dataview.bins_start, 0);
|
2016-03-19 00:49:20 +08:00
|
|
|
|
|
|
|
testClient.drain(done);
|
|
|
|
});
|
|
|
|
});
|
2016-03-19 00:22:02 +08:00
|
|
|
});
|