1
|
1
|
import { EChartsOption } from 'echarts';
|
2
|
2
|
import { fontSize } from '../../detail/config/util';
|
3
|
|
-import { visualOptionField } from '../../detail/config/visualOptions';
|
4
|
|
-import { DataComponentRecord, DataSource } from '/@/api/dataBoard/model';
|
|
3
|
+import { Gradient, visualOptionField } from '../../detail/config/visualOptions';
|
|
4
|
+import { DataComponentRecord, DataSource, GradientInfo } from '/@/api/dataBoard/model';
|
5
|
5
|
import { buildUUID } from '/@/utils/uuid';
|
6
|
6
|
|
7
|
7
|
export type InstrumentComponentType = 'instrument-component-1' | 'instrument-component-2';
|
...
|
...
|
@@ -15,8 +15,9 @@ export type GradientKey = |
15
|
15
|
| visualOptionField.THIRD_PHASE_VALUE;
|
16
|
16
|
|
17
|
17
|
export interface GradientInfoRecord {
|
18
|
|
- key: GradientKey;
|
19
|
|
- value: number | string;
|
|
18
|
+ key: Gradient;
|
|
19
|
+ value: number;
|
|
20
|
+ color: string;
|
20
|
21
|
}
|
21
|
22
|
|
22
|
23
|
export interface DashBoardValue {
|
...
|
...
|
@@ -148,34 +149,42 @@ export const instrumentComponent1 = (params?: { value: number; unit: string }): |
148
|
149
|
};
|
149
|
150
|
|
150
|
151
|
export const instrumentComponent2 = (params?: {
|
151
|
|
- gradient: GradientInfoRecord[];
|
|
152
|
+ gradient: GradientInfo[];
|
152
|
153
|
value: number;
|
153
|
154
|
unit: string;
|
154
|
155
|
}): EChartsOption => {
|
155
|
156
|
const { gradient = [], value = 0, unit = 'km/h' } = params || {};
|
|
157
|
+ const firstRecord = getGradient(Gradient.FIRST, gradient);
|
|
158
|
+ const secondRecord = getGradient(Gradient.SECOND, gradient);
|
|
159
|
+ const thirdRecord = getGradient(Gradient.THIRD, gradient);
|
|
160
|
+
|
|
161
|
+ let max = thirdRecord?.value || secondRecord?.value || firstRecord?.value || 70;
|
|
162
|
+ max = Number(1 + Array(String(max).length).fill(0).join(''));
|
|
163
|
+
|
|
164
|
+ const firstGradient = firstRecord?.value ? firstRecord.value / max : 0.3;
|
|
165
|
+ const secondGradient = secondRecord?.value ? secondRecord.value / max : 0.7;
|
|
166
|
+ // const thirdGradient = thirdRecord?.value ? thirdRecord.value / max : 1;
|
|
167
|
+
|
|
168
|
+ console.log();
|
156
|
169
|
return {
|
157
|
170
|
series: [
|
158
|
171
|
{
|
159
|
172
|
type: 'gauge',
|
|
173
|
+ min: 0,
|
|
174
|
+ max,
|
|
175
|
+ // startAngle: 225,
|
|
176
|
+ // endAngle: -70,
|
|
177
|
+ // splitNumber: 10,
|
160
|
178
|
axisLine: {
|
161
|
179
|
lineStyle: {
|
162
|
|
- width: 30,
|
|
180
|
+ width: 20,
|
163
|
181
|
color: [
|
|
182
|
+ [firstGradient, (getGradientValue(Gradient.FIRST, gradient) as string) || '#67e0e3'],
|
164
|
183
|
[
|
165
|
|
- 0.3,
|
166
|
|
- (getGradientValue(visualOptionField.FIRST_PHASE_COLOR, gradient) as string) ||
|
167
|
|
- '#67e0e3',
|
168
|
|
- ],
|
169
|
|
- [
|
170
|
|
- 0.7,
|
171
|
|
- (getGradientValue(visualOptionField.SECOND_PHASE_COLOR, gradient) as string) ||
|
172
|
|
- '#37a2da',
|
173
|
|
- ],
|
174
|
|
- [
|
175
|
|
- 1,
|
176
|
|
- (getGradientValue(visualOptionField.THIRD_PHASE_COLOR, gradient) as string) ||
|
177
|
|
- '#fd666d',
|
|
184
|
+ secondGradient,
|
|
185
|
+ (getGradientValue(Gradient.SECOND, gradient) as string) || '#37a2da',
|
178
|
186
|
],
|
|
187
|
+ [1, (getGradientValue(Gradient.THIRD, gradient) as string) || '#fd666d'],
|
179
|
188
|
],
|
180
|
189
|
},
|
181
|
190
|
},
|
...
|
...
|
@@ -187,6 +196,7 @@ export const instrumentComponent2 = (params?: { |
187
|
196
|
axisTick: {
|
188
|
197
|
distance: -30,
|
189
|
198
|
length: 8,
|
|
199
|
+ splitNumber: max / 100,
|
190
|
200
|
lineStyle: {
|
191
|
201
|
color: '#fff',
|
192
|
202
|
width: 2,
|
...
|
...
|
@@ -202,7 +212,7 @@ export const instrumentComponent2 = (params?: { |
202
|
212
|
},
|
203
|
213
|
axisLabel: {
|
204
|
214
|
color: 'auto',
|
205
|
|
- distance: 35,
|
|
215
|
+ distance: 22,
|
206
|
216
|
fontSize: 6,
|
207
|
217
|
},
|
208
|
218
|
detail: {
|
...
|
...
|
@@ -221,12 +231,15 @@ export const instrumentComponent2 = (params?: { |
221
|
231
|
};
|
222
|
232
|
};
|
223
|
233
|
|
224
|
|
-export const getGradientValue = (key: GradientKey, record: GradientInfoRecord[]) => {
|
225
|
|
- return record.find((item) => item.key === key)?.value;
|
|
234
|
+export const getGradientValue = (key: Gradient, record: GradientInfo[]) => {
|
|
235
|
+ return record.find((item) => item.key === key)?.color;
|
|
236
|
+};
|
|
237
|
+
|
|
238
|
+export const getGradient = (key: Gradient, record: GradientInfo[]) => {
|
|
239
|
+ return record.find((item) => item.key === key);
|
226
|
240
|
};
|
227
|
241
|
|
228
|
242
|
export const update_instrument_1_font = (radio: number) => {
|
229
|
|
- console.log(fontSize({ radio, basic: 14 }));
|
230
|
243
|
return {
|
231
|
244
|
series: [
|
232
|
245
|
{
|
...
|
...
|
@@ -242,7 +255,7 @@ export const update_instrument_1_font = (radio: number) => { |
242
|
255
|
};
|
243
|
256
|
|
244
|
257
|
export const update_instrument_2_font = (radio: number) => {
|
245
|
|
- const axisLabelFontSize = fontSize({ radio, basic: 10, max: 25 });
|
|
258
|
+ const axisLabelFontSize = fontSize({ radio, basic: 10, max: 20 });
|
246
|
259
|
return {
|
247
|
260
|
series: [
|
248
|
261
|
{
|
...
|
...
|
@@ -257,14 +270,27 @@ export const update_instrument_2_font = (radio: number) => { |
257
|
270
|
} as EChartsOption;
|
258
|
271
|
};
|
259
|
272
|
|
|
273
|
+function setGradientInfo(dataSource: DataSource) {
|
|
274
|
+ const componentInfo = dataSource.componentInfo;
|
|
275
|
+ return instrumentComponent2({
|
|
276
|
+ unit: componentInfo.unit,
|
|
277
|
+ value: 0,
|
|
278
|
+ gradient: componentInfo.gradientInfo,
|
|
279
|
+ });
|
|
280
|
+}
|
|
281
|
+
|
260
|
282
|
export const transformDashboardComponentConfig = (
|
261
|
283
|
config: DashboardComponentLayout,
|
262
|
284
|
record: DataComponentRecord,
|
263
|
285
|
dataSourceRecord: DataSource
|
264
|
286
|
) => {
|
|
287
|
+ let chartOption = config.chartOption;
|
|
288
|
+ if (config.componentType === 'instrument-component-2') {
|
|
289
|
+ chartOption = setGradientInfo(dataSourceRecord);
|
|
290
|
+ }
|
265
|
291
|
return {
|
266
|
292
|
layout: {
|
267
|
|
- chartOption: config.chartOption,
|
|
293
|
+ chartOption: chartOption,
|
268
|
294
|
componentType: config.componentType,
|
269
|
295
|
} as DashboardComponentLayout,
|
270
|
296
|
value: {
|
...
|
...
|
|