@cloudcare/guance-front-tools 1.0.6 → 1.0.8

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.
@@ -106,6 +106,22 @@ function sortPanelItemsByRowCol(panels) {
106
106
  return -1;
107
107
  });
108
108
  }
109
+ // 数字转成abc
110
+ function tenToTweenty(source = 1) {
111
+ let numArr = [];
112
+ source--;
113
+ do {
114
+ numArr.push(source % 26);
115
+ source = Math.floor(source / 26);
116
+ } while (source > 0);
117
+ return numArr
118
+ .reverse()
119
+ .map((item, index) => {
120
+ return String.fromCharCode(item + 97 + (index === numArr.length - 1 ? 0 : -1));
121
+ })
122
+ .join('')
123
+ .toUpperCase();
124
+ }
109
125
  function getGridH(h, rowHeight, margin) {
110
126
  return Math.round(h * rowHeight + Math.max(0, 2 * (h - 1)) * margin);
111
127
  }
@@ -135,10 +151,12 @@ function covertPanelToGuanceChart(grafanaPanel, rowPanel) {
135
151
  }
136
152
  const queries = [];
137
153
  if (targets && targets.length) {
154
+ let currentIndex = 0;
138
155
  targets.forEach((_target) => {
139
156
  const queryStr = _target.expr || _target.query;
140
157
  if (!queryStr)
141
158
  return;
159
+ currentIndex++;
142
160
  const queryItem = {
143
161
  datasource: 'dataflux',
144
162
  qtype: 'promql',
@@ -146,6 +164,8 @@ function covertPanelToGuanceChart(grafanaPanel, rowPanel) {
146
164
  query: {
147
165
  q: replaceVariableStr(queryStr),
148
166
  type: 'promql',
167
+ code: tenToTweenty(currentIndex),
168
+ promqlCode: currentIndex,
149
169
  },
150
170
  };
151
171
  queries.push(queryItem);
@@ -110,6 +110,22 @@ function sortPanelItemsByRowCol(panels: Panel[]): Panel[] {
110
110
  return -1
111
111
  })
112
112
  }
113
+ // 数字转成abc
114
+ function tenToTweenty(source: number = 1): string {
115
+ let numArr: any = []
116
+ source--
117
+ do {
118
+ numArr.push(source % 26)
119
+ source = Math.floor(source / 26)
120
+ } while (source > 0)
121
+ return numArr
122
+ .reverse()
123
+ .map((item: number, index: number) => {
124
+ return String.fromCharCode(item + 97 + (index === numArr.length - 1 ? 0 : -1))
125
+ })
126
+ .join('')
127
+ .toUpperCase()
128
+ }
113
129
  function getGridH(h: number, rowHeight: number, margin: number) {
114
130
  return Math.round(h * rowHeight + Math.max(0, 2 * (h - 1)) * margin)
115
131
  }
@@ -140,9 +156,11 @@ function covertPanelToGuanceChart(grafanaPanel: Panel, rowPanel: RowPanel | unde
140
156
  }
141
157
  const queries: GuanceChartQueries = []
142
158
  if (targets && targets.length) {
159
+ let currentIndex = 0
143
160
  targets.forEach((_target) => {
144
161
  const queryStr: string | unknown = _target.expr || _target.query
145
162
  if (!queryStr) return
163
+ currentIndex++
146
164
  const queryItem: GuanceChartQueryItem = {
147
165
  datasource: 'dataflux',
148
166
  qtype: 'promql',
@@ -150,6 +168,8 @@ function covertPanelToGuanceChart(grafanaPanel: Panel, rowPanel: RowPanel | unde
150
168
  query: {
151
169
  q: replaceVariableStr(queryStr as string),
152
170
  type: 'promql',
171
+ code: tenToTweenty(currentIndex),
172
+ promqlCode: currentIndex,
153
173
  },
154
174
  }
155
175
  queries.push(queryItem)
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@cloudcare/guance-front-tools",
3
- "version": "1.0.6",
3
+ "version": "1.0.8",
4
4
  "publishConfig": {
5
5
  "access": "public"
6
6
  },