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