win-chart 3.0.2 → 3.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.
Files changed (57) hide show
  1. package/dist/bun/index.js +5 -0
  2. package/dist/bun/index.js.map +25 -0
  3. package/dist/bun/types/components/ChartWrapper.d.ts +1 -0
  4. package/dist/bun/types/components/EarthChart.d.ts +15 -0
  5. package/dist/bun/types/components/GanttChart.d.ts +8 -0
  6. package/dist/bun/types/components/WinChart.d.ts +2 -0
  7. package/dist/bun/types/components/__tests__/Playground.test.d.ts +1 -0
  8. package/dist/bun/types/components/__tests__/WinChart.test.d.ts +1 -0
  9. package/dist/bun/types/index.d.ts +8 -0
  10. package/dist/bun/types/types/index.d.ts +126 -0
  11. package/dist/bun/types/utils/const.d.ts +14 -0
  12. package/dist/bun/types/utils/data.d.ts +20 -0
  13. package/dist/bun/types/utils/earthMockData.d.ts +7 -0
  14. package/dist/bun/types/utils/getAreaSpec.d.ts +14 -0
  15. package/dist/bun/types/utils/getBarSpec.d.ts +14 -0
  16. package/dist/bun/types/utils/getChartOptions.d.ts +7 -0
  17. package/dist/bun/types/utils/getColumnSpec.d.ts +14 -0
  18. package/dist/bun/types/utils/getDualSpec.d.ts +14 -0
  19. package/dist/bun/types/utils/getFunnelSpec.d.ts +8 -0
  20. package/dist/bun/types/utils/getLineSpec.d.ts +8 -0
  21. package/dist/bun/types/utils/getPieSpec.d.ts +13 -0
  22. package/dist/bun/types/utils/getRadarSpec.d.ts +7 -0
  23. package/dist/bun/types/utils/tool.d.ts +140 -0
  24. package/dist/cjs/components/__tests__/Playground.test.cjs +90 -0
  25. package/dist/cjs/components/__tests__/WinChart.test.cjs +112 -0
  26. package/dist/cjs/stories/WinChart.stories.cjs +524 -0
  27. package/dist/cjs/utils/const.cjs +21 -0
  28. package/dist/cjs/utils/getAreaSpec.cjs +2 -18
  29. package/dist/cjs/utils/getBarSpec.cjs +7 -21
  30. package/dist/cjs/utils/getColumnSpec.cjs +3 -18
  31. package/dist/cjs/utils/getDualSpec.cjs +3 -24
  32. package/dist/cjs/utils/getFunnelSpec.cjs +2 -3
  33. package/dist/cjs/utils/getLineSpec.cjs +2 -9
  34. package/dist/cjs/utils/getPieSpec.cjs +3 -6
  35. package/dist/cjs/utils/getRadarSpec.cjs +1 -3
  36. package/dist/cjs/utils/tool.cjs +7 -4
  37. package/dist/esm/components/__tests__/Playground.test.js +84 -0
  38. package/dist/esm/components/__tests__/WinChart.test.js +106 -0
  39. package/dist/esm/stories/WinChart.stories.js +466 -0
  40. package/dist/esm/utils/const.js +16 -1
  41. package/dist/esm/utils/getAreaSpec.js +3 -19
  42. package/dist/esm/utils/getBarSpec.js +8 -22
  43. package/dist/esm/utils/getColumnSpec.js +3 -18
  44. package/dist/esm/utils/getDualSpec.js +3 -24
  45. package/dist/esm/utils/getFunnelSpec.js +2 -3
  46. package/dist/esm/utils/getLineSpec.js +2 -9
  47. package/dist/esm/utils/getPieSpec.js +3 -6
  48. package/dist/esm/utils/getRadarSpec.js +2 -4
  49. package/dist/esm/utils/tool.js +7 -4
  50. package/dist/types/components/__tests__/Playground.test.d.ts +1 -0
  51. package/dist/types/components/__tests__/WinChart.test.d.ts +1 -0
  52. package/dist/types/index.d.ts +1 -1
  53. package/dist/types/types/index.d.ts +1 -2
  54. package/dist/types/utils/const.d.ts +6 -0
  55. package/dist/types/utils/getDualSpec.d.ts +1 -0
  56. package/dist/types/utils/tool.d.ts +2 -1
  57. package/package.json +28 -6
@@ -1,10 +1,9 @@
1
1
  import { arraySum, dataDescOrder, getLabelColor, handleToPercent } from "./tool.js";
2
+ import { ITEM_TOOLTIP_OPT } from "./const.js";
2
3
  const getPieOpt = (winChartProps)=>{
3
4
  const total = arraySum(winChartProps.data?.map((item)=>item.value));
4
5
  return {
5
- tooltip: {
6
- trigger: 'item'
7
- },
6
+ tooltip: ITEM_TOOLTIP_OPT,
8
7
  legend: {
9
8
  bottom: 0,
10
9
  type: 'scroll'
@@ -39,9 +38,7 @@ const getPieOpt = (winChartProps)=>{
39
38
  const getPieCycleOpt = (winChartProps)=>{
40
39
  const total = arraySum(winChartProps.data?.map((item)=>item.value));
41
40
  return {
42
- tooltip: {
43
- trigger: 'item'
44
- },
41
+ tooltip: ITEM_TOOLTIP_OPT,
45
42
  legend: {
46
43
  bottom: 0,
47
44
  type: 'scroll'
@@ -1,12 +1,10 @@
1
1
  import { rgba } from "polished";
2
- import { COLOR_LIST } from "./const.js";
2
+ import { COLOR_LIST, ITEM_TOOLTIP_OPT } from "./const.js";
3
3
  import { arrDeduplication } from "./tool.js";
4
4
  const getRadarOpt = (winChartProps)=>{
5
5
  const typeList = arrDeduplication(winChartProps.data?.map((item)=>winChartProps.reserveValueWithLabelType ? item.label : item.type));
6
6
  return {
7
- tooltip: {
8
- trigger: 'item'
9
- },
7
+ tooltip: ITEM_TOOLTIP_OPT,
10
8
  legend: {
11
9
  bottom: 0,
12
10
  type: 'scroll'
@@ -133,14 +133,17 @@ const mergeSeriesOption = (option, seriesOption)=>{
133
133
  return option;
134
134
  };
135
135
  const getLabelColor = (opt)=>'dark' === opt.theme ? 'rgba(255, 255, 255, 0.7)' : 'rgba(0, 0, 0, 0.7)';
136
- function aggregateStackData(data) {
136
+ function aggregateStackData(data, labels) {
137
137
  const result = data.reduce((acc, item)=>{
138
138
  const { label, value } = item;
139
- if (!acc[label]) acc[label] = 0;
139
+ if (void 0 === acc[label]) acc[label] = 0;
140
140
  if (value) acc[label] += Number(value);
141
141
  return acc;
142
142
  }, {});
143
- const totals = Object.values(result).map((totalValue)=>parseFloat(totalValue.toFixed(2)));
144
- return totals;
143
+ if (labels && labels.length > 0) return labels.map((label)=>{
144
+ const val = result[label] || 0;
145
+ return parseFloat(val.toFixed(2));
146
+ });
147
+ return Object.values(result).map((totalValue)=>parseFloat(totalValue.toFixed(2)));
145
148
  }
146
149
  export { aggregateStackData, arrDeduplication, arraySum, checkEntityArr, dataDescOrder, debounce, getDataTypes, getExtraDataTypes, getGradientColor, getLabelColor, getMainAxisLabels, getSeriesDataByType, getSeriesLabelConfig, getXAxisOpt, handleMainAxisLabel, handleSort, handleToPercent, isNonEmptyArray, mergeSeriesOption, sortArray, sortArrayByLabel };
@@ -0,0 +1 @@
1
+ export {};
@@ -3,6 +3,6 @@ import { WinChart } from './components/WinChart';
3
3
  import { WinChartType } from './types';
4
4
  import type { IChartInfo, IWinChartProps } from './types';
5
5
  import { EarthChart } from './components/EarthChart';
6
- export { WinChart, WinChartType, echarts, EarthChart, };
6
+ export { WinChart, WinChartType, echarts, EarthChart };
7
7
  export type { IWinChartProps, IChartInfo };
8
8
  export default WinChart;
@@ -53,7 +53,7 @@ export interface IWinChartProps {
53
53
  */
54
54
  showStackTotal?: boolean;
55
55
  }
56
- interface ICenterConfig {
56
+ export interface ICenterConfig {
57
57
  /**
58
58
  * 自定义统计显示内容
59
59
  */
@@ -124,4 +124,3 @@ export declare enum WinChartType {
124
124
  */
125
125
  RADAR = "radar"
126
126
  }
127
- export {};
@@ -1,3 +1,4 @@
1
+ import * as echarts from 'echarts';
1
2
  /**
2
3
  * 色值
3
4
  */
@@ -6,3 +7,8 @@ export declare const COLOR_LIST: string[];
6
7
  * 通用配置
7
8
  */
8
9
  export declare const commonOpt: Partial<echarts.EChartsOption>;
10
+ /**
11
+ * 通用 Tooltip 配置
12
+ */
13
+ export declare const COMMON_TOOLTIP_OPT: echarts.TooltipComponentOption;
14
+ export declare const ITEM_TOOLTIP_OPT: echarts.TooltipComponentOption;
@@ -1,4 +1,5 @@
1
1
  import { IWinChartProps } from '../types';
2
+ import * as echarts from 'echarts';
2
3
  /**
3
4
  * 双轴图(分组柱状 折线)
4
5
  * @param winChartProps
@@ -134,6 +134,7 @@ export declare const getLabelColor: (opt: Partial<IWinChartProps>) => "rgba(255,
134
134
  /**
135
135
  * 计算堆叠图汇总数据
136
136
  * @param data
137
+ * @param labels 主轴标签列表,用于保证顺序一致
137
138
  * @returns
138
139
  */
139
- export declare function aggregateStackData(data: IChartInfo[]): number[];
140
+ export declare function aggregateStackData(data: IChartInfo[], labels?: string[]): number[];
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "win-chart",
3
- "version": "3.0.2",
3
+ "version": "3.0.3",
4
4
  "description": "菜鸟地网统一图表组件",
5
5
  "sideEffects": false,
6
6
  "exports": {
@@ -19,7 +19,11 @@
19
19
  "type": "module",
20
20
  "scripts": {
21
21
  "dev": "rsbuild dev",
22
- "build": "rslib build"
22
+ "build": "rslib build",
23
+ "test": "vitest --exclude **/Playground.test.tsx --exclude **/dist/**",
24
+ "test:ui": "vitest --ui",
25
+ "storybook": "storybook dev -p 6006",
26
+ "build-storybook": "storybook build"
23
27
  },
24
28
  "keywords": [
25
29
  "chart",
@@ -27,12 +31,12 @@
27
31
  "component"
28
32
  ],
29
33
  "dependencies": {
30
- "dayjs": "^1.11.19",
31
34
  "deepmerge": "^4.3.1",
32
35
  "echarts": "^6.0.0",
33
36
  "echarts-gl": "^2.0.9",
34
37
  "polished": "^4.3.1",
35
- "styled-components": "^6.1.19"
38
+ "styled-components": "^6.1.19",
39
+ "zrender": "^5.6.0"
36
40
  },
37
41
  "peerDependencies": {
38
42
  "react": "^18.3.1 || ^19.0.0",
@@ -43,21 +47,39 @@
43
47
  "@rsbuild/core": "~1.6.9",
44
48
  "@rsbuild/plugin-react": "^1.4.2",
45
49
  "@rslib/core": "^0.18.2",
50
+ "@storybook/addon-a11y": "^10.1.0",
51
+ "@storybook/addon-docs": "^10.1.0",
52
+ "@storybook/addon-onboarding": "^10.1.0",
53
+ "@storybook/react": "^10.1.0",
54
+ "@storybook/test": "^8.6.14",
55
+ "@testing-library/react": "^16.3.0",
46
56
  "@types/node": "^20.19.25",
47
57
  "@types/react": "^18.3.27",
48
58
  "@types/react-dom": "^18.3.7",
59
+ "@vitejs/plugin-react": "^5.1.1",
60
+ "@vitest/browser": "^4.0.14",
61
+ "@vitest/browser-playwright": "^4.0.14",
62
+ "@vitest/ui": "^4.0.14",
49
63
  "eslint": "^9.39.1",
50
64
  "eslint-plugin-react": "^7.37.5",
51
65
  "eslint-plugin-react-hooks": "^5.2.0",
66
+ "eslint-plugin-storybook": "^10.1.0",
52
67
  "globals": "^15.15.0",
68
+ "playwright": "^1.57.0",
53
69
  "prettier": "^3.7.1",
70
+ "storybook": "^10.1.0",
71
+ "storybook-react-rsbuild": "^3.0.0",
54
72
  "tslib": "^2.8.1",
55
73
  "typescript": "^5.9.3",
56
- "typescript-eslint": "^8.48.0"
74
+ "typescript-eslint": "^8.48.0",
75
+ "vitest": "^4.0.14"
57
76
  },
58
77
  "publishConfig": {
59
78
  "access": "public"
60
79
  },
61
80
  "license": "MIT",
62
- "repository": "http://gitlab.alibaba-inc.com/ground-net-front/win-chart.git"
81
+ "repository": {
82
+ "type": "git",
83
+ "url": "http://gitlab.alibaba-inc.com/ground-net-front/win-chart.git"
84
+ }
63
85
  }