@xq-labs/data-ui-v2 0.2.1 → 0.4.0

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.
@@ -0,0 +1,492 @@
1
+ 'use strict';
2
+
3
+ var echarts = require('echarts/core');
4
+ var charts = require('echarts/charts');
5
+ var components = require('echarts/components');
6
+ var renderers = require('echarts/renderers');
7
+ var withInstall = require('./with-install-4304a8ea.js');
8
+ var colors = require('./colors-19a7242d.js');
9
+
10
+ function _interopNamespaceDefault(e) {
11
+ var n = Object.create(null);
12
+ if (e) {
13
+ Object.keys(e).forEach(function (k) {
14
+ if (k !== 'default') {
15
+ var d = Object.getOwnPropertyDescriptor(e, k);
16
+ Object.defineProperty(n, k, d.get ? d : {
17
+ enumerable: true,
18
+ get: function () { return e[k]; }
19
+ });
20
+ }
21
+ });
22
+ }
23
+ n.default = e;
24
+ return Object.freeze(n);
25
+ }
26
+
27
+ var echarts__namespace = /*#__PURE__*/_interopNamespaceDefault(echarts);
28
+
29
+ function toNumber(value) {
30
+ var fallback = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 0;
31
+ var numericValue = Number(value);
32
+ return Number.isFinite(numericValue) ? numericValue : fallback;
33
+ }
34
+ function isValidKey(value) {
35
+ return typeof value === 'string' && value.trim() !== '';
36
+ }
37
+ function normalizeColor(value) {
38
+ return typeof value === 'string' && value.trim() !== '' ? value.trim() : '';
39
+ }
40
+ function pickSeriesColor(item, index, colors$1) {
41
+ var itemColor = normalizeColor(item && item.color);
42
+ var colorList = Array.isArray(colors$1) ? colors$1 : [];
43
+ var paletteColor = normalizeColor(colorList[index]);
44
+ var defaultColor = colors.DEFAULT_COLORS[index % colors.DEFAULT_COLORS.length];
45
+ return itemColor || paletteColor || defaultColor;
46
+ }
47
+
48
+ /**
49
+ * 归一化雷达图指标配置。
50
+ * 指标 key 是业务字段映射的核心,缺失 key 的指标会被过滤,避免数值顺序错位。
51
+ */
52
+ function normalizeRadarIndicators() {
53
+ var indicators = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : [];
54
+ var rawIndicators = Array.isArray(indicators) ? indicators : [];
55
+ return rawIndicators.filter(function (item) {
56
+ return item && isValidKey(item.key);
57
+ }).map(function (item) {
58
+ var min = toNumber(item.min, 0);
59
+ var max = Math.max(min, toNumber(item.max, 100));
60
+ return {
61
+ key: item.key.trim(),
62
+ name: item.name === undefined || item.name === '' ? item.key.trim() : String(item.name),
63
+ min: min,
64
+ max: max,
65
+ unit: item.unit === undefined ? '' : String(item.unit)
66
+ };
67
+ });
68
+ }
69
+
70
+ /**
71
+ * 归一化雷达图业务数据。
72
+ * 输出结构同时保留原始数据,便于后续 tooltip 或 customOption 做业务级扩展。
73
+ */
74
+ function normalizeRadarData() {
75
+ var _ref = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {},
76
+ data = _ref.data,
77
+ indicators = _ref.indicators,
78
+ _ref$nameKey = _ref.nameKey,
79
+ nameKey = _ref$nameKey === void 0 ? 'name' : _ref$nameKey,
80
+ _ref$colors = _ref.colors,
81
+ colors = _ref$colors === void 0 ? [] : _ref$colors;
82
+ var rawData = Array.isArray(data) ? data : [];
83
+ var safeNameKey = isValidKey(nameKey) ? nameKey : 'name';
84
+ return rawData.map(function () {
85
+ var item = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
86
+ var index = arguments.length > 1 ? arguments[1] : undefined;
87
+ var name = item[safeNameKey] === undefined || item[safeNameKey] === '' ? "\u6570\u636E".concat(index + 1) : String(item[safeNameKey]);
88
+ var color = pickSeriesColor(item, index, colors);
89
+ return {
90
+ name: name,
91
+ value: indicators.map(function (indicator) {
92
+ return toNumber(item[indicator.key], 0);
93
+ }),
94
+ color: color,
95
+ rawData: item
96
+ };
97
+ });
98
+ }
99
+
100
+ /**
101
+ * 汇总 RadarChart 构建层所需的标准协议。
102
+ */
103
+ function normalizeRadarInput() {
104
+ var _ref2 = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {},
105
+ data = _ref2.data,
106
+ indicators = _ref2.indicators,
107
+ nameKey = _ref2.nameKey,
108
+ colors = _ref2.colors;
109
+ var normalizedIndicators = normalizeRadarIndicators(indicators);
110
+ var normalizedData = normalizeRadarData({
111
+ data: data,
112
+ indicators: normalizedIndicators,
113
+ nameKey: nameKey,
114
+ colors: colors
115
+ });
116
+ return {
117
+ indicators: normalizedIndicators,
118
+ seriesData: normalizedData
119
+ };
120
+ }
121
+
122
+ var RADAR_PRESETS = {
123
+ compare: {
124
+ legend: {
125
+ show: true,
126
+ bottom: 0
127
+ },
128
+ radar: {
129
+ radius: '68%',
130
+ center: ['50%', '48%'],
131
+ splitNumber: 4
132
+ }
133
+ },
134
+ score: {
135
+ legend: {
136
+ show: false
137
+ },
138
+ radar: {
139
+ radius: '72%',
140
+ center: ['50%', '50%'],
141
+ splitNumber: 5
142
+ }
143
+ }
144
+ };
145
+
146
+ /**
147
+ * 获取雷达图预设配置。
148
+ * 未命中时回退到 compare,保证异常 preset 不影响基础渲染。
149
+ */
150
+ function getRadarPreset() {
151
+ var preset = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : 'compare';
152
+ return RADAR_PRESETS[preset] || RADAR_PRESETS.compare;
153
+ }
154
+
155
+ function hexToRgba(color, opacity) {
156
+ var normalizedColor = typeof color === 'string' ? color.trim() : '';
157
+ var hex = normalizedColor.replace('#', '');
158
+ if (!/^([0-9a-fA-F]{3}|[0-9a-fA-F]{6})$/.test(hex)) {
159
+ return normalizedColor;
160
+ }
161
+ var fullHex = hex.length === 3 ? hex.split('').map(function (item) {
162
+ return item + item;
163
+ }).join('') : hex;
164
+ var red = parseInt(fullHex.slice(0, 2), 16);
165
+ var green = parseInt(fullHex.slice(2, 4), 16);
166
+ var blue = parseInt(fullHex.slice(4, 6), 16);
167
+ return "rgba(".concat(red, ", ").concat(green, ", ").concat(blue, ", ").concat(opacity, ")");
168
+ }
169
+
170
+ /**
171
+ * 面积雷达图:折线、拐点和半透明面积都使用当前系列色。
172
+ */
173
+ function createAreaRadarOption(_ref) {
174
+ var seriesData = _ref.seriesData;
175
+ return {
176
+ series: [{
177
+ type: 'radar',
178
+ data: seriesData.map(function (item) {
179
+ return {
180
+ name: item.name,
181
+ value: item.value,
182
+ rawData: item.rawData,
183
+ lineStyle: {
184
+ width: 2,
185
+ color: item.color
186
+ },
187
+ itemStyle: {
188
+ color: item.color
189
+ },
190
+ areaStyle: {
191
+ color: hexToRgba(item.color, 0.16)
192
+ }
193
+ };
194
+ })
195
+ }]
196
+ };
197
+ }
198
+
199
+ /**
200
+ * 折线雷达图:只展示轮廓线与拐点,不生成面积填充。
201
+ */
202
+ function createLineRadarOption(_ref) {
203
+ var seriesData = _ref.seriesData;
204
+ return {
205
+ series: [{
206
+ type: 'radar',
207
+ data: seriesData.map(function (item) {
208
+ return {
209
+ name: item.name,
210
+ value: item.value,
211
+ rawData: item.rawData,
212
+ lineStyle: {
213
+ width: 2,
214
+ color: item.color
215
+ },
216
+ itemStyle: {
217
+ color: item.color
218
+ }
219
+ };
220
+ })
221
+ }]
222
+ };
223
+ }
224
+
225
+ var DEFAULT_VARIANT = 'area';
226
+ var RADAR_PUBLIC_VARIANTS = ['area', 'line'];
227
+ var variantFactory = {
228
+ area: createAreaRadarOption,
229
+ line: createLineRadarOption
230
+ };
231
+ function resolveVariantName(variant) {
232
+ return RADAR_PUBLIC_VARIANTS.includes(variant) ? variant : DEFAULT_VARIANT;
233
+ }
234
+
235
+ /**
236
+ * 构建雷达图公共基础 option。
237
+ * indicator 使用 adapter 已归一化后的结果,避免业务字段顺序与 ECharts value 数组错位。
238
+ */
239
+ function createBaseRadarOption(normalizedInput) {
240
+ var legendData = normalizedInput.seriesData.map(function (item) {
241
+ return item.name;
242
+ });
243
+ return {
244
+ color: colors.DEFAULT_COLORS,
245
+ tooltip: {
246
+ trigger: 'item'
247
+ },
248
+ legend: {
249
+ data: legendData
250
+ },
251
+ radar: {
252
+ indicator: normalizedInput.indicators.map(function (item) {
253
+ return {
254
+ name: item.name,
255
+ max: item.max,
256
+ min: item.min
257
+ };
258
+ })
259
+ },
260
+ series: []
261
+ };
262
+ }
263
+
264
+ /**
265
+ * 构建 RadarChart 最终 option。
266
+ * 合并顺序保持与现有图表一致:base -> preset -> variant -> customOption。
267
+ */
268
+ function buildRadarOption() {
269
+ var _ref = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {},
270
+ data = _ref.data,
271
+ indicators = _ref.indicators,
272
+ _ref$nameKey = _ref.nameKey,
273
+ nameKey = _ref$nameKey === void 0 ? 'name' : _ref$nameKey,
274
+ _ref$variant = _ref.variant,
275
+ variant = _ref$variant === void 0 ? DEFAULT_VARIANT : _ref$variant,
276
+ _ref$preset = _ref.preset,
277
+ preset = _ref$preset === void 0 ? 'compare' : _ref$preset,
278
+ _ref$colors = _ref.colors,
279
+ colors$1 = _ref$colors === void 0 ? [] : _ref$colors,
280
+ customOption = _ref.customOption;
281
+ var normalizedInput = normalizeRadarInput({
282
+ data: data,
283
+ indicators: indicators,
284
+ nameKey: nameKey,
285
+ colors: colors$1
286
+ });
287
+ var baseOption = createBaseRadarOption(normalizedInput);
288
+ var presetOption = getRadarPreset(preset);
289
+ var resolvedVariant = resolveVariantName(variant);
290
+ var createVariantOption = variantFactory[resolvedVariant] || variantFactory[DEFAULT_VARIANT];
291
+ var variantOption = createVariantOption(normalizedInput);
292
+ return colors.mergeChartOption(colors.mergeChartOption(baseOption, presetOption, variantOption), customOption);
293
+ }
294
+
295
+ //
296
+ //
297
+ //
298
+ //
299
+ //
300
+ //
301
+ //
302
+ //
303
+ //
304
+ //
305
+ //
306
+ //
307
+
308
+
309
+ /**
310
+ * RadarChart 使用 ECharts 按需模式,必须显式注册雷达图系列和 radar 坐标系。
311
+ */
312
+ echarts__namespace.use([charts.RadarChart, components.TooltipComponent, components.LegendComponent, components.RadarComponent, components.TitleComponent, renderers.CanvasRenderer]);
313
+ var script = {
314
+ name: 'RadarChart',
315
+ components: {
316
+ BaseChart: withInstall.BaseChart
317
+ },
318
+ props: {
319
+ /**
320
+ * 雷达图业务数据数组。
321
+ * 每一项代表一个雷达系列,例如本月、上月、目标值等。
322
+ */
323
+ data: {
324
+ type: Array,
325
+ "default": function _default() {
326
+ return [];
327
+ }
328
+ },
329
+ /**
330
+ * 雷达指标配置。
331
+ * key 用来映射 data 中的字段,name/max/min 用来生成 ECharts indicator。
332
+ */
333
+ indicators: {
334
+ type: Array,
335
+ "default": function _default() {
336
+ return [];
337
+ }
338
+ },
339
+ /**
340
+ * 系列名称字段。
341
+ * 默认读取 data[i].name,适配大多数业务数据。
342
+ */
343
+ nameKey: {
344
+ type: String,
345
+ "default": 'name'
346
+ },
347
+ /**
348
+ * 雷达图公开视觉形态:
349
+ * - area:带半透明面积填充
350
+ * - line:仅展示折线和拐点
351
+ */
352
+ variant: {
353
+ type: String,
354
+ "default": 'area',
355
+ validator: function validator(value) {
356
+ return RADAR_PUBLIC_VARIANTS.includes(value);
357
+ }
358
+ },
359
+ /**
360
+ * 展示预设。
361
+ * compare 用于多对象对比,score 用于单对象能力画像。
362
+ */
363
+ preset: {
364
+ type: String,
365
+ "default": 'compare'
366
+ },
367
+ /**
368
+ * 组件级系列色板。
369
+ * 优先级低于 data[i].color,高于内置默认色板。
370
+ */
371
+ colors: {
372
+ type: Array,
373
+ "default": function _default() {
374
+ return [];
375
+ }
376
+ },
377
+ /**
378
+ * 额外透传给 ECharts option 的自定义配置。
379
+ * 会在 base / preset / variant 合并后作为最高优先级覆盖。
380
+ */
381
+ customOption: {
382
+ type: Object,
383
+ "default": function _default() {
384
+ return {};
385
+ }
386
+ },
387
+ /**
388
+ * 图表 loading 状态。
389
+ * 由 BaseChart 统一接管组件层遮罩式 loading UI。
390
+ */
391
+ loading: {
392
+ type: Boolean,
393
+ "default": false
394
+ },
395
+ /**
396
+ * 统一状态展示配置。
397
+ * 负责收拢空态文案、空态图片与 loading 文案。
398
+ */
399
+ stateConfig: {
400
+ type: Object,
401
+ "default": function _default() {
402
+ return {};
403
+ }
404
+ },
405
+ /**
406
+ * 图表容器高度。
407
+ * 支持数字像素值或原样透传的 CSS 高度字符串。
408
+ */
409
+ height: {
410
+ type: [String, Number],
411
+ "default": 320
412
+ }
413
+ },
414
+ computed: {
415
+ /**
416
+ * data 为空或 indicators 缺少有效 key 时进入空态,避免渲染无指标雷达图。
417
+ */
418
+ isEmpty: function isEmpty() {
419
+ var hasIndicator = Array.isArray(this.indicators) ? this.indicators.some(function (item) {
420
+ return item && typeof item.key === 'string' && item.key.trim();
421
+ }) : false;
422
+ return colors.isEmptyData(this.data) || !hasIndicator;
423
+ },
424
+ /**
425
+ * 将公开 props 汇总为 builder 所需输入。
426
+ */
427
+ chartOption: function chartOption() {
428
+ return buildRadarOption({
429
+ data: this.data,
430
+ indicators: this.indicators,
431
+ nameKey: this.nameKey,
432
+ variant: this.variant,
433
+ preset: this.preset,
434
+ colors: this.colors,
435
+ customOption: this.customOption
436
+ });
437
+ }
438
+ }
439
+ };
440
+
441
+ var css_248z = "\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n";
442
+ withInstall.styleInject(css_248z);
443
+
444
+ /* script */
445
+ var __vue_script__ = script;
446
+ /* template */
447
+ var __vue_render__ = function __vue_render__() {
448
+ var _vm = this;
449
+ var _h = _vm.$createElement;
450
+ var _c = _vm._self._c || _h;
451
+ return _c("BaseChart", {
452
+ attrs: {
453
+ option: _vm.chartOption,
454
+ loading: _vm.loading,
455
+ empty: _vm.isEmpty,
456
+ "state-config": _vm.stateConfig,
457
+ height: _vm.height
458
+ },
459
+ on: {
460
+ "chart-click": function chartClick($event) {
461
+ return _vm.$emit("chart-click", $event);
462
+ },
463
+ ready: function ready($event) {
464
+ return _vm.$emit("ready", $event);
465
+ }
466
+ }
467
+ });
468
+ };
469
+ var __vue_staticRenderFns__ = [];
470
+ __vue_render__._withStripped = true;
471
+
472
+ /* style */
473
+ var __vue_inject_styles__ = undefined;
474
+ /* scoped */
475
+ var __vue_scope_id__ = "data-v-0bf4201f";
476
+ /* module identifier */
477
+ var __vue_module_identifier__ = undefined;
478
+ /* functional template */
479
+ var __vue_is_functional_template__ = false;
480
+ /* style inject */
481
+
482
+ /* style inject SSR */
483
+
484
+ /* style inject shadow dom */
485
+
486
+ var __vue_component__ = /*#__PURE__*/withInstall.normalizeComponent({
487
+ render: __vue_render__,
488
+ staticRenderFns: __vue_staticRenderFns__
489
+ }, __vue_inject_styles__, __vue_script__, __vue_scope_id__, __vue_is_functional_template__, __vue_module_identifier__, false, undefined, undefined, undefined);
490
+ var RadarChart = __vue_component__;
491
+
492
+ exports.RadarChart = RadarChart;