@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,110 @@
|
|
|
1
|
+
import { Fragment, jsx, jsxs } from "react/jsx-runtime";
|
|
2
|
+
import "react";
|
|
3
|
+
import { Popover } from "@arco-design/web-react";
|
|
4
|
+
import { nodeMap } from "../../core/ChartConfig.js";
|
|
5
|
+
import { NodePopoverContent } from "./NodePopoverContent.js";
|
|
6
|
+
const NodeDetail = ({ chartWidth, chartOffset, dvRows, ratio = 1 })=>{
|
|
7
|
+
console.log(dvRows, 'dvRows');
|
|
8
|
+
return /*#__PURE__*/ jsx("div", {
|
|
9
|
+
style: {
|
|
10
|
+
display: 'flex',
|
|
11
|
+
justifyContent: 'space-around',
|
|
12
|
+
width: chartWidth,
|
|
13
|
+
lineHeight: '14px',
|
|
14
|
+
cursor: 'pointer',
|
|
15
|
+
position: 'absolute',
|
|
16
|
+
bottom: -20,
|
|
17
|
+
left: chartOffset
|
|
18
|
+
},
|
|
19
|
+
children: dvRows.length > 0 && dvRows.filter((item)=>!item?.groupType?.includes('_compare') && !item?.indicatorType?.includes('_compare')).map((item, index)=>{
|
|
20
|
+
const infos = [].concat(item.nodeInfos?.info || [], item.nodeInfos?.infosCompare || []);
|
|
21
|
+
return /*#__PURE__*/ jsx(Fragment, {
|
|
22
|
+
children: chartWidth / (dvRows.length / ratio) > 30 ? /*#__PURE__*/ jsx("div", {
|
|
23
|
+
style: {
|
|
24
|
+
width: chartWidth / (dvRows.length / ratio),
|
|
25
|
+
overflow: 'hidden',
|
|
26
|
+
textOverflow: 'ellipsis',
|
|
27
|
+
textAlign: 'center',
|
|
28
|
+
transform: "translateY(-10px)"
|
|
29
|
+
},
|
|
30
|
+
children: infos.length > 0 ? /*#__PURE__*/ jsxs(Popover, {
|
|
31
|
+
blurToHide: true,
|
|
32
|
+
unmountOnExit: true,
|
|
33
|
+
position: "right",
|
|
34
|
+
style: {
|
|
35
|
+
maxWidth: 'auto'
|
|
36
|
+
},
|
|
37
|
+
content: /*#__PURE__*/ jsx(NodePopoverContent, {
|
|
38
|
+
nodeInfos: infos
|
|
39
|
+
}),
|
|
40
|
+
children: [
|
|
41
|
+
infos.map((_info, _index)=>_index <= 1 ? /*#__PURE__*/ jsxs("div", {
|
|
42
|
+
style: {
|
|
43
|
+
whiteSpace: 'nowrap',
|
|
44
|
+
width: chartWidth / (dvRows.length / ratio),
|
|
45
|
+
overflow: 'hidden',
|
|
46
|
+
textOverflow: 'ellipsis',
|
|
47
|
+
textAlign: 'center',
|
|
48
|
+
color: _info?.type !== void 0 ? nodeMap.get(_info.type)?.color : void 0,
|
|
49
|
+
margin: '0 auto'
|
|
50
|
+
},
|
|
51
|
+
children: [
|
|
52
|
+
_info?.name,
|
|
53
|
+
_info?.flag ? '·结束' : ''
|
|
54
|
+
]
|
|
55
|
+
}, `index${_index}`) : null),
|
|
56
|
+
infos.length > 2 ? /*#__PURE__*/ jsx("div", {
|
|
57
|
+
style: {
|
|
58
|
+
whiteSpace: 'nowrap',
|
|
59
|
+
width: chartWidth / (dvRows.length / ratio),
|
|
60
|
+
overflow: 'hidden',
|
|
61
|
+
textOverflow: 'ellipsis',
|
|
62
|
+
textAlign: 'center',
|
|
63
|
+
color: '#6549f2',
|
|
64
|
+
margin: '0 auto'
|
|
65
|
+
},
|
|
66
|
+
children: 0 == item.node && `>>${infos.length}`
|
|
67
|
+
}) : null
|
|
68
|
+
]
|
|
69
|
+
}) : null
|
|
70
|
+
}, index) : /*#__PURE__*/ jsx("div", {
|
|
71
|
+
style: {
|
|
72
|
+
width: 10,
|
|
73
|
+
transform: 'translateY(-14px)'
|
|
74
|
+
},
|
|
75
|
+
children: infos.length > 0 && /*#__PURE__*/ jsx(Popover, {
|
|
76
|
+
blurToHide: true,
|
|
77
|
+
unmountOnExit: true,
|
|
78
|
+
position: "right",
|
|
79
|
+
style: {
|
|
80
|
+
maxWidth: 'auto'
|
|
81
|
+
},
|
|
82
|
+
content: /*#__PURE__*/ jsx(NodePopoverContent, {
|
|
83
|
+
nodeInfos: infos
|
|
84
|
+
}),
|
|
85
|
+
children: /*#__PURE__*/ jsx("div", {
|
|
86
|
+
style: 1 == infos.length ? {
|
|
87
|
+
width: 6,
|
|
88
|
+
height: 6,
|
|
89
|
+
border: `2px solid ${item.color}`,
|
|
90
|
+
borderRadius: '50%',
|
|
91
|
+
margin: '0 auto'
|
|
92
|
+
} : {
|
|
93
|
+
width: 6,
|
|
94
|
+
height: 6,
|
|
95
|
+
margin: '0 auto',
|
|
96
|
+
border: "2px solid",
|
|
97
|
+
borderRadius: '50%',
|
|
98
|
+
borderColor: "transparent",
|
|
99
|
+
backgroundImage: "linear-gradient(to right, #fff, #fff), linear-gradient(0deg, rgb(50, 197, 255) 0px, rgb(182, 32, 224) 44%, rgb(247, 181, 0) 99%)",
|
|
100
|
+
backgroundClip: "padding-box, border-box",
|
|
101
|
+
backgroundOrigin: "padding-box, border-box"
|
|
102
|
+
}
|
|
103
|
+
})
|
|
104
|
+
})
|
|
105
|
+
}, index)
|
|
106
|
+
});
|
|
107
|
+
})
|
|
108
|
+
});
|
|
109
|
+
};
|
|
110
|
+
export { NodeDetail };
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
type NodeInfoItem = {
|
|
3
|
+
area: string;
|
|
4
|
+
description: string;
|
|
5
|
+
endDate: string;
|
|
6
|
+
flag: number;
|
|
7
|
+
name: string;
|
|
8
|
+
startDate: string;
|
|
9
|
+
type: number;
|
|
10
|
+
};
|
|
11
|
+
type NodeGeomProps = {
|
|
12
|
+
pointData: {
|
|
13
|
+
info: Array<NodeInfoItem>;
|
|
14
|
+
infosCompare: Array<NodeInfoItem>;
|
|
15
|
+
};
|
|
16
|
+
pointP: {
|
|
17
|
+
x: number;
|
|
18
|
+
y: number;
|
|
19
|
+
};
|
|
20
|
+
isLegend?: boolean;
|
|
21
|
+
};
|
|
22
|
+
export declare const NodeGeom: React.FC<NodeGeomProps>;
|
|
23
|
+
export {};
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import { Fragment, jsx, jsxs } from "react/jsx-runtime";
|
|
2
|
+
import "react";
|
|
3
|
+
import { Axis, Geom, Legend } from "bizcharts";
|
|
4
|
+
import { NodePopover } from "./NodePopover.js";
|
|
5
|
+
const NodeGeom = ({ pointData, pointP, isLegend = true })=>/*#__PURE__*/ jsxs(Fragment, {
|
|
6
|
+
children: [
|
|
7
|
+
/*#__PURE__*/ jsx(Geom, {
|
|
8
|
+
type: "point",
|
|
9
|
+
position: "groupName*node",
|
|
10
|
+
size: 4,
|
|
11
|
+
shape: 'hollow-circle',
|
|
12
|
+
color: [
|
|
13
|
+
'color',
|
|
14
|
+
(color)=>color
|
|
15
|
+
],
|
|
16
|
+
style: {
|
|
17
|
+
lineWidth: 3
|
|
18
|
+
},
|
|
19
|
+
tooltip: false
|
|
20
|
+
}),
|
|
21
|
+
/*#__PURE__*/ jsx(Axis, {
|
|
22
|
+
name: "node",
|
|
23
|
+
visible: false
|
|
24
|
+
}),
|
|
25
|
+
isLegend && /*#__PURE__*/ jsx(Legend, {
|
|
26
|
+
name: "color",
|
|
27
|
+
visible: false
|
|
28
|
+
}),
|
|
29
|
+
/*#__PURE__*/ jsx(NodePopover, {
|
|
30
|
+
pointData: pointData,
|
|
31
|
+
pointP: pointP
|
|
32
|
+
})
|
|
33
|
+
]
|
|
34
|
+
});
|
|
35
|
+
export { NodeGeom };
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
type NodeInfoItem = {
|
|
3
|
+
area: string;
|
|
4
|
+
description: string;
|
|
5
|
+
endDate: string;
|
|
6
|
+
flag: number;
|
|
7
|
+
name: string;
|
|
8
|
+
startDate: string;
|
|
9
|
+
type: number;
|
|
10
|
+
};
|
|
11
|
+
type NodePopoverProps = {
|
|
12
|
+
pointData: {
|
|
13
|
+
info: Array<NodeInfoItem>;
|
|
14
|
+
infosCompare: Array<NodeInfoItem>;
|
|
15
|
+
};
|
|
16
|
+
pointP: {
|
|
17
|
+
x: number;
|
|
18
|
+
y: number;
|
|
19
|
+
};
|
|
20
|
+
};
|
|
21
|
+
export declare const NodePopover: React.FC<NodePopoverProps>;
|
|
22
|
+
export {};
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
import { Fragment, jsx } from "react/jsx-runtime";
|
|
2
|
+
import { useEffect, useState } from "react";
|
|
3
|
+
import { Popover } from "@arco-design/web-react";
|
|
4
|
+
import { NodePopoverContent } from "./NodePopoverContent.js";
|
|
5
|
+
const NodePopover = ({ pointData, pointP })=>{
|
|
6
|
+
const [nodeInfos, setNodeInfos] = useState([]);
|
|
7
|
+
useEffect(()=>{
|
|
8
|
+
setNodeInfos([
|
|
9
|
+
...pointData.info,
|
|
10
|
+
...pointData.infosCompare
|
|
11
|
+
]);
|
|
12
|
+
}, [
|
|
13
|
+
pointData
|
|
14
|
+
]);
|
|
15
|
+
return /*#__PURE__*/ jsx(Fragment, {
|
|
16
|
+
children: /*#__PURE__*/ jsx(Popover, {
|
|
17
|
+
blurToHide: true,
|
|
18
|
+
unmountOnExit: true,
|
|
19
|
+
position: "right",
|
|
20
|
+
style: {
|
|
21
|
+
maxWidth: 'auto'
|
|
22
|
+
},
|
|
23
|
+
content: /*#__PURE__*/ jsx(Fragment, {
|
|
24
|
+
children: /*#__PURE__*/ jsx(NodePopoverContent, {
|
|
25
|
+
nodeInfos: nodeInfos
|
|
26
|
+
})
|
|
27
|
+
}),
|
|
28
|
+
children: /*#__PURE__*/ jsx("div", {
|
|
29
|
+
style: {
|
|
30
|
+
position: 'absolute',
|
|
31
|
+
top: pointP.y - 10,
|
|
32
|
+
left: pointP.x - 10,
|
|
33
|
+
zIndex: 999,
|
|
34
|
+
width: 20,
|
|
35
|
+
height: 20
|
|
36
|
+
}
|
|
37
|
+
})
|
|
38
|
+
})
|
|
39
|
+
});
|
|
40
|
+
};
|
|
41
|
+
export { NodePopover };
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
type NodeInfoItem = {
|
|
3
|
+
area: string;
|
|
4
|
+
description: string;
|
|
5
|
+
endDate: string;
|
|
6
|
+
flag: number;
|
|
7
|
+
name: string;
|
|
8
|
+
startDate: string;
|
|
9
|
+
type: number;
|
|
10
|
+
};
|
|
11
|
+
type NodePopoverContentProps = {
|
|
12
|
+
nodeInfos: Array<NodeInfoItem>;
|
|
13
|
+
};
|
|
14
|
+
export declare const NodePopoverContent: React.FC<NodePopoverContentProps>;
|
|
15
|
+
export {};
|
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
import { jsx, jsxs } from "react/jsx-runtime";
|
|
2
|
+
import "react";
|
|
3
|
+
import { Tag } from "@arco-design/web-react";
|
|
4
|
+
import { nodeMap } from "../../core/ChartConfig.js";
|
|
5
|
+
const NodePopoverContent = ({ nodeInfos })=>/*#__PURE__*/ jsx("div", {
|
|
6
|
+
style: {
|
|
7
|
+
maxHeight: 'calc(100vh - 200px)',
|
|
8
|
+
overflowY: 'auto'
|
|
9
|
+
},
|
|
10
|
+
children: nodeInfos.length > 0 && nodeInfos.map((item, index)=>{
|
|
11
|
+
const info = nodeMap.get(item.type);
|
|
12
|
+
return /*#__PURE__*/ jsxs("div", {
|
|
13
|
+
style: {
|
|
14
|
+
width: 540,
|
|
15
|
+
padding: 8,
|
|
16
|
+
background: (index + 1) % 2 === 1 ? '#fff' : '#f7f8fa',
|
|
17
|
+
...index < nodeInfos.length - 1 ? {
|
|
18
|
+
borderBottom: '1px solid #e5e6eb'
|
|
19
|
+
} : {}
|
|
20
|
+
},
|
|
21
|
+
children: [
|
|
22
|
+
/*#__PURE__*/ jsxs("div", {
|
|
23
|
+
style: {
|
|
24
|
+
display: 'flex',
|
|
25
|
+
justifyContent: 'space-between'
|
|
26
|
+
},
|
|
27
|
+
children: [
|
|
28
|
+
/*#__PURE__*/ jsxs("div", {
|
|
29
|
+
style: {
|
|
30
|
+
display: 'flex'
|
|
31
|
+
},
|
|
32
|
+
children: [
|
|
33
|
+
/*#__PURE__*/ jsx(Tag, {
|
|
34
|
+
color: info?.bgc,
|
|
35
|
+
style: {
|
|
36
|
+
color: info?.color
|
|
37
|
+
},
|
|
38
|
+
children: info?.des
|
|
39
|
+
}),
|
|
40
|
+
/*#__PURE__*/ jsxs("div", {
|
|
41
|
+
style: {
|
|
42
|
+
fontSize: 14,
|
|
43
|
+
fontWeight: 'bold',
|
|
44
|
+
color: '#1d2129',
|
|
45
|
+
marginLeft: 4
|
|
46
|
+
},
|
|
47
|
+
children: [
|
|
48
|
+
item.name,
|
|
49
|
+
item?.flag ? '·结束' : ''
|
|
50
|
+
]
|
|
51
|
+
})
|
|
52
|
+
]
|
|
53
|
+
}),
|
|
54
|
+
/*#__PURE__*/ jsxs("div", {
|
|
55
|
+
style: {
|
|
56
|
+
fontSize: 12,
|
|
57
|
+
color: '#86909c',
|
|
58
|
+
lineHeight: '28px'
|
|
59
|
+
},
|
|
60
|
+
children: [
|
|
61
|
+
item.startDate,
|
|
62
|
+
item?.endDate ? `~${item?.endDate}` : ''
|
|
63
|
+
]
|
|
64
|
+
})
|
|
65
|
+
]
|
|
66
|
+
}),
|
|
67
|
+
/*#__PURE__*/ jsx("div", {
|
|
68
|
+
style: {
|
|
69
|
+
fontSize: 12,
|
|
70
|
+
color: '#1d2129'
|
|
71
|
+
},
|
|
72
|
+
children: item.description
|
|
73
|
+
}),
|
|
74
|
+
/*#__PURE__*/ jsx("div", {
|
|
75
|
+
style: {
|
|
76
|
+
fontSize: 12,
|
|
77
|
+
color: '#4e5969'
|
|
78
|
+
},
|
|
79
|
+
children: item.area
|
|
80
|
+
})
|
|
81
|
+
]
|
|
82
|
+
}, index);
|
|
83
|
+
})
|
|
84
|
+
});
|
|
85
|
+
export { NodePopoverContent };
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* X轴灰色背景组件
|
|
3
|
+
* 用于在图表中为指定的 x 轴数据点添加灰色背景
|
|
4
|
+
*/
|
|
5
|
+
import React from 'react';
|
|
6
|
+
export interface XAxisBackgroundProps {
|
|
7
|
+
/** x 轴字段名 */
|
|
8
|
+
x: string;
|
|
9
|
+
/** 原始数据 */
|
|
10
|
+
data: any[];
|
|
11
|
+
/** 是否渲染背景 */
|
|
12
|
+
isHighlight: boolean;
|
|
13
|
+
/** 筛选函数,返回 true 表示该数据点需要显示背景 */
|
|
14
|
+
filterFn: (item: any) => boolean;
|
|
15
|
+
/** 主图柱状图的宽度(可选,用于精确控制背景宽度) */
|
|
16
|
+
mainBarSize?: number;
|
|
17
|
+
/** 数据长度(可选,用于动态调整背景宽度) */
|
|
18
|
+
dataLength?: number;
|
|
19
|
+
/** 背景高度(可选,默认 1000) */
|
|
20
|
+
backgroundHeight?: number;
|
|
21
|
+
/** 背景颜色(可选,默认 '#cccccc') */
|
|
22
|
+
backgroundColor?: string;
|
|
23
|
+
/** 背景透明度(可选,默认 0.8) */
|
|
24
|
+
backgroundOpacity?: number;
|
|
25
|
+
/** 背景宽度倍数(可选,默认 1.2,表示比主图宽 20%) */
|
|
26
|
+
sizeMultiplier?: number;
|
|
27
|
+
/** 是否水平布局 */
|
|
28
|
+
isHorizontal?: boolean;
|
|
29
|
+
}
|
|
30
|
+
declare const XAxisBackground: React.FC<XAxisBackgroundProps>;
|
|
31
|
+
export default XAxisBackground;
|
|
@@ -0,0 +1,93 @@
|
|
|
1
|
+
import { jsx, jsxs } from "react/jsx-runtime";
|
|
2
|
+
import { useEffect, useMemo, useRef } from "react";
|
|
3
|
+
import { Axis, Coordinate, Interval, View } from "bizcharts";
|
|
4
|
+
const STRIPE_PATTERN_THRESHOLD = 10;
|
|
5
|
+
const XAxisBackground = ({ x, data, isHighlight, filterFn, mainBarSize, dataLength, backgroundHeight = 1000, backgroundColor = '#f1f1f1', backgroundOpacity = 0.8, sizeMultiplier = 1.2, isHorizontal = false })=>{
|
|
6
|
+
const backgroundPatternRef = useRef(null);
|
|
7
|
+
const createBackgroundPattern = (color)=>{
|
|
8
|
+
const patternCanvas = document.createElement('canvas');
|
|
9
|
+
patternCanvas.width = 20;
|
|
10
|
+
patternCanvas.height = 20;
|
|
11
|
+
const patternCtx = patternCanvas.getContext('2d');
|
|
12
|
+
if (!patternCtx) return patternCanvas;
|
|
13
|
+
patternCtx.fillStyle = color;
|
|
14
|
+
patternCtx.fillRect(0, 0, patternCanvas.width, patternCanvas.height);
|
|
15
|
+
return patternCanvas;
|
|
16
|
+
};
|
|
17
|
+
useEffect(()=>{
|
|
18
|
+
const offscreen = document.createElement('canvas');
|
|
19
|
+
const ctx = offscreen.getContext('2d');
|
|
20
|
+
if (!ctx) return;
|
|
21
|
+
const sourceCanvas = createBackgroundPattern(backgroundColor);
|
|
22
|
+
const pattern = ctx.createPattern(sourceCanvas, 'repeat');
|
|
23
|
+
if (pattern) backgroundPatternRef.current = pattern;
|
|
24
|
+
}, [
|
|
25
|
+
backgroundColor
|
|
26
|
+
]);
|
|
27
|
+
const backgroundData = useMemo(()=>{
|
|
28
|
+
const allXValues = new Set();
|
|
29
|
+
const filteredXValues = new Set();
|
|
30
|
+
data.forEach((item)=>{
|
|
31
|
+
if (item[x]) {
|
|
32
|
+
allXValues.add(item[x]);
|
|
33
|
+
if (filterFn(item)) filteredXValues.add(item[x]);
|
|
34
|
+
}
|
|
35
|
+
});
|
|
36
|
+
return Array.from(allXValues).map((xValue)=>({
|
|
37
|
+
[x]: xValue,
|
|
38
|
+
indicatorValue: filteredXValues.has(xValue) ? backgroundHeight : 0,
|
|
39
|
+
isBackground: true
|
|
40
|
+
}));
|
|
41
|
+
}, [
|
|
42
|
+
data,
|
|
43
|
+
x,
|
|
44
|
+
filterFn,
|
|
45
|
+
backgroundHeight
|
|
46
|
+
]);
|
|
47
|
+
const backgroundSize = useMemo(()=>{
|
|
48
|
+
if (mainBarSize) return mainBarSize * sizeMultiplier * (isHorizontal ? 0.5 : 1);
|
|
49
|
+
const length = dataLength || data.length;
|
|
50
|
+
return length > STRIPE_PATTERN_THRESHOLD ? 50 : 80;
|
|
51
|
+
}, [
|
|
52
|
+
mainBarSize,
|
|
53
|
+
dataLength,
|
|
54
|
+
data.length,
|
|
55
|
+
sizeMultiplier
|
|
56
|
+
]);
|
|
57
|
+
if (0 === backgroundData.length || !isHighlight) return null;
|
|
58
|
+
return /*#__PURE__*/ jsxs(View, {
|
|
59
|
+
data: backgroundData,
|
|
60
|
+
scale: {
|
|
61
|
+
indicatorValue: {
|
|
62
|
+
type: 'linear',
|
|
63
|
+
max: backgroundHeight
|
|
64
|
+
}
|
|
65
|
+
},
|
|
66
|
+
padding: 0,
|
|
67
|
+
children: [
|
|
68
|
+
/*#__PURE__*/ jsx(Interval, {
|
|
69
|
+
position: `${x}*indicatorValue`,
|
|
70
|
+
style: {
|
|
71
|
+
fill: backgroundPatternRef.current || backgroundColor,
|
|
72
|
+
fillOpacity: backgroundPatternRef.current ? backgroundOpacity : 1,
|
|
73
|
+
cursor: 'default'
|
|
74
|
+
},
|
|
75
|
+
tooltip: false,
|
|
76
|
+
size: backgroundSize
|
|
77
|
+
}),
|
|
78
|
+
/*#__PURE__*/ jsx(Coordinate, {
|
|
79
|
+
transpose: isHorizontal
|
|
80
|
+
}),
|
|
81
|
+
/*#__PURE__*/ jsx(Axis, {
|
|
82
|
+
name: "indicatorValue",
|
|
83
|
+
visible: false
|
|
84
|
+
}),
|
|
85
|
+
/*#__PURE__*/ jsx(Axis, {
|
|
86
|
+
name: x,
|
|
87
|
+
visible: false
|
|
88
|
+
})
|
|
89
|
+
]
|
|
90
|
+
});
|
|
91
|
+
};
|
|
92
|
+
const shared_XAxisBackground = XAxisBackground;
|
|
93
|
+
export { shared_XAxisBackground as default };
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 图表配置接口
|
|
3
|
+
*/
|
|
4
|
+
export interface ChartConfig {
|
|
5
|
+
/** 基础图表配置 */
|
|
6
|
+
baseChartConfig: {
|
|
7
|
+
appendPadding?: number[];
|
|
8
|
+
padding?: string | number[];
|
|
9
|
+
autoFit?: boolean;
|
|
10
|
+
limitInPlot?: boolean;
|
|
11
|
+
forceUpdate?: boolean;
|
|
12
|
+
animate?: {
|
|
13
|
+
leave?: boolean;
|
|
14
|
+
};
|
|
15
|
+
};
|
|
16
|
+
/** 主题配置 */
|
|
17
|
+
theme: {
|
|
18
|
+
colors: string[];
|
|
19
|
+
combineColors?: string[];
|
|
20
|
+
};
|
|
21
|
+
/** 布局配置 */
|
|
22
|
+
layout: {
|
|
23
|
+
barPaddingRight?: number;
|
|
24
|
+
horBarPaddingRight?: number;
|
|
25
|
+
};
|
|
26
|
+
}
|
|
27
|
+
/**
|
|
28
|
+
* 默认图表配置
|
|
29
|
+
*/
|
|
30
|
+
export declare const defaultChartConfig: ChartConfig;
|
|
31
|
+
/**
|
|
32
|
+
* 从 bizcharts 主题获取颜色(如果可用)
|
|
33
|
+
*/
|
|
34
|
+
export declare const getThemeColors: () => string[];
|
|
35
|
+
/**
|
|
36
|
+
* 合并配置
|
|
37
|
+
*/
|
|
38
|
+
export declare const mergeChartConfig: (defaultConfig: ChartConfig, userConfig: Partial<ChartConfig>) => ChartConfig;
|
|
39
|
+
export declare const nodeMap: Map<number, {
|
|
40
|
+
des: string;
|
|
41
|
+
color: string;
|
|
42
|
+
bgc: string;
|
|
43
|
+
}>;
|
|
44
|
+
export declare const nodeTextMap: Map<string, {
|
|
45
|
+
type: number;
|
|
46
|
+
color: string;
|
|
47
|
+
bgc: string;
|
|
48
|
+
}>;
|
|
@@ -0,0 +1,152 @@
|
|
|
1
|
+
import { getTheme } from "bizcharts";
|
|
2
|
+
const defaultChartConfig = {
|
|
3
|
+
baseChartConfig: {
|
|
4
|
+
appendPadding: [
|
|
5
|
+
20,
|
|
6
|
+
0,
|
|
7
|
+
10,
|
|
8
|
+
0
|
|
9
|
+
],
|
|
10
|
+
padding: 'auto',
|
|
11
|
+
autoFit: true,
|
|
12
|
+
limitInPlot: false,
|
|
13
|
+
forceUpdate: false,
|
|
14
|
+
animate: {
|
|
15
|
+
leave: false
|
|
16
|
+
}
|
|
17
|
+
},
|
|
18
|
+
theme: {
|
|
19
|
+
colors: [
|
|
20
|
+
'#5B8FF9',
|
|
21
|
+
'#5AD8A6',
|
|
22
|
+
'#5D7092',
|
|
23
|
+
'#F6BD16',
|
|
24
|
+
'#6F5EF9',
|
|
25
|
+
'#6DC8EC',
|
|
26
|
+
'#945FB9',
|
|
27
|
+
'#FF9845',
|
|
28
|
+
'#1E9493',
|
|
29
|
+
'#FF99C3',
|
|
30
|
+
'#8CD85A',
|
|
31
|
+
'#FE765E',
|
|
32
|
+
'#67A1FF',
|
|
33
|
+
'#D85ACB',
|
|
34
|
+
'#F95B8F'
|
|
35
|
+
],
|
|
36
|
+
combineColors: [
|
|
37
|
+
'#FF8C00',
|
|
38
|
+
'#FFD700'
|
|
39
|
+
]
|
|
40
|
+
},
|
|
41
|
+
layout: {
|
|
42
|
+
barPaddingRight: 10,
|
|
43
|
+
horBarPaddingRight: 50
|
|
44
|
+
}
|
|
45
|
+
};
|
|
46
|
+
const getThemeColors = ()=>{
|
|
47
|
+
try {
|
|
48
|
+
const theme = getTheme();
|
|
49
|
+
return theme.colors10 || defaultChartConfig.theme.colors;
|
|
50
|
+
} catch {
|
|
51
|
+
return defaultChartConfig.theme.colors;
|
|
52
|
+
}
|
|
53
|
+
};
|
|
54
|
+
const mergeChartConfig = (defaultConfig, userConfig)=>({
|
|
55
|
+
baseChartConfig: {
|
|
56
|
+
...defaultConfig.baseChartConfig,
|
|
57
|
+
...userConfig.baseChartConfig
|
|
58
|
+
},
|
|
59
|
+
theme: {
|
|
60
|
+
...defaultConfig.theme,
|
|
61
|
+
...userConfig.theme
|
|
62
|
+
},
|
|
63
|
+
layout: {
|
|
64
|
+
...defaultConfig.layout,
|
|
65
|
+
...userConfig.layout
|
|
66
|
+
}
|
|
67
|
+
});
|
|
68
|
+
const nodeMap = new Map([
|
|
69
|
+
[
|
|
70
|
+
1,
|
|
71
|
+
{
|
|
72
|
+
des: '版本信息',
|
|
73
|
+
color: '#F5319D',
|
|
74
|
+
bgc: '#FFE8F1'
|
|
75
|
+
}
|
|
76
|
+
],
|
|
77
|
+
[
|
|
78
|
+
2,
|
|
79
|
+
{
|
|
80
|
+
des: '市场信息',
|
|
81
|
+
color: '#0FC6C2',
|
|
82
|
+
bgc: '#E8FFFB'
|
|
83
|
+
}
|
|
84
|
+
],
|
|
85
|
+
[
|
|
86
|
+
3,
|
|
87
|
+
{
|
|
88
|
+
des: '投放信息',
|
|
89
|
+
color: '#F77234',
|
|
90
|
+
bgc: '#FFF3E8'
|
|
91
|
+
}
|
|
92
|
+
],
|
|
93
|
+
[
|
|
94
|
+
4,
|
|
95
|
+
{
|
|
96
|
+
des: '节假日信息',
|
|
97
|
+
color: '#7816FF',
|
|
98
|
+
bgc: '#F5E8FF'
|
|
99
|
+
}
|
|
100
|
+
],
|
|
101
|
+
[
|
|
102
|
+
5,
|
|
103
|
+
{
|
|
104
|
+
des: '地区突发事件',
|
|
105
|
+
color: '#F53F3F',
|
|
106
|
+
bgc: '#FFECE8'
|
|
107
|
+
}
|
|
108
|
+
]
|
|
109
|
+
]);
|
|
110
|
+
const nodeTextMap = new Map([
|
|
111
|
+
[
|
|
112
|
+
'版本信息',
|
|
113
|
+
{
|
|
114
|
+
type: 1,
|
|
115
|
+
color: '#F5319D',
|
|
116
|
+
bgc: '#FFE8F1'
|
|
117
|
+
}
|
|
118
|
+
],
|
|
119
|
+
[
|
|
120
|
+
'市场信息',
|
|
121
|
+
{
|
|
122
|
+
type: 2,
|
|
123
|
+
color: '#0FC6C2',
|
|
124
|
+
bgc: '#E8FFFB'
|
|
125
|
+
}
|
|
126
|
+
],
|
|
127
|
+
[
|
|
128
|
+
'投放信息',
|
|
129
|
+
{
|
|
130
|
+
type: 3,
|
|
131
|
+
color: '#F77234',
|
|
132
|
+
bgc: '#FFF3E8'
|
|
133
|
+
}
|
|
134
|
+
],
|
|
135
|
+
[
|
|
136
|
+
'节假日信息',
|
|
137
|
+
{
|
|
138
|
+
type: 4,
|
|
139
|
+
color: '#7816FF',
|
|
140
|
+
bgc: '#F5E8FF'
|
|
141
|
+
}
|
|
142
|
+
],
|
|
143
|
+
[
|
|
144
|
+
'地区突发事件',
|
|
145
|
+
{
|
|
146
|
+
type: 5,
|
|
147
|
+
color: '#F53F3F',
|
|
148
|
+
bgc: '#FFECE8'
|
|
149
|
+
}
|
|
150
|
+
]
|
|
151
|
+
]);
|
|
152
|
+
export { defaultChartConfig, getThemeColors, mergeChartConfig, nodeMap, nodeTextMap };
|