@cloudcare/guance-front-tools 1.0.15 → 1.0.16
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/cjs/scripts/convert-grafana-dashboard-core.js +1512 -1604
- package/lib/cjs/scripts/convert-grafana-dashboard.js +108 -125
- package/lib/esm/scripts/convert-grafana-dashboard-core.js +1508 -1603
- package/lib/esm/scripts/convert-grafana-dashboard.js +101 -123
- package/package.json +1 -1
- package/scripts/sync-converter.mjs +17 -1
- package/skills/grafana-to-guance-dashboard/scripts/convert-grafana-dashboard-core.js +1508 -1603
- package/skills/grafana-to-guance-dashboard/scripts/convert-grafana-dashboard.mjs +101 -123
- package/test/cli.test.mjs +3 -10
|
@@ -1,1770 +1,1678 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.convertDashboard = convertDashboard;
|
|
1
4
|
const PANEL_TYPE_MAP = {
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
}
|
|
19
|
-
|
|
5
|
+
stat: 'singlestat',
|
|
6
|
+
singlestat: 'singlestat',
|
|
7
|
+
timeseries: 'sequence',
|
|
8
|
+
graph: 'sequence',
|
|
9
|
+
trend: 'sequence',
|
|
10
|
+
bargauge: 'toplist',
|
|
11
|
+
gauge: 'gauge',
|
|
12
|
+
barchart: 'bar',
|
|
13
|
+
piechart: 'pie',
|
|
14
|
+
table: 'table',
|
|
15
|
+
text: 'text',
|
|
16
|
+
heatmap: 'heatmap',
|
|
17
|
+
histogram: 'histogram',
|
|
18
|
+
treemap: 'treemap',
|
|
19
|
+
geomap: 'worldmap',
|
|
20
|
+
logs: 'log',
|
|
21
|
+
};
|
|
20
22
|
const GRAFANA_BUILTIN_VARS = new Set([
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
])
|
|
33
|
-
|
|
23
|
+
'__interval',
|
|
24
|
+
'__interval_ms',
|
|
25
|
+
'__range',
|
|
26
|
+
'__range_s',
|
|
27
|
+
'__range_ms',
|
|
28
|
+
'__from',
|
|
29
|
+
'__to',
|
|
30
|
+
'__dashboard',
|
|
31
|
+
'__name',
|
|
32
|
+
'__org',
|
|
33
|
+
'__user',
|
|
34
|
+
]);
|
|
34
35
|
const PROMQL_RESERVED_WORDS = new Set([
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
])
|
|
47
|
-
|
|
36
|
+
'and',
|
|
37
|
+
'or',
|
|
38
|
+
'unless',
|
|
39
|
+
'by',
|
|
40
|
+
'without',
|
|
41
|
+
'on',
|
|
42
|
+
'ignoring',
|
|
43
|
+
'group_left',
|
|
44
|
+
'group_right',
|
|
45
|
+
'bool',
|
|
46
|
+
'offset',
|
|
47
|
+
]);
|
|
48
48
|
const UNIT_MAP = {
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
}
|
|
65
|
-
|
|
49
|
+
percent: ['percent', 'percent'],
|
|
50
|
+
bytes: ['digital', 'B'],
|
|
51
|
+
decbytes: ['digital', 'B'],
|
|
52
|
+
bits: ['digital', 'b'],
|
|
53
|
+
deckbytes: ['digital', 'KB'],
|
|
54
|
+
decgbytes: ['digital', 'GB'],
|
|
55
|
+
ms: ['time', 'ms'],
|
|
56
|
+
s: ['time', 's'],
|
|
57
|
+
m: ['time', 'min'],
|
|
58
|
+
h: ['time', 'h'],
|
|
59
|
+
d: ['time', 'd'],
|
|
60
|
+
short: ['custom', 'short'],
|
|
61
|
+
none: ['custom', 'none'],
|
|
62
|
+
reqps: ['custom', 'reqps'],
|
|
63
|
+
ops: ['custom', 'ops'],
|
|
64
|
+
};
|
|
66
65
|
const COMPARE_OPTIONS = {
|
|
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
|
-
|
|
66
|
+
hourCompare: { label: '小时同比', value: 'hourCompare' },
|
|
67
|
+
dayCompare: { label: '日同比', value: 'dayCompare' },
|
|
68
|
+
weekCompare: { label: '周同比', value: 'weekCompare' },
|
|
69
|
+
monthCompare: { label: '月同比', value: 'monthCompare' },
|
|
70
|
+
circleCompare: { label: '环比', value: 'circleCompare' },
|
|
71
|
+
};
|
|
72
|
+
function convertDashboard(grafanaDashboard, options = {}) {
|
|
73
|
+
var _a, _b;
|
|
74
|
+
const variableNames = new Set((((_a = grafanaDashboard.templating) === null || _a === void 0 ? void 0 : _a.list) || []).map((item) => item === null || item === void 0 ? void 0 : item.name).filter(Boolean));
|
|
75
|
+
const state = {
|
|
76
|
+
groups: [],
|
|
77
|
+
groupUnfoldStatus: {},
|
|
78
|
+
charts: [],
|
|
79
|
+
};
|
|
80
|
+
const sortedPanels = sortPanels(grafanaDashboard.panels || []);
|
|
81
|
+
collectPanels(sortedPanels, state, null, variableNames, options);
|
|
82
|
+
return pruneEmpty({
|
|
83
|
+
title: grafanaDashboard.title || '',
|
|
84
|
+
description: grafanaDashboard.description || undefined,
|
|
85
|
+
tags: grafanaDashboard.tags || undefined,
|
|
86
|
+
uid: grafanaDashboard.uid || undefined,
|
|
87
|
+
dashboardExtend: {
|
|
88
|
+
groupUnfoldStatus: state.groupUnfoldStatus,
|
|
89
|
+
},
|
|
90
|
+
main: {
|
|
91
|
+
vars: convertVariables(((_b = grafanaDashboard.templating) === null || _b === void 0 ? void 0 : _b.list) || [], variableNames),
|
|
92
|
+
charts: state.charts,
|
|
93
|
+
groups: state.groups,
|
|
94
|
+
type: 'template',
|
|
95
|
+
},
|
|
96
|
+
});
|
|
97
|
+
}
|
|
102
98
|
function collectPanels(panels, state, inheritedGroup = null, variableNames = new Set(), options = {}) {
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
99
|
+
let activeRow = inheritedGroup;
|
|
100
|
+
let openRowPanel = null;
|
|
101
|
+
for (const panel of panels) {
|
|
102
|
+
if (panel.type === 'row') {
|
|
103
|
+
const rowName = panel.title || '';
|
|
104
|
+
if (rowName) {
|
|
105
|
+
state.groups.push({ name: rowName });
|
|
106
|
+
state.groupUnfoldStatus[rowName] = !panel.collapsed;
|
|
107
|
+
}
|
|
108
|
+
if (panel.collapsed) {
|
|
109
|
+
collectPanels(sortPanels(panel.panels || []), state, rowName || null, variableNames, options);
|
|
110
|
+
activeRow = inheritedGroup;
|
|
111
|
+
openRowPanel = null;
|
|
112
|
+
}
|
|
113
|
+
else {
|
|
114
|
+
activeRow = rowName || null;
|
|
115
|
+
openRowPanel = panel;
|
|
116
|
+
}
|
|
117
|
+
continue;
|
|
118
|
+
}
|
|
119
|
+
const chart = convertPanel(panel, activeRow, openRowPanel, variableNames, options);
|
|
120
|
+
if (chart) {
|
|
121
|
+
state.charts.push(chart);
|
|
122
|
+
}
|
|
123
123
|
}
|
|
124
|
-
|
|
125
|
-
const chart = convertPanel(panel, activeRow, openRowPanel, variableNames, options)
|
|
126
|
-
if (chart) {
|
|
127
|
-
state.charts.push(chart)
|
|
128
|
-
}
|
|
129
|
-
}
|
|
130
124
|
}
|
|
131
|
-
|
|
132
125
|
function sortPanels(panels) {
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
126
|
+
return [...panels].sort((left, right) => {
|
|
127
|
+
var _a, _b, _c, _d;
|
|
128
|
+
const leftPos = left.gridPos || {};
|
|
129
|
+
const rightPos = right.gridPos || {};
|
|
130
|
+
const leftY = (_a = leftPos.y) !== null && _a !== void 0 ? _a : Number.MAX_SAFE_INTEGER;
|
|
131
|
+
const rightY = (_b = rightPos.y) !== null && _b !== void 0 ? _b : Number.MAX_SAFE_INTEGER;
|
|
132
|
+
if (leftY !== rightY)
|
|
133
|
+
return leftY - rightY;
|
|
134
|
+
const leftX = (_c = leftPos.x) !== null && _c !== void 0 ? _c : Number.MAX_SAFE_INTEGER;
|
|
135
|
+
const rightX = (_d = rightPos.x) !== null && _d !== void 0 ? _d : Number.MAX_SAFE_INTEGER;
|
|
136
|
+
if (leftX !== rightX)
|
|
137
|
+
return leftX - rightX;
|
|
138
|
+
return (left.id || 0) - (right.id || 0);
|
|
139
|
+
});
|
|
140
|
+
}
|
|
146
141
|
function convertVariables(variables, variableNames) {
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
142
|
+
return variables
|
|
143
|
+
.map((variable, index) => convertVariable(variable, index, variableNames))
|
|
144
|
+
.filter(Boolean);
|
|
150
145
|
}
|
|
151
|
-
|
|
152
146
|
function convertVariable(variable, index, variableNames) {
|
|
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
|
-
|
|
147
|
+
const variableType = String(variable.type || '');
|
|
148
|
+
const current = variable.current || {};
|
|
149
|
+
const currentText = stringifyCurrent(current.text);
|
|
150
|
+
const currentValue = stringifyCurrent(current.value);
|
|
151
|
+
const includeAll = Boolean(variable.includeAll);
|
|
152
|
+
const defaultVal = {
|
|
153
|
+
label: normalizeAllValue(currentText, variable.allValue),
|
|
154
|
+
value: normalizeAllValue(currentValue, variable.allValue, true),
|
|
155
|
+
};
|
|
156
|
+
const base = {
|
|
157
|
+
name: variable.label || variable.name || '',
|
|
158
|
+
seq: index,
|
|
159
|
+
code: variable.name || `var_${index}`,
|
|
160
|
+
hide: variable.hide && variable.hide !== 0 ? 1 : 0,
|
|
161
|
+
multiple: Boolean(variable.multi),
|
|
162
|
+
includeStar: includeAll,
|
|
163
|
+
valueSort: 'desc',
|
|
164
|
+
extend: pruneEmpty({
|
|
165
|
+
originalType: variableType,
|
|
166
|
+
description: variable.description || undefined,
|
|
167
|
+
starMeaning: includeAll ? '*' : undefined,
|
|
168
|
+
options: Array.isArray(variable.options) ? variable.options : undefined,
|
|
169
|
+
refresh: variable.refresh,
|
|
170
|
+
skipUrlSync: variable.skipUrlSync,
|
|
171
|
+
sort: variable.sort,
|
|
172
|
+
}),
|
|
173
|
+
};
|
|
174
|
+
if (variableType === 'textbox' || variableType === 'constant' || variableType === 'interval') {
|
|
175
|
+
return pruneEmpty({
|
|
176
|
+
...base,
|
|
177
|
+
datasource: 'custom',
|
|
178
|
+
type: 'CUSTOM_LIST',
|
|
179
|
+
multiple: false,
|
|
180
|
+
includeStar: false,
|
|
181
|
+
definition: {
|
|
182
|
+
value: variable.query || currentValue || '',
|
|
183
|
+
defaultVal,
|
|
184
|
+
},
|
|
185
|
+
});
|
|
186
|
+
}
|
|
187
|
+
if (variableType === 'custom' || variableType === 'datasource') {
|
|
188
|
+
return pruneEmpty({
|
|
189
|
+
...base,
|
|
190
|
+
datasource: 'custom',
|
|
191
|
+
type: 'CUSTOM_LIST',
|
|
192
|
+
definition: {
|
|
193
|
+
value: variable.query || extractCustomOptions(variable.options || []),
|
|
194
|
+
defaultVal,
|
|
195
|
+
},
|
|
196
|
+
});
|
|
197
|
+
}
|
|
198
|
+
if (variableType === 'query') {
|
|
199
|
+
const queryString = extractVariableQuery(variable);
|
|
200
|
+
const queryKind = inferVariableQueryType(variable, queryString);
|
|
201
|
+
return pruneEmpty({
|
|
202
|
+
...base,
|
|
203
|
+
datasource: queryKind === 'FIELD' ? 'object' : 'dataflux',
|
|
204
|
+
type: queryKind,
|
|
205
|
+
definition: {
|
|
206
|
+
tag: '',
|
|
207
|
+
field: queryKind === 'FIELD' ? extractFieldName(queryString) : '',
|
|
208
|
+
value: replaceVariables(queryString || '', variableNames),
|
|
209
|
+
metric: extractMetricName(queryString, variableNames),
|
|
210
|
+
object: queryKind === 'FIELD' ? 'HOST' : '',
|
|
211
|
+
defaultVal,
|
|
212
|
+
},
|
|
213
|
+
});
|
|
214
|
+
}
|
|
211
215
|
return pruneEmpty({
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
})
|
|
224
|
-
}
|
|
225
|
-
|
|
226
|
-
return pruneEmpty({
|
|
227
|
-
...base,
|
|
228
|
-
datasource: 'custom',
|
|
229
|
-
type: 'CUSTOM_LIST',
|
|
230
|
-
multiple: false,
|
|
231
|
-
includeStar: false,
|
|
232
|
-
definition: {
|
|
233
|
-
value: variable.query || currentValue || '',
|
|
234
|
-
defaultVal,
|
|
235
|
-
},
|
|
236
|
-
})
|
|
237
|
-
}
|
|
238
|
-
|
|
216
|
+
...base,
|
|
217
|
+
datasource: 'custom',
|
|
218
|
+
type: 'CUSTOM_LIST',
|
|
219
|
+
multiple: false,
|
|
220
|
+
includeStar: false,
|
|
221
|
+
definition: {
|
|
222
|
+
value: variable.query || currentValue || '',
|
|
223
|
+
defaultVal,
|
|
224
|
+
},
|
|
225
|
+
});
|
|
226
|
+
}
|
|
239
227
|
function convertPanel(panel, groupName, rowPanel, variableNames, options) {
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
return pruneEmpty({
|
|
252
|
-
name: replaceVariables(panel.title || '', variableNames),
|
|
253
|
-
type: chartType,
|
|
254
|
-
group: { name: group },
|
|
255
|
-
pos: position,
|
|
256
|
-
extend: {
|
|
257
|
-
settings,
|
|
258
|
-
links: links.length ? links : undefined,
|
|
259
|
-
sourcePanelType: options.keepGrafanaMeta ? panel.type : undefined,
|
|
260
|
-
sourcePanelId: options.keepGrafanaMeta ? panel.id : undefined,
|
|
261
|
-
pluginVersion: options.keepGrafanaMeta ? panel.pluginVersion || undefined : undefined,
|
|
262
|
-
grafana: options.keepGrafanaMeta
|
|
263
|
-
? pruneEmpty({
|
|
264
|
-
fieldConfig: panel.fieldConfig,
|
|
265
|
-
options: panel.options,
|
|
266
|
-
transformations: panel.transformations,
|
|
267
|
-
transparent: panel.transparent,
|
|
268
|
-
repeat: panel.repeat,
|
|
269
|
-
datasource: panel.datasource,
|
|
270
|
-
})
|
|
271
|
-
: undefined,
|
|
272
|
-
},
|
|
273
|
-
queries,
|
|
274
|
-
})
|
|
275
|
-
}
|
|
276
|
-
|
|
277
|
-
function buildPosition(panel, rowPanel) {
|
|
278
|
-
const gridPos = panel.gridPos || {}
|
|
279
|
-
const rowOffset = rowPanel?.gridPos?.y ?? 0
|
|
280
|
-
const rawY = typeof gridPos.y === 'number' ? gridPos.y - rowOffset : 0
|
|
281
|
-
|
|
282
|
-
return {
|
|
283
|
-
x: numberOr(gridPos.x, 0),
|
|
284
|
-
y: round1(rawY * 1.9 + 0.5),
|
|
285
|
-
w: numberOr(gridPos.w, 12),
|
|
286
|
-
h: round1(numberOr(gridPos.h, 8) * 1.9 + 0.1),
|
|
287
|
-
}
|
|
288
|
-
}
|
|
289
|
-
|
|
290
|
-
function buildQueries(panel, chartType, variableNames, options = {}) {
|
|
291
|
-
const queries = []
|
|
292
|
-
const targets = Array.isArray(panel.targets) ? panel.targets : []
|
|
293
|
-
|
|
294
|
-
for (let index = 0; index < targets.length; index++) {
|
|
295
|
-
const target = targets[index]
|
|
296
|
-
const queryText = extractTargetQuery(target)
|
|
297
|
-
if (!queryText) continue
|
|
298
|
-
|
|
299
|
-
const qtype = inferQueryLanguage(target, queryText)
|
|
300
|
-
const normalizedQueryText = normalizeTargetQuery(queryText, qtype, options)
|
|
301
|
-
queries.push(
|
|
302
|
-
pruneEmpty({
|
|
303
|
-
name: target.legendFormat || target.alias || '',
|
|
228
|
+
const chartType = inferChartType(panel);
|
|
229
|
+
if (!chartType || !panel.gridPos) {
|
|
230
|
+
return null;
|
|
231
|
+
}
|
|
232
|
+
const queries = buildQueries(panel, chartType, variableNames, options);
|
|
233
|
+
const settings = buildSettings(panel, chartType, queries, variableNames);
|
|
234
|
+
const links = extractPanelLinks(panel, variableNames);
|
|
235
|
+
const group = groupName !== null && groupName !== void 0 ? groupName : null;
|
|
236
|
+
const position = buildPosition(panel, rowPanel);
|
|
237
|
+
return pruneEmpty({
|
|
238
|
+
name: replaceVariables(panel.title || '', variableNames),
|
|
304
239
|
type: chartType,
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
240
|
+
group: { name: group },
|
|
241
|
+
pos: position,
|
|
242
|
+
extend: {
|
|
243
|
+
settings,
|
|
244
|
+
links: links.length ? links : undefined,
|
|
245
|
+
sourcePanelType: options.keepGrafanaMeta ? panel.type : undefined,
|
|
246
|
+
sourcePanelId: options.keepGrafanaMeta ? panel.id : undefined,
|
|
247
|
+
pluginVersion: options.keepGrafanaMeta ? panel.pluginVersion || undefined : undefined,
|
|
248
|
+
grafana: options.keepGrafanaMeta
|
|
249
|
+
? pruneEmpty({
|
|
250
|
+
fieldConfig: panel.fieldConfig,
|
|
251
|
+
options: panel.options,
|
|
252
|
+
transformations: panel.transformations,
|
|
253
|
+
transparent: panel.transparent,
|
|
254
|
+
repeat: panel.repeat,
|
|
255
|
+
datasource: panel.datasource,
|
|
256
|
+
})
|
|
257
|
+
: undefined,
|
|
315
258
|
},
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
259
|
+
queries,
|
|
260
|
+
});
|
|
261
|
+
}
|
|
262
|
+
function buildPosition(panel, rowPanel) {
|
|
263
|
+
var _a, _b;
|
|
264
|
+
const gridPos = panel.gridPos || {};
|
|
265
|
+
const rowOffset = (_b = (_a = rowPanel === null || rowPanel === void 0 ? void 0 : rowPanel.gridPos) === null || _a === void 0 ? void 0 : _a.y) !== null && _b !== void 0 ? _b : 0;
|
|
266
|
+
const rawY = typeof gridPos.y === 'number' ? gridPos.y - rowOffset : 0;
|
|
267
|
+
return {
|
|
268
|
+
x: numberOr(gridPos.x, 0),
|
|
269
|
+
y: round1(rawY * 1.9 + 0.5),
|
|
270
|
+
w: numberOr(gridPos.w, 12),
|
|
271
|
+
h: round1(numberOr(gridPos.h, 8) * 1.9 + 0.1),
|
|
272
|
+
};
|
|
273
|
+
}
|
|
274
|
+
function buildQueries(panel, chartType, variableNames, options = {}) {
|
|
275
|
+
var _a;
|
|
276
|
+
const queries = [];
|
|
277
|
+
const targets = Array.isArray(panel.targets) ? panel.targets : [];
|
|
278
|
+
for (let index = 0; index < targets.length; index++) {
|
|
279
|
+
const target = targets[index];
|
|
280
|
+
const queryText = extractTargetQuery(target);
|
|
281
|
+
if (!queryText)
|
|
282
|
+
continue;
|
|
283
|
+
const qtype = inferQueryLanguage(target, queryText);
|
|
284
|
+
const normalizedQueryText = normalizeTargetQuery(queryText, qtype, options);
|
|
285
|
+
queries.push(pruneEmpty({
|
|
286
|
+
name: target.legendFormat || target.alias || '',
|
|
287
|
+
type: chartType,
|
|
288
|
+
qtype,
|
|
289
|
+
datasource: 'dataflux',
|
|
290
|
+
disabled: Boolean(target.hide),
|
|
291
|
+
query: {
|
|
292
|
+
q: replaceVariables(normalizedQueryText, variableNames),
|
|
293
|
+
code: normalizeQueryCode(target.refId, index),
|
|
294
|
+
type: qtype,
|
|
295
|
+
promqlCode: qtype === 'promql' ? index + 1 : undefined,
|
|
296
|
+
alias: target.legendFormat || target.alias || '',
|
|
297
|
+
field: target.field || undefined,
|
|
298
|
+
},
|
|
299
|
+
extend: pruneEmpty({
|
|
300
|
+
refId: target.refId || undefined,
|
|
301
|
+
datasource: target.datasource || undefined,
|
|
302
|
+
editorMode: target.editorMode || undefined,
|
|
303
|
+
queryMode: target.queryMode || undefined,
|
|
304
|
+
}),
|
|
305
|
+
}));
|
|
306
|
+
}
|
|
307
|
+
if (chartType === 'text' && ((_a = panel.options) === null || _a === void 0 ? void 0 : _a.content)) {
|
|
308
|
+
queries.push({
|
|
309
|
+
query: {
|
|
310
|
+
content: replaceVariables(panel.options.content, variableNames),
|
|
311
|
+
},
|
|
312
|
+
});
|
|
313
|
+
}
|
|
314
|
+
return queries;
|
|
335
315
|
}
|
|
336
|
-
|
|
337
316
|
function buildSettings(panel, chartType, queries, variableNames) {
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
|
|
442
|
-
|
|
443
|
-
|
|
444
|
-
|
|
445
|
-
|
|
446
|
-
|
|
447
|
-
|
|
448
|
-
|
|
449
|
-
|
|
450
|
-
|
|
451
|
-
|
|
452
|
-
|
|
453
|
-
|
|
454
|
-
|
|
455
|
-
|
|
456
|
-
|
|
457
|
-
|
|
458
|
-
|
|
459
|
-
|
|
460
|
-
|
|
461
|
-
|
|
462
|
-
|
|
463
|
-
|
|
464
|
-
|
|
465
|
-
|
|
466
|
-
|
|
467
|
-
|
|
468
|
-
|
|
469
|
-
|
|
470
|
-
|
|
471
|
-
|
|
472
|
-
|
|
473
|
-
|
|
474
|
-
|
|
475
|
-
|
|
476
|
-
|
|
477
|
-
|
|
478
|
-
|
|
479
|
-
|
|
480
|
-
|
|
481
|
-
|
|
482
|
-
|
|
483
|
-
|
|
484
|
-
|
|
485
|
-
|
|
486
|
-
|
|
487
|
-
|
|
488
|
-
|
|
489
|
-
|
|
490
|
-
|
|
491
|
-
|
|
492
|
-
|
|
493
|
-
|
|
494
|
-
|
|
495
|
-
|
|
496
|
-
|
|
497
|
-
|
|
498
|
-
|
|
499
|
-
|
|
500
|
-
|
|
501
|
-
|
|
502
|
-
|
|
503
|
-
|
|
504
|
-
|
|
505
|
-
|
|
506
|
-
|
|
507
|
-
|
|
508
|
-
|
|
509
|
-
|
|
510
|
-
|
|
511
|
-
|
|
512
|
-
|
|
513
|
-
|
|
514
|
-
|
|
515
|
-
|
|
516
|
-
|
|
517
|
-
|
|
518
|
-
|
|
519
|
-
|
|
520
|
-
|
|
521
|
-
|
|
522
|
-
})
|
|
523
|
-
|
|
524
|
-
|
|
525
|
-
return pruneEmpty(settings)
|
|
526
|
-
}
|
|
527
|
-
|
|
317
|
+
var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q, _r, _s, _t, _u, _v, _w, _x;
|
|
318
|
+
const defaults = ((_a = panel.fieldConfig) === null || _a === void 0 ? void 0 : _a.defaults) || {};
|
|
319
|
+
const custom = defaults.custom || {};
|
|
320
|
+
const options = panel.options || {};
|
|
321
|
+
const legend = options.legend || panel.legend || {};
|
|
322
|
+
const transformationInfo = parseTransformations(panel.transformations || []);
|
|
323
|
+
const aliases = buildAliases(queries);
|
|
324
|
+
const tableColumns = buildTableColumns(panel.fieldConfig, transformationInfo.organize, variableNames);
|
|
325
|
+
const fieldOverrides = buildFieldOverrides(panel.fieldConfig, variableNames);
|
|
326
|
+
const legacyGauge = panel.gauge || {};
|
|
327
|
+
const valueMappings = buildLegacyValueMappings(panel.valueMaps);
|
|
328
|
+
const rangeMappings = buildLegacyRangeMappings(panel.rangeMaps);
|
|
329
|
+
const mappingItems = [...buildMappings(defaults.mappings), ...valueMappings, ...rangeMappings];
|
|
330
|
+
const explicitUnit = firstDefined(defaults.unit, panel.format, (_c = (_b = panel.yaxes) === null || _b === void 0 ? void 0 : _b[0]) === null || _c === void 0 ? void 0 : _c.format);
|
|
331
|
+
const unit = explicitUnit || inferUnitFromQueries(queries, chartType);
|
|
332
|
+
const precision = firstDefinedNumber(defaults.decimals, panel.decimals);
|
|
333
|
+
const min = firstDefinedNumber(defaults.min, legacyGauge.minValue, (_e = (_d = panel.yaxes) === null || _d === void 0 ? void 0 : _d[0]) === null || _e === void 0 ? void 0 : _e.min);
|
|
334
|
+
const max = firstDefinedNumber(defaults.max, legacyGauge.maxValue, (_g = (_f = panel.yaxes) === null || _f === void 0 ? void 0 : _f[0]) === null || _g === void 0 ? void 0 : _g.max);
|
|
335
|
+
const lineWidth = firstDefinedNumber(custom.lineWidth, panel.linewidth);
|
|
336
|
+
const fillOpacity = firstDefinedNumber(custom.fillOpacity, normalizeLegacyFill(panel.fill));
|
|
337
|
+
const reduceOptions = options.reduceOptions || {};
|
|
338
|
+
const legendValues = mapLegendCalcs(((_h = legend.calcs) === null || _h === void 0 ? void 0 : _h.length) ? legend.calcs : extractLegacyLegendCalcs(legend));
|
|
339
|
+
const connectNulls = normalizeConnectNulls(firstDefined(custom.spanNulls, panel.nullPointMode));
|
|
340
|
+
const pointMode = firstDefined(custom.showPoints, panel.points === true ? 'always' : panel.points === false ? 'never' : undefined);
|
|
341
|
+
const graphMode = options.graphMode || undefined;
|
|
342
|
+
const legacyTextMode = panel.valueName || undefined;
|
|
343
|
+
const workspaceInfo = extractWorkspaceInfo(panel.targets || []);
|
|
344
|
+
const tooltip = options.tooltip || panel.tooltip || {};
|
|
345
|
+
const statText = options.text || {};
|
|
346
|
+
const textInfo = chartType === 'text' ? analyzeTextPanel(options.content, options.mode) : null;
|
|
347
|
+
const tableFooter = options.footer || {};
|
|
348
|
+
const tableSortBy = Array.isArray(options.sortBy) ? options.sortBy : [];
|
|
349
|
+
const tableCustom = chartType === 'table' ? custom : {};
|
|
350
|
+
const compareInfo = inferCompareSettings(queries, chartType);
|
|
351
|
+
const sortInfo = inferSortSettings(chartType, legend, tableSortBy);
|
|
352
|
+
const customUnits = buildCustomUnits(panel.fieldConfig);
|
|
353
|
+
const customColors = buildCustomColors(panel.fieldConfig);
|
|
354
|
+
const colorMappings = buildColorMappings(panel.fieldConfig, chartType);
|
|
355
|
+
const valColorMappings = buildValColorMappings(panel.fieldConfig, transformationInfo.organize);
|
|
356
|
+
const effectiveUnitType = customUnits.length ? 'custom' : unit ? 'global' : undefined;
|
|
357
|
+
const slimit = inferSeriesLimit(queries, options, chartType);
|
|
358
|
+
const settings = {
|
|
359
|
+
showTitle: true,
|
|
360
|
+
titleDesc: panel.description || '',
|
|
361
|
+
isSampling: true,
|
|
362
|
+
changeWorkspace: workspaceInfo.changeWorkspace,
|
|
363
|
+
workspaceUUID: workspaceInfo.workspaceUUID,
|
|
364
|
+
workspaceName: workspaceInfo.workspaceName,
|
|
365
|
+
showFieldMapping: false,
|
|
366
|
+
openThousandsSeparator: true,
|
|
367
|
+
precision: typeof precision === 'number' ? String(precision) : '2',
|
|
368
|
+
timeInterval: normalizeTimeInterval(firstDefined(panel.interval, (_k = (_j = panel.targets) === null || _j === void 0 ? void 0 : _j.find((item) => item.interval)) === null || _k === void 0 ? void 0 : _k.interval, 'auto')),
|
|
369
|
+
fixedTime: panel.timeFrom || '',
|
|
370
|
+
maxPointCount: (_l = panel.maxDataPoints) !== null && _l !== void 0 ? _l : null,
|
|
371
|
+
showLegend: legend.showLegend,
|
|
372
|
+
legendPostion: mapLegendPlacement(legend.placement),
|
|
373
|
+
legendValues,
|
|
374
|
+
showLegend: firstDefined(legend.showLegend, legend.show),
|
|
375
|
+
showLine: chartType === 'sequence' ? inferShowLine(panel, custom) : undefined,
|
|
376
|
+
lineType: mapLineInterpolation(custom.lineInterpolation),
|
|
377
|
+
connectNulls,
|
|
378
|
+
openStack: inferOpenStack(panel, custom),
|
|
379
|
+
stackType: mapStackType(firstDefined((_m = custom.stacking) === null || _m === void 0 ? void 0 : _m.mode, panel.stack ? 'normal' : 'none')),
|
|
380
|
+
chartType: inferDisplayChartType(panel, chartType),
|
|
381
|
+
isTimeInterval: chartType === 'sequence' || chartType === 'bar' || chartType === 'heatmap' || chartType === 'histogram',
|
|
382
|
+
xAxisShowType: chartType === 'sequence' || chartType === 'bar' ? 'time' : undefined,
|
|
383
|
+
unitType: effectiveUnitType,
|
|
384
|
+
globalUnit: customUnits.length ? undefined : mapUnit(unit),
|
|
385
|
+
units: customUnits.length ? customUnits : undefined,
|
|
386
|
+
colors: customColors.length ? customColors : undefined,
|
|
387
|
+
colorMappings: colorMappings.length ? colorMappings : undefined,
|
|
388
|
+
levels: buildLevels(defaults.thresholds),
|
|
389
|
+
slimit,
|
|
390
|
+
mappings: mappingItems,
|
|
391
|
+
alias: aliases,
|
|
392
|
+
min,
|
|
393
|
+
max,
|
|
394
|
+
showPercent: Array.isArray(options.displayLabels) ? options.displayLabels.includes('percent') : undefined,
|
|
395
|
+
showLabel: chartType === 'pie' ? Array.isArray(options.displayLabels) && options.displayLabels.length > 0 : undefined,
|
|
396
|
+
showLabelValue: Array.isArray(options.displayLabels)
|
|
397
|
+
? options.displayLabels.includes('value') || options.displayLabels.includes('name')
|
|
398
|
+
: undefined,
|
|
399
|
+
direction: options.orientation || undefined,
|
|
400
|
+
queryMode: chartType === 'table' ? 'toGroupColumn' : undefined,
|
|
401
|
+
showTableHead: chartType === 'table' ? options.showHeader !== false : undefined,
|
|
402
|
+
pageEnable: chartType === 'table' ? false : undefined,
|
|
403
|
+
pageSize: chartType === 'table' ? 20 : undefined,
|
|
404
|
+
showColumns: chartType === 'table' ? tableColumns.map((column) => column.title || column.field) : undefined,
|
|
405
|
+
valMappings: chartType === 'table' ? buildTableMappings(panel.fieldConfig, transformationInfo.organize) : undefined,
|
|
406
|
+
valColorMappings: chartType === 'table' && valColorMappings.length ? valColorMappings : undefined,
|
|
407
|
+
legendValueOpen: Array.isArray(legend.values) ? legend.values.includes('value') : undefined,
|
|
408
|
+
legendValuePercentOpen: Array.isArray(legend.values) ? legend.values.includes('percent') : undefined,
|
|
409
|
+
showTopSize: chartType === 'toplist' ? true : undefined,
|
|
410
|
+
topSize: chartType === 'toplist' ? extractReduceLimit(options) : undefined,
|
|
411
|
+
scientificNotation: unit === 'short' ? true : undefined,
|
|
412
|
+
mainMeasurementQueryCode: ((_p = (_o = queries[0]) === null || _o === void 0 ? void 0 : _o.query) === null || _p === void 0 ? void 0 : _p.code) || undefined,
|
|
413
|
+
mainMeasurementLimit: chartType === 'pie' ? extractReduceLimit(options) : undefined,
|
|
414
|
+
color: ((_q = defaults.color) === null || _q === void 0 ? void 0 : _q.fixedColor) || undefined,
|
|
415
|
+
fontColor: options.colorMode === 'value' ? (_r = defaults.color) === null || _r === void 0 ? void 0 : _r.fixedColor : undefined,
|
|
416
|
+
bgColor: options.colorMode === 'background' ? (_s = defaults.color) === null || _s === void 0 ? void 0 : _s.fixedColor : undefined,
|
|
417
|
+
sequenceChartType: chartType === 'singlestat' && graphMode ? inferSequenceChartType(panel, graphMode) : undefined,
|
|
418
|
+
showLineAxis: chartType === 'singlestat' ? graphMode !== 'none' : undefined,
|
|
419
|
+
repeatChartVariable: typeof panel.repeat === 'string' && panel.repeat ? panel.repeat : undefined,
|
|
420
|
+
repeatChartRowLimit: typeof panel.maxPerRow === 'number' ? panel.maxPerRow : undefined,
|
|
421
|
+
compares: compareInfo.compares,
|
|
422
|
+
compareType: compareInfo.compareType,
|
|
423
|
+
openCompare: compareInfo.openCompare,
|
|
424
|
+
compareChartType: compareInfo.compareChartType,
|
|
425
|
+
mainMeasurementSort: sortInfo.mainMeasurementSort,
|
|
426
|
+
sorderByOrder: sortInfo.sorderByOrder,
|
|
427
|
+
};
|
|
428
|
+
const links = extractPanelLinks(panel);
|
|
429
|
+
if (links.length) {
|
|
430
|
+
settings.queryCodes = queries.map((query) => { var _a; return (_a = query.query) === null || _a === void 0 ? void 0 : _a.code; }).filter(Boolean);
|
|
431
|
+
}
|
|
432
|
+
settings.extend = pruneEmpty({
|
|
433
|
+
appearance: pruneEmpty({
|
|
434
|
+
lineWidth,
|
|
435
|
+
fillOpacity,
|
|
436
|
+
gradientMode: custom.gradientMode || undefined,
|
|
437
|
+
pointMode,
|
|
438
|
+
pointSize: firstDefinedNumber(custom.pointSize, panel.pointradius),
|
|
439
|
+
axisPlacement: custom.axisPlacement || undefined,
|
|
440
|
+
axisLabel: custom.axisLabel || undefined,
|
|
441
|
+
axisColorMode: custom.axisColorMode || undefined,
|
|
442
|
+
axisCenteredZero: typeof custom.axisCenteredZero === 'boolean' ? custom.axisCenteredZero : undefined,
|
|
443
|
+
axisSoftMin: numberOrUndefined(custom.axisSoftMin),
|
|
444
|
+
axisSoftMax: numberOrUndefined(custom.axisSoftMax),
|
|
445
|
+
barAlignment: numberOrUndefined(custom.barAlignment),
|
|
446
|
+
scaleDistribution: custom.scaleDistribution || undefined,
|
|
447
|
+
drawStyle: custom.drawStyle || undefined,
|
|
448
|
+
lineStyle: custom.lineStyle || undefined,
|
|
449
|
+
spanNulls: custom.spanNulls,
|
|
450
|
+
stackingGroup: ((_t = custom.stacking) === null || _t === void 0 ? void 0 : _t.group) || undefined,
|
|
451
|
+
graphMode,
|
|
452
|
+
colorMode: options.colorMode || undefined,
|
|
453
|
+
fieldColorMode: ((_u = defaults.color) === null || _u === void 0 ? void 0 : _u.mode) || undefined,
|
|
454
|
+
fixedColor: ((_v = defaults.color) === null || _v === void 0 ? void 0 : _v.fixedColor) || undefined,
|
|
455
|
+
thresholdsMode: ((_w = defaults.thresholds) === null || _w === void 0 ? void 0 : _w.mode) || undefined,
|
|
456
|
+
thresholdsStyleMode: ((_x = custom.thresholdsStyle) === null || _x === void 0 ? void 0 : _x.mode) || undefined,
|
|
457
|
+
textMode: options.textMode || legacyTextMode,
|
|
458
|
+
reduceCalcs: Array.isArray(reduceOptions.calcs) ? reduceOptions.calcs : undefined,
|
|
459
|
+
reduceFields: reduceOptions.fields || undefined,
|
|
460
|
+
reduceValues: typeof reduceOptions.values === 'boolean' ? reduceOptions.values : undefined,
|
|
461
|
+
pieType: options.pieType || undefined,
|
|
462
|
+
gaugeMode: chartType === 'gauge' || panel.type === 'singlestat' ? inferGaugeMode(panel, options, legacyGauge) : undefined,
|
|
463
|
+
thresholdMarkers: typeof legacyGauge.thresholdMarkers === 'boolean' ? legacyGauge.thresholdMarkers : undefined,
|
|
464
|
+
thresholdLabels: typeof legacyGauge.thresholdLabels === 'boolean' ? legacyGauge.thresholdLabels : undefined,
|
|
465
|
+
hideFrom: custom.hideFrom || undefined,
|
|
466
|
+
justifyMode: options.justifyMode || undefined,
|
|
467
|
+
titleSize: typeof statText.titleSize === 'number' ? statText.titleSize : undefined,
|
|
468
|
+
valueSize: typeof statText.valueSize === 'number' ? statText.valueSize : undefined,
|
|
469
|
+
}),
|
|
470
|
+
legend: pruneEmpty({
|
|
471
|
+
displayMode: legend.displayMode || undefined,
|
|
472
|
+
sortBy: legend.sortBy || legend.sort || undefined,
|
|
473
|
+
sortDesc: typeof legend.sortDesc === 'boolean' ? legend.sortDesc : undefined,
|
|
474
|
+
width: firstDefinedNumber(legend.width, legend.sideWidth),
|
|
475
|
+
}),
|
|
476
|
+
tooltip: pruneEmpty({
|
|
477
|
+
mode: tooltip.mode || tooltip.sharedMode || undefined,
|
|
478
|
+
sort: tooltip.sort || tooltip.value_type || undefined,
|
|
479
|
+
}),
|
|
480
|
+
table: chartType === 'table'
|
|
481
|
+
? pruneEmpty({
|
|
482
|
+
align: tableCustom.align || undefined,
|
|
483
|
+
displayMode: tableCustom.displayMode || undefined,
|
|
484
|
+
sortBy: tableSortBy,
|
|
485
|
+
footer: pruneEmpty({
|
|
486
|
+
fields: tableFooter.fields || undefined,
|
|
487
|
+
reducer: Array.isArray(tableFooter.reducer) ? tableFooter.reducer : undefined,
|
|
488
|
+
show: typeof tableFooter.show === 'boolean' ? tableFooter.show : undefined,
|
|
489
|
+
}),
|
|
490
|
+
})
|
|
491
|
+
: undefined,
|
|
492
|
+
text: textInfo || undefined,
|
|
493
|
+
tableColumns: chartType === 'table' && tableColumns.length ? tableColumns : undefined,
|
|
494
|
+
fieldOverrides: fieldOverrides.length ? fieldOverrides : undefined,
|
|
495
|
+
transformations: transformationInfo.normalized.length ? transformationInfo.normalized : undefined,
|
|
496
|
+
fieldFilterPattern: transformationInfo.fieldFilterPattern || undefined,
|
|
497
|
+
valueFilters: transformationInfo.valueFilters.length ? transformationInfo.valueFilters : undefined,
|
|
498
|
+
layout: pruneEmpty({
|
|
499
|
+
repeatDirection: panel.repeatDirection || undefined,
|
|
500
|
+
}),
|
|
501
|
+
});
|
|
502
|
+
return pruneEmpty(settings);
|
|
503
|
+
}
|
|
528
504
|
function buildLevels(thresholds) {
|
|
529
|
-
|
|
530
|
-
|
|
531
|
-
|
|
532
|
-
|
|
533
|
-
|
|
534
|
-
|
|
535
|
-
|
|
536
|
-
}))
|
|
537
|
-
}
|
|
538
|
-
|
|
505
|
+
const steps = Array.isArray(thresholds === null || thresholds === void 0 ? void 0 : thresholds.steps) ? thresholds.steps : [];
|
|
506
|
+
return steps
|
|
507
|
+
.filter((step) => typeof step.value === 'number' || typeof step.color === 'string')
|
|
508
|
+
.map((step, index) => ({
|
|
509
|
+
title: `Level ${index + 1}`,
|
|
510
|
+
value: typeof step.value === 'number' ? step.value : 0,
|
|
511
|
+
bgColor: normalizeColor(step.color),
|
|
512
|
+
}));
|
|
513
|
+
}
|
|
539
514
|
function buildMappings(mappings) {
|
|
540
|
-
|
|
541
|
-
|
|
542
|
-
|
|
543
|
-
|
|
544
|
-
|
|
545
|
-
|
|
546
|
-
|
|
547
|
-
|
|
548
|
-
|
|
549
|
-
|
|
550
|
-
|
|
551
|
-
|
|
552
|
-
|
|
553
|
-
|
|
554
|
-
|
|
555
|
-
|
|
556
|
-
|
|
557
|
-
|
|
558
|
-
|
|
559
|
-
|
|
560
|
-
|
|
561
|
-
|
|
515
|
+
var _a;
|
|
516
|
+
if (!Array.isArray(mappings))
|
|
517
|
+
return [];
|
|
518
|
+
const result = [];
|
|
519
|
+
for (const mapping of mappings) {
|
|
520
|
+
if (mapping.type === 'value' && mapping.options && typeof mapping.options === 'object') {
|
|
521
|
+
for (const [rawValue, item] of Object.entries(mapping.options)) {
|
|
522
|
+
result.push({
|
|
523
|
+
originalVal: [rawValue],
|
|
524
|
+
operation: '=',
|
|
525
|
+
mappingVal: item.text || rawValue,
|
|
526
|
+
});
|
|
527
|
+
}
|
|
528
|
+
}
|
|
529
|
+
if (mapping.type === 'range' && mapping.options) {
|
|
530
|
+
const from = mapping.options.from;
|
|
531
|
+
const to = mapping.options.to;
|
|
532
|
+
result.push({
|
|
533
|
+
originalVal: [String(from !== null && from !== void 0 ? from : ''), String(to !== null && to !== void 0 ? to : '')],
|
|
534
|
+
operation: 'between',
|
|
535
|
+
mappingVal: ((_a = mapping.options.result) === null || _a === void 0 ? void 0 : _a.text) || '',
|
|
536
|
+
});
|
|
537
|
+
}
|
|
562
538
|
}
|
|
563
|
-
|
|
564
|
-
|
|
565
|
-
return result
|
|
539
|
+
return result;
|
|
566
540
|
}
|
|
567
|
-
|
|
568
541
|
function buildTableMappings(fieldConfig, organize) {
|
|
569
|
-
|
|
570
|
-
|
|
571
|
-
|
|
572
|
-
|
|
573
|
-
|
|
574
|
-
|
|
575
|
-
|
|
576
|
-
|
|
577
|
-
|
|
578
|
-
|
|
579
|
-
|
|
580
|
-
|
|
581
|
-
|
|
582
|
-
|
|
583
|
-
|
|
584
|
-
|
|
585
|
-
|
|
586
|
-
|
|
542
|
+
var _a;
|
|
543
|
+
const overrideMappings = [];
|
|
544
|
+
const overrides = Array.isArray(fieldConfig === null || fieldConfig === void 0 ? void 0 : fieldConfig.overrides) ? fieldConfig.overrides : [];
|
|
545
|
+
const organizeMaps = createOrganizeMaps(organize);
|
|
546
|
+
for (const override of overrides) {
|
|
547
|
+
const field = (_a = override.matcher) === null || _a === void 0 ? void 0 : _a.options;
|
|
548
|
+
if (!field)
|
|
549
|
+
continue;
|
|
550
|
+
const displayField = resolveDisplayFieldName(field, organizeMaps);
|
|
551
|
+
const properties = Array.isArray(override.properties) ? override.properties : [];
|
|
552
|
+
for (const property of properties) {
|
|
553
|
+
if (property.id !== 'mappings')
|
|
554
|
+
continue;
|
|
555
|
+
const mappings = buildMappings(property.value);
|
|
556
|
+
for (const mapping of mappings) {
|
|
557
|
+
overrideMappings.push({
|
|
558
|
+
field: displayField,
|
|
559
|
+
...mapping,
|
|
560
|
+
});
|
|
561
|
+
}
|
|
562
|
+
}
|
|
587
563
|
}
|
|
588
|
-
|
|
589
|
-
|
|
590
|
-
return overrideMappings
|
|
564
|
+
return overrideMappings;
|
|
591
565
|
}
|
|
592
|
-
|
|
593
566
|
function buildTableColumns(fieldConfig, organize, variableNames = new Set()) {
|
|
594
|
-
|
|
595
|
-
|
|
596
|
-
|
|
597
|
-
|
|
598
|
-
|
|
599
|
-
|
|
600
|
-
|
|
601
|
-
|
|
602
|
-
|
|
603
|
-
|
|
604
|
-
|
|
605
|
-
|
|
606
|
-
|
|
607
|
-
|
|
608
|
-
|
|
609
|
-
|
|
610
|
-
|
|
611
|
-
|
|
567
|
+
var _a, _b;
|
|
568
|
+
const columns = new Map();
|
|
569
|
+
const defaultCustom = ((_a = fieldConfig === null || fieldConfig === void 0 ? void 0 : fieldConfig.defaults) === null || _a === void 0 ? void 0 : _a.custom) || {};
|
|
570
|
+
const overrides = Array.isArray(fieldConfig === null || fieldConfig === void 0 ? void 0 : fieldConfig.overrides) ? fieldConfig.overrides : [];
|
|
571
|
+
const organizeMaps = createOrganizeMaps(organize);
|
|
572
|
+
const { renamedFields, excludedFields, indexedFields } = organizeMaps;
|
|
573
|
+
for (const override of overrides) {
|
|
574
|
+
const rawField = (_b = override.matcher) === null || _b === void 0 ? void 0 : _b.options;
|
|
575
|
+
if (!rawField)
|
|
576
|
+
continue;
|
|
577
|
+
const field = resolveRawFieldName(rawField, organizeMaps);
|
|
578
|
+
if (excludedFields[field] === true || excludedFields[rawField] === true)
|
|
579
|
+
continue;
|
|
580
|
+
const columnKey = resolveDisplayFieldName(field, organizeMaps);
|
|
581
|
+
const currentColumn = columns.get(columnKey) || {
|
|
582
|
+
field,
|
|
583
|
+
title: columnKey,
|
|
584
|
+
order: typeof indexedFields[field] === 'number' ? indexedFields[field] : undefined,
|
|
585
|
+
align: defaultCustom.align || undefined,
|
|
586
|
+
displayMode: defaultCustom.displayMode || undefined,
|
|
587
|
+
};
|
|
588
|
+
for (const property of override.properties || []) {
|
|
589
|
+
if (property.id === 'custom.width') {
|
|
590
|
+
currentColumn.width = property.value;
|
|
591
|
+
}
|
|
592
|
+
if (property.id === 'custom.align') {
|
|
593
|
+
currentColumn.align = property.value;
|
|
594
|
+
}
|
|
595
|
+
if (property.id === 'custom.displayMode') {
|
|
596
|
+
currentColumn.displayMode = property.value;
|
|
597
|
+
}
|
|
598
|
+
if (property.id === 'links') {
|
|
599
|
+
currentColumn.links = Array.isArray(property.value)
|
|
600
|
+
? property.value.map((link) => normalizeGuanceLinkItem(link, variableNames))
|
|
601
|
+
: undefined;
|
|
602
|
+
}
|
|
603
|
+
if (property.id === 'mappings') {
|
|
604
|
+
currentColumn.mappings = buildMappings(property.value);
|
|
605
|
+
}
|
|
606
|
+
}
|
|
607
|
+
columns.set(columnKey, pruneEmpty(currentColumn));
|
|
612
608
|
}
|
|
613
|
-
|
|
614
|
-
|
|
615
|
-
|
|
616
|
-
|
|
617
|
-
|
|
618
|
-
|
|
619
|
-
|
|
620
|
-
|
|
621
|
-
|
|
622
|
-
|
|
623
|
-
|
|
624
|
-
|
|
625
|
-
|
|
626
|
-
|
|
627
|
-
|
|
628
|
-
|
|
629
|
-
|
|
630
|
-
|
|
609
|
+
if (organize) {
|
|
610
|
+
for (const [field, order] of Object.entries(indexedFields)) {
|
|
611
|
+
if (excludedFields[field] === true)
|
|
612
|
+
continue;
|
|
613
|
+
const columnKey = resolveDisplayFieldName(field, organizeMaps);
|
|
614
|
+
if (columns.has(columnKey)) {
|
|
615
|
+
const currentColumn = columns.get(columnKey);
|
|
616
|
+
currentColumn.field = field;
|
|
617
|
+
currentColumn.order = typeof order === 'number' ? order : currentColumn.order;
|
|
618
|
+
currentColumn.title = columnKey;
|
|
619
|
+
columns.set(columnKey, pruneEmpty(currentColumn));
|
|
620
|
+
continue;
|
|
621
|
+
}
|
|
622
|
+
columns.set(columnKey, pruneEmpty({
|
|
623
|
+
field,
|
|
624
|
+
title: columnKey,
|
|
625
|
+
order: typeof order === 'number' ? order : undefined,
|
|
626
|
+
}));
|
|
627
|
+
}
|
|
631
628
|
}
|
|
632
|
-
columns.
|
|
633
|
-
}
|
|
634
|
-
|
|
635
|
-
if (organize) {
|
|
636
|
-
for (const [field, order] of Object.entries(indexedFields)) {
|
|
637
|
-
if (excludedFields[field] === true) continue
|
|
638
|
-
const columnKey = resolveDisplayFieldName(field, organizeMaps)
|
|
639
|
-
if (columns.has(columnKey)) {
|
|
640
|
-
const currentColumn = columns.get(columnKey)
|
|
641
|
-
currentColumn.field = field
|
|
642
|
-
currentColumn.order = typeof order === 'number' ? order : currentColumn.order
|
|
643
|
-
currentColumn.title = columnKey
|
|
644
|
-
columns.set(columnKey, pruneEmpty(currentColumn))
|
|
645
|
-
continue
|
|
646
|
-
}
|
|
647
|
-
columns.set(
|
|
648
|
-
columnKey,
|
|
649
|
-
pruneEmpty({
|
|
650
|
-
field,
|
|
651
|
-
title: columnKey,
|
|
652
|
-
order: typeof order === 'number' ? order : undefined,
|
|
653
|
-
})
|
|
654
|
-
)
|
|
655
|
-
}
|
|
656
|
-
}
|
|
657
|
-
|
|
658
|
-
return finalizeTableColumns([...columns.values()])
|
|
629
|
+
return finalizeTableColumns([...columns.values()]);
|
|
659
630
|
}
|
|
660
|
-
|
|
661
631
|
function buildAliases(queries) {
|
|
662
|
-
|
|
663
|
-
|
|
664
|
-
|
|
665
|
-
|
|
666
|
-
|
|
667
|
-
|
|
668
|
-
}))
|
|
669
|
-
}
|
|
670
|
-
|
|
632
|
+
return queries
|
|
633
|
+
.filter((query) => { var _a; return (_a = query.query) === null || _a === void 0 ? void 0 : _a.alias; })
|
|
634
|
+
.map((query) => ({
|
|
635
|
+
alias: query.query.alias,
|
|
636
|
+
key: query.query.code || query.name || '',
|
|
637
|
+
name: query.query.code || query.name || '',
|
|
638
|
+
}));
|
|
639
|
+
}
|
|
671
640
|
function buildCustomUnits(fieldConfig) {
|
|
672
|
-
|
|
673
|
-
|
|
674
|
-
|
|
675
|
-
|
|
676
|
-
|
|
677
|
-
|
|
678
|
-
|
|
679
|
-
|
|
680
|
-
|
|
681
|
-
|
|
682
|
-
|
|
683
|
-
|
|
684
|
-
|
|
685
|
-
|
|
686
|
-
|
|
687
|
-
|
|
688
|
-
|
|
689
|
-
|
|
690
|
-
|
|
691
|
-
})
|
|
692
|
-
)
|
|
693
|
-
}
|
|
694
|
-
|
|
695
|
-
return units
|
|
696
|
-
}
|
|
697
|
-
|
|
698
|
-
function buildCustomColors(fieldConfig) {
|
|
699
|
-
const overrides = Array.isArray(fieldConfig?.overrides) ? fieldConfig.overrides : []
|
|
700
|
-
const colors = []
|
|
701
|
-
|
|
702
|
-
for (const override of overrides) {
|
|
703
|
-
const rawKey = String(override?.matcher?.options || '').trim()
|
|
704
|
-
if (!rawKey) continue
|
|
705
|
-
|
|
706
|
-
const colorProperty = Array.isArray(override?.properties)
|
|
707
|
-
? override.properties.find((property) => property?.id === 'color')
|
|
708
|
-
: undefined
|
|
709
|
-
const fixedColor = colorProperty?.value?.fixedColor
|
|
710
|
-
const colorMode = colorProperty?.value?.mode
|
|
711
|
-
if (typeof fixedColor !== 'string' || !fixedColor) continue
|
|
712
|
-
if (colorMode && colorMode !== 'fixed') continue
|
|
713
|
-
|
|
714
|
-
colors.push(
|
|
715
|
-
pruneEmpty({
|
|
716
|
-
key: rawKey,
|
|
717
|
-
name: rawKey,
|
|
718
|
-
color: normalizeColor(fixedColor),
|
|
719
|
-
})
|
|
720
|
-
)
|
|
721
|
-
}
|
|
722
|
-
|
|
723
|
-
return colors
|
|
724
|
-
}
|
|
725
|
-
|
|
726
|
-
function buildColorMappings(fieldConfig, chartType) {
|
|
727
|
-
if (chartType !== 'toplist') return []
|
|
728
|
-
|
|
729
|
-
const steps = Array.isArray(fieldConfig?.defaults?.thresholds?.steps) ? fieldConfig.defaults.thresholds.steps : []
|
|
730
|
-
if (steps.length === 0) return []
|
|
731
|
-
|
|
732
|
-
const mappings = []
|
|
733
|
-
for (let index = 0; index < steps.length; index++) {
|
|
734
|
-
const current = steps[index]
|
|
735
|
-
const next = steps[index + 1]
|
|
736
|
-
const bgColor = normalizeColor(current?.color)
|
|
737
|
-
const start = current?.value
|
|
738
|
-
const end = next?.value
|
|
739
|
-
|
|
740
|
-
if (typeof start === 'number' && typeof end === 'number') {
|
|
741
|
-
mappings.push({
|
|
742
|
-
value: [start, end],
|
|
743
|
-
bgColor,
|
|
744
|
-
operation: 'between',
|
|
745
|
-
})
|
|
746
|
-
continue
|
|
641
|
+
var _a;
|
|
642
|
+
const overrides = Array.isArray(fieldConfig === null || fieldConfig === void 0 ? void 0 : fieldConfig.overrides) ? fieldConfig.overrides : [];
|
|
643
|
+
const units = [];
|
|
644
|
+
for (const override of overrides) {
|
|
645
|
+
const rawKey = String(((_a = override === null || override === void 0 ? void 0 : override.matcher) === null || _a === void 0 ? void 0 : _a.options) || '').trim();
|
|
646
|
+
if (!rawKey)
|
|
647
|
+
continue;
|
|
648
|
+
const unitProperty = Array.isArray(override === null || override === void 0 ? void 0 : override.properties)
|
|
649
|
+
? override.properties.find((property) => (property === null || property === void 0 ? void 0 : property.id) === 'unit')
|
|
650
|
+
: undefined;
|
|
651
|
+
if (!unitProperty || typeof unitProperty.value !== 'string')
|
|
652
|
+
continue;
|
|
653
|
+
const unit = unitProperty.value;
|
|
654
|
+
units.push(pruneEmpty({
|
|
655
|
+
key: rawKey,
|
|
656
|
+
name: rawKey,
|
|
657
|
+
unit,
|
|
658
|
+
units: mapUnit(unit),
|
|
659
|
+
}));
|
|
747
660
|
}
|
|
748
|
-
|
|
749
|
-
|
|
750
|
-
|
|
751
|
-
|
|
752
|
-
|
|
753
|
-
|
|
754
|
-
|
|
755
|
-
|
|
661
|
+
return units;
|
|
662
|
+
}
|
|
663
|
+
function buildCustomColors(fieldConfig) {
|
|
664
|
+
var _a, _b, _c;
|
|
665
|
+
const overrides = Array.isArray(fieldConfig === null || fieldConfig === void 0 ? void 0 : fieldConfig.overrides) ? fieldConfig.overrides : [];
|
|
666
|
+
const colors = [];
|
|
667
|
+
for (const override of overrides) {
|
|
668
|
+
const rawKey = String(((_a = override === null || override === void 0 ? void 0 : override.matcher) === null || _a === void 0 ? void 0 : _a.options) || '').trim();
|
|
669
|
+
if (!rawKey)
|
|
670
|
+
continue;
|
|
671
|
+
const colorProperty = Array.isArray(override === null || override === void 0 ? void 0 : override.properties)
|
|
672
|
+
? override.properties.find((property) => (property === null || property === void 0 ? void 0 : property.id) === 'color')
|
|
673
|
+
: undefined;
|
|
674
|
+
const fixedColor = (_b = colorProperty === null || colorProperty === void 0 ? void 0 : colorProperty.value) === null || _b === void 0 ? void 0 : _b.fixedColor;
|
|
675
|
+
const colorMode = (_c = colorProperty === null || colorProperty === void 0 ? void 0 : colorProperty.value) === null || _c === void 0 ? void 0 : _c.mode;
|
|
676
|
+
if (typeof fixedColor !== 'string' || !fixedColor)
|
|
677
|
+
continue;
|
|
678
|
+
if (colorMode && colorMode !== 'fixed')
|
|
679
|
+
continue;
|
|
680
|
+
colors.push(pruneEmpty({
|
|
681
|
+
key: rawKey,
|
|
682
|
+
name: rawKey,
|
|
683
|
+
color: normalizeColor(fixedColor),
|
|
684
|
+
}));
|
|
756
685
|
}
|
|
757
|
-
|
|
758
|
-
|
|
759
|
-
|
|
760
|
-
|
|
761
|
-
|
|
762
|
-
|
|
763
|
-
|
|
686
|
+
return colors;
|
|
687
|
+
}
|
|
688
|
+
function buildColorMappings(fieldConfig, chartType) {
|
|
689
|
+
var _a, _b;
|
|
690
|
+
if (chartType !== 'toplist')
|
|
691
|
+
return [];
|
|
692
|
+
const steps = Array.isArray((_b = (_a = fieldConfig === null || fieldConfig === void 0 ? void 0 : fieldConfig.defaults) === null || _a === void 0 ? void 0 : _a.thresholds) === null || _b === void 0 ? void 0 : _b.steps) ? fieldConfig.defaults.thresholds.steps : [];
|
|
693
|
+
if (steps.length === 0)
|
|
694
|
+
return [];
|
|
695
|
+
const mappings = [];
|
|
696
|
+
for (let index = 0; index < steps.length; index++) {
|
|
697
|
+
const current = steps[index];
|
|
698
|
+
const next = steps[index + 1];
|
|
699
|
+
const bgColor = normalizeColor(current === null || current === void 0 ? void 0 : current.color);
|
|
700
|
+
const start = current === null || current === void 0 ? void 0 : current.value;
|
|
701
|
+
const end = next === null || next === void 0 ? void 0 : next.value;
|
|
702
|
+
if (typeof start === 'number' && typeof end === 'number') {
|
|
703
|
+
mappings.push({
|
|
704
|
+
value: [start, end],
|
|
705
|
+
bgColor,
|
|
706
|
+
operation: 'between',
|
|
707
|
+
});
|
|
708
|
+
continue;
|
|
709
|
+
}
|
|
710
|
+
if (typeof start === 'number') {
|
|
711
|
+
mappings.push({
|
|
712
|
+
value: [start],
|
|
713
|
+
bgColor,
|
|
714
|
+
operation: '>=',
|
|
715
|
+
});
|
|
716
|
+
continue;
|
|
717
|
+
}
|
|
718
|
+
if (typeof end === 'number') {
|
|
719
|
+
mappings.push({
|
|
720
|
+
value: [end],
|
|
721
|
+
bgColor,
|
|
722
|
+
operation: '<',
|
|
723
|
+
});
|
|
724
|
+
}
|
|
764
725
|
}
|
|
765
|
-
|
|
766
|
-
|
|
767
|
-
return mappings
|
|
726
|
+
return mappings;
|
|
768
727
|
}
|
|
769
|
-
|
|
770
728
|
function buildValColorMappings(fieldConfig, organize) {
|
|
771
|
-
|
|
772
|
-
|
|
773
|
-
|
|
774
|
-
|
|
775
|
-
|
|
776
|
-
|
|
777
|
-
|
|
778
|
-
|
|
779
|
-
|
|
780
|
-
|
|
781
|
-
|
|
782
|
-
|
|
783
|
-
|
|
784
|
-
|
|
785
|
-
|
|
786
|
-
|
|
787
|
-
|
|
788
|
-
|
|
789
|
-
|
|
790
|
-
|
|
791
|
-
|
|
792
|
-
|
|
793
|
-
|
|
794
|
-
|
|
795
|
-
|
|
796
|
-
|
|
797
|
-
})
|
|
798
|
-
)
|
|
729
|
+
var _a, _b;
|
|
730
|
+
const overrides = Array.isArray(fieldConfig === null || fieldConfig === void 0 ? void 0 : fieldConfig.overrides) ? fieldConfig.overrides : [];
|
|
731
|
+
const organizeMaps = createOrganizeMaps(organize);
|
|
732
|
+
const mappings = [];
|
|
733
|
+
for (const override of overrides) {
|
|
734
|
+
const rawField = (_a = override === null || override === void 0 ? void 0 : override.matcher) === null || _a === void 0 ? void 0 : _a.options;
|
|
735
|
+
if (!rawField)
|
|
736
|
+
continue;
|
|
737
|
+
const field = resolveDisplayFieldName(resolveRawFieldName(rawField, organizeMaps), organizeMaps);
|
|
738
|
+
const properties = Array.isArray(override === null || override === void 0 ? void 0 : override.properties) ? override.properties : [];
|
|
739
|
+
const mappingProperty = properties.find((property) => (property === null || property === void 0 ? void 0 : property.id) === 'mappings');
|
|
740
|
+
if (!mappingProperty)
|
|
741
|
+
continue;
|
|
742
|
+
const colorProperty = properties.find((property) => (property === null || property === void 0 ? void 0 : property.id) === 'color');
|
|
743
|
+
const fixedColor = typeof ((_b = colorProperty === null || colorProperty === void 0 ? void 0 : colorProperty.value) === null || _b === void 0 ? void 0 : _b.fixedColor) === 'string' ? normalizeColor(colorProperty.value.fixedColor) : '';
|
|
744
|
+
const tableMappings = buildMappings(mappingProperty.value);
|
|
745
|
+
for (const mapping of tableMappings) {
|
|
746
|
+
mappings.push(pruneEmpty({
|
|
747
|
+
field,
|
|
748
|
+
value: mapping.originalVal,
|
|
749
|
+
bgColor: '',
|
|
750
|
+
fontColor: fixedColor,
|
|
751
|
+
lineColor: '',
|
|
752
|
+
operation: mapping.operation,
|
|
753
|
+
}));
|
|
754
|
+
}
|
|
799
755
|
}
|
|
800
|
-
|
|
801
|
-
|
|
802
|
-
return mappings
|
|
756
|
+
return mappings;
|
|
803
757
|
}
|
|
804
|
-
|
|
805
758
|
function buildFieldOverrides(fieldConfig, variableNames = new Set()) {
|
|
806
|
-
|
|
807
|
-
|
|
808
|
-
|
|
809
|
-
|
|
810
|
-
|
|
811
|
-
|
|
812
|
-
|
|
813
|
-
|
|
814
|
-
|
|
815
|
-
|
|
816
|
-
|
|
817
|
-
|
|
818
|
-
|
|
819
|
-
|
|
820
|
-
|
|
821
|
-
|
|
822
|
-
})
|
|
823
|
-
|
|
824
|
-
|
|
825
|
-
|
|
826
|
-
}
|
|
827
|
-
|
|
828
|
-
return normalized
|
|
829
|
-
}
|
|
830
|
-
|
|
759
|
+
var _a, _b;
|
|
760
|
+
const overrides = Array.isArray(fieldConfig === null || fieldConfig === void 0 ? void 0 : fieldConfig.overrides) ? fieldConfig.overrides : [];
|
|
761
|
+
const normalized = [];
|
|
762
|
+
for (const override of overrides) {
|
|
763
|
+
const properties = Array.isArray(override.properties) ? override.properties : [];
|
|
764
|
+
const normalizedProperties = properties
|
|
765
|
+
.map((property) => normalizeOverrideProperty(property, variableNames))
|
|
766
|
+
.filter(Boolean);
|
|
767
|
+
if (normalizedProperties.length === 0)
|
|
768
|
+
continue;
|
|
769
|
+
normalized.push(pruneEmpty({
|
|
770
|
+
matcher: pruneEmpty({
|
|
771
|
+
id: ((_a = override.matcher) === null || _a === void 0 ? void 0 : _a.id) || undefined,
|
|
772
|
+
options: (_b = override.matcher) === null || _b === void 0 ? void 0 : _b.options,
|
|
773
|
+
}),
|
|
774
|
+
properties: normalizedProperties,
|
|
775
|
+
}));
|
|
776
|
+
}
|
|
777
|
+
return normalized;
|
|
778
|
+
}
|
|
831
779
|
function normalizeOverrideProperty(property, variableNames = new Set()) {
|
|
832
|
-
|
|
833
|
-
|
|
834
|
-
|
|
780
|
+
if (!(property === null || property === void 0 ? void 0 : property.id))
|
|
781
|
+
return undefined;
|
|
782
|
+
if (property.id === 'links') {
|
|
783
|
+
return pruneEmpty({
|
|
784
|
+
id: property.id,
|
|
785
|
+
value: Array.isArray(property.value)
|
|
786
|
+
? property.value.map((link) => normalizeGuanceLinkItem(link, variableNames))
|
|
787
|
+
: undefined,
|
|
788
|
+
});
|
|
789
|
+
}
|
|
835
790
|
return pruneEmpty({
|
|
836
|
-
|
|
837
|
-
|
|
838
|
-
|
|
839
|
-
|
|
840
|
-
})
|
|
841
|
-
}
|
|
842
|
-
|
|
843
|
-
return pruneEmpty({
|
|
844
|
-
id: property.id,
|
|
845
|
-
value: property.value,
|
|
846
|
-
})
|
|
847
|
-
}
|
|
848
|
-
|
|
791
|
+
id: property.id,
|
|
792
|
+
value: property.value,
|
|
793
|
+
});
|
|
794
|
+
}
|
|
849
795
|
function analyzeTextPanel(content, mode) {
|
|
850
|
-
|
|
851
|
-
|
|
852
|
-
|
|
853
|
-
|
|
854
|
-
|
|
855
|
-
|
|
856
|
-
|
|
857
|
-
|
|
858
|
-
|
|
859
|
-
|
|
860
|
-
|
|
861
|
-
|
|
862
|
-
|
|
863
|
-
|
|
864
|
-
}
|
|
865
|
-
|
|
796
|
+
if (typeof content !== 'string' || !content.trim())
|
|
797
|
+
return undefined;
|
|
798
|
+
const normalizedMode = typeof mode === 'string' ? mode : undefined;
|
|
799
|
+
const containsScript = /<script\b/i.test(content);
|
|
800
|
+
const containsHtml = /<[a-z][\s\S]*>/i.test(content);
|
|
801
|
+
const contentKind = containsScript ? 'interactive_html' : containsHtml ? 'html' : 'markdown';
|
|
802
|
+
const actions = extractTextActions(content);
|
|
803
|
+
return pruneEmpty({
|
|
804
|
+
mode: normalizedMode,
|
|
805
|
+
contentKind,
|
|
806
|
+
containsScript: containsScript || undefined,
|
|
807
|
+
actions: actions.length ? actions : undefined,
|
|
808
|
+
});
|
|
809
|
+
}
|
|
866
810
|
function extractTextActions(content) {
|
|
867
|
-
|
|
868
|
-
|
|
869
|
-
|
|
870
|
-
|
|
871
|
-
|
|
872
|
-
|
|
873
|
-
|
|
874
|
-
|
|
875
|
-
|
|
876
|
-
|
|
877
|
-
|
|
878
|
-
|
|
879
|
-
|
|
880
|
-
|
|
881
|
-
|
|
882
|
-
|
|
883
|
-
|
|
884
|
-
|
|
885
|
-
|
|
886
|
-
|
|
887
|
-
|
|
888
|
-
|
|
889
|
-
|
|
890
|
-
|
|
891
|
-
|
|
892
|
-
|
|
893
|
-
|
|
894
|
-
|
|
895
|
-
|
|
896
|
-
|
|
897
|
-
|
|
898
|
-
|
|
899
|
-
|
|
900
|
-
|
|
901
|
-
|
|
902
|
-
|
|
903
|
-
|
|
904
|
-
|
|
905
|
-
}
|
|
906
|
-
|
|
907
|
-
return actions
|
|
811
|
+
var _a, _b;
|
|
812
|
+
const actions = [];
|
|
813
|
+
const seen = new Set();
|
|
814
|
+
const anchorRegex = /<a\b[^>]*href=(['"])(.*?)\1[^>]*>([\s\S]*?)<\/a>/gi;
|
|
815
|
+
for (const match of content.matchAll(anchorRegex)) {
|
|
816
|
+
const url = (match[2] || '').trim();
|
|
817
|
+
const label = stripHtmlTags(match[3] || '').trim();
|
|
818
|
+
pushTextAction(actions, seen, {
|
|
819
|
+
title: label || undefined,
|
|
820
|
+
url: url || undefined,
|
|
821
|
+
open: url === '#' ? 'curWin' : 'newWin',
|
|
822
|
+
type: inferGuanceLinkType({ title: label, url }),
|
|
823
|
+
show: true,
|
|
824
|
+
showChanged: false,
|
|
825
|
+
});
|
|
826
|
+
}
|
|
827
|
+
const constUrlRegex = /\bconst\s+([A-Za-z_$][A-Za-z0-9_$]*)\s*=\s*([`'"])([\s\S]*?)\2\s*;/g;
|
|
828
|
+
const constantUrls = new Map();
|
|
829
|
+
for (const match of content.matchAll(constUrlRegex)) {
|
|
830
|
+
constantUrls.set(match[1], match[3]);
|
|
831
|
+
}
|
|
832
|
+
const windowOpenRegex = /window\.open\(\s*([A-Za-z_$][A-Za-z0-9_$]*|[`'"][\s\S]*?[`'"])\s*(?:,\s*([`'"][\s\S]*?[`'"]))?\s*\)/g;
|
|
833
|
+
for (const match of content.matchAll(windowOpenRegex)) {
|
|
834
|
+
const rawTarget = ((_a = match[1]) === null || _a === void 0 ? void 0 : _a.trim()) || '';
|
|
835
|
+
const rawBlank = ((_b = match[2]) === null || _b === void 0 ? void 0 : _b.trim()) || '';
|
|
836
|
+
const directUrl = unwrapQuoted(rawTarget);
|
|
837
|
+
const variableUrl = constantUrls.get(rawTarget);
|
|
838
|
+
const url = directUrl || variableUrl;
|
|
839
|
+
pushTextAction(actions, seen, {
|
|
840
|
+
title: inferActionTitle(content, url),
|
|
841
|
+
url: url || undefined,
|
|
842
|
+
open: rawBlank.includes('_blank') ? 'newWin' : 'curWin',
|
|
843
|
+
type: inferGuanceLinkType({ title: inferActionTitle(content, url), url }),
|
|
844
|
+
show: true,
|
|
845
|
+
showChanged: false,
|
|
846
|
+
});
|
|
847
|
+
}
|
|
848
|
+
return actions;
|
|
908
849
|
}
|
|
909
|
-
|
|
910
850
|
function pushTextAction(actions, seen, action) {
|
|
911
|
-
|
|
912
|
-
|
|
913
|
-
|
|
914
|
-
|
|
915
|
-
|
|
851
|
+
const normalized = pruneEmpty(action);
|
|
852
|
+
const key = JSON.stringify(normalized);
|
|
853
|
+
if (!key || seen.has(key) || Object.keys(normalized).length === 0)
|
|
854
|
+
return;
|
|
855
|
+
seen.add(key);
|
|
856
|
+
actions.push(normalized);
|
|
916
857
|
}
|
|
917
|
-
|
|
918
858
|
function inferActionTitle(content, url) {
|
|
919
|
-
|
|
920
|
-
|
|
921
|
-
|
|
922
|
-
|
|
923
|
-
|
|
859
|
+
if (typeof url !== 'string' || !url)
|
|
860
|
+
return undefined;
|
|
861
|
+
if (content.includes('HotCall') || url.includes('hotcall'))
|
|
862
|
+
return 'HotCall';
|
|
863
|
+
if (content.includes('业务大盘'))
|
|
864
|
+
return '业务大盘';
|
|
865
|
+
if (content.includes('拓扑图') || content.includes('traceLink'))
|
|
866
|
+
return '跳转观测云';
|
|
867
|
+
return undefined;
|
|
924
868
|
}
|
|
925
|
-
|
|
926
869
|
function unwrapQuoted(value) {
|
|
927
|
-
|
|
928
|
-
|
|
929
|
-
|
|
930
|
-
|
|
931
|
-
|
|
932
|
-
|
|
933
|
-
|
|
934
|
-
|
|
935
|
-
}
|
|
936
|
-
|
|
870
|
+
if (typeof value !== 'string')
|
|
871
|
+
return '';
|
|
872
|
+
const trimmed = value.trim();
|
|
873
|
+
if (trimmed.length < 2)
|
|
874
|
+
return '';
|
|
875
|
+
const quote = trimmed[0];
|
|
876
|
+
if ((quote === '"' || quote === "'" || quote === '`') && trimmed.at(-1) === quote) {
|
|
877
|
+
return trimmed.slice(1, -1);
|
|
878
|
+
}
|
|
879
|
+
return '';
|
|
880
|
+
}
|
|
937
881
|
function stripHtmlTags(value) {
|
|
938
|
-
|
|
882
|
+
return String(value).replace(/<[^>]+>/g, ' ');
|
|
939
883
|
}
|
|
940
|
-
|
|
941
884
|
function normalizeColumnTitle(field, renamedField) {
|
|
942
|
-
|
|
943
|
-
|
|
885
|
+
if (typeof renamedField === 'string' && renamedField.trim())
|
|
886
|
+
return renamedField.trim();
|
|
887
|
+
return field;
|
|
944
888
|
}
|
|
945
|
-
|
|
946
889
|
function finalizeTableColumns(columns) {
|
|
947
|
-
|
|
948
|
-
|
|
949
|
-
|
|
950
|
-
|
|
951
|
-
|
|
952
|
-
|
|
953
|
-
|
|
954
|
-
|
|
890
|
+
const mergedColumns = new Map();
|
|
891
|
+
for (const column of columns) {
|
|
892
|
+
const key = column.title || column.field;
|
|
893
|
+
const existing = mergedColumns.get(key);
|
|
894
|
+
if (!existing) {
|
|
895
|
+
mergedColumns.set(key, { ...column });
|
|
896
|
+
continue;
|
|
897
|
+
}
|
|
898
|
+
mergedColumns.set(key, pruneEmpty({
|
|
899
|
+
...existing,
|
|
900
|
+
...column,
|
|
901
|
+
field: existing.field || column.field,
|
|
902
|
+
title: key,
|
|
903
|
+
order: Math.min(numberOr(existing.order, Number.MAX_SAFE_INTEGER), numberOr(column.order, Number.MAX_SAFE_INTEGER)),
|
|
904
|
+
width: firstDefined(existing.width, column.width),
|
|
905
|
+
align: firstDefined(existing.align, column.align),
|
|
906
|
+
displayMode: firstDefined(existing.displayMode, column.displayMode),
|
|
907
|
+
links: existing.links || column.links,
|
|
908
|
+
mappings: existing.mappings || column.mappings,
|
|
909
|
+
}));
|
|
955
910
|
}
|
|
956
|
-
|
|
957
|
-
|
|
958
|
-
key,
|
|
959
|
-
pruneEmpty({
|
|
960
|
-
...existing,
|
|
961
|
-
...column,
|
|
962
|
-
field: existing.field || column.field,
|
|
963
|
-
title: key,
|
|
964
|
-
order: Math.min(numberOr(existing.order, Number.MAX_SAFE_INTEGER), numberOr(column.order, Number.MAX_SAFE_INTEGER)),
|
|
965
|
-
width: firstDefined(existing.width, column.width),
|
|
966
|
-
align: firstDefined(existing.align, column.align),
|
|
967
|
-
displayMode: firstDefined(existing.displayMode, column.displayMode),
|
|
968
|
-
links: existing.links || column.links,
|
|
969
|
-
mappings: existing.mappings || column.mappings,
|
|
970
|
-
})
|
|
971
|
-
)
|
|
972
|
-
}
|
|
973
|
-
|
|
974
|
-
return [...mergedColumns.values()].sort(
|
|
975
|
-
(left, right) => numberOr(left.order, Number.MAX_SAFE_INTEGER) - numberOr(right.order, Number.MAX_SAFE_INTEGER)
|
|
976
|
-
)
|
|
977
|
-
}
|
|
978
|
-
|
|
911
|
+
return [...mergedColumns.values()].sort((left, right) => numberOr(left.order, Number.MAX_SAFE_INTEGER) - numberOr(right.order, Number.MAX_SAFE_INTEGER));
|
|
912
|
+
}
|
|
979
913
|
function createOrganizeMaps(organize) {
|
|
980
|
-
|
|
981
|
-
|
|
982
|
-
|
|
983
|
-
|
|
984
|
-
|
|
985
|
-
|
|
986
|
-
|
|
987
|
-
|
|
988
|
-
|
|
914
|
+
const renamedFields = (organize === null || organize === void 0 ? void 0 : organize.renameByName) || {};
|
|
915
|
+
const excludedFields = (organize === null || organize === void 0 ? void 0 : organize.excludeByName) || {};
|
|
916
|
+
const indexedFields = (organize === null || organize === void 0 ? void 0 : organize.indexByName) || {};
|
|
917
|
+
const displayToRaw = {};
|
|
918
|
+
for (const [rawField, renamedField] of Object.entries(renamedFields)) {
|
|
919
|
+
const title = normalizeColumnTitle(rawField, renamedField);
|
|
920
|
+
if (title && title !== rawField) {
|
|
921
|
+
displayToRaw[title] = rawField;
|
|
922
|
+
}
|
|
989
923
|
}
|
|
990
|
-
|
|
991
|
-
|
|
992
|
-
|
|
993
|
-
|
|
994
|
-
|
|
995
|
-
|
|
996
|
-
|
|
997
|
-
}
|
|
998
|
-
}
|
|
999
|
-
|
|
924
|
+
return {
|
|
925
|
+
renamedFields,
|
|
926
|
+
excludedFields,
|
|
927
|
+
indexedFields,
|
|
928
|
+
displayToRaw,
|
|
929
|
+
};
|
|
930
|
+
}
|
|
1000
931
|
function resolveRawFieldName(field, organizeMaps) {
|
|
1001
|
-
|
|
932
|
+
return organizeMaps.displayToRaw[field] || field;
|
|
1002
933
|
}
|
|
1003
|
-
|
|
1004
934
|
function resolveDisplayFieldName(field, organizeMaps) {
|
|
1005
|
-
|
|
935
|
+
return normalizeColumnTitle(field, organizeMaps.renamedFields[field]);
|
|
1006
936
|
}
|
|
1007
|
-
|
|
1008
937
|
function parseTransformations(transformations) {
|
|
1009
|
-
|
|
1010
|
-
|
|
1011
|
-
|
|
1012
|
-
|
|
1013
|
-
|
|
1014
|
-
|
|
1015
|
-
|
|
1016
|
-
|
|
1017
|
-
|
|
1018
|
-
|
|
1019
|
-
|
|
1020
|
-
|
|
1021
|
-
|
|
1022
|
-
|
|
1023
|
-
|
|
1024
|
-
|
|
1025
|
-
|
|
1026
|
-
|
|
1027
|
-
|
|
1028
|
-
|
|
1029
|
-
|
|
1030
|
-
|
|
1031
|
-
|
|
1032
|
-
|
|
1033
|
-
|
|
1034
|
-
|
|
1035
|
-
|
|
1036
|
-
|
|
1037
|
-
|
|
1038
|
-
|
|
1039
|
-
|
|
1040
|
-
|
|
1041
|
-
|
|
1042
|
-
|
|
1043
|
-
|
|
1044
|
-
|
|
1045
|
-
|
|
1046
|
-
|
|
1047
|
-
|
|
1048
|
-
|
|
1049
|
-
|
|
1050
|
-
|
|
1051
|
-
|
|
1052
|
-
|
|
1053
|
-
|
|
1054
|
-
|
|
1055
|
-
mode: transformation.options?.type || undefined,
|
|
1056
|
-
filters,
|
|
1057
|
-
})
|
|
1058
|
-
)
|
|
1059
|
-
continue
|
|
938
|
+
var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l;
|
|
939
|
+
const normalized = [];
|
|
940
|
+
let organize = null;
|
|
941
|
+
let fieldFilterPattern = '';
|
|
942
|
+
const valueFilters = [];
|
|
943
|
+
for (const transformation of Array.isArray(transformations) ? transformations : []) {
|
|
944
|
+
if (!(transformation === null || transformation === void 0 ? void 0 : transformation.id))
|
|
945
|
+
continue;
|
|
946
|
+
if (transformation.id === 'organize') {
|
|
947
|
+
organize = transformation.options || {};
|
|
948
|
+
normalized.push(pruneEmpty({
|
|
949
|
+
type: 'organize',
|
|
950
|
+
renameByName: organize.renameByName,
|
|
951
|
+
excludeByName: organize.excludeByName,
|
|
952
|
+
indexByName: organize.indexByName,
|
|
953
|
+
}));
|
|
954
|
+
continue;
|
|
955
|
+
}
|
|
956
|
+
if (transformation.id === 'filterFieldsByName') {
|
|
957
|
+
fieldFilterPattern = ((_b = (_a = transformation.options) === null || _a === void 0 ? void 0 : _a.include) === null || _b === void 0 ? void 0 : _b.pattern) || ((_d = (_c = transformation.options) === null || _c === void 0 ? void 0 : _c.exclude) === null || _d === void 0 ? void 0 : _d.pattern) || '';
|
|
958
|
+
normalized.push(pruneEmpty({
|
|
959
|
+
type: 'filterFieldsByName',
|
|
960
|
+
include: (_e = transformation.options) === null || _e === void 0 ? void 0 : _e.include,
|
|
961
|
+
exclude: (_f = transformation.options) === null || _f === void 0 ? void 0 : _f.exclude,
|
|
962
|
+
}));
|
|
963
|
+
continue;
|
|
964
|
+
}
|
|
965
|
+
if (transformation.id === 'filterByValue') {
|
|
966
|
+
const filters = Array.isArray((_g = transformation.options) === null || _g === void 0 ? void 0 : _g.filters) ? transformation.options.filters : [];
|
|
967
|
+
valueFilters.push(pruneEmpty({
|
|
968
|
+
match: ((_h = transformation.options) === null || _h === void 0 ? void 0 : _h.match) || undefined,
|
|
969
|
+
type: ((_j = transformation.options) === null || _j === void 0 ? void 0 : _j.type) || undefined,
|
|
970
|
+
filters,
|
|
971
|
+
}));
|
|
972
|
+
normalized.push(pruneEmpty({
|
|
973
|
+
type: 'filterByValue',
|
|
974
|
+
match: ((_k = transformation.options) === null || _k === void 0 ? void 0 : _k.match) || undefined,
|
|
975
|
+
mode: ((_l = transformation.options) === null || _l === void 0 ? void 0 : _l.type) || undefined,
|
|
976
|
+
filters,
|
|
977
|
+
}));
|
|
978
|
+
continue;
|
|
979
|
+
}
|
|
980
|
+
normalized.push(pruneEmpty({
|
|
981
|
+
type: transformation.id,
|
|
982
|
+
options: transformation.options,
|
|
983
|
+
}));
|
|
1060
984
|
}
|
|
1061
|
-
|
|
1062
|
-
|
|
1063
|
-
|
|
1064
|
-
|
|
1065
|
-
|
|
1066
|
-
|
|
1067
|
-
|
|
1068
|
-
}
|
|
1069
|
-
|
|
1070
|
-
return {
|
|
1071
|
-
organize,
|
|
1072
|
-
fieldFilterPattern,
|
|
1073
|
-
valueFilters,
|
|
1074
|
-
normalized,
|
|
1075
|
-
}
|
|
1076
|
-
}
|
|
1077
|
-
|
|
985
|
+
return {
|
|
986
|
+
organize,
|
|
987
|
+
fieldFilterPattern,
|
|
988
|
+
valueFilters,
|
|
989
|
+
normalized,
|
|
990
|
+
};
|
|
991
|
+
}
|
|
1078
992
|
function extractPanelLinks(panel, variableNames) {
|
|
1079
|
-
|
|
1080
|
-
|
|
1081
|
-
|
|
1082
|
-
|
|
1083
|
-
(override.properties || [])
|
|
1084
|
-
|
|
1085
|
-
|
|
1086
|
-
|
|
1087
|
-
|
|
1088
|
-
|
|
1089
|
-
|
|
1090
|
-
|
|
1091
|
-
|
|
1092
|
-
|
|
1093
|
-
|
|
1094
|
-
|
|
1095
|
-
|
|
1096
|
-
|
|
1097
|
-
links
|
|
1098
|
-
|
|
1099
|
-
|
|
1100
|
-
return links
|
|
1101
|
-
}
|
|
1102
|
-
|
|
993
|
+
var _a, _b;
|
|
994
|
+
const links = [];
|
|
995
|
+
const defaults = ((_a = panel.fieldConfig) === null || _a === void 0 ? void 0 : _a.defaults) || {};
|
|
996
|
+
const overrideLinks = Array.isArray((_b = panel.fieldConfig) === null || _b === void 0 ? void 0 : _b.overrides)
|
|
997
|
+
? panel.fieldConfig.overrides.flatMap((override) => (override.properties || [])
|
|
998
|
+
.filter((property) => property.id === 'links')
|
|
999
|
+
.flatMap((property) => property.value || []))
|
|
1000
|
+
: [];
|
|
1001
|
+
const allLinks = [
|
|
1002
|
+
...(Array.isArray(panel.links) ? panel.links : []),
|
|
1003
|
+
...(Array.isArray(defaults.links) ? defaults.links : []),
|
|
1004
|
+
...overrideLinks,
|
|
1005
|
+
];
|
|
1006
|
+
for (const link of allLinks) {
|
|
1007
|
+
if (!link || !link.url)
|
|
1008
|
+
continue;
|
|
1009
|
+
links.push(normalizeGuanceLinkItem(link, variableNames));
|
|
1010
|
+
}
|
|
1011
|
+
return links;
|
|
1012
|
+
}
|
|
1103
1013
|
function normalizeGuanceLinkItem(link, variableNames = new Set()) {
|
|
1104
|
-
|
|
1105
|
-
|
|
1106
|
-
|
|
1107
|
-
|
|
1108
|
-
|
|
1109
|
-
|
|
1110
|
-
|
|
1111
|
-
}
|
|
1112
|
-
|
|
1014
|
+
return pruneEmpty({
|
|
1015
|
+
url: replaceVariables(link.url || '', variableNames),
|
|
1016
|
+
open: Boolean(link.targetBlank) ? 'newWin' : 'curWin',
|
|
1017
|
+
show: true,
|
|
1018
|
+
type: inferGuanceLinkType(link),
|
|
1019
|
+
showChanged: false,
|
|
1020
|
+
});
|
|
1021
|
+
}
|
|
1113
1022
|
function inferGuanceLinkType(link) {
|
|
1114
|
-
|
|
1115
|
-
|
|
1116
|
-
|
|
1117
|
-
|
|
1118
|
-
|
|
1119
|
-
|
|
1120
|
-
|
|
1121
|
-
|
|
1122
|
-
|
|
1123
|
-
|
|
1124
|
-
|
|
1125
|
-
|
|
1126
|
-
|
|
1127
|
-
|
|
1128
|
-
|
|
1023
|
+
const title = String((link === null || link === void 0 ? void 0 : link.title) || '').toLowerCase();
|
|
1024
|
+
const url = String((link === null || link === void 0 ? void 0 : link.url) || '').toLowerCase();
|
|
1025
|
+
const combined = `${title} ${url}`;
|
|
1026
|
+
if (url.includes('pipeline-log'))
|
|
1027
|
+
return 'custom';
|
|
1028
|
+
if (url.includes('/tracing/'))
|
|
1029
|
+
return 'tracing';
|
|
1030
|
+
if (url.includes('/logindi/') || url.includes('/log/') || url.includes('/logging/'))
|
|
1031
|
+
return 'logging';
|
|
1032
|
+
if (url.includes('/objectadmin/docker_containers') || url.includes('/container'))
|
|
1033
|
+
return 'container';
|
|
1034
|
+
if (url.includes('/objectadmin/host_processes') || url.includes('/process'))
|
|
1035
|
+
return 'processes';
|
|
1036
|
+
if (url.includes('/scene/builtinview/detail') || url.includes('/host'))
|
|
1037
|
+
return 'host';
|
|
1038
|
+
if (title.includes('trace') || title.includes('tracing'))
|
|
1039
|
+
return 'tracing';
|
|
1040
|
+
if (title.includes('日志'))
|
|
1041
|
+
return 'logging';
|
|
1042
|
+
return 'custom';
|
|
1043
|
+
}
|
|
1129
1044
|
function inferChartType(panel) {
|
|
1130
|
-
|
|
1045
|
+
return PANEL_TYPE_MAP[panel.type] || null;
|
|
1131
1046
|
}
|
|
1132
|
-
|
|
1133
1047
|
function inferDisplayChartType(panel, chartType) {
|
|
1134
|
-
|
|
1135
|
-
|
|
1136
|
-
|
|
1137
|
-
|
|
1138
|
-
|
|
1139
|
-
|
|
1140
|
-
|
|
1141
|
-
|
|
1142
|
-
|
|
1143
|
-
|
|
1144
|
-
|
|
1145
|
-
|
|
1146
|
-
|
|
1147
|
-
|
|
1048
|
+
var _a, _b, _c, _d, _e, _f, _g;
|
|
1049
|
+
if (chartType === 'pie') {
|
|
1050
|
+
return ((_a = panel.options) === null || _a === void 0 ? void 0 : _a.pieType) === 'donut' ? 'donut' : 'pie';
|
|
1051
|
+
}
|
|
1052
|
+
if (chartType === 'bar')
|
|
1053
|
+
return 'bar';
|
|
1054
|
+
if (chartType === 'toplist')
|
|
1055
|
+
return 'bar';
|
|
1056
|
+
const drawStyle = (_d = (_c = (_b = panel.fieldConfig) === null || _b === void 0 ? void 0 : _b.defaults) === null || _c === void 0 ? void 0 : _c.custom) === null || _d === void 0 ? void 0 : _d.drawStyle;
|
|
1057
|
+
const fillOpacity = (_g = (_f = (_e = panel.fieldConfig) === null || _e === void 0 ? void 0 : _e.defaults) === null || _f === void 0 ? void 0 : _f.custom) === null || _g === void 0 ? void 0 : _g.fillOpacity;
|
|
1058
|
+
if (drawStyle === 'bars')
|
|
1059
|
+
return 'bar';
|
|
1060
|
+
if (fillOpacity && fillOpacity > 0)
|
|
1061
|
+
return 'areaLine';
|
|
1062
|
+
return 'line';
|
|
1063
|
+
}
|
|
1148
1064
|
function inferQueryLanguage(target, queryText) {
|
|
1149
|
-
|
|
1150
|
-
|
|
1151
|
-
|
|
1152
|
-
|
|
1153
|
-
|
|
1154
|
-
|
|
1155
|
-
|
|
1156
|
-
|
|
1157
|
-
|
|
1158
|
-
|
|
1159
|
-
|
|
1160
|
-
|
|
1065
|
+
const datasourceType = getDatasourceType(target.datasource);
|
|
1066
|
+
// Guance datasource defaults to DQL unless the Grafana target explicitly marks the query as PromQL.
|
|
1067
|
+
if (target.qtype === 'promql')
|
|
1068
|
+
return 'promql';
|
|
1069
|
+
if (target.qtype === 'dql')
|
|
1070
|
+
return 'dql';
|
|
1071
|
+
if (datasourceType.includes('guance-guance-datasource'))
|
|
1072
|
+
return 'dql';
|
|
1073
|
+
if (isPrometheusLikeDatasource(datasourceType))
|
|
1074
|
+
return 'promql';
|
|
1075
|
+
if (isDqlLikeDatasource(datasourceType))
|
|
1076
|
+
return 'dql';
|
|
1077
|
+
if (/^\s*(with|select)\b/i.test(queryText))
|
|
1078
|
+
return 'dql';
|
|
1079
|
+
if (/^[A-Z]::/.test(queryText))
|
|
1080
|
+
return 'dql';
|
|
1081
|
+
return 'promql';
|
|
1082
|
+
}
|
|
1161
1083
|
function inferVariableQueryType(variable, queryString) {
|
|
1162
|
-
|
|
1163
|
-
|
|
1164
|
-
|
|
1165
|
-
|
|
1166
|
-
|
|
1167
|
-
|
|
1168
|
-
|
|
1169
|
-
|
|
1170
|
-
|
|
1171
|
-
|
|
1172
|
-
|
|
1173
|
-
|
|
1084
|
+
var _a;
|
|
1085
|
+
const datasourceType = getDatasourceType(variable.datasource);
|
|
1086
|
+
const explicitQtype = String(((_a = variable.query) === null || _a === void 0 ? void 0 : _a.qtype) || '').toLowerCase();
|
|
1087
|
+
if (datasourceType.includes('object'))
|
|
1088
|
+
return 'FIELD';
|
|
1089
|
+
if (explicitQtype === 'promql')
|
|
1090
|
+
return 'PROMQL_QUERY';
|
|
1091
|
+
if (explicitQtype === 'dql')
|
|
1092
|
+
return 'QUERY';
|
|
1093
|
+
if (isDqlLikeDatasource(datasourceType) && /^\s*(with|select)\b/i.test(queryString))
|
|
1094
|
+
return 'QUERY';
|
|
1095
|
+
if (/field_values\(/i.test(queryString) || /label_values\(/i.test(queryString))
|
|
1096
|
+
return 'QUERY';
|
|
1097
|
+
if (/^[A-Z]::/.test(queryString) || /L\('/.test(queryString))
|
|
1098
|
+
return 'QUERY';
|
|
1099
|
+
if (/^\s*(with|select)\b/i.test(queryString))
|
|
1100
|
+
return 'QUERY';
|
|
1101
|
+
return 'PROMQL_QUERY';
|
|
1102
|
+
}
|
|
1174
1103
|
function extractVariableQuery(variable) {
|
|
1175
|
-
|
|
1176
|
-
|
|
1177
|
-
|
|
1178
|
-
|
|
1179
|
-
|
|
1180
|
-
|
|
1181
|
-
|
|
1182
|
-
|
|
1104
|
+
if (typeof variable.query === 'string')
|
|
1105
|
+
return variable.query;
|
|
1106
|
+
if (variable.query && typeof variable.query === 'object') {
|
|
1107
|
+
return variable.query.rawQuery || variable.query.query || variable.query.expr || '';
|
|
1108
|
+
}
|
|
1109
|
+
if (typeof variable.definition === 'string')
|
|
1110
|
+
return variable.definition;
|
|
1111
|
+
return '';
|
|
1112
|
+
}
|
|
1183
1113
|
function extractTargetQuery(target) {
|
|
1184
|
-
|
|
1185
|
-
|
|
1186
|
-
|
|
1187
|
-
|
|
1188
|
-
|
|
1114
|
+
const candidates = [target.expr, target.query, target.queryText, target.expression, target.rawSql];
|
|
1115
|
+
for (const candidate of candidates) {
|
|
1116
|
+
if (typeof candidate === 'string' && candidate.trim())
|
|
1117
|
+
return candidate;
|
|
1118
|
+
}
|
|
1119
|
+
return '';
|
|
1189
1120
|
}
|
|
1190
|
-
|
|
1191
1121
|
function extractWorkspaceInfo(targets) {
|
|
1192
|
-
|
|
1193
|
-
|
|
1194
|
-
|
|
1195
|
-
|
|
1196
|
-
|
|
1197
|
-
|
|
1198
|
-
|
|
1122
|
+
const workspaceUUIDs = [];
|
|
1123
|
+
const workspaceNames = [];
|
|
1124
|
+
for (const target of Array.isArray(targets) ? targets : []) {
|
|
1125
|
+
for (const item of Array.isArray(target.workspaceUUIDs) ? target.workspaceUUIDs : []) {
|
|
1126
|
+
if ((item === null || item === void 0 ? void 0 : item.value) && !workspaceUUIDs.includes(item.value))
|
|
1127
|
+
workspaceUUIDs.push(item.value);
|
|
1128
|
+
if ((item === null || item === void 0 ? void 0 : item.label) && !workspaceNames.includes(item.label))
|
|
1129
|
+
workspaceNames.push(item.label);
|
|
1130
|
+
}
|
|
1199
1131
|
}
|
|
1200
|
-
|
|
1201
|
-
|
|
1202
|
-
|
|
1203
|
-
|
|
1204
|
-
|
|
1205
|
-
|
|
1206
|
-
})
|
|
1207
|
-
}
|
|
1208
|
-
|
|
1132
|
+
return pruneEmpty({
|
|
1133
|
+
changeWorkspace: workspaceUUIDs.length > 0,
|
|
1134
|
+
workspaceUUID: workspaceUUIDs.length ? workspaceUUIDs.join(',') : undefined,
|
|
1135
|
+
workspaceName: workspaceNames.length ? workspaceNames : undefined,
|
|
1136
|
+
});
|
|
1137
|
+
}
|
|
1209
1138
|
function normalizeTargetQuery(queryText, qtype, options = {}) {
|
|
1210
|
-
|
|
1211
|
-
|
|
1212
|
-
|
|
1139
|
+
if (qtype !== 'promql')
|
|
1140
|
+
return queryText;
|
|
1141
|
+
if (!options.guancePromqlCompatible)
|
|
1142
|
+
return queryText;
|
|
1143
|
+
return normalizePromqlForGuance(queryText);
|
|
1213
1144
|
}
|
|
1214
|
-
|
|
1215
1145
|
function extractMetricName(queryString, variableNames) {
|
|
1216
|
-
|
|
1217
|
-
|
|
1218
|
-
|
|
1219
|
-
|
|
1146
|
+
if (/^\s*(with|select)\b/i.test(queryString))
|
|
1147
|
+
return '';
|
|
1148
|
+
const labelValuesMatch = queryString.match(/label_values\(([^,]+),\s*([^)]+)\)/i);
|
|
1149
|
+
if (labelValuesMatch)
|
|
1150
|
+
return replaceVariables(labelValuesMatch[1].trim(), variableNames);
|
|
1151
|
+
return '';
|
|
1220
1152
|
}
|
|
1221
|
-
|
|
1222
1153
|
function extractFieldName(queryString) {
|
|
1223
|
-
|
|
1224
|
-
|
|
1225
|
-
|
|
1226
|
-
|
|
1227
|
-
|
|
1154
|
+
const fieldValuesMatch = queryString.match(/field_values\(`?([^`)\s]+)`?\)/i);
|
|
1155
|
+
if (fieldValuesMatch)
|
|
1156
|
+
return fieldValuesMatch[1].trim();
|
|
1157
|
+
const labelValuesMatch = queryString.match(/label_values\([^,]+,\s*([^)]+)\)/i);
|
|
1158
|
+
if (labelValuesMatch)
|
|
1159
|
+
return labelValuesMatch[1].replace(/[`'"]/g, '').trim();
|
|
1160
|
+
return '';
|
|
1228
1161
|
}
|
|
1229
|
-
|
|
1230
1162
|
function normalizeTimeInterval(value) {
|
|
1231
|
-
|
|
1232
|
-
|
|
1233
|
-
|
|
1234
|
-
|
|
1163
|
+
if (!value || typeof value !== 'string')
|
|
1164
|
+
return 'auto';
|
|
1165
|
+
const normalized = value.trim();
|
|
1166
|
+
if (!normalized)
|
|
1167
|
+
return 'auto';
|
|
1168
|
+
return normalized;
|
|
1235
1169
|
}
|
|
1236
|
-
|
|
1237
1170
|
function normalizePromqlForGuance(queryText) {
|
|
1238
|
-
|
|
1239
|
-
|
|
1240
|
-
|
|
1241
|
-
|
|
1242
|
-
|
|
1243
|
-
|
|
1244
|
-
|
|
1245
|
-
|
|
1246
|
-
|
|
1247
|
-
|
|
1248
|
-
|
|
1249
|
-
|
|
1250
|
-
|
|
1251
|
-
|
|
1252
|
-
|
|
1253
|
-
|
|
1254
|
-
|
|
1255
|
-
|
|
1256
|
-
|
|
1257
|
-
|
|
1171
|
+
if (typeof queryText !== 'string' || !queryText.trim())
|
|
1172
|
+
return queryText;
|
|
1173
|
+
let result = '';
|
|
1174
|
+
let index = 0;
|
|
1175
|
+
let braceDepth = 0;
|
|
1176
|
+
while (index < queryText.length) {
|
|
1177
|
+
const current = queryText[index];
|
|
1178
|
+
if (current === '{') {
|
|
1179
|
+
braceDepth++;
|
|
1180
|
+
result += current;
|
|
1181
|
+
index++;
|
|
1182
|
+
continue;
|
|
1183
|
+
}
|
|
1184
|
+
if (current === '}') {
|
|
1185
|
+
braceDepth = Math.max(0, braceDepth - 1);
|
|
1186
|
+
result += current;
|
|
1187
|
+
index++;
|
|
1188
|
+
continue;
|
|
1189
|
+
}
|
|
1190
|
+
if (braceDepth === 0 && /[A-Za-z_:]/.test(current)) {
|
|
1191
|
+
let end = index + 1;
|
|
1192
|
+
while (end < queryText.length && /[A-Za-z0-9_:]/.test(queryText[end]))
|
|
1193
|
+
end++;
|
|
1194
|
+
const token = queryText.slice(index, end);
|
|
1195
|
+
let lookahead = end;
|
|
1196
|
+
while (lookahead < queryText.length && /\s/.test(queryText[lookahead]))
|
|
1197
|
+
lookahead++;
|
|
1198
|
+
const next = queryText[lookahead];
|
|
1199
|
+
if (next === '{' || next === '[') {
|
|
1200
|
+
result += toGuancePromqlMetricName(token);
|
|
1201
|
+
index = end;
|
|
1202
|
+
continue;
|
|
1203
|
+
}
|
|
1204
|
+
}
|
|
1205
|
+
result += current;
|
|
1206
|
+
index++;
|
|
1258
1207
|
}
|
|
1259
|
-
|
|
1260
|
-
|
|
1261
|
-
let end = index + 1
|
|
1262
|
-
while (end < queryText.length && /[A-Za-z0-9_:]/.test(queryText[end])) end++
|
|
1263
|
-
const token = queryText.slice(index, end)
|
|
1264
|
-
let lookahead = end
|
|
1265
|
-
while (lookahead < queryText.length && /\s/.test(queryText[lookahead])) lookahead++
|
|
1266
|
-
const next = queryText[lookahead]
|
|
1267
|
-
if (next === '{' || next === '[') {
|
|
1268
|
-
result += toGuancePromqlMetricName(token)
|
|
1269
|
-
index = end
|
|
1270
|
-
continue
|
|
1271
|
-
}
|
|
1272
|
-
}
|
|
1273
|
-
|
|
1274
|
-
result += current
|
|
1275
|
-
index++
|
|
1276
|
-
}
|
|
1277
|
-
|
|
1278
|
-
return result
|
|
1279
|
-
}
|
|
1280
|
-
|
|
1208
|
+
return result;
|
|
1209
|
+
}
|
|
1281
1210
|
function inferUnitFromQueries(queries, chartType) {
|
|
1282
|
-
|
|
1283
|
-
|
|
1284
|
-
|
|
1285
|
-
|
|
1286
|
-
|
|
1287
|
-
|
|
1288
|
-
|
|
1289
|
-
|
|
1290
|
-
|
|
1291
|
-
|
|
1292
|
-
|
|
1293
|
-
|
|
1294
|
-
}
|
|
1295
|
-
|
|
1296
|
-
let bestUnit = inferredUnits[0]
|
|
1297
|
-
let bestCount = counts.get(bestUnit) || 0
|
|
1298
|
-
for (const unit of inferredUnits) {
|
|
1299
|
-
const currentCount = counts.get(unit) || 0
|
|
1300
|
-
if (currentCount > bestCount) {
|
|
1301
|
-
bestUnit = unit
|
|
1302
|
-
bestCount = currentCount
|
|
1211
|
+
if (!Array.isArray(queries) || queries.length === 0)
|
|
1212
|
+
return undefined;
|
|
1213
|
+
if (['text', 'table', 'topology', 'iframe', 'picture', 'video'].includes(chartType))
|
|
1214
|
+
return undefined;
|
|
1215
|
+
const inferredUnits = queries
|
|
1216
|
+
.map((query) => { var _a; return inferUnitFromQueryText(((_a = query === null || query === void 0 ? void 0 : query.query) === null || _a === void 0 ? void 0 : _a.q) || ''); })
|
|
1217
|
+
.filter(Boolean);
|
|
1218
|
+
if (inferredUnits.length === 0)
|
|
1219
|
+
return undefined;
|
|
1220
|
+
const counts = new Map();
|
|
1221
|
+
for (const unit of inferredUnits) {
|
|
1222
|
+
counts.set(unit, (counts.get(unit) || 0) + 1);
|
|
1303
1223
|
}
|
|
1304
|
-
|
|
1305
|
-
|
|
1306
|
-
|
|
1224
|
+
let bestUnit = inferredUnits[0];
|
|
1225
|
+
let bestCount = counts.get(bestUnit) || 0;
|
|
1226
|
+
for (const unit of inferredUnits) {
|
|
1227
|
+
const currentCount = counts.get(unit) || 0;
|
|
1228
|
+
if (currentCount > bestCount) {
|
|
1229
|
+
bestUnit = unit;
|
|
1230
|
+
bestCount = currentCount;
|
|
1231
|
+
}
|
|
1232
|
+
}
|
|
1233
|
+
return bestUnit;
|
|
1307
1234
|
}
|
|
1308
|
-
|
|
1309
1235
|
function inferCompareSettings(queries, chartType) {
|
|
1310
|
-
|
|
1311
|
-
|
|
1312
|
-
|
|
1313
|
-
|
|
1314
|
-
|
|
1315
|
-
|
|
1316
|
-
}
|
|
1317
|
-
|
|
1318
|
-
const compareTypes = []
|
|
1319
|
-
for (const query of queries) {
|
|
1320
|
-
const compareType = inferCompareTypeFromQuery(query?.query?.q || '')
|
|
1321
|
-
if (compareType && !compareTypes.includes(compareType)) {
|
|
1322
|
-
compareTypes.push(compareType)
|
|
1236
|
+
var _a;
|
|
1237
|
+
if (!Array.isArray(queries) || queries.length === 0) {
|
|
1238
|
+
return { compares: undefined, compareType: undefined, openCompare: undefined, compareChartType: undefined };
|
|
1239
|
+
}
|
|
1240
|
+
if (!['sequence', 'singlestat'].includes(chartType)) {
|
|
1241
|
+
return { compares: undefined, compareType: undefined, openCompare: undefined, compareChartType: undefined };
|
|
1323
1242
|
}
|
|
1324
|
-
|
|
1325
|
-
|
|
1326
|
-
|
|
1327
|
-
|
|
1328
|
-
|
|
1329
|
-
|
|
1330
|
-
|
|
1331
|
-
|
|
1332
|
-
|
|
1333
|
-
|
|
1334
|
-
|
|
1335
|
-
|
|
1336
|
-
|
|
1337
|
-
|
|
1243
|
+
const compareTypes = [];
|
|
1244
|
+
for (const query of queries) {
|
|
1245
|
+
const compareType = inferCompareTypeFromQuery(((_a = query === null || query === void 0 ? void 0 : query.query) === null || _a === void 0 ? void 0 : _a.q) || '');
|
|
1246
|
+
if (compareType && !compareTypes.includes(compareType)) {
|
|
1247
|
+
compareTypes.push(compareType);
|
|
1248
|
+
}
|
|
1249
|
+
}
|
|
1250
|
+
if (compareTypes.length === 0) {
|
|
1251
|
+
return { compares: undefined, compareType: undefined, openCompare: undefined, compareChartType: undefined };
|
|
1252
|
+
}
|
|
1253
|
+
return {
|
|
1254
|
+
compares: compareTypes.map((type) => COMPARE_OPTIONS[type]).filter(Boolean),
|
|
1255
|
+
compareType: compareTypes,
|
|
1256
|
+
openCompare: true,
|
|
1257
|
+
compareChartType: chartType,
|
|
1258
|
+
};
|
|
1259
|
+
}
|
|
1338
1260
|
function inferCompareTypeFromQuery(queryText) {
|
|
1339
|
-
|
|
1340
|
-
|
|
1341
|
-
|
|
1342
|
-
|
|
1343
|
-
|
|
1344
|
-
|
|
1345
|
-
|
|
1346
|
-
|
|
1347
|
-
|
|
1348
|
-
|
|
1349
|
-
|
|
1261
|
+
if (typeof queryText !== 'string' || !queryText.trim())
|
|
1262
|
+
return undefined;
|
|
1263
|
+
const normalized = queryText.toLowerCase();
|
|
1264
|
+
if (/\boffset\s+1h\b/.test(normalized))
|
|
1265
|
+
return 'hourCompare';
|
|
1266
|
+
if (/\boffset\s+1d\b/.test(normalized))
|
|
1267
|
+
return 'dayCompare';
|
|
1268
|
+
if (/\boffset\s+(7d|1w)\b/.test(normalized))
|
|
1269
|
+
return 'weekCompare';
|
|
1270
|
+
if (/\boffset\s+(30d|4w)\b/.test(normalized))
|
|
1271
|
+
return 'monthCompare';
|
|
1272
|
+
return undefined;
|
|
1273
|
+
}
|
|
1350
1274
|
function inferSortSettings(chartType, legend, tableSortBy) {
|
|
1351
|
-
|
|
1352
|
-
|
|
1353
|
-
|
|
1354
|
-
|
|
1355
|
-
|
|
1356
|
-
|
|
1357
|
-
|
|
1358
|
-
}
|
|
1359
|
-
|
|
1275
|
+
const sequenceSort = inferSequenceSortOrder(legend);
|
|
1276
|
+
const mainMeasurementSort = inferMainMeasurementSort(chartType, legend, tableSortBy);
|
|
1277
|
+
return {
|
|
1278
|
+
sorderByOrder: sequenceSort,
|
|
1279
|
+
mainMeasurementSort,
|
|
1280
|
+
};
|
|
1281
|
+
}
|
|
1360
1282
|
function inferSeriesLimit(queries, options, chartType) {
|
|
1361
|
-
|
|
1362
|
-
|
|
1363
|
-
|
|
1364
|
-
|
|
1365
|
-
|
|
1366
|
-
|
|
1367
|
-
|
|
1368
|
-
|
|
1369
|
-
|
|
1370
|
-
return undefined
|
|
1371
|
-
}
|
|
1372
|
-
|
|
1283
|
+
const explicitLimit = extractReduceLimit(options);
|
|
1284
|
+
if (['pie', 'toplist', 'treemap'].includes(chartType)) {
|
|
1285
|
+
return extractTopkLimit(queries) || explicitLimit;
|
|
1286
|
+
}
|
|
1287
|
+
if (['sequence', 'table'].includes(chartType)) {
|
|
1288
|
+
return extractTopkLimit(queries) || undefined;
|
|
1289
|
+
}
|
|
1290
|
+
return undefined;
|
|
1291
|
+
}
|
|
1373
1292
|
function extractTopkLimit(queries) {
|
|
1374
|
-
|
|
1375
|
-
|
|
1376
|
-
|
|
1377
|
-
const
|
|
1378
|
-
|
|
1379
|
-
|
|
1380
|
-
|
|
1381
|
-
|
|
1382
|
-
|
|
1383
|
-
|
|
1384
|
-
|
|
1385
|
-
}
|
|
1386
|
-
|
|
1293
|
+
var _a;
|
|
1294
|
+
if (!Array.isArray(queries))
|
|
1295
|
+
return undefined;
|
|
1296
|
+
for (const query of queries) {
|
|
1297
|
+
const queryText = String(((_a = query === null || query === void 0 ? void 0 : query.query) === null || _a === void 0 ? void 0 : _a.q) || '');
|
|
1298
|
+
const match = queryText.match(/\btopk\s*\(\s*(\d+)/i);
|
|
1299
|
+
if (!match)
|
|
1300
|
+
continue;
|
|
1301
|
+
const limit = Number(match[1]);
|
|
1302
|
+
if (Number.isFinite(limit))
|
|
1303
|
+
return limit;
|
|
1304
|
+
}
|
|
1305
|
+
return undefined;
|
|
1306
|
+
}
|
|
1387
1307
|
function inferSequenceSortOrder(legend) {
|
|
1388
|
-
|
|
1389
|
-
|
|
1390
|
-
|
|
1391
|
-
|
|
1308
|
+
if (typeof (legend === null || legend === void 0 ? void 0 : legend.sortDesc) === 'boolean') {
|
|
1309
|
+
return legend.sortDesc ? 'desc' : 'asc';
|
|
1310
|
+
}
|
|
1311
|
+
return undefined;
|
|
1392
1312
|
}
|
|
1393
|
-
|
|
1394
1313
|
function inferMainMeasurementSort(chartType, legend, tableSortBy) {
|
|
1395
|
-
|
|
1396
|
-
|
|
1397
|
-
|
|
1398
|
-
|
|
1399
|
-
|
|
1400
|
-
|
|
1314
|
+
if (!['pie', 'toplist', 'table', 'treemap'].includes(chartType))
|
|
1315
|
+
return undefined;
|
|
1316
|
+
if (chartType === 'table') {
|
|
1317
|
+
const primarySort = Array.isArray(tableSortBy) ? tableSortBy[0] : undefined;
|
|
1318
|
+
if (primarySort && typeof primarySort.desc === 'boolean') {
|
|
1319
|
+
return primarySort.desc ? 'top' : 'bottom';
|
|
1320
|
+
}
|
|
1401
1321
|
}
|
|
1402
|
-
|
|
1403
|
-
|
|
1404
|
-
|
|
1405
|
-
return
|
|
1406
|
-
|
|
1407
|
-
|
|
1408
|
-
return undefined
|
|
1409
|
-
}
|
|
1410
|
-
|
|
1322
|
+
if (typeof (legend === null || legend === void 0 ? void 0 : legend.sortDesc) === 'boolean') {
|
|
1323
|
+
return legend.sortDesc ? 'top' : 'bottom';
|
|
1324
|
+
}
|
|
1325
|
+
return undefined;
|
|
1326
|
+
}
|
|
1411
1327
|
function inferUnitFromQueryText(queryText) {
|
|
1412
|
-
|
|
1413
|
-
|
|
1414
|
-
|
|
1415
|
-
|
|
1416
|
-
|
|
1417
|
-
|
|
1418
|
-
|
|
1419
|
-
|
|
1420
|
-
|
|
1421
|
-
|
|
1422
|
-
|
|
1423
|
-
|
|
1424
|
-
|
|
1425
|
-
|
|
1426
|
-
|
|
1427
|
-
|
|
1428
|
-
|
|
1429
|
-
|
|
1430
|
-
|
|
1431
|
-
|
|
1432
|
-
|
|
1433
|
-
|
|
1434
|
-
|
|
1435
|
-
|
|
1436
|
-
|
|
1437
|
-
|
|
1438
|
-
|
|
1439
|
-
|
|
1440
|
-
|
|
1441
|
-
|
|
1442
|
-
|
|
1443
|
-
|
|
1444
|
-
|
|
1445
|
-
|
|
1446
|
-
|
|
1447
|
-
|
|
1448
|
-
|
|
1449
|
-
|
|
1450
|
-
|
|
1451
|
-
|
|
1452
|
-
|
|
1453
|
-
|
|
1454
|
-
|
|
1455
|
-
|
|
1456
|
-
|
|
1457
|
-
|
|
1458
|
-
|
|
1459
|
-
return 's'
|
|
1460
|
-
}
|
|
1461
|
-
|
|
1462
|
-
if (
|
|
1463
|
-
/\bqps\b|\brps\b|reqps|requests?_per_second|interface_qps|host_qps|requests?_total/.test(normalized) && isRateLike
|
|
1464
|
-
) {
|
|
1465
|
-
return 'reqps'
|
|
1466
|
-
}
|
|
1467
|
-
|
|
1468
|
-
if (
|
|
1469
|
-
/\btps\b|\biops\b|\bops\b|operations?_per_second|ops_total/.test(normalized) && isRateLike
|
|
1470
|
-
) {
|
|
1471
|
-
return 'ops'
|
|
1472
|
-
}
|
|
1473
|
-
|
|
1474
|
-
if (
|
|
1475
|
-
/cpu:load\d+s|load5s|load1s|load15s|system_load/.test(normalized)
|
|
1476
|
-
) {
|
|
1477
|
-
return 'short'
|
|
1478
|
-
}
|
|
1479
|
-
|
|
1480
|
-
if (
|
|
1481
|
-
!isRateLike &&
|
|
1482
|
-
/goroutines?|threads?|connections?|conn_count|fd|file_descriptors?|queue(_size|_depth)?|pool(_size)?|inflight|pending|blocked|active_requests|jvm_.*_count|_count\b|_total\b|count_over_time\(/.test(normalized)
|
|
1483
|
-
) {
|
|
1484
|
-
return 'none'
|
|
1485
|
-
}
|
|
1486
|
-
|
|
1487
|
-
if (
|
|
1488
|
-
/_seconds\b/.test(normalized) && !/rate\(|increase\(|irate\(/.test(normalized)
|
|
1489
|
-
) {
|
|
1490
|
-
return 's'
|
|
1491
|
-
}
|
|
1492
|
-
|
|
1493
|
-
return undefined
|
|
1494
|
-
}
|
|
1495
|
-
|
|
1328
|
+
if (typeof queryText !== 'string' || !queryText.trim())
|
|
1329
|
+
return undefined;
|
|
1330
|
+
const normalized = queryText.toLowerCase();
|
|
1331
|
+
const isRateLike = /rate\(|irate\(|increase\(|delta\(|deriv\(/.test(normalized);
|
|
1332
|
+
if (/cpu.*(?:usage|utili[sz]ation|used)|cpu_usage|cpu_used|usage_seconds_total/.test(normalized) &&
|
|
1333
|
+
/limit|quota|max|capacity|total|cores?|100/.test(normalized)) {
|
|
1334
|
+
return 'percent';
|
|
1335
|
+
}
|
|
1336
|
+
if (/memory.*(?:usage|used|utili[sz]ation)|heap.*used|rss|working_set|used_bytes|usage_bytes/.test(normalized)) {
|
|
1337
|
+
return 'bytes';
|
|
1338
|
+
}
|
|
1339
|
+
if (/disk.*(?:usage|used|utili[sz]ation)|filesystem.*(?:avail|free|size|used)|storage.*(?:used|usage)/.test(normalized)) {
|
|
1340
|
+
return 'bytes';
|
|
1341
|
+
}
|
|
1342
|
+
if (/error_rate|success_rate|failure_rate|biz_error_rate|_ratio\b|_percent\b|percent/.test(normalized) ||
|
|
1343
|
+
/container_cpu_usage_seconds_total/.test(normalized) && /kube_pod_container_resource_limits/.test(normalized) ||
|
|
1344
|
+
/\*\s*100\b/.test(normalized)) {
|
|
1345
|
+
return 'percent';
|
|
1346
|
+
}
|
|
1347
|
+
if (/p99|p95|p90|latency|duration|response_time|cost\b|elapsed|load_time|_ms\b|milliseconds?/.test(normalized) ||
|
|
1348
|
+
/performance_host_interface_p\d+/.test(normalized)) {
|
|
1349
|
+
return 'ms';
|
|
1350
|
+
}
|
|
1351
|
+
if (/_bytes\b|_bytes_total\b|memory|heap|rss|bandwidth|byte\b/.test(normalized)) {
|
|
1352
|
+
return 'bytes';
|
|
1353
|
+
}
|
|
1354
|
+
if (/gc_pause_seconds|gc.*(?:pause|time)|duration_seconds|latency_seconds|response_seconds/.test(normalized)) {
|
|
1355
|
+
return 's';
|
|
1356
|
+
}
|
|
1357
|
+
if (/\bqps\b|\brps\b|reqps|requests?_per_second|interface_qps|host_qps|requests?_total/.test(normalized) && isRateLike) {
|
|
1358
|
+
return 'reqps';
|
|
1359
|
+
}
|
|
1360
|
+
if (/\btps\b|\biops\b|\bops\b|operations?_per_second|ops_total/.test(normalized) && isRateLike) {
|
|
1361
|
+
return 'ops';
|
|
1362
|
+
}
|
|
1363
|
+
if (/cpu:load\d+s|load5s|load1s|load15s|system_load/.test(normalized)) {
|
|
1364
|
+
return 'short';
|
|
1365
|
+
}
|
|
1366
|
+
if (!isRateLike &&
|
|
1367
|
+
/goroutines?|threads?|connections?|conn_count|fd|file_descriptors?|queue(_size|_depth)?|pool(_size)?|inflight|pending|blocked|active_requests|jvm_.*_count|_count\b|_total\b|count_over_time\(/.test(normalized)) {
|
|
1368
|
+
return 'none';
|
|
1369
|
+
}
|
|
1370
|
+
if (/_seconds\b/.test(normalized) && !/rate\(|increase\(|irate\(/.test(normalized)) {
|
|
1371
|
+
return 's';
|
|
1372
|
+
}
|
|
1373
|
+
return undefined;
|
|
1374
|
+
}
|
|
1496
1375
|
function toGuancePromqlMetricName(token) {
|
|
1497
|
-
|
|
1498
|
-
|
|
1499
|
-
|
|
1500
|
-
|
|
1501
|
-
|
|
1502
|
-
|
|
1503
|
-
|
|
1504
|
-
|
|
1505
|
-
|
|
1506
|
-
|
|
1376
|
+
if (!token)
|
|
1377
|
+
return token;
|
|
1378
|
+
if (token.includes(':'))
|
|
1379
|
+
return token;
|
|
1380
|
+
if (!token.includes('_'))
|
|
1381
|
+
return token;
|
|
1382
|
+
if (token.startsWith('__'))
|
|
1383
|
+
return token;
|
|
1384
|
+
if (PROMQL_RESERVED_WORDS.has(token))
|
|
1385
|
+
return token;
|
|
1386
|
+
const firstUnderscore = token.indexOf('_');
|
|
1387
|
+
if (firstUnderscore <= 0 || firstUnderscore === token.length - 1)
|
|
1388
|
+
return token;
|
|
1389
|
+
return `${token.slice(0, firstUnderscore)}:${token.slice(firstUnderscore + 1)}`;
|
|
1390
|
+
}
|
|
1507
1391
|
function getDatasourceType(datasource) {
|
|
1508
|
-
|
|
1392
|
+
return String((datasource === null || datasource === void 0 ? void 0 : datasource.type) || datasource || '').toLowerCase();
|
|
1509
1393
|
}
|
|
1510
|
-
|
|
1511
1394
|
function isPrometheusLikeDatasource(datasourceType) {
|
|
1512
|
-
|
|
1395
|
+
return datasourceType.includes('prometheus') || datasourceType.includes('guance-guance-datasource');
|
|
1513
1396
|
}
|
|
1514
|
-
|
|
1515
1397
|
function isDqlLikeDatasource(datasourceType) {
|
|
1516
|
-
|
|
1517
|
-
|
|
1518
|
-
|
|
1519
|
-
|
|
1520
|
-
|
|
1521
|
-
|
|
1522
|
-
|
|
1523
|
-
|
|
1524
|
-
|
|
1525
|
-
|
|
1526
|
-
|
|
1527
|
-
|
|
1528
|
-
|
|
1529
|
-
)
|
|
1530
|
-
}
|
|
1531
|
-
|
|
1398
|
+
return (datasourceType.includes('mysql') ||
|
|
1399
|
+
datasourceType.includes('postgres') ||
|
|
1400
|
+
datasourceType.includes('mssql') ||
|
|
1401
|
+
datasourceType.includes('sql') ||
|
|
1402
|
+
datasourceType.includes('loki') ||
|
|
1403
|
+
datasourceType.includes('elasticsearch') ||
|
|
1404
|
+
datasourceType.includes('opensearch') ||
|
|
1405
|
+
datasourceType.includes('cloudwatch') ||
|
|
1406
|
+
datasourceType.includes('influx') ||
|
|
1407
|
+
datasourceType.includes('tempo') ||
|
|
1408
|
+
datasourceType.includes('jaeger') ||
|
|
1409
|
+
datasourceType.includes('zipkin'));
|
|
1410
|
+
}
|
|
1532
1411
|
function extractReduceLimit(options) {
|
|
1533
|
-
|
|
1534
|
-
|
|
1412
|
+
var _a;
|
|
1413
|
+
const limit = (_a = options.reduceOptions) === null || _a === void 0 ? void 0 : _a.limit;
|
|
1414
|
+
return typeof limit === 'number' ? limit : 10;
|
|
1535
1415
|
}
|
|
1536
|
-
|
|
1537
1416
|
function extractCustomOptions(options) {
|
|
1538
|
-
|
|
1539
|
-
|
|
1540
|
-
|
|
1541
|
-
|
|
1542
|
-
|
|
1543
|
-
|
|
1544
|
-
|
|
1545
|
-
|
|
1417
|
+
if (!Array.isArray(options))
|
|
1418
|
+
return '';
|
|
1419
|
+
return options
|
|
1420
|
+
.filter((item) => item && item.value !== '$__all')
|
|
1421
|
+
.map((item) => item.text || item.value || '')
|
|
1422
|
+
.filter(Boolean)
|
|
1423
|
+
.join(',');
|
|
1424
|
+
}
|
|
1546
1425
|
function mapLegendPlacement(value) {
|
|
1547
|
-
|
|
1548
|
-
|
|
1549
|
-
|
|
1550
|
-
|
|
1551
|
-
|
|
1426
|
+
if (value === 'bottom')
|
|
1427
|
+
return 'bottom';
|
|
1428
|
+
if (value === 'right')
|
|
1429
|
+
return 'right';
|
|
1430
|
+
if (value === 'left')
|
|
1431
|
+
return 'left';
|
|
1432
|
+
if (value === 'top')
|
|
1433
|
+
return 'top';
|
|
1434
|
+
return 'none';
|
|
1552
1435
|
}
|
|
1553
|
-
|
|
1554
1436
|
function mapLegendCalcs(values) {
|
|
1555
|
-
|
|
1556
|
-
|
|
1557
|
-
|
|
1558
|
-
|
|
1559
|
-
|
|
1437
|
+
if (!Array.isArray(values))
|
|
1438
|
+
return [];
|
|
1439
|
+
const allowed = new Set(['first', 'last', 'avg', 'min', 'max', 'sum', 'count']);
|
|
1440
|
+
return values
|
|
1441
|
+
.map((value) => String(value).toLowerCase())
|
|
1442
|
+
.filter((value) => allowed.has(value));
|
|
1560
1443
|
}
|
|
1561
|
-
|
|
1562
1444
|
function extractLegacyLegendCalcs(legend) {
|
|
1563
|
-
|
|
1564
|
-
|
|
1565
|
-
|
|
1566
|
-
|
|
1567
|
-
|
|
1568
|
-
|
|
1569
|
-
|
|
1570
|
-
|
|
1571
|
-
|
|
1572
|
-
|
|
1445
|
+
if (!legend || typeof legend !== 'object')
|
|
1446
|
+
return [];
|
|
1447
|
+
const calcs = [];
|
|
1448
|
+
if (legend.current)
|
|
1449
|
+
calcs.push('last');
|
|
1450
|
+
if (legend.avg)
|
|
1451
|
+
calcs.push('avg');
|
|
1452
|
+
if (legend.min)
|
|
1453
|
+
calcs.push('min');
|
|
1454
|
+
if (legend.max)
|
|
1455
|
+
calcs.push('max');
|
|
1456
|
+
if (legend.total)
|
|
1457
|
+
calcs.push('sum');
|
|
1458
|
+
return calcs;
|
|
1459
|
+
}
|
|
1573
1460
|
function mapLineInterpolation(value) {
|
|
1574
|
-
|
|
1575
|
-
|
|
1576
|
-
|
|
1577
|
-
|
|
1461
|
+
if (value === 'smooth')
|
|
1462
|
+
return 'smooth';
|
|
1463
|
+
if (value === 'stepAfter')
|
|
1464
|
+
return 'stepAfter';
|
|
1465
|
+
if (value === 'stepBefore')
|
|
1466
|
+
return 'stepBefore';
|
|
1467
|
+
return 'linear';
|
|
1578
1468
|
}
|
|
1579
|
-
|
|
1580
1469
|
function mapStackType(value) {
|
|
1581
|
-
|
|
1582
|
-
|
|
1583
|
-
|
|
1470
|
+
if (value === 'percent')
|
|
1471
|
+
return 'percent';
|
|
1472
|
+
if (value === 'normal')
|
|
1473
|
+
return 'time';
|
|
1474
|
+
return 'time';
|
|
1584
1475
|
}
|
|
1585
|
-
|
|
1586
1476
|
function inferShowLine(panel, custom) {
|
|
1587
|
-
|
|
1588
|
-
|
|
1589
|
-
|
|
1477
|
+
if (typeof panel.lines === 'boolean')
|
|
1478
|
+
return panel.lines;
|
|
1479
|
+
if (custom.drawStyle === 'bars')
|
|
1480
|
+
return false;
|
|
1481
|
+
return true;
|
|
1590
1482
|
}
|
|
1591
|
-
|
|
1592
1483
|
function inferOpenStack(panel, custom) {
|
|
1593
|
-
|
|
1594
|
-
|
|
1595
|
-
|
|
1484
|
+
var _a;
|
|
1485
|
+
if ((_a = custom.stacking) === null || _a === void 0 ? void 0 : _a.mode)
|
|
1486
|
+
return custom.stacking.mode !== 'none';
|
|
1487
|
+
if (typeof panel.stack === 'boolean')
|
|
1488
|
+
return panel.stack;
|
|
1489
|
+
return undefined;
|
|
1596
1490
|
}
|
|
1597
|
-
|
|
1598
1491
|
function inferSequenceChartType(panel, graphMode) {
|
|
1599
|
-
|
|
1600
|
-
|
|
1601
|
-
|
|
1492
|
+
if (graphMode === 'area')
|
|
1493
|
+
return 'line';
|
|
1494
|
+
if (graphMode === 'none')
|
|
1495
|
+
return undefined;
|
|
1496
|
+
return inferDisplayChartType(panel, 'sequence') === 'bar' ? 'bar' : 'line';
|
|
1602
1497
|
}
|
|
1603
|
-
|
|
1604
1498
|
function inferGaugeMode(panel, options, legacyGauge) {
|
|
1605
|
-
|
|
1606
|
-
|
|
1607
|
-
|
|
1608
|
-
|
|
1499
|
+
if (panel.type === 'gauge')
|
|
1500
|
+
return 'gauge';
|
|
1501
|
+
if (legacyGauge.show)
|
|
1502
|
+
return 'gauge';
|
|
1503
|
+
if (options.graphMode === 'none')
|
|
1504
|
+
return 'value';
|
|
1505
|
+
return 'value';
|
|
1609
1506
|
}
|
|
1610
|
-
|
|
1611
1507
|
function normalizeConnectNulls(value) {
|
|
1612
|
-
|
|
1613
|
-
|
|
1614
|
-
|
|
1615
|
-
|
|
1616
|
-
|
|
1508
|
+
if (typeof value === 'boolean')
|
|
1509
|
+
return value;
|
|
1510
|
+
if (typeof value === 'number')
|
|
1511
|
+
return value > 0;
|
|
1512
|
+
if (value === 'connected')
|
|
1513
|
+
return true;
|
|
1514
|
+
if (value === 'null' || value === 'null as zero')
|
|
1515
|
+
return false;
|
|
1516
|
+
return undefined;
|
|
1617
1517
|
}
|
|
1618
|
-
|
|
1619
1518
|
function mapUnit(unit) {
|
|
1620
|
-
|
|
1621
|
-
|
|
1622
|
-
|
|
1623
|
-
|
|
1519
|
+
if (!unit)
|
|
1520
|
+
return [];
|
|
1521
|
+
const mapped = UNIT_MAP[String(unit).toLowerCase()];
|
|
1522
|
+
if (mapped)
|
|
1523
|
+
return mapped;
|
|
1524
|
+
return ['custom', String(unit)];
|
|
1624
1525
|
}
|
|
1625
|
-
|
|
1626
1526
|
function buildLegacyValueMappings(valueMaps) {
|
|
1627
|
-
|
|
1628
|
-
|
|
1629
|
-
|
|
1630
|
-
|
|
1631
|
-
|
|
1632
|
-
|
|
1633
|
-
|
|
1634
|
-
|
|
1635
|
-
}
|
|
1636
|
-
|
|
1527
|
+
if (!Array.isArray(valueMaps))
|
|
1528
|
+
return [];
|
|
1529
|
+
return valueMaps
|
|
1530
|
+
.filter((item) => item && Object.prototype.hasOwnProperty.call(item, 'value'))
|
|
1531
|
+
.map((item) => ({
|
|
1532
|
+
originalVal: [String(item.value)],
|
|
1533
|
+
operation: normalizeLegacyMappingOperation(item.op),
|
|
1534
|
+
mappingVal: item.text || String(item.value),
|
|
1535
|
+
}));
|
|
1536
|
+
}
|
|
1637
1537
|
function buildLegacyRangeMappings(rangeMaps) {
|
|
1638
|
-
|
|
1639
|
-
|
|
1640
|
-
|
|
1641
|
-
|
|
1642
|
-
|
|
1643
|
-
|
|
1644
|
-
|
|
1645
|
-
|
|
1538
|
+
if (!Array.isArray(rangeMaps))
|
|
1539
|
+
return [];
|
|
1540
|
+
return rangeMaps.map((item) => {
|
|
1541
|
+
var _a, _b;
|
|
1542
|
+
return ({
|
|
1543
|
+
originalVal: [String((_a = item.from) !== null && _a !== void 0 ? _a : ''), String((_b = item.to) !== null && _b !== void 0 ? _b : '')],
|
|
1544
|
+
operation: 'between',
|
|
1545
|
+
mappingVal: item.text || '',
|
|
1546
|
+
});
|
|
1547
|
+
});
|
|
1548
|
+
}
|
|
1646
1549
|
function normalizeLegacyMappingOperation(value) {
|
|
1647
|
-
|
|
1648
|
-
|
|
1649
|
-
|
|
1550
|
+
const allowed = new Set(['>', '>=', '<', '<=', '=', '!=', 'between', '=~', '!=~', 'nodata']);
|
|
1551
|
+
if (allowed.has(value))
|
|
1552
|
+
return value;
|
|
1553
|
+
return '=';
|
|
1650
1554
|
}
|
|
1651
|
-
|
|
1652
1555
|
function normalizeLegacyFill(value) {
|
|
1653
|
-
|
|
1654
|
-
|
|
1556
|
+
if (typeof value !== 'number')
|
|
1557
|
+
return undefined;
|
|
1558
|
+
return Math.max(0, Math.min(100, value * 10));
|
|
1655
1559
|
}
|
|
1656
|
-
|
|
1657
1560
|
function firstDefinedNumber(...values) {
|
|
1658
|
-
|
|
1659
|
-
|
|
1660
|
-
|
|
1661
|
-
|
|
1561
|
+
for (const value of values) {
|
|
1562
|
+
if (typeof value === 'number' && Number.isFinite(value))
|
|
1563
|
+
return value;
|
|
1564
|
+
}
|
|
1565
|
+
return undefined;
|
|
1662
1566
|
}
|
|
1663
|
-
|
|
1664
1567
|
function replaceVariables(input, variableNames = new Set()) {
|
|
1665
|
-
|
|
1666
|
-
|
|
1667
|
-
|
|
1668
|
-
|
|
1669
|
-
|
|
1670
|
-
|
|
1671
|
-
|
|
1672
|
-
|
|
1673
|
-
|
|
1674
|
-
|
|
1675
|
-
|
|
1676
|
-
|
|
1677
|
-
return `${prefix}#{${variable}}`
|
|
1568
|
+
if (typeof input !== 'string')
|
|
1569
|
+
return input;
|
|
1570
|
+
return input
|
|
1571
|
+
.replace(/\$\{([^}]+)\}/g, (match, expression) => {
|
|
1572
|
+
const variable = normalizeTemplateVariable(expression);
|
|
1573
|
+
if (!variable)
|
|
1574
|
+
return match;
|
|
1575
|
+
if (GRAFANA_BUILTIN_VARS.has(variable))
|
|
1576
|
+
return match;
|
|
1577
|
+
if (!variableNames.has(variable))
|
|
1578
|
+
return match;
|
|
1579
|
+
return `#{${variable}}`;
|
|
1678
1580
|
})
|
|
1581
|
+
.replace(/(^|[^{])\$([A-Za-z0-9_]+)/g, (match, prefix, variable) => {
|
|
1582
|
+
if (GRAFANA_BUILTIN_VARS.has(variable))
|
|
1583
|
+
return match;
|
|
1584
|
+
if (!variableNames.has(variable))
|
|
1585
|
+
return match;
|
|
1586
|
+
return `${prefix}#{${variable}}`;
|
|
1587
|
+
});
|
|
1679
1588
|
}
|
|
1680
|
-
|
|
1681
1589
|
function normalizeTemplateVariable(expression) {
|
|
1682
|
-
|
|
1683
|
-
|
|
1684
|
-
|
|
1685
|
-
|
|
1686
|
-
|
|
1590
|
+
const trimmed = String(expression).trim();
|
|
1591
|
+
if (!trimmed)
|
|
1592
|
+
return '';
|
|
1593
|
+
const beforeFormat = trimmed.split(':')[0];
|
|
1594
|
+
if (!/^[A-Za-z0-9_.]+$/.test(beforeFormat))
|
|
1595
|
+
return '';
|
|
1596
|
+
return beforeFormat;
|
|
1687
1597
|
}
|
|
1688
|
-
|
|
1689
1598
|
function normalizeQueryCode(refId, index) {
|
|
1690
|
-
|
|
1691
|
-
|
|
1692
|
-
|
|
1599
|
+
if (typeof refId === 'string' && refId.trim())
|
|
1600
|
+
return refId.trim();
|
|
1601
|
+
const codePoint = 65 + index;
|
|
1602
|
+
return String.fromCharCode(codePoint);
|
|
1693
1603
|
}
|
|
1694
|
-
|
|
1695
1604
|
function stringifyCurrent(value) {
|
|
1696
|
-
|
|
1697
|
-
|
|
1698
|
-
|
|
1699
|
-
|
|
1605
|
+
if (Array.isArray(value))
|
|
1606
|
+
return value.join(',');
|
|
1607
|
+
if (typeof value === 'string')
|
|
1608
|
+
return value;
|
|
1609
|
+
if (typeof value === 'number' || typeof value === 'boolean')
|
|
1610
|
+
return String(value);
|
|
1611
|
+
return '';
|
|
1700
1612
|
}
|
|
1701
|
-
|
|
1702
1613
|
function normalizeAllValue(value, allValue, isValue = false) {
|
|
1703
|
-
|
|
1704
|
-
|
|
1705
|
-
|
|
1706
|
-
|
|
1614
|
+
if (value === 'All')
|
|
1615
|
+
return allValue === '.*' ? '*' : 'all values';
|
|
1616
|
+
if (value === '$__all')
|
|
1617
|
+
return allValue === '.*' ? '*' : '__all__';
|
|
1618
|
+
if (isValue && value === '.*')
|
|
1619
|
+
return '*';
|
|
1620
|
+
return value;
|
|
1707
1621
|
}
|
|
1708
|
-
|
|
1709
1622
|
function normalizeColor(color) {
|
|
1710
|
-
|
|
1711
|
-
|
|
1623
|
+
if (!color)
|
|
1624
|
+
return '#999999';
|
|
1625
|
+
return String(color);
|
|
1712
1626
|
}
|
|
1713
|
-
|
|
1714
1627
|
function numberOr(value, fallback) {
|
|
1715
|
-
|
|
1628
|
+
return typeof value === 'number' && Number.isFinite(value) ? value : fallback;
|
|
1716
1629
|
}
|
|
1717
|
-
|
|
1718
1630
|
function numberOrUndefined(value) {
|
|
1719
|
-
|
|
1631
|
+
return typeof value === 'number' && Number.isFinite(value) ? value : undefined;
|
|
1720
1632
|
}
|
|
1721
|
-
|
|
1722
1633
|
function round1(value) {
|
|
1723
|
-
|
|
1634
|
+
return Number(value.toFixed(1));
|
|
1724
1635
|
}
|
|
1725
|
-
|
|
1726
1636
|
function firstDefined(...values) {
|
|
1727
|
-
|
|
1728
|
-
|
|
1729
|
-
|
|
1730
|
-
|
|
1637
|
+
for (const value of values) {
|
|
1638
|
+
if (value !== undefined && value !== null && value !== '')
|
|
1639
|
+
return value;
|
|
1640
|
+
}
|
|
1641
|
+
return undefined;
|
|
1731
1642
|
}
|
|
1732
|
-
|
|
1733
1643
|
function pruneEmpty(value) {
|
|
1734
|
-
|
|
1735
|
-
|
|
1736
|
-
|
|
1737
|
-
|
|
1738
|
-
|
|
1739
|
-
|
|
1740
|
-
|
|
1741
|
-
|
|
1742
|
-
|
|
1743
|
-
|
|
1744
|
-
|
|
1745
|
-
|
|
1746
|
-
|
|
1747
|
-
|
|
1748
|
-
|
|
1749
|
-
|
|
1750
|
-
|
|
1751
|
-
|
|
1752
|
-
})
|
|
1753
|
-
|
|
1754
|
-
return Object.fromEntries(entries)
|
|
1644
|
+
if (Array.isArray(value)) {
|
|
1645
|
+
return value
|
|
1646
|
+
.map((item) => pruneEmpty(item))
|
|
1647
|
+
.filter((item) => item !== undefined);
|
|
1648
|
+
}
|
|
1649
|
+
if (!value || typeof value !== 'object') {
|
|
1650
|
+
return value;
|
|
1651
|
+
}
|
|
1652
|
+
const entries = Object.entries(value)
|
|
1653
|
+
.map(([key, current]) => [key, pruneEmpty(current)])
|
|
1654
|
+
.filter(([, current]) => {
|
|
1655
|
+
if (current === undefined)
|
|
1656
|
+
return false;
|
|
1657
|
+
if (Array.isArray(current) && current.length === 0)
|
|
1658
|
+
return false;
|
|
1659
|
+
if (current && typeof current === 'object' && !Array.isArray(current) && Object.keys(current).length === 0)
|
|
1660
|
+
return false;
|
|
1661
|
+
return true;
|
|
1662
|
+
});
|
|
1663
|
+
return Object.fromEntries(entries);
|
|
1755
1664
|
}
|
|
1756
|
-
|
|
1757
1665
|
function readJson(filePath) {
|
|
1758
|
-
|
|
1666
|
+
return JSON.parse(fs.readFileSync(filePath, 'utf8'));
|
|
1759
1667
|
}
|
|
1760
|
-
|
|
1761
1668
|
function forEachFile(directoryPath, callback) {
|
|
1762
|
-
|
|
1763
|
-
|
|
1764
|
-
|
|
1765
|
-
|
|
1766
|
-
|
|
1767
|
-
|
|
1669
|
+
for (const entry of fs.readdirSync(directoryPath, { withFileTypes: true })) {
|
|
1670
|
+
const entryPath = path.join(directoryPath, entry.name);
|
|
1671
|
+
if (entry.isDirectory()) {
|
|
1672
|
+
forEachFile(entryPath, callback);
|
|
1673
|
+
}
|
|
1674
|
+
else {
|
|
1675
|
+
callback(entryPath);
|
|
1676
|
+
}
|
|
1768
1677
|
}
|
|
1769
|
-
}
|
|
1770
1678
|
}
|