Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Zero filled ts #438

Merged
merged 2 commits into from
Aug 29, 2013
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 24 additions & 12 deletions panels/histogram/module.js
Original file line number Diff line number Diff line change
Expand Up @@ -391,7 +391,7 @@ angular.module('kibana.histogram', [])
// when rendering stacked bars, we need to ensure each point that has data is zero-filled
// so that the stacking happens in the proper order
var required_times = [];
if (scope.panel.bars && stack) {
if (scope.data.length > 1) {
required_times = _.uniq(Array.prototype.concat.apply([], _.map(scope.data, function (query) {
return query.time_series.getOrderedTimes();
})).sort(), true);
Expand Down Expand Up @@ -457,6 +457,10 @@ angular.module('kibana.histogram', [])
return parseInt(val, 10);
}

function getDatesTime(date) {
return Math.floor(date.getTime() / 1000)*1000;
}

/**
* 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
Expand All @@ -474,7 +478,7 @@ angular.module('kibana.histogram', [])
* the series.
*/
this.ZeroFilled = function (opts) {
this.opts = _.defaults(opts, {
opts = _.defaults(opts, {
interval: '10m',
start_date: null,
end_date: null,
Expand All @@ -486,13 +490,9 @@ angular.module('kibana.histogram', [])

// will keep all values here, keyed by their time
this._data = {};

if (opts.start_date) {
this.addValue(opts.start_date, null);
}
if (opts.end_date) {
this.addValue(opts.end_date, null);
}
this.start_time = opts.start_date && getDatesTime(opts.start_date);
this.end_time = opts.end_date && getDatesTime(opts.end_date);
this.opts = opts;
};

/**
Expand All @@ -502,7 +502,7 @@ angular.module('kibana.histogram', [])
*/
this.ZeroFilled.prototype.addValue = function (time, value) {
if (time instanceof Date) {
time = Math.floor(time.getTime() / 1000)*1000;
time = getDatesTime(time);
} else {
time = base10Int(time);
}
Expand Down Expand Up @@ -536,20 +536,32 @@ angular.module('kibana.histogram', [])
this.ZeroFilled.prototype.getFlotPairs = function (required_times) {
var times = this.getOrderedTimes(required_times),
strategy,
pairs;
pairs,
pairs_empty;

if(this.opts.fill_style === 'all') {
strategy = this._getAllFlotPairs;
} else {
strategy = this._getMinFlotPairs;
}

return _.reduce(
pairs = _.reduce(
times, // what
strategy, // how
[], // where
this // context
);

// if the start and end of the pairs are inside either the start or end time,
// add those times to the series with null values so the graph will stretch to contain them.
if (this.start_time && (pairs.length === 0 || pairs[0][0] > this.start_time)) {
pairs.unshift([this.start_time, null]);
}
if (this.end_time && (pairs.length === 0 || pairs[pairs.length - 1][0] < this.end_time)) {
pairs.push([this.end_time, null]);
}

return pairs;
};

/**
Expand Down