Windshaft-cartodb/lib/cartodb/models/dataview/histogram.js

38 lines
1.3 KiB
JavaScript
Raw Normal View History

2017-09-06 19:47:19 +08:00
const debug = require('debug')('windshaft:dataview:histogram');
const NumericHistogram = require('./numeric-histogram');
const DateHistogram = require('./date-histogram');
2017-09-06 21:52:13 +08:00
const TYPE = 'histogram';
const DATE_HISTOGRAM = 'DateHistogram';
const NUMERIC_HISTOGRAM = 'NumericHistogram';
2017-09-06 21:52:13 +08:00
module.exports = class Histogram {
2017-09-06 19:43:54 +08:00
constructor (query, options, queries) {
switch (this._getHistogramSubtype(options)) {
case DATE_HISTOGRAM:
debug('Delegating to DateHistogram with options: %j', options)
this.dataview = new DateHistogram(query, options, queries);
break;
case NUMERIC_HISTOGRAM:
debug('Delegating to NumericHistogram with options: %j', options)
this.dataview = new NumericHistogram(query, options, queries);
break;
default:
throw new Error('Unsupported Histogram type');
2017-09-06 19:43:54 +08:00
}
}
_getHistogramSubtype (options) {
if(options.bins && !options.aggregation) {
return NUMERIC_HISTOGRAM
} else if(options.aggregation && !options.bins) {
return DATE_HISTOGRAM
2017-09-06 19:43:54 +08:00
}
}
getResult (psql, override, callback) {
this.dataview.getResult(psql, override, callback);
}
};