diff --git a/public/app/features/panel/panelDirective.js b/public/app/features/panel/panelDirective.js index 18ab6d7891c..a697aab4722 100644 --- a/public/app/features/panel/panelDirective.js +++ b/public/app/features/panel/panelDirective.js @@ -40,8 +40,6 @@ function (angular, $, config) { }; }); - var targetLetters = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ'; - module.directive('queryEditorLoader', function($compile, $parse, datasourceSrv) { return { restrict: 'E', @@ -59,7 +57,6 @@ function (angular, $, config) { editorScope = scope.$new(); editorScope.datasource = ds; - editorScope.targetLetters = targetLetters; var panelEl = angular.element(document.createElement('metric-query-editor-' + ds.meta.type)); elem.append(panelEl); diff --git a/public/app/features/panel/panelSrv.js b/public/app/features/panel/panelSrv.js index 718e20caa34..784525c0528 100644 --- a/public/app/features/panel/panelSrv.js +++ b/public/app/features/panel/panelSrv.js @@ -44,7 +44,20 @@ function (angular, _, config) { }; $scope.addDataQuery = function(datasource) { - $scope.panel.targets.push({target: '', datasource: datasource}); + var letters = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ'; + var target = {}; + + if (datasource) { + target.datasource = datasource; + } + + target.refId = _.find(letters, function(refId) { + return _.every($scope.panel.targets, function(other) { + return other.refId !== refId; + }); + }); + + $scope.panel.targets.push(target); }; $scope.removeDataQuery = function (query) { diff --git a/public/app/plugins/datasource/graphite/datasource.js b/public/app/plugins/datasource/graphite/datasource.js index e9f2a6efe5d..cd7c66d67a8 100644 --- a/public/app/plugins/datasource/graphite/datasource.js +++ b/public/app/plugins/datasource/graphite/datasource.js @@ -228,21 +228,13 @@ function (angular, _, $, config, kbn, moment) { return backendSrv.datasourceRequest(options); }; - GraphiteDatasource.prototype._seriesRefLetters = [ - '#A', '#B', '#C', '#D', - '#E', '#F', '#G', '#H', - '#I', '#J', '#K', '#L', - '#M', '#N', '#O', '#P', - '#Q', '#R', '#S', '#T', - '#U', '#V', '#W', '#X', - '#Y', '#Z' - ]; + GraphiteDatasource.prototype._seriesRefLetters = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ'; GraphiteDatasource.prototype.buildGraphiteParams = function(options, scopedVars) { var graphite_options = ['from', 'until', 'rawData', 'format', 'maxDataPoints', 'cacheTimeout']; var clean_options = [], targets = {}; var target, targetValue, i; - var regex = /(\#[A-Z])/g; + var regex = /\#([A-Z])/g; var intervalFormatFixRegex = /'(\d+)m'/gi; if (options.format !== 'png') { @@ -259,13 +251,17 @@ function (angular, _, $, config, kbn, moment) { continue; } + if (!target.refId) { + target.refId = this._seriesRefLetters[i]; + } + targetValue = templateSrv.replace(target.target, scopedVars); targetValue = targetValue.replace(intervalFormatFixRegex, fixIntervalFormat); - targets[this._seriesRefLetters[i]] = targetValue; + targets[target.refId] = targetValue; } - function nestedSeriesRegexReplacer(match) { - return targets[match]; + function nestedSeriesRegexReplacer(match, g1) { + return targets[g1]; } for (i = 0; i < options.targets.length; i++) { @@ -274,9 +270,9 @@ function (angular, _, $, config, kbn, moment) { continue; } - targetValue = targets[this._seriesRefLetters[i]]; + targetValue = targets[target.refId]; targetValue = targetValue.replace(regex, nestedSeriesRegexReplacer); - targets[this._seriesRefLetters[i]] = targetValue; + targets[target.refId] = targetValue; if (!target.hide) { clean_options.push("target=" + encodeURIComponent(targetValue)); diff --git a/public/app/plugins/datasource/graphite/partials/query.editor.html b/public/app/plugins/datasource/graphite/partials/query.editor.html index 6361f05f584..a26dfd0e52e 100755 --- a/public/app/plugins/datasource/graphite/partials/query.editor.html +++ b/public/app/plugins/datasource/graphite/partials/query.editor.html @@ -48,7 +48,7 @@