moved the timeSeries service into the histogram module.
This commit is contained in:
committed by
Rashid Khan
parent
1274a718dc
commit
e858d3cb62
@@ -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;
|
||||
};
|
||||
});
|
||||
@@ -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;
|
||||
};
|
||||
});
|
||||
Reference in New Issue
Block a user