@cloudcare/guance-front-tools 1.0.9 → 1.0.11

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.
@@ -75,10 +75,10 @@ const grafanaPanelTypeToGuanceChartMap = {
75
75
  };
76
76
  const GRAFANA_KEYWORKD = ['__interval'];
77
77
  function replaceVariableStr(grafanaExpr) {
78
- return grafanaExpr.replace(/\$([\d_\w]+)/g, (match, $0) => {
79
- if (GRAFANA_KEYWORKD.includes($0))
78
+ return grafanaExpr.replace(/\$\{?([\d_\w]+)\}?/g, function (match, variable) {
79
+ if (GRAFANA_KEYWORKD.includes(variable))
80
80
  return match;
81
- return `#{${$0}}`;
81
+ return `#{${variable}}`;
82
82
  });
83
83
  }
84
84
  /**
@@ -120,7 +120,7 @@ function tenToTweenty(source = 1) {
120
120
  return String.fromCharCode(item + 97 + (index === numArr.length - 1 ? 0 : -1));
121
121
  })
122
122
  .join('')
123
- .toUpperCase();
123
+ .toLowerCase();
124
124
  }
125
125
  function getGridH(h, rowHeight, margin) {
126
126
  return Math.round(h * rowHeight + Math.max(0, 2 * (h - 1)) * margin);
@@ -141,19 +141,21 @@ function covertPanelToGuanceChart(grafanaPanel, rowPanel) {
141
141
  if (rowPanel) {
142
142
  const { gridPos: rowGridPos } = rowPanel;
143
143
  if (rowGridPos && gridPos) {
144
- pos = {
145
- x: gridPos.x,
146
- w: gridPos.w,
147
- y: gridPos.y - rowGridPos.y,
148
- h: gridPos.h,
149
- };
144
+ if (!rowPanel.collapsed) {
145
+ pos = {
146
+ x: gridPos.x,
147
+ w: gridPos.w,
148
+ y: gridPos.y - rowGridPos.y,
149
+ h: gridPos.h,
150
+ };
151
+ }
150
152
  }
151
153
  }
152
154
  const queries = [];
153
155
  if (targets && targets.length) {
154
156
  let currentIndex = 0;
155
157
  targets.forEach((_target) => {
156
- const queryStr = _target.expr || _target.query;
158
+ const queryStr = _target.expr || _target.query || _target.queryText;
157
159
  if (!queryStr)
158
160
  return;
159
161
  currentIndex++;
@@ -205,7 +207,7 @@ function covertPanelToGuanceChart(grafanaPanel, rowPanel) {
205
207
  h: getGuanceHByGrafanaH(pos.h),
206
208
  w: pos.w,
207
209
  },
208
- name: title || '',
210
+ name: replaceVariableStr(title || ''),
209
211
  queries: queries,
210
212
  type: chartType,
211
213
  };
@@ -412,3 +414,4 @@ export function run(args) {
412
414
  }
413
415
  });
414
416
  }
417
+ // console.log(JSON.stringify(result, null, 2))
@@ -13,7 +13,7 @@ import type {
13
13
  ChartTextSettings,
14
14
  } from '../generated/dashboardCharts'
15
15
  import type { DashboardData as GrafanaDashboardType, VariableModel, Panel, RowPanel } from './grafana-dashbord'
16
-
16
+ import dataJson from '../example/test2.json'
17
17
  // 1. Graph (折线图) - 用于展示时间序列数据的线图或柱状图。
18
18
  // 2. Stat (统计) - 用于显示单个数值,如当前值、最小值或最大值。
19
19
  // 3. Gauge (仪表盘) - 用于显示单个数值,并通过仪表盘样式进行可视化。
@@ -79,9 +79,9 @@ const grafanaPanelTypeToGuanceChartMap: { [key: string]: GuanceChartType } = {
79
79
  }
80
80
  const GRAFANA_KEYWORKD = ['__interval']
81
81
  function replaceVariableStr(grafanaExpr: string): string {
82
- return grafanaExpr.replace(/\$([\d_\w]+)/g, (match, $0) => {
83
- if (GRAFANA_KEYWORKD.includes($0)) return match
84
- return `#{${$0}}`
82
+ return grafanaExpr.replace(/\$\{?([\d_\w]+)\}?/g, function (match, variable) {
83
+ if (GRAFANA_KEYWORKD.includes(variable)) return match
84
+ return `#{${variable}}`
85
85
  })
86
86
  }
87
87
  /**
@@ -124,7 +124,7 @@ function tenToTweenty(source: number = 1): string {
124
124
  return String.fromCharCode(item + 97 + (index === numArr.length - 1 ? 0 : -1))
125
125
  })
126
126
  .join('')
127
- .toUpperCase()
127
+ .toLowerCase()
128
128
  }
129
129
  function getGridH(h: number, rowHeight: number, margin: number) {
130
130
  return Math.round(h * rowHeight + Math.max(0, 2 * (h - 1)) * margin)
@@ -146,11 +146,13 @@ function covertPanelToGuanceChart(grafanaPanel: Panel, rowPanel: RowPanel | unde
146
146
  if (rowPanel) {
147
147
  const { gridPos: rowGridPos } = rowPanel
148
148
  if (rowGridPos && gridPos) {
149
- pos = {
150
- x: gridPos.x,
151
- w: gridPos.w,
152
- y: gridPos.y - rowGridPos.y,
153
- h: gridPos.h,
149
+ if (!rowPanel.collapsed) {
150
+ pos = {
151
+ x: gridPos.x,
152
+ w: gridPos.w,
153
+ y: gridPos.y - rowGridPos.y,
154
+ h: gridPos.h,
155
+ }
154
156
  }
155
157
  }
156
158
  }
@@ -158,7 +160,7 @@ function covertPanelToGuanceChart(grafanaPanel: Panel, rowPanel: RowPanel | unde
158
160
  if (targets && targets.length) {
159
161
  let currentIndex = 0
160
162
  targets.forEach((_target) => {
161
- const queryStr: string | unknown = _target.expr || _target.query
163
+ const queryStr: string | unknown = _target.expr || _target.query || _target.queryText
162
164
  if (!queryStr) return
163
165
  currentIndex++
164
166
  const queryItem: GuanceChartQueryItem = {
@@ -209,7 +211,7 @@ function covertPanelToGuanceChart(grafanaPanel: Panel, rowPanel: RowPanel | unde
209
211
  h: getGuanceHByGrafanaH(pos.h),
210
212
  w: pos.w,
211
213
  },
212
- name: title || '',
214
+ name: replaceVariableStr(title || ''),
213
215
  queries: queries,
214
216
  type: chartType,
215
217
  }
@@ -416,3 +418,4 @@ export async function run(args) {
416
418
  throw new Error(err)
417
419
  }
418
420
  }
421
+ // console.log(JSON.stringify(result, null, 2))
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@cloudcare/guance-front-tools",
3
- "version": "1.0.9",
3
+ "version": "1.0.11",
4
4
  "publishConfig": {
5
5
  "access": "public"
6
6
  },
@@ -10,7 +10,7 @@
10
10
  "bin": {
11
11
  "grafanaCovertToGuance": "cli.js"
12
12
  },
13
- "description": "观测云前端工具",
13
+ "description": "Guance front tools",
14
14
  "type": "module",
15
15
  "main": "lib/cjs/src/index.js",
16
16
  "types": "lib/cjs/src/index.d.ts",