Move getBinStart and populateBinStart function to a class method

This commit is contained in:
Daniel García Aubert 2017-09-06 15:38:23 +02:00
parent 288656301b
commit 392e004879

View File

@ -379,7 +379,7 @@ module.exports = class Histogram extends BaseWidget {
basicsQuery = overrideBasicsQueryTpl({
_query: _query,
_column: _column,
_start: getBinStart(override),
_start: this.getBinStart(override),
_end: getBinEnd(override)
});
@ -493,7 +493,7 @@ module.exports = class Histogram extends BaseWidget {
_query: _query,
_column: _column,
_aggregation: _aggregation,
_start: getBinStart(override),
_start: this.getBinStart(override),
_end: getBinEnd(override),
_offset: parseOffset(_offset, _aggregation)
});
@ -585,7 +585,7 @@ module.exports = class Histogram extends BaseWidget {
var binsCount = getBinsCount(override);
var width = getWidth(override);
var binsStart = getBinStart(override);
var binsStart = this.getBinStart(override);
var nulls = 0;
var infinities = 0;
var nans = 0;
@ -603,7 +603,7 @@ module.exports = class Histogram extends BaseWidget {
timestampStart = firstRow.timestamp_start;
infinities = firstRow.infinities_count;
nans = firstRow.nans_count;
binsStart = populateBinStart(override, firstRow);
binsStart = this.populateBinStart(override, firstRow);
if (Number.isFinite(timestampStart)) {
aggregation = this.getAggregation(override);
@ -665,6 +665,27 @@ module.exports = class Histogram extends BaseWidget {
return 0;
}
getBinStart (override) {
if (override.hasOwnProperty('start') && override.hasOwnProperty('end')) {
return Math.min(override.start, override.end);
}
return override.start || 0;
}
populateBinStart (override, firstRow) {
var binStart;
if (firstRow.hasOwnProperty('timestamp')) {
binStart = firstRow.timestamp;
} else if (override.hasOwnProperty('start')) {
binStart = this.getBinStart(override);
} else {
binStart = firstRow.min;
}
return binStart;
}
};
var DATE_AGGREGATIONS = {
@ -678,13 +699,6 @@ var DATE_AGGREGATIONS = {
'year': true
};
function getBinStart(override) {
if (override.hasOwnProperty('start') && override.hasOwnProperty('end')) {
return Math.min(override.start, override.end);
}
return override.start || 0;
}
function getBinEnd(override) {
if (override.hasOwnProperty('start') && override.hasOwnProperty('end')) {
return Math.max(override.start, override.end);
@ -719,16 +733,3 @@ function parseOffset(offset, aggregation) {
return '' + offsetInHours;
}
function populateBinStart(override, firstRow) {
var binStart;
if (firstRow.hasOwnProperty('timestamp')) {
binStart = firstRow.timestamp;
} else if (override.hasOwnProperty('start')) {
binStart = getBinStart(override);
} else {
binStart = firstRow.min;
}
return binStart;
}