Skip to content
Open
Show file tree
Hide file tree
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
40 changes: 37 additions & 3 deletions src/module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import {
Field,
ArrayVector,
FieldType,
stringToJsRegex
} from '@grafana/data';

import _ from 'lodash';
Expand Down Expand Up @@ -234,6 +235,7 @@ class DiscretePanelCtrl extends CanvasPanelCtrl {
return;
}

this._applyRegexPattern();
this._updateRenderDimensions();
this._updateSelectionMatrix();
this._updateCanvasSize();
Expand Down Expand Up @@ -597,13 +599,12 @@ class DiscretePanelCtrl extends CanvasPanelCtrl {
if (isExternal) {
const rect = this.canvas.getBoundingClientRect();
pageY = rect.top + evt.pos.panelRelY * rect.height;
if (pageY < 0 || pageY > $(window).innerHeight()) {
if (pageY < 0 || pageY > window.innerHeight) {
// Skip Hidden tooltip
this.$tooltip.detach();
return;
}
pageY += $(window).scrollTop();

pageY += $(window).scrollTop() || 0;
const elapsed = this.range.to - this.range.from;
const pX = (evt.pos.x - this.range.from) / elapsed;
pageX = rect.left + pX * rect.width;
Expand Down Expand Up @@ -727,6 +728,39 @@ class DiscretePanelCtrl extends CanvasPanelCtrl {
appEvents.emit('graph-hover-clear');
this.render();
}
_applyRegexPattern() {
let seriesList: any = this.data;
if (seriesList && seriesList.length > 0) {
for (let i = 0; i < seriesList.length; i++) {
if (!seriesList[i].seriesName) {
seriesList[i].seriesName = seriesList[i].name
}
if (this.panel.regexPattern !== '' && this.panel.regexPattern !== undefined) {
const regexVal = stringToJsRegex(this.panel.regexPattern);
if (seriesList[i].seriesName && regexVal.test(seriesList[i].seriesName.toString())) {
const temp = regexVal.exec(seriesList[i].seriesName.toString());
if (!temp) {
continue;
}
let extractedtxt = '';
if (temp.length > 1) {
temp.slice(1).forEach((value, i) => {
if (value) {
extractedtxt += extractedtxt.length > 0 ? ' ' + value.toString() : value.toString();
}
});
seriesList[i].name = extractedtxt;
}
} else {
seriesList[i].name = seriesList[i].seriesName;
}
} else {
seriesList[i].name = seriesList[i].seriesName;
}
}
this.data = seriesList;
}
}

_updateRenderDimensions() {
this._renderDimensions = {};
Expand Down
10 changes: 10 additions & 0 deletions src/partials/editor.legend.html
Original file line number Diff line number Diff line change
Expand Up @@ -78,5 +78,15 @@ <h5 class="section-heading">Values</h5>

</div>
</div>
<!-- Regex-->
<div class="section gf-form-group">
<h5 class="section-heading">Regex</h5>
<div class="gf-form">
<label class="gf-form-label width-8">Regex Pattern
<tip>Optional, The values in the specified column are filtered and displayed according to this regex. Ex: String: Url|broadcom.com|mirror|location-1 regex: /Url\|(.*?)\|/ Output: broadcom.com</tip>
</label>
<input type="text" class="gf-form-input" ng-model="ctrl.panel.regexPattern" ng-blur="ctrl.render()" placeholder="regex">
</div>
</div>

</div>