Working on non time series X-axis feature.

This commit is contained in:
Alexander Zobnin 2016-08-14 17:33:18 +03:00
parent 1eca0d7c53
commit 7588ee974d
3 changed files with 77 additions and 12 deletions

View File

@ -28,7 +28,7 @@ function (angular, $, moment, _, kbn, GraphTooltip) {
var ctrl = scope.ctrl;
var dashboard = ctrl.dashboard;
var panel = ctrl.panel;
var data, annotations;
var data, annotations, histogramData;
var sortedSeries;
var legendSideLastValue = null;
var rootScope = scope.$root;
@ -226,22 +226,37 @@ function (angular, $, moment, _, kbn, GraphTooltip) {
}
};
for (var i = 0; i < data.length; i++) {
var series = data[i];
series.data = series.getFlotPairs(series.nullPointMode || panel.nullPointMode);
if (panel.xaxis.mode === 'histogram') {
histogramData = formatToHistogram(data, _.last);
// if hidden remove points and disable stack
if (ctrl.hiddenSeries[series.alias]) {
series.data = [];
series.stack = false;
if (histogramData.length && histogramData[0].ticks.length) {
// options.series.bars.barWidth = histogramData[0].ticks.length / 1.5;
options.series.bars.barWidth = 0.7;
// options.series.bars.align = 'center';
}
} else {
for (var i = 0; i < data.length; i++) {
var series = data[i];
series.data = series.getFlotPairs(series.nullPointMode || panel.nullPointMode);
// if hidden remove points and disable stack
if (ctrl.hiddenSeries[series.alias]) {
series.data = [];
series.stack = false;
}
}
if (data.length && data[0].stats.timeStep) {
options.series.bars.barWidth = data[0].stats.timeStep / 1.5;
}
}
if (data.length && data[0].stats.timeStep) {
options.series.bars.barWidth = data[0].stats.timeStep / 1.5;
if (panel.xaxis.mode === 'histogram') {
addXAxis(options);
} else {
addTimeAxis(options);
}
addTimeAxis(options);
addGridThresholds(options, panel);
addAnnotations(options);
configureAxisOptions(data, options);
@ -275,6 +290,24 @@ function (angular, $, moment, _, kbn, GraphTooltip) {
}
}
function formatToHistogram(data, getValueCallback) {
var histogram = [data[0]];
histogram[0].data = _.map(data, function(series, index) {
var values = _.remove(_.map(series.datapoints, function(point) {
return point[0];
}), null);
var calculatedPoint = getValueCallback(values);
return [index, calculatedPoint];
});
histogram[0].ticks = _.map(data, function(series, index) {
return [index, series.alias];
});
return histogram;
}
function translateFillOption(fill) {
return fill === 0 ? 0.001 : fill/10;
}
@ -305,6 +338,20 @@ function (angular, $, moment, _, kbn, GraphTooltip) {
};
}
function addXAxis(options) {
var ticks = histogramData[0].ticks;
options.xaxis = {
timezone: dashboard.getTimezone(),
show: panel.xaxis.show,
mode: null,
min: 0,
max: ticks.length,
label: "Datetime",
ticks: ticks
};
}
function addGridThresholds(options, panel) {
if (_.isNumber(panel.grid.threshold1)) {
var limit1 = panel.grid.thresholdLine ? panel.grid.threshold1 : (panel.grid.threshold2 || null);

View File

@ -20,6 +20,7 @@ class GraphCtrl extends MetricsPanelCtrl {
seriesList: any = [];
logScales: any;
unitFormats: any;
xAxisModes: any;
annotationsPromise: any;
datapointsCount: number;
datapointsOutside: boolean;
@ -50,7 +51,8 @@ class GraphCtrl extends MetricsPanelCtrl {
}
],
xaxis: {
show: true
show: true,
mode: 'timeseries'
},
grid : {
threshold1: null,
@ -138,6 +140,11 @@ class GraphCtrl extends MetricsPanelCtrl {
'log (base 1024)': 1024
};
this.unitFormats = kbn.getUnitFormats();
this.xAxisModes = {
'Time Series': 'timeseries',
'Histogram': 'histogram'
};
}
onInitPanelActions(actions) {

View File

@ -40,6 +40,17 @@
<div class="section gf-form-group">
<h5 class="section-heading">X-Axis</h5>
<gf-form-switch class="gf-form" label="Show" label-class="width-5" checked="ctrl.panel.xaxis.show" on-change="ctrl.render()"></gf-form-switch>
<div class="gf-form">
<label class="gf-form-label width-5">Mode</label>
<div class="gf-form-select-wrapper max-width-15">
<select class="gf-form-input"
ng-model="ctrl.panel.xaxis.mode"
ng-options="v as k for (k, v) in ctrl.xAxisModes"
ng-change="ctrl.render()">
</select>
</div>
</div>
</div>
<div class="section gf-form-group">