@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.
Files changed (66) hide show
  1. package/README.md +143 -0
  2. package/dist/adapters/DataAdapter.d.ts +33 -0
  3. package/dist/adapters/DataAdapter.js +75 -0
  4. package/dist/adapters/TypeAdapter.d.ts +40 -0
  5. package/dist/adapters/TypeAdapter.js +26 -0
  6. package/dist/components/base/BarChart.d.ts +7 -0
  7. package/dist/components/base/BarChart.js +362 -0
  8. package/dist/components/base/BarChart.lazy.d.ts +5 -0
  9. package/dist/components/base/BarChart.lazy.js +2 -0
  10. package/dist/components/base/LineChart.d.ts +7 -0
  11. package/dist/components/base/LineChart.js +321 -0
  12. package/dist/components/base/LineChart.lazy.d.ts +5 -0
  13. package/dist/components/base/LineChart.lazy.js +2 -0
  14. package/dist/components/composite/BarLineAdapter.d.ts +22 -0
  15. package/dist/components/composite/BarLineAdapter.js +61 -0
  16. package/dist/components/composite/BarLineAdapter.lazy.d.ts +5 -0
  17. package/dist/components/composite/BarLineAdapter.lazy.js +2 -0
  18. package/dist/components/composite/BarLineChart.d.ts +7 -0
  19. package/dist/components/composite/BarLineChart.js +255 -0
  20. package/dist/components/composite/BarLineChart.lazy.d.ts +5 -0
  21. package/dist/components/composite/BarLineChart.lazy.js +2 -0
  22. package/dist/components/composite/BarLineCompareWeekend.d.ts +10 -0
  23. package/dist/components/composite/BarLineCompareWeekend.js +502 -0
  24. package/dist/components/composite/GroupBarLine.d.ts +11 -0
  25. package/dist/components/composite/GroupBarLine.js +546 -0
  26. package/dist/components/composite/GroupBarLine.lazy.d.ts +5 -0
  27. package/dist/components/composite/GroupBarLine.lazy.js +2 -0
  28. package/dist/components/composite/GroupCompare.d.ts +10 -0
  29. package/dist/components/composite/GroupCompare.js +620 -0
  30. package/dist/components/shared/AuxiliaryLine.d.ts +8 -0
  31. package/dist/components/shared/AuxiliaryLine.js +64 -0
  32. package/dist/components/shared/NodeDetail.d.ts +9 -0
  33. package/dist/components/shared/NodeDetail.js +110 -0
  34. package/dist/components/shared/NodeGeom.d.ts +23 -0
  35. package/dist/components/shared/NodeGeom.js +35 -0
  36. package/dist/components/shared/NodePopover.d.ts +22 -0
  37. package/dist/components/shared/NodePopover.js +41 -0
  38. package/dist/components/shared/NodePopoverContent.d.ts +15 -0
  39. package/dist/components/shared/NodePopoverContent.js +85 -0
  40. package/dist/components/shared/XAxisBackground.d.ts +31 -0
  41. package/dist/components/shared/XAxisBackground.js +93 -0
  42. package/dist/core/ChartConfig.d.ts +48 -0
  43. package/dist/core/ChartConfig.js +152 -0
  44. package/dist/core/ChartContext.d.ts +49 -0
  45. package/dist/core/ChartContext.js +31 -0
  46. package/dist/core/ChartTypes.d.ts +119 -0
  47. package/dist/core/ChartTypes.js +0 -0
  48. package/dist/index.d.ts +29 -0
  49. package/dist/index.js +21 -0
  50. package/dist/services/DataTransformService.d.ts +22 -0
  51. package/dist/services/DataTransformService.js +29 -0
  52. package/dist/services/FormatterService.d.ts +24 -0
  53. package/dist/services/FormatterService.js +22 -0
  54. package/dist/utils/__tests__/formatters.test.d.ts +1 -0
  55. package/dist/utils/__tests__/formatters.test.js +333 -0
  56. package/dist/utils/chartHelpers.d.ts +52 -0
  57. package/dist/utils/chartHelpers.js +112 -0
  58. package/dist/utils/dataTransform.d.ts +12 -0
  59. package/dist/utils/dataTransform.js +64 -0
  60. package/dist/utils/formatters.d.ts +37 -0
  61. package/dist/utils/formatters.js +127 -0
  62. package/dist/utils/indicatorHelpers.d.ts +16 -0
  63. package/dist/utils/indicatorHelpers.js +15 -0
  64. package/dist/utils/lazyHelpers.d.ts +29 -0
  65. package/dist/utils/lazyHelpers.js +15 -0
  66. package/package.json +68 -0
@@ -0,0 +1,2 @@
1
+ import BarChart from "./BarChart.js";
2
+ export { BarChart as default };
@@ -0,0 +1,7 @@
1
+ /**
2
+ * 基础折线图组件
3
+ */
4
+ import React from 'react';
5
+ import type { BaseChartProps } from '../../core/ChartTypes';
6
+ declare const _default: React.NamedExoticComponent<BaseChartProps>;
7
+ export default _default;
@@ -0,0 +1,321 @@
1
+ import { Fragment, jsx, jsxs } from "react/jsx-runtime";
2
+ import { memo, useCallback, useEffect, useMemo, useState } from "react";
3
+ import { Axis, Chart, Line, Tooltip, View } from "bizcharts";
4
+ import { useChartContext } from "../../core/ChartContext.js";
5
+ import { mergeChartConfig } from "../../core/ChartConfig.js";
6
+ import { calculateBarWidth, getAxisFormat, getAxisHorPaddingByText, getChartKey } from "../../utils/chartHelpers.js";
7
+ import AuxiliaryLine from "../shared/AuxiliaryLine.js";
8
+ import XAxisBackground from "../shared/XAxisBackground.js";
9
+ import { DataAdapter } from "../../adapters/DataAdapter.js";
10
+ import { NodeDetail } from "../shared/NodeDetail.js";
11
+ import { NodeGeom } from "../shared/NodeGeom.js";
12
+ const LineChart = ({ height = 300, data, x = '', y = '', indicatorMap, onChartClick, legend = '', config, nodeSetting = {
13
+ showType: 0,
14
+ type: []
15
+ }, auxiliaryLineData, highlightDate = [] })=>{
16
+ const { formatter, dataTransform, config: contextConfig } = useChartContext();
17
+ const mergedConfig = useMemo(()=>mergeChartConfig(contextConfig, {}), [
18
+ contextConfig
19
+ ]);
20
+ const safeIndicatorMap = indicatorMap || contextConfig.indicatorMap || {};
21
+ const safeLegend = legend || y;
22
+ const chartConfig = config || {};
23
+ const { isDataTag = false, isHighlight = true } = chartConfig;
24
+ const transformedData = useMemo(()=>{
25
+ const result = DataAdapter.transform(data, 'line', {
26
+ type: 'line',
27
+ x,
28
+ y
29
+ });
30
+ return result.map((item)=>dataTransform.processNodeInfo(item, contextConfig.nodeMap));
31
+ }, [
32
+ data,
33
+ x,
34
+ y,
35
+ dataTransform,
36
+ contextConfig.nodeMap
37
+ ]);
38
+ const [chartWidth, setChartWidth] = useState(0);
39
+ const [chartOffset, setChartOffset] = useState(0);
40
+ const [padding, setPadding] = useState([
41
+ 10,
42
+ 0
43
+ ]);
44
+ const [axisHorPadding, setAxisHorPadding] = useState(0);
45
+ const [pointP, setPointP] = useState({
46
+ x: 0,
47
+ y: 0
48
+ });
49
+ const [pointData, setPointData] = useState({
50
+ info: [],
51
+ infosCompare: []
52
+ });
53
+ const [mainBarSize, setMainBarSize] = useState(void 0);
54
+ const maxY = useMemo(()=>{
55
+ const values = transformedData.filter((item)=>'-' !== item[y] && void 0 !== item[y] && null !== item[y]).map((item)=>Number(item[y]));
56
+ const maxData = Math.max(...values.length > 0 ? values : [
57
+ 0
58
+ ]);
59
+ const maxAuxiliary = auxiliaryLineData?.length ? Math.max(...auxiliaryLineData.map((item)=>item.value)) : 0;
60
+ return Math.max(maxData, maxAuxiliary);
61
+ }, [
62
+ transformedData,
63
+ y,
64
+ auxiliaryLineData
65
+ ]);
66
+ useEffect(()=>{
67
+ if (nodeSetting?.showType === 2 && chartWidth / transformedData.length > 30) if (transformedData.some((item)=>item?.nodeLen > 2)) setPadding([
68
+ 10,
69
+ 10,
70
+ 40,
71
+ 0
72
+ ]);
73
+ else transformedData.some((item)=>item?.nodeLen === 2) ? setPadding([
74
+ 10,
75
+ 10,
76
+ 24,
77
+ 0
78
+ ]) : setPadding([
79
+ 20,
80
+ 10,
81
+ 10,
82
+ 0
83
+ ]);
84
+ else setPadding([
85
+ 20,
86
+ 10,
87
+ 10,
88
+ 0
89
+ ]);
90
+ }, [
91
+ chartWidth,
92
+ transformedData
93
+ ]);
94
+ useEffect(()=>{
95
+ if (maxY > Math.max(...transformedData.filter((item)=>'-' !== item[y]).map((item)=>item[y]))) setPadding((pre)=>[
96
+ 25,
97
+ pre[1],
98
+ pre[2],
99
+ pre[3]
100
+ ]);
101
+ }, [
102
+ maxY,
103
+ transformedData,
104
+ y
105
+ ]);
106
+ const filterFn = useMemo(()=>(item)=>highlightDate?.includes(item.groupName) ?? false, [
107
+ highlightDate
108
+ ]);
109
+ const formatAxis = useCallback((val)=>{
110
+ setAxisHorPadding(getAxisHorPaddingByText(val, safeIndicatorMap, safeLegend) - 22);
111
+ return getAxisFormat(val, safeIndicatorMap, safeLegend);
112
+ }, [
113
+ safeIndicatorMap,
114
+ safeLegend
115
+ ]);
116
+ return /*#__PURE__*/ jsxs(Chart, {
117
+ height: height,
118
+ data: transformedData,
119
+ ...mergedConfig.baseChartConfig,
120
+ appendPadding: padding,
121
+ onClick: (e, chart)=>{
122
+ const value = chart.getTooltipItems({
123
+ x: e.x,
124
+ y: e.y
125
+ });
126
+ onChartClick && onChartClick(value[0]);
127
+ },
128
+ scale: {
129
+ [y]: {
130
+ type: 'linear-strict',
131
+ max: maxY,
132
+ nice: true
133
+ }
134
+ },
135
+ onPointMouseover: (e)=>{
136
+ if (1 === nodeSetting.showType) {
137
+ setPointP({
138
+ x: e.data.x,
139
+ y: e.data.y
140
+ });
141
+ setPointData(e.data.data.nodeInfos || {
142
+ info: [],
143
+ infosCompare: []
144
+ });
145
+ }
146
+ },
147
+ onAfterrender: (_e, chart)=>{
148
+ if (2 === nodeSetting.showType) {
149
+ setChartWidth(chart.coordinateBBox.width);
150
+ setChartOffset(chart.coordinateBBox.x);
151
+ }
152
+ const estimatedBarWidth = calculateBarWidth(chart, transformedData, x, 0.5);
153
+ if (void 0 !== estimatedBarWidth) setMainBarSize(estimatedBarWidth);
154
+ },
155
+ children: [
156
+ /*#__PURE__*/ jsx(XAxisBackground, {
157
+ x: x,
158
+ data: transformedData,
159
+ isHighlight: isHighlight,
160
+ filterFn: filterFn,
161
+ dataLength: transformedData.length,
162
+ mainBarSize: mainBarSize
163
+ }),
164
+ /*#__PURE__*/ jsx(Line, {
165
+ position: `${x}*${y}`,
166
+ style: {
167
+ cursor: 'pointer'
168
+ },
169
+ shape: "smooth",
170
+ label: [
171
+ y,
172
+ (v)=>{
173
+ const content = isDataTag ? formatter.formatIndicator(v, safeIndicatorMap[safeLegend]) : void 0;
174
+ return {
175
+ content: content || ''
176
+ };
177
+ }
178
+ ]
179
+ }),
180
+ /*#__PURE__*/ jsx(Tooltip, {
181
+ shared: true,
182
+ showCrosshairs: true,
183
+ children: (title, items)=>/*#__PURE__*/ jsxs("div", {
184
+ style: {
185
+ padding: '10px 0'
186
+ },
187
+ children: [
188
+ title,
189
+ items && /*#__PURE__*/ jsxs(Fragment, {
190
+ children: [
191
+ /*#__PURE__*/ jsx("div", {
192
+ style: {
193
+ marginTop: '10px'
194
+ },
195
+ children: items.map((it, index)=>/*#__PURE__*/ jsxs("div", {
196
+ style: {
197
+ display: 'flex',
198
+ justifyContent: 'space-between'
199
+ },
200
+ children: [
201
+ /*#__PURE__*/ jsxs("span", {
202
+ children: [
203
+ /*#__PURE__*/ jsx("span", {
204
+ style: {
205
+ width: '8px',
206
+ height: '8px',
207
+ backgroundColor: it.color,
208
+ display: 'inline-block',
209
+ borderRadius: '50%',
210
+ marginRight: '8px'
211
+ }
212
+ }),
213
+ safeIndicatorMap[safeLegend]?.indicatorName || '',
214
+ ":"
215
+ ]
216
+ }),
217
+ /*#__PURE__*/ jsx("span", {
218
+ style: {
219
+ fontWeight: 'bold',
220
+ paddingLeft: '10px'
221
+ },
222
+ children: formatter.formatIndicator(it.value, safeIndicatorMap[safeLegend])
223
+ })
224
+ ]
225
+ }, index))
226
+ }),
227
+ auxiliaryLineData && auxiliaryLineData.map((item, index)=>/*#__PURE__*/ jsxs("div", {
228
+ style: {
229
+ marginLeft: '16px',
230
+ marginTop: '10px',
231
+ display: 'flex',
232
+ justifyContent: 'space-between'
233
+ },
234
+ children: [
235
+ /*#__PURE__*/ jsxs("div", {
236
+ style: {
237
+ marginRight: '8px'
238
+ },
239
+ children: [
240
+ item.name,
241
+ ":"
242
+ ]
243
+ }),
244
+ /*#__PURE__*/ jsx("div", {
245
+ children: formatter.formatIndicator(item.value, safeIndicatorMap[safeLegend])
246
+ })
247
+ ]
248
+ }, index))
249
+ ]
250
+ })
251
+ ]
252
+ })
253
+ }),
254
+ auxiliaryLineData && auxiliaryLineData.length > 0 && /*#__PURE__*/ jsxs(View, {
255
+ data: transformedData,
256
+ scale: {
257
+ [y]: {
258
+ type: 'linear-strict',
259
+ max: maxY,
260
+ nice: true
261
+ }
262
+ },
263
+ padding: [
264
+ 0,
265
+ 0,
266
+ 0,
267
+ -axisHorPadding
268
+ ],
269
+ children: [
270
+ /*#__PURE__*/ jsx(Axis, {
271
+ name: y,
272
+ visible: false
273
+ }),
274
+ /*#__PURE__*/ jsx(Axis, {
275
+ name: x,
276
+ visible: false
277
+ }),
278
+ /*#__PURE__*/ jsx(Line, {
279
+ position: `${x}*${y}`,
280
+ visible: false
281
+ }),
282
+ auxiliaryLineData.map((item, index)=>/*#__PURE__*/ jsx(AuxiliaryLine, {
283
+ name: item.name,
284
+ value: item.value
285
+ }, index))
286
+ ]
287
+ }, axisHorPadding),
288
+ /*#__PURE__*/ jsx(Axis, {
289
+ name: y,
290
+ label: {
291
+ formatter: formatAxis
292
+ }
293
+ }),
294
+ /*#__PURE__*/ jsx(Axis, {
295
+ grid: null,
296
+ name: x,
297
+ label: {
298
+ autoEllipsis: true
299
+ }
300
+ }),
301
+ transformedData.some((item)=>item?.nodeInfos?.info?.length > 0 || item?.nodeInfos?.infosCompare?.length > 0) && /*#__PURE__*/ jsxs(Fragment, {
302
+ children: [
303
+ 1 === nodeSetting.showType && NodeGeom && /*#__PURE__*/ jsx(NodeGeom, {
304
+ pointData: pointData,
305
+ pointP: pointP
306
+ }),
307
+ 2 === nodeSetting.showType && NodeDetail && (0 === chartOffset || chartOffset) && /*#__PURE__*/ jsx(NodeDetail, {
308
+ chartWidth: chartWidth,
309
+ chartOffset: chartOffset,
310
+ dvRows: transformedData
311
+ })
312
+ ]
313
+ })
314
+ ]
315
+ }, getChartKey({
316
+ config,
317
+ nodeSetting
318
+ }));
319
+ };
320
+ const base_LineChart = /*#__PURE__*/ memo(LineChart);
321
+ export { base_LineChart as default };
@@ -0,0 +1,5 @@
1
+ /**
2
+ * LineChart Lazy Loading 入口
3
+ * 提供默认导出,支持 lazy() 直接使用
4
+ */
5
+ export { default } from './LineChart';
@@ -0,0 +1,2 @@
1
+ import LineChart from "./LineChart.js";
2
+ export { LineChart as default };
@@ -0,0 +1,22 @@
1
+ /**
2
+ * 组合图(不带对比时间)
3
+ * barLine 到 groupBarLine 的数据适配器组件
4
+ */
5
+ import React from 'react';
6
+ import type { BaseChartProps } from '../../core/ChartTypes';
7
+ interface BarLineAdapterProps extends Omit<BaseChartProps, 'legend'> {
8
+ x?: string;
9
+ y?: string;
10
+ z?: string;
11
+ config?: {
12
+ isDataTag?: boolean;
13
+ isLegend?: boolean;
14
+ isCombineDataTag?: boolean;
15
+ isDescend?: boolean;
16
+ isClickable?: boolean;
17
+ };
18
+ highlightDate?: string[];
19
+ indicators?: string[];
20
+ }
21
+ declare const BarLineAdapter: React.FC<BarLineAdapterProps>;
22
+ export default BarLineAdapter;
@@ -0,0 +1,61 @@
1
+ import { jsx } from "react/jsx-runtime";
2
+ import { useMemo } from "react";
3
+ import GroupBarLine from "./GroupBarLine.js";
4
+ const transformDataToGroupBarLineFormat = (data, x = 'groupName', y = '', indicators)=>{
5
+ if (!data || 0 === data.length) return [];
6
+ return data.map((item)=>{
7
+ const indicatorData = item?.indicatorData || {};
8
+ return indicators && indicators?.length > 0 ? indicators?.map((key, index)=>{
9
+ const indicatorItem = indicatorData[key];
10
+ return {
11
+ groupName: item[x],
12
+ groupType: key,
13
+ groupValue: indicatorItem,
14
+ isCombine: 0 !== index,
15
+ percent: 1,
16
+ nodeInfos: item.nodeInfos,
17
+ total: indicatorItem
18
+ };
19
+ }) : Object.keys(indicatorData).map((key)=>{
20
+ const indicatorItem = indicatorData[key];
21
+ return {
22
+ groupName: item[x],
23
+ groupType: key,
24
+ groupValue: indicatorItem,
25
+ isCombine: key !== y,
26
+ percent: 1,
27
+ nodeInfos: item.nodeInfos,
28
+ total: indicatorItem
29
+ };
30
+ });
31
+ }).flat();
32
+ };
33
+ const BarLineAdapter = ({ height, data, x = 'groupName', y = '', z: _z = '', indicatorMap, config = {
34
+ isLegend: true,
35
+ isDataTag: false,
36
+ isCombineDataTag: false,
37
+ isDescend: false,
38
+ isClickable: true
39
+ }, auxiliaryLineData, onChartClick = ()=>{}, highlightDate = [], nodeSetting, indicators = [] })=>{
40
+ const transformedData = useMemo(()=>transformDataToGroupBarLineFormat(data, x, y, indicators), [
41
+ data,
42
+ x,
43
+ y,
44
+ indicators
45
+ ]);
46
+ return /*#__PURE__*/ jsx(GroupBarLine, {
47
+ height: height,
48
+ data: transformedData,
49
+ x: x,
50
+ y: y,
51
+ legend: "groupType",
52
+ indicatorMap: indicatorMap,
53
+ config: config,
54
+ auxiliaryLineData: auxiliaryLineData,
55
+ onChartClick: onChartClick,
56
+ highlightDate: highlightDate,
57
+ nodeSetting: nodeSetting
58
+ });
59
+ };
60
+ const composite_BarLineAdapter = BarLineAdapter;
61
+ export { composite_BarLineAdapter as default };
@@ -0,0 +1,5 @@
1
+ /**
2
+ * BarLineAdapter Lazy Loading 入口
3
+ * 提供默认导出,支持 lazy() 直接使用
4
+ */
5
+ export { default } from './BarLineAdapter';
@@ -0,0 +1,2 @@
1
+ import BarLineAdapter from "./BarLineAdapter.js";
2
+ export { BarLineAdapter as default };
@@ -0,0 +1,7 @@
1
+ /**
2
+ * 柱状折线组合图组件
3
+ */
4
+ import React from 'react';
5
+ import type { BaseChartProps } from '../../core/ChartTypes';
6
+ declare const _default: React.NamedExoticComponent<BaseChartProps>;
7
+ export default _default;