|
@@ -6,82 +6,46 @@ define([
|
|
|
'kbn',
|
|
'kbn',
|
|
|
'moment',
|
|
'moment',
|
|
|
'components/timeSeries',
|
|
'components/timeSeries',
|
|
|
- './seriesOverridesCtrl',
|
|
|
|
|
|
|
+ 'components/panelmeta',
|
|
|
'services/panelSrv',
|
|
'services/panelSrv',
|
|
|
'services/annotationsSrv',
|
|
'services/annotationsSrv',
|
|
|
'services/datasourceSrv',
|
|
'services/datasourceSrv',
|
|
|
- 'jquery.flot',
|
|
|
|
|
- 'jquery.flot.events',
|
|
|
|
|
- 'jquery.flot.selection',
|
|
|
|
|
- 'jquery.flot.time',
|
|
|
|
|
- 'jquery.flot.stack',
|
|
|
|
|
- 'jquery.flot.stackpercent',
|
|
|
|
|
- 'jquery.flot.crosshair'
|
|
|
|
|
|
|
+ './seriesOverridesCtrl',
|
|
|
|
|
+ './graph',
|
|
|
|
|
+ './legend',
|
|
|
],
|
|
],
|
|
|
-function (angular, app, $, _, kbn, moment, TimeSeries) {
|
|
|
|
|
|
|
+function (angular, app, $, _, kbn, moment, TimeSeries, PanelMeta) {
|
|
|
'use strict';
|
|
'use strict';
|
|
|
|
|
|
|
|
var module = angular.module('grafana.panels.graph');
|
|
var module = angular.module('grafana.panels.graph');
|
|
|
- app.useModule(module);
|
|
|
|
|
|
|
|
|
|
module.controller('GraphCtrl', function($scope, $rootScope, panelSrv, annotationsSrv, timeSrv) {
|
|
module.controller('GraphCtrl', function($scope, $rootScope, panelSrv, annotationsSrv, timeSrv) {
|
|
|
|
|
|
|
|
- $scope.panelMeta = {
|
|
|
|
|
- modals : [],
|
|
|
|
|
- editorTabs: [],
|
|
|
|
|
- fullEditorTabs : [
|
|
|
|
|
- {
|
|
|
|
|
- title: 'General',
|
|
|
|
|
- src:'app/partials/panelgeneral.html'
|
|
|
|
|
- },
|
|
|
|
|
- {
|
|
|
|
|
- title: 'Metrics',
|
|
|
|
|
- src:'app/partials/metrics.html'
|
|
|
|
|
- },
|
|
|
|
|
- {
|
|
|
|
|
- title:'Axes & Grid',
|
|
|
|
|
- src:'app/panels/graph/axisEditor.html'
|
|
|
|
|
- },
|
|
|
|
|
- {
|
|
|
|
|
- title:'Display Styles',
|
|
|
|
|
- src:'app/panels/graph/styleEditor.html'
|
|
|
|
|
- }
|
|
|
|
|
- ],
|
|
|
|
|
- fullscreenEdit: true,
|
|
|
|
|
- fullscreenView: true,
|
|
|
|
|
- description : "Graphing"
|
|
|
|
|
- };
|
|
|
|
|
|
|
+ $scope.panelMeta = new PanelMeta({
|
|
|
|
|
+ description: 'Graph panel',
|
|
|
|
|
+ fullscreen: true,
|
|
|
|
|
+ metricsEditor: true
|
|
|
|
|
+ });
|
|
|
|
|
+
|
|
|
|
|
+ $scope.panelMeta.addEditorTab('Axes & Grid', 'app/panels/graph/axisEditor.html');
|
|
|
|
|
+ $scope.panelMeta.addEditorTab('Display Styles', 'app/panels/graph/styleEditor.html');
|
|
|
|
|
+
|
|
|
|
|
+ $scope.panelMeta.addExtendedMenuItem('Export CSV', '', 'exportCsv()');
|
|
|
|
|
+ $scope.panelMeta.addExtendedMenuItem('Toggle legend', '', 'toggleLegend()');
|
|
|
|
|
|
|
|
// Set and populate defaults
|
|
// Set and populate defaults
|
|
|
var _d = {
|
|
var _d = {
|
|
|
-
|
|
|
|
|
|
|
+ // datasource name, null = default datasource
|
|
|
datasource: null,
|
|
datasource: null,
|
|
|
-
|
|
|
|
|
- /** @scratch /panels/histogram/3
|
|
|
|
|
- * renderer:: sets client side (flot) or native graphite png renderer (png)
|
|
|
|
|
- */
|
|
|
|
|
|
|
+ // sets client side (flot) or native graphite png renderer (png)
|
|
|
renderer: 'flot',
|
|
renderer: 'flot',
|
|
|
- /** @scratch /panels/histogram/3
|
|
|
|
|
- * x-axis:: Show the x-axis
|
|
|
|
|
- */
|
|
|
|
|
|
|
+ // Show/hide the x-axis
|
|
|
'x-axis' : true,
|
|
'x-axis' : true,
|
|
|
- /** @scratch /panels/histogram/3
|
|
|
|
|
- * y-axis:: Show the y-axis
|
|
|
|
|
- */
|
|
|
|
|
|
|
+ // Show/hide y-axis
|
|
|
'y-axis' : true,
|
|
'y-axis' : true,
|
|
|
- /** @scratch /panels/histogram/3
|
|
|
|
|
- * scale:: Scale the y-axis by this factor
|
|
|
|
|
- */
|
|
|
|
|
- scale : 1,
|
|
|
|
|
- /** @scratch /panels/histogram/3
|
|
|
|
|
- * y_formats :: 'none','bytes','bits','bps','short', 's', 'ms'
|
|
|
|
|
- */
|
|
|
|
|
|
|
+ // y axis formats, [left axis,right axis]
|
|
|
y_formats : ['short', 'short'],
|
|
y_formats : ['short', 'short'],
|
|
|
- /** @scratch /panels/histogram/5
|
|
|
|
|
- * grid object:: Min and max y-axis values
|
|
|
|
|
- * grid.min::: Minimum y-axis value
|
|
|
|
|
- * grid.ma1::: Maximum y-axis value
|
|
|
|
|
- */
|
|
|
|
|
|
|
+ // grid options
|
|
|
grid : {
|
|
grid : {
|
|
|
leftMax: null,
|
|
leftMax: null,
|
|
|
rightMax: null,
|
|
rightMax: null,
|
|
@@ -92,48 +56,23 @@ function (angular, app, $, _, kbn, moment, TimeSeries) {
|
|
|
threshold1Color: 'rgba(216, 200, 27, 0.27)',
|
|
threshold1Color: 'rgba(216, 200, 27, 0.27)',
|
|
|
threshold2Color: 'rgba(234, 112, 112, 0.22)'
|
|
threshold2Color: 'rgba(234, 112, 112, 0.22)'
|
|
|
},
|
|
},
|
|
|
-
|
|
|
|
|
- annotate : {
|
|
|
|
|
- enable : false,
|
|
|
|
|
- },
|
|
|
|
|
-
|
|
|
|
|
- /** @scratch /panels/histogram/3
|
|
|
|
|
- * resolution:: If auto_int is true, shoot for this many bars.
|
|
|
|
|
- */
|
|
|
|
|
- resolution : 100,
|
|
|
|
|
-
|
|
|
|
|
- /** @scratch /panels/histogram/3
|
|
|
|
|
- * ==== Drawing options
|
|
|
|
|
- * lines:: Show line chart
|
|
|
|
|
- */
|
|
|
|
|
|
|
+ // show/hide lines
|
|
|
lines : true,
|
|
lines : true,
|
|
|
- /** @scratch /panels/histogram/3
|
|
|
|
|
- * fill:: Area fill factor for line charts, 1-10
|
|
|
|
|
- */
|
|
|
|
|
|
|
+ // fill factor
|
|
|
fill : 0,
|
|
fill : 0,
|
|
|
- /** @scratch /panels/histogram/3
|
|
|
|
|
- * linewidth:: Weight of lines in pixels
|
|
|
|
|
- */
|
|
|
|
|
|
|
+ // line width in pixels
|
|
|
linewidth : 1,
|
|
linewidth : 1,
|
|
|
- /** @scratch /panels/histogram/3
|
|
|
|
|
- * points:: Show points on chart
|
|
|
|
|
- */
|
|
|
|
|
|
|
+ // show hide points
|
|
|
points : false,
|
|
points : false,
|
|
|
- /** @scratch /panels/histogram/3
|
|
|
|
|
- * pointradius:: Size of points in pixels
|
|
|
|
|
- */
|
|
|
|
|
|
|
+ // point radius in pixels
|
|
|
pointradius : 5,
|
|
pointradius : 5,
|
|
|
- /** @scratch /panels/histogram/3
|
|
|
|
|
- * bars:: Show bars on chart
|
|
|
|
|
- */
|
|
|
|
|
|
|
+ // show hide bars
|
|
|
bars : false,
|
|
bars : false,
|
|
|
- /** @scratch /panels/histogram/3
|
|
|
|
|
- * stack:: Stack multiple series
|
|
|
|
|
- */
|
|
|
|
|
|
|
+ // enable/disable stacking
|
|
|
stack : false,
|
|
stack : false,
|
|
|
- /** @scratch /panels/histogram/3
|
|
|
|
|
- * legend:: Display the legend
|
|
|
|
|
- */
|
|
|
|
|
|
|
+ // stack percentage mode
|
|
|
|
|
+ percentage : false,
|
|
|
|
|
+ // legend options
|
|
|
legend: {
|
|
legend: {
|
|
|
show: true, // disable/enable legend
|
|
show: true, // disable/enable legend
|
|
|
values: false, // disable/enable legend values
|
|
values: false, // disable/enable legend values
|
|
@@ -143,31 +82,20 @@ function (angular, app, $, _, kbn, moment, TimeSeries) {
|
|
|
total: false,
|
|
total: false,
|
|
|
avg: false
|
|
avg: false
|
|
|
},
|
|
},
|
|
|
- /** @scratch /panels/histogram/3
|
|
|
|
|
- * ==== Transformations
|
|
|
|
|
- /** @scratch /panels/histogram/3
|
|
|
|
|
- * percentage:: Show the y-axis as a percentage of the axis total. Only makes sense for multiple
|
|
|
|
|
- * queries
|
|
|
|
|
- */
|
|
|
|
|
- percentage : false,
|
|
|
|
|
- /** @scratch /panels/histogram/3
|
|
|
|
|
- * zerofill:: Improves the accuracy of line charts at a small performance cost.
|
|
|
|
|
- */
|
|
|
|
|
- zerofill : true,
|
|
|
|
|
-
|
|
|
|
|
|
|
+ // how null points should be handled
|
|
|
nullPointMode : 'connected',
|
|
nullPointMode : 'connected',
|
|
|
-
|
|
|
|
|
|
|
+ // staircase line mode
|
|
|
steppedLine: false,
|
|
steppedLine: false,
|
|
|
-
|
|
|
|
|
|
|
+ // tooltip options
|
|
|
tooltip : {
|
|
tooltip : {
|
|
|
value_type: 'cumulative',
|
|
value_type: 'cumulative',
|
|
|
shared: false,
|
|
shared: false,
|
|
|
},
|
|
},
|
|
|
-
|
|
|
|
|
|
|
+ // metric queries
|
|
|
targets: [{}],
|
|
targets: [{}],
|
|
|
-
|
|
|
|
|
|
|
+ // series color overrides
|
|
|
aliasColors: {},
|
|
aliasColors: {},
|
|
|
-
|
|
|
|
|
|
|
+ // other style overrides
|
|
|
seriesOverrides: [],
|
|
seriesOverrides: [],
|
|
|
};
|
|
};
|
|
|
|
|
|
|
@@ -178,11 +106,17 @@ function (angular, app, $, _, kbn, moment, TimeSeries) {
|
|
|
_.defaults($scope.panel.legend, _d.legend);
|
|
_.defaults($scope.panel.legend, _d.legend);
|
|
|
|
|
|
|
|
$scope.hiddenSeries = {};
|
|
$scope.hiddenSeries = {};
|
|
|
|
|
+ $scope.seriesList = [];
|
|
|
|
|
|
|
|
$scope.updateTimeRange = function () {
|
|
$scope.updateTimeRange = function () {
|
|
|
$scope.range = timeSrv.timeRange();
|
|
$scope.range = timeSrv.timeRange();
|
|
|
$scope.rangeUnparsed = timeSrv.timeRange(false);
|
|
$scope.rangeUnparsed = timeSrv.timeRange(false);
|
|
|
- $scope.resolution = Math.ceil($(window).width() * ($scope.panel.span / 12));
|
|
|
|
|
|
|
+ if ($scope.panel.maxDataPoints) {
|
|
|
|
|
+ $scope.resolution = $scope.panel.maxDataPoints;
|
|
|
|
|
+ }
|
|
|
|
|
+ else {
|
|
|
|
|
+ $scope.resolution = Math.ceil($(window).width() * ($scope.panel.span / 12));
|
|
|
|
|
+ }
|
|
|
$scope.interval = kbn.calculateInterval($scope.range, $scope.resolution, $scope.panel.interval);
|
|
$scope.interval = kbn.calculateInterval($scope.range, $scope.resolution, $scope.panel.interval);
|
|
|
};
|
|
};
|
|
|
|
|
|
|
@@ -206,13 +140,13 @@ function (angular, app, $, _, kbn, moment, TimeSeries) {
|
|
|
$scope.panelMeta.loading = false;
|
|
$scope.panelMeta.loading = false;
|
|
|
$scope.panelMeta.error = err.message || "Timeseries data request error";
|
|
$scope.panelMeta.error = err.message || "Timeseries data request error";
|
|
|
$scope.inspector.error = err;
|
|
$scope.inspector.error = err;
|
|
|
|
|
+ $scope.seriesList = [];
|
|
|
$scope.render([]);
|
|
$scope.render([]);
|
|
|
});
|
|
});
|
|
|
};
|
|
};
|
|
|
|
|
|
|
|
$scope.dataHandler = function(results) {
|
|
$scope.dataHandler = function(results) {
|
|
|
$scope.panelMeta.loading = false;
|
|
$scope.panelMeta.loading = false;
|
|
|
- $scope.legend = [];
|
|
|
|
|
|
|
|
|
|
// png renderer returns just a url
|
|
// png renderer returns just a url
|
|
|
if (_.isString(results)) {
|
|
if (_.isString(results)) {
|
|
@@ -224,16 +158,16 @@ function (angular, app, $, _, kbn, moment, TimeSeries) {
|
|
|
$scope.datapointsCount = 0;
|
|
$scope.datapointsCount = 0;
|
|
|
$scope.datapointsOutside = false;
|
|
$scope.datapointsOutside = false;
|
|
|
|
|
|
|
|
- var data = _.map(results.data, $scope.seriesHandler);
|
|
|
|
|
|
|
+ $scope.seriesList = _.map(results.data, $scope.seriesHandler);
|
|
|
|
|
|
|
|
$scope.datapointsWarning = $scope.datapointsCount === 0 || $scope.datapointsOutside;
|
|
$scope.datapointsWarning = $scope.datapointsCount === 0 || $scope.datapointsOutside;
|
|
|
|
|
|
|
|
$scope.annotationsPromise
|
|
$scope.annotationsPromise
|
|
|
.then(function(annotations) {
|
|
.then(function(annotations) {
|
|
|
- data.annotations = annotations;
|
|
|
|
|
- $scope.render(data);
|
|
|
|
|
|
|
+ $scope.seriesList.annotations = annotations;
|
|
|
|
|
+ $scope.render($scope.seriesList);
|
|
|
}, function() {
|
|
}, function() {
|
|
|
- $scope.render(data);
|
|
|
|
|
|
|
+ $scope.render($scope.seriesList);
|
|
|
});
|
|
});
|
|
|
};
|
|
};
|
|
|
|
|
|
|
@@ -242,20 +176,14 @@ function (angular, app, $, _, kbn, moment, TimeSeries) {
|
|
|
var alias = seriesData.target;
|
|
var alias = seriesData.target;
|
|
|
var color = $scope.panel.aliasColors[alias] || $rootScope.colors[index];
|
|
var color = $scope.panel.aliasColors[alias] || $rootScope.colors[index];
|
|
|
|
|
|
|
|
- var seriesInfo = {
|
|
|
|
|
- alias: alias,
|
|
|
|
|
- color: color,
|
|
|
|
|
- };
|
|
|
|
|
-
|
|
|
|
|
- $scope.legend.push(seriesInfo);
|
|
|
|
|
-
|
|
|
|
|
var series = new TimeSeries({
|
|
var series = new TimeSeries({
|
|
|
datapoints: datapoints,
|
|
datapoints: datapoints,
|
|
|
- info: seriesInfo,
|
|
|
|
|
|
|
+ alias: alias,
|
|
|
|
|
+ color: color,
|
|
|
});
|
|
});
|
|
|
|
|
|
|
|
if (datapoints && datapoints.length > 0) {
|
|
if (datapoints && datapoints.length > 0) {
|
|
|
- var last = moment.utc(datapoints[datapoints.length - 1][1] * 1000);
|
|
|
|
|
|
|
+ var last = moment.utc(datapoints[datapoints.length - 1][1]);
|
|
|
var from = moment.utc($scope.range.from);
|
|
var from = moment.utc($scope.range.from);
|
|
|
if (last - from < -10000) {
|
|
if (last - from < -10000) {
|
|
|
$scope.datapointsOutside = true;
|
|
$scope.datapointsOutside = true;
|
|
@@ -268,7 +196,7 @@ function (angular, app, $, _, kbn, moment, TimeSeries) {
|
|
|
};
|
|
};
|
|
|
|
|
|
|
|
$scope.render = function(data) {
|
|
$scope.render = function(data) {
|
|
|
- $scope.$emit('render', data);
|
|
|
|
|
|
|
+ $scope.$broadcast('render', data);
|
|
|
};
|
|
};
|
|
|
|
|
|
|
|
$scope.changeSeriesColor = function(series, color) {
|
|
$scope.changeSeriesColor = function(series, color) {
|
|
@@ -278,18 +206,18 @@ function (angular, app, $, _, kbn, moment, TimeSeries) {
|
|
|
};
|
|
};
|
|
|
|
|
|
|
|
$scope.toggleSeries = function(serie, event) {
|
|
$scope.toggleSeries = function(serie, event) {
|
|
|
- if ($scope.hiddenSeries[serie.alias]) {
|
|
|
|
|
- delete $scope.hiddenSeries[serie.alias];
|
|
|
|
|
- }
|
|
|
|
|
- else {
|
|
|
|
|
- $scope.hiddenSeries[serie.alias] = true;
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
if (event.ctrlKey || event.metaKey || event.shiftKey) {
|
|
if (event.ctrlKey || event.metaKey || event.shiftKey) {
|
|
|
|
|
+ if ($scope.hiddenSeries[serie.alias]) {
|
|
|
|
|
+ delete $scope.hiddenSeries[serie.alias];
|
|
|
|
|
+ }
|
|
|
|
|
+ else {
|
|
|
|
|
+ $scope.hiddenSeries[serie.alias] = true;
|
|
|
|
|
+ }
|
|
|
|
|
+ } else {
|
|
|
$scope.toggleSeriesExclusiveMode(serie);
|
|
$scope.toggleSeriesExclusiveMode(serie);
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- $scope.$emit('toggleLegend', $scope.legend);
|
|
|
|
|
|
|
+ $scope.render();
|
|
|
};
|
|
};
|
|
|
|
|
|
|
|
$scope.toggleSeriesExclusiveMode = function(serie) {
|
|
$scope.toggleSeriesExclusiveMode = function(serie) {
|
|
@@ -300,7 +228,7 @@ function (angular, app, $, _, kbn, moment, TimeSeries) {
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
// check if every other series is hidden
|
|
// check if every other series is hidden
|
|
|
- var alreadyExclusive = _.every($scope.legend, function(value) {
|
|
|
|
|
|
|
+ var alreadyExclusive = _.every($scope.seriesList, function(value) {
|
|
|
if (value.alias === serie.alias) {
|
|
if (value.alias === serie.alias) {
|
|
|
return true;
|
|
return true;
|
|
|
}
|
|
}
|
|
@@ -310,13 +238,13 @@ function (angular, app, $, _, kbn, moment, TimeSeries) {
|
|
|
|
|
|
|
|
if (alreadyExclusive) {
|
|
if (alreadyExclusive) {
|
|
|
// remove all hidden series
|
|
// remove all hidden series
|
|
|
- _.each($scope.legend, function(value) {
|
|
|
|
|
|
|
+ _.each($scope.seriesList, function(value) {
|
|
|
delete $scope.hiddenSeries[value.alias];
|
|
delete $scope.hiddenSeries[value.alias];
|
|
|
});
|
|
});
|
|
|
}
|
|
}
|
|
|
else {
|
|
else {
|
|
|
// hide all but this serie
|
|
// hide all but this serie
|
|
|
- _.each($scope.legend, function(value) {
|
|
|
|
|
|
|
+ _.each($scope.seriesList, function(value) {
|
|
|
if (value.alias === serie.alias) {
|
|
if (value.alias === serie.alias) {
|
|
|
return;
|
|
return;
|
|
|
}
|
|
}
|
|
@@ -341,8 +269,8 @@ function (angular, app, $, _, kbn, moment, TimeSeries) {
|
|
|
$scope.render();
|
|
$scope.render();
|
|
|
};
|
|
};
|
|
|
|
|
|
|
|
- $scope.addSeriesOverride = function() {
|
|
|
|
|
- $scope.panel.seriesOverrides.push({});
|
|
|
|
|
|
|
+ $scope.addSeriesOverride = function(override) {
|
|
|
|
|
+ $scope.panel.seriesOverrides.push(override || {});
|
|
|
};
|
|
};
|
|
|
|
|
|
|
|
$scope.removeSeriesOverride = function(override) {
|
|
$scope.removeSeriesOverride = function(override) {
|
|
@@ -350,12 +278,14 @@ function (angular, app, $, _, kbn, moment, TimeSeries) {
|
|
|
$scope.render();
|
|
$scope.render();
|
|
|
};
|
|
};
|
|
|
|
|
|
|
|
- $scope.toggleEditorHelp = function(index) {
|
|
|
|
|
- if ($scope.editorHelpIndex === index) {
|
|
|
|
|
- $scope.editorHelpIndex = null;
|
|
|
|
|
- return;
|
|
|
|
|
- }
|
|
|
|
|
- $scope.editorHelpIndex = index;
|
|
|
|
|
|
|
+ // Called from panel menu
|
|
|
|
|
+ $scope.toggleLegend = function() {
|
|
|
|
|
+ $scope.panel.legend.show = !$scope.panel.legend.show;
|
|
|
|
|
+ $scope.get_data();
|
|
|
|
|
+ };
|
|
|
|
|
+
|
|
|
|
|
+ $scope.exportCsv = function() {
|
|
|
|
|
+ kbn.exportSeriesListToCsv($scope.seriesList);
|
|
|
};
|
|
};
|
|
|
|
|
|
|
|
panelSrv.init($scope);
|
|
panelSrv.init($scope);
|