Skip to content

Commit

Permalink
Made regex match work for per series overrides, #425, #700
Browse files Browse the repository at this point in the history
  • Loading branch information
torkelo committed Aug 20, 2014
1 parent 062fe72 commit 939e957
Show file tree
Hide file tree
Showing 5 changed files with 41 additions and 9 deletions.
12 changes: 11 additions & 1 deletion src/app/directives/grafanaGraph.js
Original file line number Diff line number Diff line change
Expand Up @@ -183,6 +183,16 @@ function (angular, $, kbn, moment, _) {
}
}

function matchSeriesOverride(aliasOrRegex, seriesAlias) {
if (aliasOrRegex[0] === '/') {
var match = aliasOrRegex.match(new RegExp('^/(.*?)/(g?i?m?y?)$'));
var regex = new RegExp(match[1], match[2]);
return seriesAlias.match(regex) != null;
}

return aliasOrRegex === seriesAlias;
}

function applySeriesOverrideOptions(series) {
series.lines = {};
series.points = {};
Expand All @@ -191,7 +201,7 @@ function (angular, $, kbn, moment, _) {

for (var i = 0; i < scope.panel.seriesOverrides.length; i++) {
var override = scope.panel.seriesOverrides[i];
if (override.alias !== series.info.alias) {
if (!matchSeriesOverride(override.alias, series.info.alias)) {
continue;
}
if (override.lines !== void 0) { series.lines.show = override.lines; }
Expand Down
14 changes: 7 additions & 7 deletions src/app/panels/graph/seriesOverridesCtrl.js
Original file line number Diff line number Diff line change
Expand Up @@ -47,13 +47,13 @@ define([
$scope.updateCurrentOverrides = function() {
$scope.currentOverrides = [];
_.each($scope.overrideMenu, function(option) {
if (!_.isUndefined($scope.override[option.propertyName])) {
$scope.currentOverrides.push({
name: option.text,
propertyName: option.propertyName,
value: String($scope.override[option.propertyName])
});
}
var value = $scope.override[option.propertyName];
if (_.isUndefined(value)) { return; }
$scope.currentOverrides.push({
name: option.text,
propertyName: option.propertyName,
value: String(value)
});
});
};

Expand Down
2 changes: 1 addition & 1 deletion src/app/panels/graph/styleEditor.html
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ <h5>Rendering</h5>

<div class="editor-row">
<div class="section">
<h5>Series specific overrides</h5>
<h5>Series specific overrides <tip>Regex match example: /server[0-3]/i </tip></h5>

<div class="grafana-target" ng-repeat="override in panel.seriesOverrides" ng-controller="SeriesOverridesCtrl">
<div class="grafana-target-inner-wrapper">
Expand Down
14 changes: 14 additions & 0 deletions src/test/specs/grafanaGraph-specs.js
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,21 @@ define([
});
});

graphScenario('override match on regex', function(ctx) {
ctx.setup(function(scope, data) {
scope.panel.lines = true;
scope.panel.seriesOverrides = [
{ alias: '/.*01/', lines: false }
];

data[1].info.alias = 'test_01';
});

it('should match second series and set pointradius, and set steppedLine', function() {
expect(ctx.plotData[0].lines.show).to.be(undefined);
expect(ctx.plotData[1].lines.show).to.be(false);
});
});

});
});
Expand Down
8 changes: 8 additions & 0 deletions src/test/specs/seriesOverridesCtrl-specs.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,14 @@ define([
});
});

describe('When removing overide', function() {
it('click should include option and value index', function() {
ctx.scope.setOverride(1,0);
ctx.scope.removeOverride({ propertyName: 'lines' });
expect(ctx.scope.currentOverrides.length).to.be(0);
});
});

});

});
Expand Down

0 comments on commit 939e957

Please sign in to comment.