@publishfx/publish-chart 1.3.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.
- package/README.md +143 -0
- package/dist/adapters/DataAdapter.d.ts +33 -0
- package/dist/adapters/DataAdapter.js +75 -0
- package/dist/adapters/TypeAdapter.d.ts +40 -0
- package/dist/adapters/TypeAdapter.js +26 -0
- package/dist/components/base/BarChart.d.ts +7 -0
- package/dist/components/base/BarChart.js +362 -0
- package/dist/components/base/BarChart.lazy.d.ts +5 -0
- package/dist/components/base/BarChart.lazy.js +2 -0
- package/dist/components/base/LineChart.d.ts +7 -0
- package/dist/components/base/LineChart.js +321 -0
- package/dist/components/base/LineChart.lazy.d.ts +5 -0
- package/dist/components/base/LineChart.lazy.js +2 -0
- package/dist/components/composite/BarLineAdapter.d.ts +22 -0
- package/dist/components/composite/BarLineAdapter.js +61 -0
- package/dist/components/composite/BarLineAdapter.lazy.d.ts +5 -0
- package/dist/components/composite/BarLineAdapter.lazy.js +2 -0
- package/dist/components/composite/BarLineChart.d.ts +7 -0
- package/dist/components/composite/BarLineChart.js +255 -0
- package/dist/components/composite/BarLineChart.lazy.d.ts +5 -0
- package/dist/components/composite/BarLineChart.lazy.js +2 -0
- package/dist/components/composite/BarLineCompareWeekend.d.ts +10 -0
- package/dist/components/composite/BarLineCompareWeekend.js +502 -0
- package/dist/components/composite/GroupBarLine.d.ts +11 -0
- package/dist/components/composite/GroupBarLine.js +546 -0
- package/dist/components/composite/GroupBarLine.lazy.d.ts +5 -0
- package/dist/components/composite/GroupBarLine.lazy.js +2 -0
- package/dist/components/composite/GroupCompare.d.ts +10 -0
- package/dist/components/composite/GroupCompare.js +620 -0
- package/dist/components/shared/AuxiliaryLine.d.ts +8 -0
- package/dist/components/shared/AuxiliaryLine.js +64 -0
- package/dist/components/shared/NodeDetail.d.ts +9 -0
- package/dist/components/shared/NodeDetail.js +110 -0
- package/dist/components/shared/NodeGeom.d.ts +23 -0
- package/dist/components/shared/NodeGeom.js +35 -0
- package/dist/components/shared/NodePopover.d.ts +22 -0
- package/dist/components/shared/NodePopover.js +41 -0
- package/dist/components/shared/NodePopoverContent.d.ts +15 -0
- package/dist/components/shared/NodePopoverContent.js +85 -0
- package/dist/components/shared/XAxisBackground.d.ts +31 -0
- package/dist/components/shared/XAxisBackground.js +93 -0
- package/dist/core/ChartConfig.d.ts +48 -0
- package/dist/core/ChartConfig.js +152 -0
- package/dist/core/ChartContext.d.ts +49 -0
- package/dist/core/ChartContext.js +31 -0
- package/dist/core/ChartTypes.d.ts +119 -0
- package/dist/core/ChartTypes.js +0 -0
- package/dist/index.d.ts +29 -0
- package/dist/index.js +21 -0
- package/dist/services/DataTransformService.d.ts +22 -0
- package/dist/services/DataTransformService.js +29 -0
- package/dist/services/FormatterService.d.ts +24 -0
- package/dist/services/FormatterService.js +22 -0
- package/dist/utils/__tests__/formatters.test.d.ts +1 -0
- package/dist/utils/__tests__/formatters.test.js +333 -0
- package/dist/utils/chartHelpers.d.ts +52 -0
- package/dist/utils/chartHelpers.js +112 -0
- package/dist/utils/dataTransform.d.ts +12 -0
- package/dist/utils/dataTransform.js +64 -0
- package/dist/utils/formatters.d.ts +37 -0
- package/dist/utils/formatters.js +127 -0
- package/dist/utils/indicatorHelpers.d.ts +16 -0
- package/dist/utils/indicatorHelpers.js +15 -0
- package/dist/utils/lazyHelpers.d.ts +29 -0
- package/dist/utils/lazyHelpers.js +15 -0
- package/package.json +68 -0
|
@@ -0,0 +1,127 @@
|
|
|
1
|
+
import { isNil } from "lodash";
|
|
2
|
+
import numeral from "numeral";
|
|
3
|
+
import big from "big.js";
|
|
4
|
+
var formatters_IndicatorUnit = /*#__PURE__*/ function(IndicatorUnit) {
|
|
5
|
+
IndicatorUnit[IndicatorUnit["Number"] = 1] = "Number";
|
|
6
|
+
IndicatorUnit[IndicatorUnit["Percentage"] = 2] = "Percentage";
|
|
7
|
+
IndicatorUnit[IndicatorUnit["Dollar"] = 3] = "Dollar";
|
|
8
|
+
IndicatorUnit[IndicatorUnit["RMB"] = 4] = "RMB";
|
|
9
|
+
return IndicatorUnit;
|
|
10
|
+
}({});
|
|
11
|
+
const UNIT_FORMAT_MAP = {
|
|
12
|
+
[1]: {},
|
|
13
|
+
[2]: {
|
|
14
|
+
suffix: '%'
|
|
15
|
+
},
|
|
16
|
+
[3]: {
|
|
17
|
+
prefix: '$'
|
|
18
|
+
},
|
|
19
|
+
[4]: {
|
|
20
|
+
prefix: '¥'
|
|
21
|
+
},
|
|
22
|
+
[""]: {}
|
|
23
|
+
};
|
|
24
|
+
function getFormatStr(fractionDigits, longFormat) {
|
|
25
|
+
let formatStr = '0,0';
|
|
26
|
+
if (fractionDigits > 0) formatStr += '.' + Array.from({
|
|
27
|
+
length: fractionDigits
|
|
28
|
+
}).map(()=>'0').join('');
|
|
29
|
+
if (longFormat) formatStr += 'a';
|
|
30
|
+
return formatStr;
|
|
31
|
+
}
|
|
32
|
+
function formatNumberV2(value, options, emptyStr = '-') {
|
|
33
|
+
const { fractionDigits = 2, prefix = '', suffix = '', longFormat = false } = options || {};
|
|
34
|
+
let result = emptyStr;
|
|
35
|
+
if (isNil(value) || 'number' == typeof value && isNaN(value) || '' === value || '-' === value) return result;
|
|
36
|
+
const formatStr = getFormatStr(fractionDigits, longFormat);
|
|
37
|
+
result = numeral(value).format(formatStr);
|
|
38
|
+
if ('NaN' === result && formatStr) result = formatStr.split(',')[1];
|
|
39
|
+
return `${prefix}${result}${suffix}`;
|
|
40
|
+
}
|
|
41
|
+
function formatPercentage(value, emptyStr) {
|
|
42
|
+
return formatNumberV2(value, {
|
|
43
|
+
suffix: '%'
|
|
44
|
+
}, emptyStr);
|
|
45
|
+
}
|
|
46
|
+
function getDefaultFormat(_indicatorID) {
|
|
47
|
+
return {
|
|
48
|
+
indicatorUnit: 1,
|
|
49
|
+
indicatorDecimal: 2
|
|
50
|
+
};
|
|
51
|
+
}
|
|
52
|
+
function formatBigNumber(value, indicatorInfo, emptyStr, longFormat) {
|
|
53
|
+
if ('' === value || '-' === value) return '-';
|
|
54
|
+
const { indicatorID, indicatorFormat } = indicatorInfo || {};
|
|
55
|
+
let format = indicatorFormat;
|
|
56
|
+
if (!format) format = getDefaultFormat(indicatorID);
|
|
57
|
+
if (!format) return formatNumberV2(value, {}, emptyStr);
|
|
58
|
+
const { suffix = '', prefix = '' } = UNIT_FORMAT_MAP[format.indicatorUnit || ''] || {};
|
|
59
|
+
let valueRes = 2 === format.indicatorUnit ? 100 * Number(value) : Number(value);
|
|
60
|
+
if (isNaN(valueRes)) return emptyStr || '-';
|
|
61
|
+
if (2 === format.indicatorUnit) return formatNumberV2(valueRes, {
|
|
62
|
+
prefix,
|
|
63
|
+
suffix,
|
|
64
|
+
fractionDigits: format.indicatorDecimal,
|
|
65
|
+
longFormat
|
|
66
|
+
}, emptyStr);
|
|
67
|
+
if (valueRes >= 1000000000) {
|
|
68
|
+
valueRes /= 1000000000;
|
|
69
|
+
return formatNumberV2(valueRes, {
|
|
70
|
+
prefix,
|
|
71
|
+
suffix: 'b',
|
|
72
|
+
fractionDigits: 2,
|
|
73
|
+
longFormat
|
|
74
|
+
}, emptyStr);
|
|
75
|
+
}
|
|
76
|
+
if (valueRes >= 1000000) {
|
|
77
|
+
valueRes /= 1000000;
|
|
78
|
+
return formatNumberV2(valueRes, {
|
|
79
|
+
prefix,
|
|
80
|
+
suffix: 'm',
|
|
81
|
+
fractionDigits: 2,
|
|
82
|
+
longFormat
|
|
83
|
+
}, emptyStr);
|
|
84
|
+
}
|
|
85
|
+
if (valueRes >= 10000) {
|
|
86
|
+
valueRes /= 1000;
|
|
87
|
+
return formatNumberV2(valueRes, {
|
|
88
|
+
prefix,
|
|
89
|
+
suffix: 'k',
|
|
90
|
+
fractionDigits: 2,
|
|
91
|
+
longFormat
|
|
92
|
+
}, emptyStr);
|
|
93
|
+
}
|
|
94
|
+
return formatNumberV2(valueRes, {
|
|
95
|
+
prefix,
|
|
96
|
+
suffix,
|
|
97
|
+
fractionDigits: format.indicatorDecimal,
|
|
98
|
+
longFormat
|
|
99
|
+
}, emptyStr);
|
|
100
|
+
}
|
|
101
|
+
function formatIndicatorV2(value, indicatorInfo, emptyStr, longFormat) {
|
|
102
|
+
if ('' === value || '-' === value) return '-';
|
|
103
|
+
const { indicatorID, indicatorFormat } = indicatorInfo || {};
|
|
104
|
+
let format = indicatorFormat;
|
|
105
|
+
if (!format) format = getDefaultFormat(indicatorID);
|
|
106
|
+
if (!format) return formatNumberV2(value, {}, emptyStr);
|
|
107
|
+
const { suffix = '', prefix = '' } = UNIT_FORMAT_MAP[format.indicatorUnit || ''] || {};
|
|
108
|
+
const valueRes = 2 === format.indicatorUnit ? 100 * Number(value) : value;
|
|
109
|
+
return formatNumberV2(valueRes, {
|
|
110
|
+
prefix,
|
|
111
|
+
suffix,
|
|
112
|
+
fractionDigits: format.indicatorDecimal,
|
|
113
|
+
longFormat
|
|
114
|
+
}, emptyStr);
|
|
115
|
+
}
|
|
116
|
+
class BigNumberUtil {
|
|
117
|
+
static from(value) {
|
|
118
|
+
return new big(value || 0);
|
|
119
|
+
}
|
|
120
|
+
static lt(value1, value2) {
|
|
121
|
+
return BigNumberUtil.from(value1).lt(value2);
|
|
122
|
+
}
|
|
123
|
+
static gt(value1, value2) {
|
|
124
|
+
return BigNumberUtil.from(value1).gt(value2);
|
|
125
|
+
}
|
|
126
|
+
}
|
|
127
|
+
export { BigNumberUtil, formatters_IndicatorUnit as IndicatorUnit, formatBigNumber, formatIndicatorV2, formatNumberV2, formatPercentage };
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 指标相关工具函数
|
|
3
|
+
*/
|
|
4
|
+
import type { IndicatorInfo } from '../core/ChartTypes';
|
|
5
|
+
/**
|
|
6
|
+
* 获取指标名称
|
|
7
|
+
*/
|
|
8
|
+
export declare const getIndicatorName: (indicatorMap: Record<string, IndicatorInfo>, val: string) => string;
|
|
9
|
+
/**
|
|
10
|
+
* 获取指标(去除后缀)
|
|
11
|
+
*/
|
|
12
|
+
export declare const getIndicator: (val: string) => string;
|
|
13
|
+
/**
|
|
14
|
+
* 获取对比指标名称
|
|
15
|
+
*/
|
|
16
|
+
export declare const getIndicatorCompareName: (indicatorMap: Record<string, IndicatorInfo>, val: string) => string;
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
const getIndicatorName = (indicatorMap, val)=>{
|
|
2
|
+
if (!indicatorMap || !indicatorMap[val]) return '';
|
|
3
|
+
const indicator = indicatorMap[val];
|
|
4
|
+
return `${indicator.indicatorFrom || ''} / ${indicator.indicatorName || ''}`;
|
|
5
|
+
};
|
|
6
|
+
const getIndicator = (val)=>{
|
|
7
|
+
let indicator = val;
|
|
8
|
+
if (val.includes('_')) indicator = val.split('_')[0];
|
|
9
|
+
return indicator;
|
|
10
|
+
};
|
|
11
|
+
const getIndicatorCompareName = (indicatorMap, val)=>{
|
|
12
|
+
const indicator = getIndicator(val);
|
|
13
|
+
return getIndicatorName(indicatorMap, indicator);
|
|
14
|
+
};
|
|
15
|
+
export { getIndicator, getIndicatorCompareName, getIndicatorName };
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Lazy Loading 辅助函数
|
|
3
|
+
* 用于简化命名导出组件的 lazy loading
|
|
4
|
+
*/
|
|
5
|
+
/**
|
|
6
|
+
* 创建 lazy 组件(从命名导出)
|
|
7
|
+
*
|
|
8
|
+
* @example
|
|
9
|
+
* const BarChart = createLazyComponent(() => import('@moonton/publish-chart'), 'BarChart');
|
|
10
|
+
*/
|
|
11
|
+
export declare function createLazyComponent<T = any>(importFn: () => Promise<{
|
|
12
|
+
[key: string]: T;
|
|
13
|
+
}>, componentName: string): () => Promise<{
|
|
14
|
+
default: T;
|
|
15
|
+
}>;
|
|
16
|
+
/**
|
|
17
|
+
* 批量创建 lazy 组件
|
|
18
|
+
*
|
|
19
|
+
* @example
|
|
20
|
+
* const { BarChart, LineChart } = createLazyComponents(
|
|
21
|
+
* () => import('@moonton/publish-chart'),
|
|
22
|
+
* ['BarChart', 'LineChart']
|
|
23
|
+
* );
|
|
24
|
+
*/
|
|
25
|
+
export declare function createLazyComponents<T = any>(importFn: () => Promise<{
|
|
26
|
+
[key: string]: T;
|
|
27
|
+
}>, componentNames: string[]): Record<string, () => Promise<{
|
|
28
|
+
default: T;
|
|
29
|
+
}>>;
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
function createLazyComponent(importFn, componentName) {
|
|
2
|
+
return ()=>importFn().then((module)=>({
|
|
3
|
+
default: module[componentName]
|
|
4
|
+
}));
|
|
5
|
+
}
|
|
6
|
+
function createLazyComponents(importFn, componentNames) {
|
|
7
|
+
const components = {};
|
|
8
|
+
componentNames.forEach((name)=>{
|
|
9
|
+
components[name] = ()=>importFn().then((module)=>({
|
|
10
|
+
default: module[name]
|
|
11
|
+
}));
|
|
12
|
+
});
|
|
13
|
+
return components;
|
|
14
|
+
}
|
|
15
|
+
export { createLazyComponent, createLazyComponents };
|
package/package.json
ADDED
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@publishfx/publish-chart",
|
|
3
|
+
"version": "1.3.0",
|
|
4
|
+
"description": "A React chart component library for the Publish platform, including BarChart, LineChart, BarLineChart and other visualization components",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"keywords": [
|
|
7
|
+
"react",
|
|
8
|
+
"chart",
|
|
9
|
+
"visualization",
|
|
10
|
+
"bizcharts",
|
|
11
|
+
"data-visualization"
|
|
12
|
+
],
|
|
13
|
+
"author": "Moonton",
|
|
14
|
+
"license": "ISC",
|
|
15
|
+
"exports": {
|
|
16
|
+
".": {
|
|
17
|
+
"types": "./dist/index.d.ts",
|
|
18
|
+
"import": "./dist/index.js"
|
|
19
|
+
}
|
|
20
|
+
},
|
|
21
|
+
"types": "./dist/index.d.ts",
|
|
22
|
+
"files": [
|
|
23
|
+
"dist"
|
|
24
|
+
],
|
|
25
|
+
"devDependencies": {
|
|
26
|
+
"@antv/data-set": "^0.11.8",
|
|
27
|
+
"@types/jest": "^29.5.12",
|
|
28
|
+
"@types/lodash": "^4.17.20",
|
|
29
|
+
"@types/react": "^18.3.18",
|
|
30
|
+
"@types/react-dom": "^18.3.5",
|
|
31
|
+
"babel-plugin-styled-components": "^2.0.7",
|
|
32
|
+
"big.js": "^6.1.1",
|
|
33
|
+
"bizcharts": "^4.1.19",
|
|
34
|
+
"dayjs": "^1.10.7",
|
|
35
|
+
"jest": "^29.7.0",
|
|
36
|
+
"less": "^4.2.0",
|
|
37
|
+
"lodash": "^4.17.21",
|
|
38
|
+
"numeral": "^2.0.6",
|
|
39
|
+
"react": "^18.3.1",
|
|
40
|
+
"react-dom": "^18.3.1",
|
|
41
|
+
"styled-components": "^5.3.11",
|
|
42
|
+
"ts-jest": "^29.1.2",
|
|
43
|
+
"typescript": "^5.9.3",
|
|
44
|
+
"@moonton/publish-components": "^2.0.3"
|
|
45
|
+
},
|
|
46
|
+
"peerDependencies": {
|
|
47
|
+
"@antv/data-set": "^0.11.8",
|
|
48
|
+
"@arco-design/web-react": "^2.66.0",
|
|
49
|
+
"@types/react": "^18.3.18",
|
|
50
|
+
"@types/react-dom": "^18.3.5",
|
|
51
|
+
"bizcharts": "^4.1.19",
|
|
52
|
+
"react": ">=18.3.1",
|
|
53
|
+
"react-dom": ">=18.3.1"
|
|
54
|
+
},
|
|
55
|
+
"publishConfig": {
|
|
56
|
+
"access": "public",
|
|
57
|
+
"registry": "https://registry.npmjs.org/"
|
|
58
|
+
},
|
|
59
|
+
"scripts": {
|
|
60
|
+
"build": "rslib build",
|
|
61
|
+
"dev": "rslib build --watch",
|
|
62
|
+
"lint": "eslint src --ext .ts,.tsx",
|
|
63
|
+
"lint:fix": "eslint src --ext .ts,.tsx --fix",
|
|
64
|
+
"test": "jest",
|
|
65
|
+
"test:watch": "jest --watch",
|
|
66
|
+
"test:coverage": "jest --coverage"
|
|
67
|
+
}
|
|
68
|
+
}
|