diff --git a/js/services.js b/js/services.js index 2615002a6b8..eceb1f8ac5e 100644 --- a/js/services.js +++ b/js/services.js @@ -870,79 +870,4 @@ angular.module('kibana.services', []) return false; }); }; -}) -.service('timeSeries', function () { - /** - * Certain graphs require 0 entries to be specified for them to render - * properly (like the line graph). So with this we will caluclate all of - * the expected time measurements, and fill the missing ones in with 0 - * @param date start The start time for the result set - * @param date end The end time for the result set - * @param integer interval The length between measurements, in es interval - * notation (1m, 30s, 1h, 15d) - */ - var undef; - function dateToSecondsWithBlankMs(date) { - // return the date as millis since epoch, with 0 millis - return Math.floor(date.getTime() / 1000)*1000; - } - function base10Int(val) { - return parseInt(val, 10); - } - this.ZeroFilled = function (interval, start, end) { - // the expected differenece between readings. - this.interval_ms = parseInt(kbn.interval_to_seconds(interval), 10) * 1000; - // will keep all values here, keyed by their time - this._data = {}; - - if (start) { - this.addValue(start, null); - } - if (end) { - this.addValue(end, null); - } - } - /** - * Add a row - * @param int time The time for the value, in - * @param any value The value at this time - */ - this.ZeroFilled.prototype.addValue = function (time, value) { - if (time instanceof Date) { - time = dateToSecondsWithBlankMs(time); - } else { - time = parseInt(time, 10); - } - if (!isNaN(time)) { - this._data[time] = (value === undef ? 0 : value); - } - }; - /** - * return the rows in the format: - * [ [time, value], [time, value], ... ] - * @return array - */ - this.ZeroFilled.prototype.getFlotPairs = function () { - // var startTime = performance.now(); - var times = _.map(_.keys(this._data), base10Int).sort() - , result = [] - , i - , next - , expected_next; - for(i = 0; i < times.length; i++) { - result.push([ times[i], this._data[times[i]] ]); - next = times[i + 1]; - expected_next = times[i] + this.interval_ms; - for(; times.length > i && next > expected_next; expected_next+= this.interval_ms) { - /** - * since we don't know how the server will round subsequent segments - * we have to recheck for blanks each time. - */ - // this._data[expected_next] = 0; - result.push([expected_next, 0]); - } - } - // console.log(Math.round((performance.now() - startTime)*100)/100, 'ms to get', result.length, 'pairs'); - return result; - }; }); \ No newline at end of file diff --git a/panels/histogram/module.js b/panels/histogram/module.js index 83a88566cb1..90de0372336 100644 --- a/panels/histogram/module.js +++ b/panels/histogram/module.js @@ -436,4 +436,75 @@ angular.module('kibana.histogram', []) }); } }; +}) +.service('timeSeries', function () { + /** + * Certain graphs require 0 entries to be specified for them to render + * properly (like the line graph). So with this we will caluclate all of + * the expected time measurements, and fill the missing ones in with 0 + * @param date start The start time for the result set + * @param date end The end time for the result set + * @param integer interval The length between measurements, in es interval + * notation (1m, 30s, 1h, 15d) + */ + var undef; + function base10Int(val) { + return parseInt(val, 10); + } + this.ZeroFilled = function (interval, start, end) { + // the expected differenece between readings. + this.interval_ms = base10Int(kbn.interval_to_seconds(interval)) * 1000; + // will keep all values here, keyed by their time + this._data = {}; + + if (start) { + this.addValue(start, null); + } + if (end) { + this.addValue(end, null); + } + } + /** + * Add a row + * @param int time The time for the value, in + * @param any value The value at this time + */ + this.ZeroFilled.prototype.addValue = function (time, value) { + if (time instanceof Date) { + time = Math.floor(time.getTime() / 1000)*1000; + } else { + time = base10Int(time); + } + if (!isNaN(time)) { + this._data[time] = (value === undef ? 0 : value); + } + }; + /** + * return the rows in the format: + * [ [time, value], [time, value], ... ] + * @return array + */ + this.ZeroFilled.prototype.getFlotPairs = function () { + // var startTime = performance.now(); + var times = _.map(_.keys(this._data), base10Int).sort() + , result = [] + , i + , next + , expected_next; + for(i = 0; i < times.length; i++) { + result.push([ times[i], this._data[times[i]] ]); + next = times[i + 1]; + expected_next = times[i] + this.interval_ms; + for(; times.length > i && next > expected_next; expected_next+= this.interval_ms) { + /** + * since we don't know how the server will round subsequent segments + * we have to recheck for blanks each time. + */ + // this._data[expected_next] = 0; + result.push([expected_next, 0]); + } + } + // console.log(Math.round((performance.now() - startTime)*100)/100, 'ms to get', result.length, 'pairs'); + return result; + }; }); \ No newline at end of file