2019-01-11 13:31:25 +01:00
|
|
|
import { getValueFormats } from '@grafana/ui';
|
2019-10-07 08:58:05 +02:00
|
|
|
import { GraphCtrl } from './module';
|
2016-09-22 16:19:44 +02:00
|
|
|
|
|
|
|
|
export class AxesEditorCtrl {
|
|
|
|
|
panel: any;
|
2019-10-07 08:58:05 +02:00
|
|
|
panelCtrl: GraphCtrl;
|
2016-09-22 16:19:44 +02:00
|
|
|
unitFormats: any;
|
|
|
|
|
logScales: any;
|
|
|
|
|
xAxisModes: any;
|
|
|
|
|
xAxisStatOptions: any;
|
|
|
|
|
xNameSegment: any;
|
|
|
|
|
|
2018-08-31 16:40:43 +02:00
|
|
|
/** @ngInject */
|
2019-06-20 20:41:01 +02:00
|
|
|
constructor(private $scope: any) {
|
2019-10-07 08:58:05 +02:00
|
|
|
this.panelCtrl = $scope.ctrl as GraphCtrl;
|
2016-09-22 16:19:44 +02:00
|
|
|
this.panel = this.panelCtrl.panel;
|
2017-09-21 16:40:18 +02:00
|
|
|
this.$scope.ctrl = this;
|
2016-09-22 16:19:44 +02:00
|
|
|
|
2019-01-11 13:31:25 +01:00
|
|
|
this.unitFormats = getValueFormats();
|
2016-09-22 16:19:44 +02:00
|
|
|
|
|
|
|
|
this.logScales = {
|
2017-12-19 16:06:54 +01:00
|
|
|
linear: 1,
|
2017-12-21 08:39:31 +01:00
|
|
|
'log (base 2)': 2,
|
|
|
|
|
'log (base 10)': 10,
|
|
|
|
|
'log (base 32)': 32,
|
|
|
|
|
'log (base 1024)': 1024,
|
2016-09-22 16:19:44 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
this.xAxisModes = {
|
2017-12-21 08:39:31 +01:00
|
|
|
Time: 'time',
|
|
|
|
|
Series: 'series',
|
|
|
|
|
Histogram: 'histogram',
|
2016-09-26 14:04:13 +02:00
|
|
|
// 'Data field': 'field',
|
2016-09-22 16:19:44 +02:00
|
|
|
};
|
|
|
|
|
|
2017-12-19 16:06:54 +01:00
|
|
|
this.xAxisStatOptions = [
|
2017-12-21 08:39:31 +01:00
|
|
|
{ text: 'Avg', value: 'avg' },
|
|
|
|
|
{ text: 'Min', value: 'min' },
|
|
|
|
|
{ text: 'Max', value: 'max' },
|
|
|
|
|
{ text: 'Total', value: 'total' },
|
|
|
|
|
{ text: 'Count', value: 'count' },
|
|
|
|
|
{ text: 'Current', value: 'current' },
|
2016-09-22 16:19:44 +02:00
|
|
|
];
|
2016-09-23 17:12:10 +02:00
|
|
|
|
2017-12-21 08:39:31 +01:00
|
|
|
if (this.panel.xaxis.mode === 'custom') {
|
2016-09-23 17:12:10 +02:00
|
|
|
if (!this.panel.xaxis.name) {
|
2017-12-21 08:39:31 +01:00
|
|
|
this.panel.xaxis.name = 'specify field';
|
2016-09-23 17:12:10 +02:00
|
|
|
}
|
|
|
|
|
}
|
2016-09-22 16:19:44 +02:00
|
|
|
}
|
|
|
|
|
|
2019-06-20 20:41:01 +02:00
|
|
|
setUnitFormat(axis: { format: any }, subItem: { value: any }) {
|
2016-09-22 16:19:44 +02:00
|
|
|
axis.format = subItem.value;
|
|
|
|
|
this.panelCtrl.render();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
render() {
|
|
|
|
|
this.panelCtrl.render();
|
|
|
|
|
}
|
|
|
|
|
|
2017-12-19 16:06:54 +01:00
|
|
|
xAxisModeChanged() {
|
2017-09-13 14:38:22 +02:00
|
|
|
this.panelCtrl.processor.setPanelDefaultsForNewXAxisMode();
|
2019-10-07 08:58:05 +02:00
|
|
|
this.panelCtrl.onDataFramesReceived(this.panelCtrl.dataList);
|
2017-09-13 14:38:22 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
xAxisValueChanged() {
|
2019-10-07 08:58:05 +02:00
|
|
|
this.panelCtrl.onDataFramesReceived(this.panelCtrl.dataList);
|
2016-09-22 16:19:44 +02:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2018-08-31 16:40:43 +02:00
|
|
|
/** @ngInject */
|
2016-09-22 16:19:44 +02:00
|
|
|
export function axesEditorComponent() {
|
2017-12-21 08:39:31 +01:00
|
|
|
'use strict';
|
2016-09-22 16:19:44 +02:00
|
|
|
return {
|
2017-12-21 08:39:31 +01:00
|
|
|
restrict: 'E',
|
2016-09-22 16:19:44 +02:00
|
|
|
scope: true,
|
2017-12-21 08:39:31 +01:00
|
|
|
templateUrl: 'public/app/plugins/panel/graph/axes_editor.html',
|
|
|
|
|
controller: AxesEditorCtrl,
|
2016-09-22 16:19:44 +02:00
|
|
|
};
|
|
|
|
|
}
|