Rename HistogramBase by BaseHistogram
This commit is contained in:
parent
6c3fa045cd
commit
ec23bfc79b
@ -8,13 +8,13 @@ const NUMERIC_HISTOGRAM = 'NumericHistogram';
|
||||
module.exports = class Histogram {
|
||||
constructor (query, options, queries) {
|
||||
this.query = query;
|
||||
this.options = options ||{};
|
||||
this.options = options || {};
|
||||
this.queries = queries;
|
||||
|
||||
this.dataview = this._getHistogramImplemetation();
|
||||
this.dataview = this._getHistogramImplementation();
|
||||
}
|
||||
|
||||
_getHistogramImplemetation (override) {
|
||||
_getHistogramImplementation (override) {
|
||||
let implementation = null;
|
||||
|
||||
switch (this._getHistogramSubtype(override)) {
|
||||
@ -31,17 +31,17 @@ module.exports = class Histogram {
|
||||
}
|
||||
|
||||
return implementation;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
_getHistogramSubtype (override = {}) {
|
||||
if(this.options.aggregation !== undefined || override.aggregation !== undefined) {
|
||||
return DATE_HISTOGRAM;
|
||||
}
|
||||
return NUMERIC_HISTOGRAM;
|
||||
}
|
||||
|
||||
|
||||
getResult (psql, override, callback) {
|
||||
this.dataview = this._getHistogramImplemetation(override);
|
||||
this.dataview = this._getHistogramImplementation(override);
|
||||
this.dataview.getResult(psql, override, callback);
|
||||
}
|
||||
|
||||
|
@ -1,4 +1,4 @@
|
||||
const HistogramBase = require('./histogramBase');
|
||||
const BaseHistogram = require('./base-histogram');
|
||||
|
||||
const dateIntervalQueryTpl = ctx => `
|
||||
WITH
|
||||
@ -165,10 +165,10 @@ const DATE_AGGREGATIONS = {
|
||||
}
|
||||
}
|
||||
*/
|
||||
module.exports = class DateHistogram extends HistogramBase {
|
||||
module.exports = class DateHistogram extends BaseHistogram {
|
||||
constructor (query, options, queries) {
|
||||
super(query, options, queries);
|
||||
|
||||
|
||||
this.aggregation = options.aggregation;
|
||||
this.offset = options.offset;
|
||||
}
|
||||
|
@ -1,77 +0,0 @@
|
||||
const BaseDataview = require('../base');
|
||||
|
||||
const TYPE = 'histogram';
|
||||
|
||||
module.exports = class HistogramBase extends BaseDataview {
|
||||
constructor (query, options, queries) {
|
||||
super();
|
||||
|
||||
if (typeof options.column !== 'string') {
|
||||
throw new Error('Histogram expects `column` in widget options');
|
||||
}
|
||||
|
||||
this.query = query;
|
||||
this.queries = queries;
|
||||
this.column = options.column;
|
||||
this.bins = options.bins;
|
||||
|
||||
this._columnType = null;
|
||||
}
|
||||
|
||||
sql (psql, override, callback) {
|
||||
if (!callback) {
|
||||
callback = override;
|
||||
override = {};
|
||||
}
|
||||
|
||||
if (this._columnType === null) {
|
||||
this.getColumnType(psql, this.column, this.queries.no_filters, (err, type) => {
|
||||
// assume numeric, will fail later
|
||||
this._columnType = 'numeric';
|
||||
if (!err && !!type) {
|
||||
this._columnType = Object.keys(type).find(function (key) {
|
||||
return type[key];
|
||||
});
|
||||
}
|
||||
this.sql(psql, override, callback);
|
||||
}, true); // use read-only transaction
|
||||
return null;
|
||||
}
|
||||
|
||||
return this._buildQuery(psql, override, callback);
|
||||
}
|
||||
|
||||
getType () {
|
||||
return TYPE;
|
||||
}
|
||||
|
||||
toString () {
|
||||
return JSON.stringify({
|
||||
_type: TYPE,
|
||||
_column: this.column,
|
||||
_query: this.query
|
||||
});
|
||||
}
|
||||
|
||||
_getBinEnd (override) {
|
||||
if (override.hasOwnProperty('start') && override.hasOwnProperty('end')) {
|
||||
return Math.max(override.start, override.end);
|
||||
}
|
||||
return override.end || 0;
|
||||
}
|
||||
|
||||
_getBinsCount (override) {
|
||||
return override.bins || 0;
|
||||
}
|
||||
|
||||
_getWidth (override) {
|
||||
let width = 0;
|
||||
const binsCount = override.bins;
|
||||
|
||||
if (binsCount && Number.isFinite(override.start) && Number.isFinite(override.end)) {
|
||||
width = (override.end - override.start) / binsCount;
|
||||
}
|
||||
|
||||
return width;
|
||||
}
|
||||
};
|
@ -1,4 +1,4 @@
|
||||
const HistogramBase = require('./histogramBase');
|
||||
const BaseHistogram = require('./base-histogram');
|
||||
|
||||
const columnCastTpl = ctx => `date_part('epoch', ${ctx.column})`;
|
||||
|
||||
@ -159,7 +159,7 @@ Numeric histogram:
|
||||
}
|
||||
}
|
||||
*/
|
||||
module.exports = class NumericHistogram extends HistogramBase {
|
||||
module.exports = class NumericHistogram extends BaseHistogram {
|
||||
constructor (query, options, queries) {
|
||||
super(query, options, queries);
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user