-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathmodule.js
245 lines (214 loc) · 9.1 KB
/
module.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
define([
'lodash',
'app/plugins/sdk',
'app/core/utils/kbn',
'moment',
'app/core/time_series',
// 'app/core/time_series2',
'app/core/utils/file_export',
// './seriesOverridesCtrl',
'./horizon',
'./legend',
],
function(_, sdk, kbn, moment, TimeSeries, fileExport) {
'use strict';
var __extends = (this && this.__extends) || function (d, b) {
for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p];
function __() { this.constructor = d; }
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
};
var panelDefaults = {
// datasource name, null = default datasource
datasource: null,
// sets client side (flot) or native graphite png renderer (png)
renderer: 'flot',
// Show/hide the x-axis
'x-axis': true,
// Show/hide y-axis
'y-axis': false,
// format (only one axis)
y_formats : ['short', 'short'],
// y_formats : ['none', 'none'],
// format: 'short',
// grid options
grid: {
leftLogBase: 1,
leftMax: null,
rightMax: null,
leftMin: null,
rightMin: null,
rightLogBase: 1,
threshold1: null,
threshold2: null,
threshold1Color: 'rgba(216, 200, 27, 0.27)',
threshold2Color: 'rgba(234, 112, 112, 0.22)'
},
// legend options
legend: {
show: true, // disable/enable legend
values: false, // disable/enable legend values
min: false,
max: false,
current: false,
total: false,
avg: false
},
// horizon
horizon: {
bands: 6,
horizonHeight: 32,
axisHeight: 25,
marginBottom: 2,
backgroundColor: '#d1d1d1',
labelColor: '#000000',
logBase: 1,
decimals: ''
},
// how null points should be handled
nullPointMode: 'connected',
// tooltip options
tooltip: {
value_type: 'cumulative',
shared: true,
},
// time overrides
timeFrom: null,
timeShift: null,
// metric queries
targets: [{}],
// other style overrides
seriesOverrides: [],
};
var HorizonCtrl = (function(_super) {
__extends(HorizonCtrl, _super);
function HorizonCtrl($scope, $injector, annotationsSrv) {
_super.call(this, $scope, $injector);
this.annotationsSrv = annotationsSrv;
this.hiddenSeries = {};
this.seriesList = [];
this.logScales = null;
this.unitFormats = null;
this.annotationsPromise = null;
this.datapointsCount = null;
this.datapointsOutside = null;
this.datapointsWarning = null;
_.defaults(this.panel, panelDefaults);
_.defaults(this.panel.tooltip, panelDefaults.tooltip);
// _.defaults(this.panel.annotate, panelDefaults.annotate);
_.defaults(this.panel.grid, panelDefaults.grid);
_.defaults(this.panel.legend, panelDefaults.legend);
_.defaults(this.panel.horizon, panelDefaults.horizon);
this.events.on('data-received', this.onDataReceived.bind(this));
this.events.on('data-error', this.onDataError.bind(this));
this.events.on('data-snapshot-load', this.onDataSnapshotLoad.bind(this));
this.events.on('init-edit-mode', this.onInitEditMode.bind(this));
this.events.on('init-panel-actions', this.onInitPanelActions.bind(this));
};
HorizonCtrl.templateUrl = 'public/plugins/creative-area-horizon-panel/module.html';
HorizonCtrl.prototype.onInitEditMode = function() {
this.icon = "fa fa-align-justify";
this.addEditorTab('Configuration', 'public/plugins/creative-area-horizon-panel/configEditor.html', 2);
this.logScales = {
'linear': 1,
'log (base 2)': 2,
'log (base 10)': 10,
'log (base 32)': 32,
'log (base 1024)': 1024
};
this.unitFormats = kbn.getUnitFormats();
};
HorizonCtrl.prototype.onInitPanelActions = function(actions) {
actions.push({text: 'Export CSV (series as rows)', click: 'ctrl.exportCsv()'});
actions.push({text: 'Export CSV (series as columns)', click: 'ctrl.exportCsvColumns()'});
}
HorizonCtrl.prototype.setUnitFormat = function(axis, subItem) {
this.panel.y_formats[axis] = subItem.value;
// this.panel.format = subItem.value;
this.render();
};
HorizonCtrl.prototype.issueQueries = function(datasource) {
this.annotationsPromise = this.annotationsSrv.getAnnotations({
dashboard: this.dashboard,
panel: this.panel,
range: this.range
});
return _super.prototype.issueQueries.call(this, datasource);
}
HorizonCtrl.prototype.zoomOut = function(evt) {
this.publishAppEvent('zoom-out', evt);
};
HorizonCtrl.prototype.onDataSnapshotLoad = function(snapshotData) {
this.annotationsPromise = this.annotationsSrv.getAnnotations({
dashboard: this.dashboard,
panel: this.panel,
range: this.range
});
this.onDataReceived(snapshotData);
};
HorizonCtrl.prototype.onDataError = function(err) {
this.seriesList = [];
this.render([]);
};
HorizonCtrl.prototype.onDataReceived = function(dataList) {
var _this = this;
// png renderer returns just a url
if (_.isString(dataList)) {
this.render(dataList);
return;
}
this.datapointsWarning = false;
this.datapointsCount = 0;
this.datapointsOutside = false;
this.seriesList = dataList.map(this.seriesHandler.bind(this));
this.datapointsWarning = this.datapointsCount === 0 || this.datapointsOutside;
this.annotationsPromise.then(function(annotations) {
_this.loading = false;
_this.seriesList.annotations = annotations;
_this.render(_this.seriesList);
}, function() {
_this.loading = false;
_this.render(_this.seriesList);
});
};
HorizonCtrl.prototype.seriesHandler = function(seriesData, index) {
var datapoints = seriesData.datapoints;
var alias = seriesData.target;
var series = new TimeSeries({
datapoints: datapoints,
alias: alias,
index: index,
});
if (datapoints && datapoints.length > 0) {
var last = moment.utc(datapoints[datapoints.length - 1][1]);
var from = moment.utc(this.range.from);
if (last - from < -10000) {
this.datapointsOutside = true;
}
this.datapointsCount += datapoints.length;
}
return series;
};
HorizonCtrl.prototype.addSeriesOverride = function(override) {
this.panel.seriesOverrides.push(override || {});
};
HorizonCtrl.prototype.removeSeriesOverride = function(override) {
this.panel.seriesOverrides = _.without(this.panel.seriesOverrides, override);
this.render();
};
HorizonCtrl.prototype.legendValuesOptionChanged = function() {
var legend = this.panel.legend;
legend.values = legend.min || legend.max || legend.avg || legend.current || legend.total;
this.render();
};
HorizonCtrl.prototype.exportCsv = function() {
fileExport.exportSeriesListToCsv(this.seriesList);
};
HorizonCtrl.prototype.exportCsvColumns = function() {
fileExport.exportSeriesListToCsvColumns(this.seriesList);
};
return HorizonCtrl;
})(sdk.MetricsPanelCtrl);
return {
PanelCtrl: HorizonCtrl
};
});