diff --git a/lib/cartodb/models/dataview/histogram.js b/lib/cartodb/models/dataview/histogram.js index 43b6ee86..01827b54 100644 --- a/lib/cartodb/models/dataview/histogram.js +++ b/lib/cartodb/models/dataview/histogram.js @@ -399,11 +399,7 @@ Histogram.prototype.format = function(result, override) { width = firstRow.bin_width || width; avg = firstRow.avg_val; nulls = firstRow.nulls_count; - binsStart = override.hasOwnProperty('start') ? - getBinStart(override) : - firstRow.hasOwnProperty('timestamp') ? - firstRow.timestamp : - firstRow.min; + binsStart = populateBinStart(override, firstRow); buckets = result.rows.map(function(row) { return _.omit(row, 'bins_number', 'bin_width', 'nulls_count', 'avg_val'); @@ -457,6 +453,20 @@ function getTimezone(timezone) { return '' + timezoneInHours; } +function populateBinStart(override, firstRow) { + var binStart; + + if (override.hasOwnProperty('start')) { + binStart = getBinStart(override); + } else if (firstRow.hasOwnProperty('timestamp')) { + binStart = firstRow.timestamp; + } else { + binStart = firstRow.min; + } + + return binStart; +} + Histogram.prototype.getType = function() { return TYPE; };