Use ES6 class syntax
This commit is contained in:
parent
af4b3d81cd
commit
5ba2dfbbd6
@ -307,7 +307,11 @@ Time series:
|
||||
}
|
||||
}
|
||||
*/
|
||||
function Histogram(query, options, queries) {
|
||||
|
||||
module.exports = class Histogram extends BaseWidget {
|
||||
constructor (query, options, queries) {
|
||||
super();
|
||||
|
||||
if (!_.isString(options.column)) {
|
||||
throw new Error('Histogram expects `column` in widget options');
|
||||
}
|
||||
@ -320,14 +324,9 @@ function Histogram(query, options, queries) {
|
||||
this.offset = options.offset;
|
||||
|
||||
this._columnType = null;
|
||||
}
|
||||
}
|
||||
|
||||
Histogram.prototype = new BaseWidget();
|
||||
Histogram.prototype.constructor = Histogram;
|
||||
|
||||
module.exports = Histogram;
|
||||
|
||||
Histogram.prototype.sql = function(psql, override, callback) {
|
||||
sql (psql, override, callback) {
|
||||
var self = this;
|
||||
|
||||
if (!callback) {
|
||||
@ -350,13 +349,13 @@ Histogram.prototype.sql = function(psql, override, callback) {
|
||||
}
|
||||
|
||||
this._buildQuery(psql, override, callback);
|
||||
};
|
||||
}
|
||||
|
||||
Histogram.prototype.isDateHistogram = function (override) {
|
||||
isDateHistogram (override) {
|
||||
return this._columnType === 'date' && (this.aggregation !== undefined || override.aggregation !== undefined);
|
||||
};
|
||||
}
|
||||
|
||||
Histogram.prototype._buildQuery = function (psql, override, callback) {
|
||||
_buildQuery (psql, override, callback) {
|
||||
var filteredQuery, basicsQuery, binsQuery;
|
||||
var _column = this.column;
|
||||
var _query = this.query;
|
||||
@ -452,28 +451,17 @@ Histogram.prototype._buildQuery = function (psql, override, callback) {
|
||||
debug(histogramSql);
|
||||
|
||||
return callback(null, histogramSql);
|
||||
};
|
||||
}
|
||||
|
||||
Histogram.prototype._shouldOverride = function (override) {
|
||||
_shouldOverride (override) {
|
||||
return override && _.has(override, 'start') && _.has(override, 'end') && _.has(override, 'bins');
|
||||
};
|
||||
}
|
||||
|
||||
Histogram.prototype._shouldOverrideBins = function (override) {
|
||||
_shouldOverrideBins (override) {
|
||||
return override && _.has(override, 'bins');
|
||||
};
|
||||
}
|
||||
|
||||
var DATE_AGGREGATIONS = {
|
||||
'auto': true,
|
||||
'minute': true,
|
||||
'hour': true,
|
||||
'day': true,
|
||||
'week': true,
|
||||
'month': true,
|
||||
'quarter': true,
|
||||
'year': true
|
||||
};
|
||||
|
||||
Histogram.prototype._buildDateHistogramQuery = function (psql, override, callback) {
|
||||
_buildDateHistogramQuery (psql, override, callback) {
|
||||
var _column = this.column;
|
||||
var _query = this.query;
|
||||
var _aggregation = override && override.aggregation ? override.aggregation : this.aggregation;
|
||||
@ -549,9 +537,9 @@ Histogram.prototype._buildDateHistogramQuery = function (psql, override, callbac
|
||||
debug(histogramSql);
|
||||
|
||||
return callback(null, histogramSql);
|
||||
};
|
||||
}
|
||||
|
||||
Histogram.prototype.getAutomaticAggregation = function (psql, callback) {
|
||||
getAutomaticAggregation (psql, callback) {
|
||||
var dateIntervalQuery = dateIntervalQueryTpl({
|
||||
query: this.query,
|
||||
column: this.column
|
||||
@ -589,9 +577,9 @@ Histogram.prototype.getAutomaticAggregation = function (psql, callback) {
|
||||
|
||||
callback(null, aggregation.name);
|
||||
});
|
||||
};
|
||||
}
|
||||
|
||||
Histogram.prototype.format = function(result, override) {
|
||||
format (result, override) {
|
||||
override = override || {};
|
||||
var buckets = [];
|
||||
|
||||
@ -649,6 +637,30 @@ Histogram.prototype.format = function(result, override) {
|
||||
avg: avg,
|
||||
bins: buckets
|
||||
};
|
||||
}
|
||||
|
||||
getType () {
|
||||
return TYPE;
|
||||
}
|
||||
|
||||
toString () {
|
||||
return JSON.stringify({
|
||||
_type: TYPE,
|
||||
_column: this.column,
|
||||
_query: this.query
|
||||
});
|
||||
}
|
||||
};
|
||||
|
||||
var DATE_AGGREGATIONS = {
|
||||
'auto': true,
|
||||
'minute': true,
|
||||
'hour': true,
|
||||
'day': true,
|
||||
'week': true,
|
||||
'month': true,
|
||||
'quarter': true,
|
||||
'year': true
|
||||
};
|
||||
|
||||
function getAggregation(override, aggregation) {
|
||||
@ -720,15 +732,3 @@ function populateBinStart(override, firstRow) {
|
||||
|
||||
return binStart;
|
||||
}
|
||||
|
||||
Histogram.prototype.getType = function() {
|
||||
return TYPE;
|
||||
};
|
||||
|
||||
Histogram.prototype.toString = function() {
|
||||
return JSON.stringify({
|
||||
_type: TYPE,
|
||||
_column: this.column,
|
||||
_query: this.query
|
||||
});
|
||||
};
|
||||
|
Loading…
Reference in New Issue
Block a user