@agions/taroviz 1.11.5 → 2.0.3
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/CHANGELOG.md +245 -0
- package/README.md +31 -46
- package/dist/cjs/index.js +1 -1
- package/dist/cjs/vendors.js +1 -1
- package/dist/cjs/vendors~echarts.js +1 -1
- package/dist/esm/index.js +1 -14270
- package/dist/esm/vendors.js +1 -16770
- package/dist/esm/vendors~echarts.js +1 -59417
- package/package.json +10 -15
- package/src/adapters/h5/index.ts +38 -38
- package/src/adapters/index.ts +32 -34
- package/src/adapters/types.ts +23 -55
- package/src/charts/boxplot/types.ts +2 -2
- package/src/charts/common/BaseChartWrapper.tsx +9 -7
- package/src/charts/createChartComponent.tsx +9 -21
- package/src/charts/createOptionChartComponent.tsx +32 -0
- package/src/charts/funnel/__tests__/index.test.tsx +99 -0
- package/src/charts/funnel/index.tsx +64 -0
- package/src/charts/funnel/types.ts +6 -0
- package/src/charts/graph/__tests__/index.test.tsx +116 -0
- package/src/charts/graph/index.tsx +70 -0
- package/src/charts/graph/types.ts +6 -0
- package/src/charts/heatmap/__tests__/index.test.tsx +139 -0
- package/src/charts/heatmap/index.tsx +107 -0
- package/src/charts/heatmap/types.ts +6 -0
- package/src/charts/index.ts +47 -57
- package/src/charts/liquid/__tests__/index.test.tsx +52 -0
- package/src/charts/liquid/index.tsx +7 -133
- package/src/charts/liquid/types.ts +6 -6
- package/src/charts/parallel/types.ts +3 -3
- package/src/charts/radar/__tests__/index.test.tsx +210 -0
- package/src/charts/radar/index.tsx +147 -0
- package/src/charts/radar/types.ts +13 -0
- package/src/charts/sankey/__tests__/index.test.tsx +124 -0
- package/src/charts/sankey/index.tsx +70 -0
- package/src/charts/sankey/types.ts +6 -0
- package/src/charts/tree/__tests__/index.test.tsx +71 -0
- package/src/charts/tree/index.tsx +1 -1
- package/src/charts/tree/types.ts +8 -8
- package/src/charts/types.ts +208 -106
- package/src/charts/wordcloud/__tests__/index.test.tsx +106 -0
- package/src/charts/wordcloud/index.tsx +79 -0
- package/src/charts/wordcloud/types.ts +6 -0
- package/src/components/DataFilter/index.tsx +7 -6
- package/src/core/animation/types.ts +6 -6
- package/src/core/components/Annotation.tsx +6 -6
- package/src/core/components/BaseChart.tsx +97 -133
- package/src/core/components/LazyChart.tsx +3 -8
- package/src/core/components/hooks/index.ts +6 -2
- package/src/core/components/hooks/usePerformance.ts +8 -2
- package/src/core/components/hooks/useVirtualScroll.ts +2 -1
- package/src/core/types/common.ts +2 -1
- package/src/core/types/platform.ts +1 -0
- package/src/core/utils/__tests__/deepClone.test.ts +317 -0
- package/src/core/utils/__tests__/index.test.ts +2 -1
- package/src/core/utils/chartInstances.ts +13 -0
- package/src/core/utils/common.ts +20 -36
- package/src/core/utils/deepClone.ts +114 -0
- package/src/core/utils/download.ts +22 -28
- package/src/core/utils/drillDown.ts +1 -0
- package/src/core/utils/events.ts +12 -0
- package/src/core/utils/export/ExportUtils.ts +2 -1
- package/src/core/utils/format.ts +44 -0
- package/src/core/utils/index.ts +18 -159
- package/src/core/utils/merge.ts +25 -0
- package/src/core/utils/performance/PerformanceAnalyzer.ts +3 -1
- package/src/core/utils/performance/hooks.ts +7 -0
- package/src/core/utils/performance/index.ts +2 -0
- package/src/{hooks → core/utils/performance}/useAnimation.ts +6 -5
- package/src/{hooks → core/utils/performance}/useDataZoom.ts +7 -2
- package/src/{hooks → core/utils/performance}/usePerformance.ts +39 -39
- package/src/{hooks → core/utils/performance}/usePerformanceHooks.ts +39 -39
- package/src/core/utils/runtime.ts +190 -0
- package/src/editor/components/ThemeSelector.tsx +3 -3
- package/src/hooks/chartConnectHelpers.ts +6 -0
- package/src/hooks/index.ts +54 -626
- package/src/hooks/types.ts +27 -0
- package/src/hooks/useChartAutoResize.ts +73 -0
- package/src/hooks/useChartConnect.ts +5 -1
- package/src/hooks/useChartDownload.ts +1 -1
- package/src/hooks/useChartHistory.ts +1 -3
- package/src/hooks/useChartInit.ts +59 -0
- package/src/hooks/useChartOptions.ts +259 -0
- package/src/hooks/useChartPerformance.ts +109 -0
- package/src/hooks/useChartSelection.ts +23 -12
- package/src/hooks/useChartTheme.ts +51 -0
- package/src/hooks/useDataTransform.ts +19 -4
- package/src/index.ts +5 -10
- package/src/react-dom.d.ts +3 -3
- package/src/themes/index.ts +30 -855
- package/src/themes/palettes/blue-green.ts +13 -0
- package/src/themes/palettes/chalk.ts +13 -0
- package/src/themes/palettes/cyber.ts +44 -0
- package/src/themes/palettes/dark.ts +52 -0
- package/src/themes/palettes/default.ts +52 -0
- package/src/themes/palettes/elegant.ts +34 -0
- package/src/themes/palettes/forest.ts +13 -0
- package/src/themes/palettes/glass.ts +49 -0
- package/src/themes/palettes/golden.ts +13 -0
- package/src/themes/palettes/neon.ts +43 -0
- package/src/themes/palettes/ocean.ts +39 -0
- package/src/themes/palettes/pastel.ts +37 -0
- package/src/themes/palettes/purple-passion.ts +13 -0
- package/src/themes/palettes/retro.ts +33 -0
- package/src/themes/palettes/sunset.ts +40 -0
- package/src/themes/palettes/walden.ts +13 -0
- package/src/themes/registry.ts +184 -0
- package/src/themes/types.ts +213 -0
- package/src/core/utils/codeGenerator/CodeGenerator.ts +0 -669
- package/src/core/utils/codeGenerator/index.ts +0 -13
- package/src/core/utils/codeGenerator/types.ts +0 -198
- package/src/core/utils/configGenerator/ConfigGenerator.ts +0 -583
- package/src/core/utils/configGenerator/index.ts +0 -13
- package/src/core/utils/configGenerator/types.ts +0 -449
- package/src/core/utils/debug/DebugPanel.tsx +0 -640
- package/src/core/utils/debug/debugger.ts +0 -322
- package/src/core/utils/debug/index.ts +0 -21
- package/src/core/utils/debug/types.ts +0 -142
package/src/charts/types.ts
CHANGED
|
@@ -3,6 +3,7 @@
|
|
|
3
3
|
*/
|
|
4
4
|
import type { CSSProperties, ReactNode } from 'react';
|
|
5
5
|
import type { EChartsOption, ECharts } from 'echarts';
|
|
6
|
+
import type { AnimationConfig } from '../core/animation/types';
|
|
6
7
|
|
|
7
8
|
// ============================================================================
|
|
8
9
|
// 基础类型定义
|
|
@@ -163,24 +164,8 @@ export interface ChartData {
|
|
|
163
164
|
// 动画配置
|
|
164
165
|
// ============================================================================
|
|
165
166
|
|
|
166
|
-
/** 动画配置 */
|
|
167
|
-
export interface AnimationConfig {
|
|
168
|
-
/** 是否启用动画 */
|
|
169
|
-
enabled?: boolean;
|
|
170
|
-
/** 动画时长 (ms) */
|
|
171
|
-
duration?: number;
|
|
172
|
-
/** 动画缓动函数 */
|
|
173
|
-
easing?: string;
|
|
174
|
-
/** 动画延迟 (ms) */
|
|
175
|
-
delay?: number;
|
|
176
|
-
/** 是否在渲染时使用动画 */
|
|
177
|
-
animate?: boolean;
|
|
178
|
-
/** 是否在数据更新时使用动画 */
|
|
179
|
-
animateUpdate?: boolean;
|
|
180
|
-
}
|
|
181
|
-
|
|
182
167
|
// ============================================================================
|
|
183
|
-
//
|
|
168
|
+
// 事件回调类型
|
|
184
169
|
// ============================================================================
|
|
185
170
|
|
|
186
171
|
/**
|
|
@@ -472,81 +457,145 @@ export interface ScatterChartProps extends BaseChartProps {
|
|
|
472
457
|
/**
|
|
473
458
|
* 雷达图属性
|
|
474
459
|
*/
|
|
475
|
-
export interface
|
|
476
|
-
/**
|
|
477
|
-
|
|
460
|
+
export interface RadarIndicator {
|
|
461
|
+
/** 指标名称 */
|
|
462
|
+
name: string;
|
|
463
|
+
/** 最大值 */
|
|
464
|
+
max: number;
|
|
465
|
+
/** 最小值(可选,默认 0) */
|
|
466
|
+
min?: number;
|
|
467
|
+
}
|
|
478
468
|
|
|
479
|
-
|
|
480
|
-
|
|
469
|
+
/** 雷达图数据系列项 */
|
|
470
|
+
export interface RadarDataItem {
|
|
471
|
+
/** 数据值数组,对应每个 indicator 的值 */
|
|
472
|
+
value: number[];
|
|
473
|
+
/** 系列名称 */
|
|
474
|
+
name?: string;
|
|
475
|
+
}
|
|
481
476
|
|
|
482
|
-
|
|
483
|
-
|
|
477
|
+
/** 雷达图面积样式配置 */
|
|
478
|
+
export interface RadarAreaStyle {
|
|
479
|
+
/** 是否显示面积填充 */
|
|
480
|
+
show?: boolean;
|
|
481
|
+
/** 填充颜色 */
|
|
482
|
+
color?: string;
|
|
483
|
+
/** 透明度 */
|
|
484
|
+
opacity?: number;
|
|
485
|
+
}
|
|
484
486
|
|
|
485
|
-
|
|
486
|
-
|
|
487
|
+
/** 雷达图线样式配置 */
|
|
488
|
+
export interface RadarLineStyle {
|
|
489
|
+
/** 线宽 */
|
|
490
|
+
width?: number;
|
|
491
|
+
/** 线型 */
|
|
492
|
+
type?: 'solid' | 'dashed' | 'dotted';
|
|
493
|
+
/** 颜色 */
|
|
494
|
+
color?: string;
|
|
495
|
+
}
|
|
496
|
+
|
|
497
|
+
/** 雷达图标签配置 */
|
|
498
|
+
export interface RadarLabel {
|
|
499
|
+
/** 是否显示标签 */
|
|
500
|
+
show?: boolean;
|
|
501
|
+
/** 标签位置 */
|
|
502
|
+
position?: 'inside' | 'outside' | 'center';
|
|
503
|
+
/** 标签格式化 */
|
|
504
|
+
formatter?: string | ((value: number, indicator: RadarIndicator) => string);
|
|
505
|
+
}
|
|
506
|
+
|
|
507
|
+
/**
|
|
508
|
+
* 雷达图属性
|
|
509
|
+
*/
|
|
510
|
+
export interface RadarChartProps extends Omit<BaseChartProps, 'data'> {
|
|
511
|
+
/** 雷达图指示器 */
|
|
512
|
+
indicators: RadarIndicator[];
|
|
513
|
+
/** 雷达图数据系列 */
|
|
514
|
+
data: RadarDataItem[];
|
|
515
|
+
/** 起始角度(0-360,默认 90) */
|
|
516
|
+
startAngle?: number;
|
|
517
|
+
/** 是否显示中心圆环 */
|
|
518
|
+
centerCircle?: boolean;
|
|
519
|
+
/** 中心圆环半径(0-1,默认 0) */
|
|
520
|
+
centerCircleSize?: number;
|
|
521
|
+
/** 面积样式 */
|
|
522
|
+
areaStyle?: RadarAreaStyle;
|
|
523
|
+
/** 线样式 */
|
|
524
|
+
lineStyle?: RadarLineStyle;
|
|
525
|
+
/** 标签配置 */
|
|
526
|
+
label?: RadarLabel;
|
|
527
|
+
/** 是否平滑曲线 */
|
|
528
|
+
smooth?: boolean;
|
|
529
|
+
/** 自定义 ECharts option 合并 */
|
|
530
|
+
optionMerge?: Partial<EChartsOption>;
|
|
531
|
+
}
|
|
532
|
+
|
|
533
|
+
/**
|
|
534
|
+
* 漏斗图数据项
|
|
535
|
+
*/
|
|
536
|
+
export interface FunnelDataItem {
|
|
537
|
+
/** 数值 */
|
|
538
|
+
value: number;
|
|
539
|
+
/** 名称 */
|
|
540
|
+
name: string;
|
|
487
541
|
}
|
|
488
542
|
|
|
489
543
|
/**
|
|
490
544
|
* 漏斗图属性
|
|
491
545
|
*/
|
|
492
|
-
export interface FunnelChartProps extends BaseChartProps {
|
|
546
|
+
export interface FunnelChartProps extends Omit<BaseChartProps, 'data'> {
|
|
547
|
+
/** 漏斗数据 */
|
|
548
|
+
data?: FunnelDataItem[];
|
|
493
549
|
/** 漏斗排序方式 */
|
|
494
550
|
sort?: 'ascending' | 'descending' | 'none';
|
|
495
|
-
|
|
496
551
|
/** 漏斗对齐方式 */
|
|
497
552
|
align?: 'left' | 'center' | 'right';
|
|
498
|
-
|
|
499
553
|
/** 间隙 */
|
|
500
554
|
gap?: number;
|
|
501
|
-
|
|
502
555
|
/** 最小高度 */
|
|
503
556
|
min?: number;
|
|
504
|
-
|
|
505
557
|
/** 最大高度 */
|
|
506
558
|
max?: number;
|
|
559
|
+
/** 自定义 ECharts option 合并 */
|
|
560
|
+
optionMerge?: Partial<EChartsOption>;
|
|
507
561
|
}
|
|
508
562
|
|
|
509
563
|
/**
|
|
510
|
-
*
|
|
564
|
+
* 热力图数据项
|
|
511
565
|
*/
|
|
512
|
-
export interface
|
|
513
|
-
/**
|
|
514
|
-
|
|
515
|
-
|
|
516
|
-
|
|
517
|
-
|
|
518
|
-
|
|
519
|
-
|
|
520
|
-
value?: number;
|
|
521
|
-
|
|
522
|
-
/** 刻度分段数 */
|
|
523
|
-
splitNumber?: number;
|
|
524
|
-
|
|
525
|
-
/** 半径 */
|
|
526
|
-
radius?: number | string;
|
|
527
|
-
|
|
528
|
-
/** 起始角度 */
|
|
529
|
-
startAngle?: number;
|
|
530
|
-
|
|
531
|
-
/** 结束角度 */
|
|
532
|
-
endAngle?: number;
|
|
566
|
+
export interface HeatmapDataItem {
|
|
567
|
+
/** X 轴索引或值 */
|
|
568
|
+
x: number | string;
|
|
569
|
+
/** Y 轴索引或值 */
|
|
570
|
+
y: number | string;
|
|
571
|
+
/** 热力值 */
|
|
572
|
+
value: number;
|
|
573
|
+
}
|
|
533
574
|
|
|
534
|
-
|
|
535
|
-
|
|
575
|
+
/**
|
|
576
|
+
* 热力图 X/Y 轴配置
|
|
577
|
+
*/
|
|
578
|
+
export interface HeatmapAxis {
|
|
579
|
+
/** 轴标签 */
|
|
580
|
+
name?: string;
|
|
581
|
+
/** 轴数据 */
|
|
582
|
+
data?: (string | number)[];
|
|
536
583
|
}
|
|
537
584
|
|
|
538
585
|
/**
|
|
539
586
|
* 热力图属性
|
|
540
587
|
*/
|
|
541
|
-
export interface HeatmapChartProps extends BaseChartProps {
|
|
588
|
+
export interface HeatmapChartProps extends Omit<BaseChartProps, 'data'> {
|
|
542
589
|
/** X 轴数据 */
|
|
543
|
-
|
|
544
|
-
|
|
590
|
+
xData?: (string | number)[];
|
|
545
591
|
/** Y 轴数据 */
|
|
546
|
-
|
|
547
|
-
|
|
592
|
+
yData?: (string | number)[];
|
|
593
|
+
/** 热力图数据 */
|
|
594
|
+
data?: HeatmapDataItem[];
|
|
548
595
|
/** 视觉映射配置 */
|
|
549
596
|
visualMap?: Record<string, unknown>;
|
|
597
|
+
/** 自定义 ECharts option 合并 */
|
|
598
|
+
optionMerge?: Partial<EChartsOption>;
|
|
550
599
|
}
|
|
551
600
|
|
|
552
601
|
/**
|
|
@@ -707,6 +756,8 @@ export interface SankeyChartProps extends BaseChartProps {
|
|
|
707
756
|
itemStyle?: Record<string, unknown>;
|
|
708
757
|
lineStyle?: Record<string, unknown>;
|
|
709
758
|
};
|
|
759
|
+
/** 自定义 ECharts option 合并 */
|
|
760
|
+
optionMerge?: Partial<EChartsOption>;
|
|
710
761
|
}
|
|
711
762
|
|
|
712
763
|
/**
|
|
@@ -739,48 +790,6 @@ export interface BoxplotChartProps extends Omit<BaseChartProps, 'data'> {
|
|
|
739
790
|
smooth?: boolean;
|
|
740
791
|
}
|
|
741
792
|
|
|
742
|
-
/**
|
|
743
|
-
* K线图/股票图属性
|
|
744
|
-
* 用于展示股票、外汇等金融数据
|
|
745
|
-
*/
|
|
746
|
-
export interface CandlestickChartProps extends Omit<BaseChartProps, 'data'> {
|
|
747
|
-
/** K线数据数组,每项为 [open, close, lowest, highest] */
|
|
748
|
-
candlestickData?: number[][];
|
|
749
|
-
|
|
750
|
-
/** X轴数据 */
|
|
751
|
-
xAxisData?: (string | number)[];
|
|
752
|
-
|
|
753
|
-
/** 数据对应的维度名 */
|
|
754
|
-
dimensions?: string[];
|
|
755
|
-
|
|
756
|
-
/** 批量数据 */
|
|
757
|
-
batchData?: Array<{
|
|
758
|
-
name: string;
|
|
759
|
-
data: number[][];
|
|
760
|
-
}>;
|
|
761
|
-
|
|
762
|
-
/** K线柱条样式 */
|
|
763
|
-
itemStyle?: Record<string, unknown>;
|
|
764
|
-
|
|
765
|
-
/** 强调状态 */
|
|
766
|
-
emphasis?: Record<string, unknown>;
|
|
767
|
-
|
|
768
|
-
/** 是否平滑曲线 */
|
|
769
|
-
smooth?: boolean;
|
|
770
|
-
|
|
771
|
-
/** 是否显示MA线 */
|
|
772
|
-
ma?: Array<{
|
|
773
|
-
period: number;
|
|
774
|
-
color?: string;
|
|
775
|
-
}>;
|
|
776
|
-
|
|
777
|
-
/** 是否显示成交量 */
|
|
778
|
-
showVolume?: boolean;
|
|
779
|
-
|
|
780
|
-
/** 成交量柱子样式 */
|
|
781
|
-
volumeBar?: Record<string, unknown>;
|
|
782
|
-
}
|
|
783
|
-
|
|
784
793
|
/**
|
|
785
794
|
* 关系图属性
|
|
786
795
|
* 用于展示节点之间的关系
|
|
@@ -839,6 +848,8 @@ export interface GraphChartProps extends BaseChartProps {
|
|
|
839
848
|
itemStyle?: Record<string, unknown>;
|
|
840
849
|
lineStyle?: Record<string, unknown>;
|
|
841
850
|
};
|
|
851
|
+
/** 自定义 ECharts option 合并 */
|
|
852
|
+
optionMerge?: Partial<EChartsOption>;
|
|
842
853
|
}
|
|
843
854
|
|
|
844
855
|
// ============================================================================
|
|
@@ -880,9 +891,98 @@ export type { EChartsOption, ECharts } from 'echarts';
|
|
|
880
891
|
export type { ECBasicOption as EChartsCoreOption } from 'echarts/types/dist/shared';
|
|
881
892
|
|
|
882
893
|
/**
|
|
883
|
-
*
|
|
884
|
-
* 用于展示文本数据的词频分布
|
|
894
|
+
* 漏斗图标签配置
|
|
885
895
|
*/
|
|
896
|
+
export interface FunnelLabel {
|
|
897
|
+
/** 是否显示标签 */
|
|
898
|
+
show?: boolean;
|
|
899
|
+
/** 标签位置 */
|
|
900
|
+
position?: 'inside' | 'outside' | 'left' | 'right';
|
|
901
|
+
/** 标签格式化 */
|
|
902
|
+
formatter?: string | ((_value: number, _name: string) => string);
|
|
903
|
+
}
|
|
904
|
+
|
|
905
|
+
/**
|
|
906
|
+
* 关系图节点数据
|
|
907
|
+
*/
|
|
908
|
+
export interface GraphNode {
|
|
909
|
+
/** 节点 ID */
|
|
910
|
+
id?: string | number;
|
|
911
|
+
/** 节点名称 */
|
|
912
|
+
name: string;
|
|
913
|
+
/** 节点值 */
|
|
914
|
+
value?: number | number[];
|
|
915
|
+
/** 节点类别 */
|
|
916
|
+
category?: number;
|
|
917
|
+
/** 节点符号 */
|
|
918
|
+
symbol?: string;
|
|
919
|
+
/** 节点符号大小 */
|
|
920
|
+
symbolSize?: number | number[];
|
|
921
|
+
/** 是否固定位置 */
|
|
922
|
+
fixed?: boolean;
|
|
923
|
+
/** X 坐标 */
|
|
924
|
+
x?: number;
|
|
925
|
+
/** Y 坐标 */
|
|
926
|
+
y?: number;
|
|
927
|
+
/** 其他自定义属性 */
|
|
928
|
+
[key: string]: unknown;
|
|
929
|
+
}
|
|
930
|
+
|
|
931
|
+
/**
|
|
932
|
+
* 关系图链接/边数据
|
|
933
|
+
*/
|
|
934
|
+
export interface GraphLink {
|
|
935
|
+
/** 源节点 */
|
|
936
|
+
source: string | number;
|
|
937
|
+
/** 目标节点 */
|
|
938
|
+
target: string | number;
|
|
939
|
+
/** 链接值 */
|
|
940
|
+
value?: number;
|
|
941
|
+
/** 线条样式 */
|
|
942
|
+
lineStyle?: Record<string, unknown>;
|
|
943
|
+
/** 其他自定义属性 */
|
|
944
|
+
[key: string]: unknown;
|
|
945
|
+
}
|
|
946
|
+
|
|
947
|
+
/**
|
|
948
|
+
* 桑基图节点数据
|
|
949
|
+
*/
|
|
950
|
+
export interface SankeyNode {
|
|
951
|
+
/** 节点名称 */
|
|
952
|
+
name: string;
|
|
953
|
+
/** 节点值 */
|
|
954
|
+
value?: number;
|
|
955
|
+
/** 其他自定义属性 */
|
|
956
|
+
[key: string]: unknown;
|
|
957
|
+
}
|
|
958
|
+
|
|
959
|
+
/**
|
|
960
|
+
* 桑基图链接/边数据
|
|
961
|
+
*/
|
|
962
|
+
export interface SankeyLink {
|
|
963
|
+
/** 源节点 */
|
|
964
|
+
source: string | number;
|
|
965
|
+
/** 目标节点 */
|
|
966
|
+
target: string | number;
|
|
967
|
+
/** 链接值 */
|
|
968
|
+
value: number;
|
|
969
|
+
/** 其他自定义属性 */
|
|
970
|
+
[key: string]: unknown;
|
|
971
|
+
}
|
|
972
|
+
|
|
973
|
+
/**
|
|
974
|
+
* 词云图数据项
|
|
975
|
+
*/
|
|
976
|
+
export interface WordCloudDataItem {
|
|
977
|
+
/** 词名 */
|
|
978
|
+
name: string;
|
|
979
|
+
/** 词频值 */
|
|
980
|
+
value: number;
|
|
981
|
+
/** 文本样式 */
|
|
982
|
+
textStyle?: Record<string, unknown>;
|
|
983
|
+
/** emphasis 状态 */
|
|
984
|
+
emphasis?: Record<string, unknown>;
|
|
985
|
+
}
|
|
886
986
|
export interface WordCloudChartProps extends BaseChartProps {
|
|
887
987
|
/** 词云数据 - 也可以通过 option.series[0].data 传入 */
|
|
888
988
|
wordCloudData?: Array<{
|
|
@@ -915,7 +1015,9 @@ export interface WordCloudChartProps extends BaseChartProps {
|
|
|
915
1015
|
|
|
916
1016
|
/** 强调状态 */
|
|
917
1017
|
emphasis?: {
|
|
918
|
-
|
|
919
|
-
|
|
1018
|
+
itemStyle?: Record<string, unknown>;
|
|
1019
|
+
lineStyle?: Record<string, unknown>;
|
|
920
1020
|
};
|
|
1021
|
+
/** 自定义 ECharts option 合并 */
|
|
1022
|
+
optionMerge?: Partial<EChartsOption>;
|
|
921
1023
|
}
|
|
@@ -0,0 +1,106 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* WordCloudChart 组件测试
|
|
3
|
+
*/
|
|
4
|
+
import React from 'react';
|
|
5
|
+
import { render, screen } from '@testing-library/react';
|
|
6
|
+
import '@testing-library/jest-dom';
|
|
7
|
+
import WordCloudChart from '../index';
|
|
8
|
+
|
|
9
|
+
// 使用正确的 mock 方式,参考 parallel 图表的测试
|
|
10
|
+
jest.mock('../../common/BaseChartWrapper');
|
|
11
|
+
jest.mock('echarts/charts', () => ({ WordCloudChart: jest.fn() }));
|
|
12
|
+
|
|
13
|
+
describe('WordCloudChart', () => {
|
|
14
|
+
const mockData = [
|
|
15
|
+
{ name: 'JavaScript', value: 100 },
|
|
16
|
+
{ name: 'TypeScript', value: 80 },
|
|
17
|
+
{ name: 'React', value: 60 },
|
|
18
|
+
{ name: 'Vue', value: 50 },
|
|
19
|
+
{ name: 'Node.js', value: 40 },
|
|
20
|
+
{ name: 'Python', value: 30 },
|
|
21
|
+
{ name: 'Go', value: 20 },
|
|
22
|
+
];
|
|
23
|
+
|
|
24
|
+
it('应该渲染词云图组件', () => {
|
|
25
|
+
render(<WordCloudChart wordCloudData={mockData} width={800} height={400} />);
|
|
26
|
+
|
|
27
|
+
expect(screen.getByTestId('base-chart-wrapper')).toBeInTheDocument();
|
|
28
|
+
});
|
|
29
|
+
|
|
30
|
+
it('应该传递正确的 option 到 BaseChart', () => {
|
|
31
|
+
render(<WordCloudChart wordCloudData={mockData} width={800} height={400} />);
|
|
32
|
+
|
|
33
|
+
const baseChartWrapper = screen.getByTestId('base-chart-wrapper');
|
|
34
|
+
const optionElement = baseChartWrapper.querySelector('[data-testid="chart-option"]');
|
|
35
|
+
const option = JSON.parse(optionElement?.textContent || '{}');
|
|
36
|
+
|
|
37
|
+
expect(option.series).toBeDefined();
|
|
38
|
+
expect(option.series.type).toBe('wordCloud');
|
|
39
|
+
expect(option.series.data).toEqual(mockData);
|
|
40
|
+
expect(option.series.shape).toBe('circle');
|
|
41
|
+
});
|
|
42
|
+
|
|
43
|
+
it('当 wordCloudData 为空时应该返回 null', () => {
|
|
44
|
+
const { container } = render(<WordCloudChart wordCloudData={[]} width={800} height={400} />);
|
|
45
|
+
|
|
46
|
+
expect(container.firstChild).toBeNull();
|
|
47
|
+
});
|
|
48
|
+
|
|
49
|
+
it('应该支持自定义 shape', () => {
|
|
50
|
+
render(<WordCloudChart wordCloudData={mockData} shape="star" width={800} height={400} />);
|
|
51
|
+
|
|
52
|
+
const baseChartWrapper = screen.getByTestId('base-chart-wrapper');
|
|
53
|
+
const optionElement = baseChartWrapper.querySelector('[data-testid="chart-option"]');
|
|
54
|
+
const option = JSON.parse(optionElement?.textContent || '{}');
|
|
55
|
+
|
|
56
|
+
expect(option.series.shape).toBe('star');
|
|
57
|
+
});
|
|
58
|
+
|
|
59
|
+
it('应该支持自定义 sizeRange', () => {
|
|
60
|
+
render(
|
|
61
|
+
<WordCloudChart wordCloudData={mockData} sizeRange={[15, 80]} width={800} height={400} />
|
|
62
|
+
);
|
|
63
|
+
|
|
64
|
+
const baseChartWrapper = screen.getByTestId('base-chart-wrapper');
|
|
65
|
+
const optionElement = baseChartWrapper.querySelector('[data-testid="chart-option"]');
|
|
66
|
+
const option = JSON.parse(optionElement?.textContent || '{}');
|
|
67
|
+
|
|
68
|
+
expect(option.series.sizeRange).toEqual([15, 80]);
|
|
69
|
+
});
|
|
70
|
+
|
|
71
|
+
it('应该支持自定义 rotationRange', () => {
|
|
72
|
+
render(
|
|
73
|
+
<WordCloudChart wordCloudData={mockData} rotationRange={[-45, 45]} width={800} height={400} />
|
|
74
|
+
);
|
|
75
|
+
|
|
76
|
+
const baseChartWrapper = screen.getByTestId('base-chart-wrapper');
|
|
77
|
+
const optionElement = baseChartWrapper.querySelector('[data-testid="chart-option"]');
|
|
78
|
+
const option = JSON.parse(optionElement?.textContent || '{}');
|
|
79
|
+
|
|
80
|
+
expect(option.series.rotationRange).toEqual([-45, 45]);
|
|
81
|
+
});
|
|
82
|
+
|
|
83
|
+
it('应该支持自定义 gridSize', () => {
|
|
84
|
+
render(<WordCloudChart wordCloudData={mockData} gridSize={10} width={800} height={400} />);
|
|
85
|
+
|
|
86
|
+
const baseChartWrapper = screen.getByTestId('base-chart-wrapper');
|
|
87
|
+
const optionElement = baseChartWrapper.querySelector('[data-testid="chart-option"]');
|
|
88
|
+
const option = JSON.parse(optionElement?.textContent || '{}');
|
|
89
|
+
|
|
90
|
+
expect(option.series.gridSize).toBe(10);
|
|
91
|
+
});
|
|
92
|
+
|
|
93
|
+
it('应该支持 optionMerge 自定义配置', () => {
|
|
94
|
+
const customTitle = { title: { text: '词云图标题', left: 'center' } };
|
|
95
|
+
|
|
96
|
+
render(
|
|
97
|
+
<WordCloudChart wordCloudData={mockData} optionMerge={customTitle} width={800} height={400} />
|
|
98
|
+
);
|
|
99
|
+
|
|
100
|
+
const baseChartWrapper = screen.getByTestId('base-chart-wrapper');
|
|
101
|
+
const optionElement = baseChartWrapper.querySelector('[data-testid="chart-option"]');
|
|
102
|
+
const option = JSON.parse(optionElement?.textContent || '{}');
|
|
103
|
+
|
|
104
|
+
expect(option.title).toEqual(customTitle.title);
|
|
105
|
+
});
|
|
106
|
+
});
|
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* TaroViz 词云图组件
|
|
3
|
+
*
|
|
4
|
+
* 基于 ECharts wordCloud 系列实现词云可视化
|
|
5
|
+
*/
|
|
6
|
+
import { createOptionChartComponent } from '@/charts/createOptionChartComponent';
|
|
7
|
+
import type { WordCloudChartProps } from './types';
|
|
8
|
+
// 类型 WordCloudDataItem 通过下方 export type 导出供外部使用
|
|
9
|
+
|
|
10
|
+
/**
|
|
11
|
+
* 构建词云图 ECharts option
|
|
12
|
+
*/
|
|
13
|
+
function buildWordCloudOption(props: WordCloudChartProps) {
|
|
14
|
+
const {
|
|
15
|
+
wordCloudData,
|
|
16
|
+
shape,
|
|
17
|
+
sizeRange,
|
|
18
|
+
rotationRange,
|
|
19
|
+
rotationStep,
|
|
20
|
+
gridSize,
|
|
21
|
+
drawOutOfBound,
|
|
22
|
+
textStyle,
|
|
23
|
+
optionMerge,
|
|
24
|
+
} = props;
|
|
25
|
+
|
|
26
|
+
// 验证数据
|
|
27
|
+
if (!wordCloudData || wordCloudData.length === 0) {
|
|
28
|
+
console.warn('[TaroViz] WordCloudChart: wordCloudData is required');
|
|
29
|
+
return null;
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
// 构建词云图 series
|
|
33
|
+
const series = {
|
|
34
|
+
type: 'wordCloud' as const,
|
|
35
|
+
shape: shape || 'circle',
|
|
36
|
+
data: wordCloudData,
|
|
37
|
+
sizeRange: sizeRange || [12, 60],
|
|
38
|
+
rotationRange: rotationRange || [-90, 90],
|
|
39
|
+
rotationStep: rotationStep || 45,
|
|
40
|
+
gridSize: gridSize || 8,
|
|
41
|
+
drawOutOfBound: drawOutOfBound !== false,
|
|
42
|
+
textStyle: {
|
|
43
|
+
fontFamily: 'sans-serif',
|
|
44
|
+
fontWeight: 'bold',
|
|
45
|
+
...textStyle,
|
|
46
|
+
},
|
|
47
|
+
emphasis: {
|
|
48
|
+
itemStyle: {
|
|
49
|
+
shadowBlur: 10,
|
|
50
|
+
shadowColor: 'rgba(0, 0, 0, 0.5)',
|
|
51
|
+
},
|
|
52
|
+
},
|
|
53
|
+
};
|
|
54
|
+
|
|
55
|
+
const option: any = {
|
|
56
|
+
tooltip: {
|
|
57
|
+
trigger: 'item',
|
|
58
|
+
formatter: (params: any) => {
|
|
59
|
+
if (!params || !params.data) return '';
|
|
60
|
+
return `<b>${params.data.name}</b><br/>词频: ${params.data.value}`;
|
|
61
|
+
},
|
|
62
|
+
},
|
|
63
|
+
series,
|
|
64
|
+
};
|
|
65
|
+
|
|
66
|
+
// 合并自定义配置
|
|
67
|
+
if (optionMerge) {
|
|
68
|
+
Object.assign(option, optionMerge);
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
return option;
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
const WordCloudChart = createOptionChartComponent<WordCloudChartProps>(
|
|
75
|
+
'WordCloudChart',
|
|
76
|
+
buildWordCloudOption
|
|
77
|
+
);
|
|
78
|
+
|
|
79
|
+
export default WordCloudChart;
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
/* eslint-disable @typescript-eslint/no-unused-vars */
|
|
1
2
|
/**
|
|
2
3
|
* DataFilter - 数据筛选器 UI 组件
|
|
3
4
|
* 提供独立的数据筛选交互界面,支持多种筛选类型
|
|
@@ -401,13 +402,13 @@ const DateFilter: React.FC<DateFilterProps> = ({ field, value, onChange, disable
|
|
|
401
402
|
* ```tsx
|
|
402
403
|
* <DataFilter
|
|
403
404
|
* fields={[
|
|
404
|
-
* {
|
|
405
|
-
* {
|
|
406
|
-
* {
|
|
407
|
-
* {
|
|
405
|
+
* { _key: 'category', label: '分类', type: 'select', options: [{ label: '苹果', _value: 'apple' }] },
|
|
406
|
+
* { _key: 'price', label: '价格区间', type: 'range', min: 0, max: 1000 },
|
|
407
|
+
* { _key: 'tags', label: '标签', type: 'checkbox', options: [{ label: '热门', _value: 'hot' }] },
|
|
408
|
+
* { _key: 'date', label: '日期', type: 'date' },
|
|
408
409
|
* ]}
|
|
409
|
-
*
|
|
410
|
-
* onChange={(
|
|
410
|
+
* _value={_filters}
|
|
411
|
+
* onChange={(_filters) => setFilters(_filters)}
|
|
411
412
|
* layout="horizontal"
|
|
412
413
|
* showReset
|
|
413
414
|
* />
|
|
@@ -241,33 +241,33 @@ export enum AnimationEventType {
|
|
|
241
241
|
/**
|
|
242
242
|
* 动画开始事件
|
|
243
243
|
*/
|
|
244
|
-
|
|
244
|
+
_ANIMATION_START = 'animationStart',
|
|
245
245
|
|
|
246
246
|
/**
|
|
247
247
|
* 动画更新事件
|
|
248
248
|
*/
|
|
249
|
-
|
|
249
|
+
_ANIMATION_UPDATE = 'animationUpdate',
|
|
250
250
|
|
|
251
251
|
/**
|
|
252
252
|
* 动画结束事件
|
|
253
253
|
*/
|
|
254
|
-
|
|
254
|
+
_ANIMATION_END = 'animationEnd',
|
|
255
255
|
|
|
256
256
|
/**
|
|
257
257
|
* 动画取消事件
|
|
258
258
|
*/
|
|
259
|
-
|
|
259
|
+
_ANIMATION_CANCEL = 'animationCancel',
|
|
260
260
|
|
|
261
261
|
/**
|
|
262
262
|
* 动画重复事件
|
|
263
263
|
*/
|
|
264
|
-
|
|
264
|
+
_ANIMATION_REPEAT = 'animationRepeat',
|
|
265
265
|
}
|
|
266
266
|
|
|
267
267
|
/**
|
|
268
268
|
* 动画事件回调类型
|
|
269
269
|
*/
|
|
270
|
-
export type AnimationEventHandler = (
|
|
270
|
+
export type AnimationEventHandler = (_event: {
|
|
271
271
|
type: AnimationEventType;
|
|
272
272
|
animationType: AnimationType;
|
|
273
273
|
chartId?: string;
|