@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,255 @@
|
|
|
1
|
+
import { Fragment, jsx, jsxs } from "react/jsx-runtime";
|
|
2
|
+
import { memo, useEffect, useMemo, useState } from "react";
|
|
3
|
+
import { Axis, Chart, Interval, Legend, Line, Tooltip } from "bizcharts";
|
|
4
|
+
import { useChartContext } from "../../core/ChartContext.js";
|
|
5
|
+
import { mergeChartConfig } from "../../core/ChartConfig.js";
|
|
6
|
+
import { getAxisFormat } from "../../utils/chartHelpers.js";
|
|
7
|
+
import { getIndicatorName } from "../../utils/indicatorHelpers.js";
|
|
8
|
+
import { DataAdapter } from "../../adapters/DataAdapter.js";
|
|
9
|
+
const BarLineChart = ({ height = 310, data, x = '', y = '', z = '', indicatorMap, onChartClick, nodeSetting = {
|
|
10
|
+
showType: 0,
|
|
11
|
+
type: []
|
|
12
|
+
} })=>{
|
|
13
|
+
const { formatter, dataTransform, config: contextConfig, businessComponents } = useChartContext();
|
|
14
|
+
const mergedConfig = useMemo(()=>mergeChartConfig(contextConfig, {}), [
|
|
15
|
+
contextConfig
|
|
16
|
+
]);
|
|
17
|
+
const safeIndicatorMap = indicatorMap || contextConfig.indicatorMap || {};
|
|
18
|
+
const transformedData = useMemo(()=>{
|
|
19
|
+
const result = DataAdapter.transform(data, 'barLine', {
|
|
20
|
+
type: 'barLine',
|
|
21
|
+
x,
|
|
22
|
+
y,
|
|
23
|
+
z
|
|
24
|
+
});
|
|
25
|
+
return result.map((item)=>dataTransform.processNodeInfo(item, contextConfig.nodeMap));
|
|
26
|
+
}, [
|
|
27
|
+
data,
|
|
28
|
+
x,
|
|
29
|
+
y,
|
|
30
|
+
z,
|
|
31
|
+
dataTransform,
|
|
32
|
+
contextConfig.nodeMap
|
|
33
|
+
]);
|
|
34
|
+
const [chartWidth, setChartWidth] = useState(0);
|
|
35
|
+
const [chartOffset, setChartOffset] = useState(0);
|
|
36
|
+
const [padding, setPadding] = useState([
|
|
37
|
+
10,
|
|
38
|
+
0
|
|
39
|
+
]);
|
|
40
|
+
const [pointP, setPointP] = useState({
|
|
41
|
+
x: 0,
|
|
42
|
+
y: 0
|
|
43
|
+
});
|
|
44
|
+
const [pointData, setPointData] = useState({
|
|
45
|
+
info: [],
|
|
46
|
+
infosCompare: []
|
|
47
|
+
});
|
|
48
|
+
let chartIns = null;
|
|
49
|
+
const scale = useMemo(()=>({
|
|
50
|
+
[y]: {
|
|
51
|
+
type: 'linear-strict'
|
|
52
|
+
},
|
|
53
|
+
[z]: {
|
|
54
|
+
type: 'linear-strict'
|
|
55
|
+
}
|
|
56
|
+
}), [
|
|
57
|
+
y,
|
|
58
|
+
z
|
|
59
|
+
]);
|
|
60
|
+
useEffect(()=>{
|
|
61
|
+
setPointP({
|
|
62
|
+
x: 0,
|
|
63
|
+
y: 0
|
|
64
|
+
});
|
|
65
|
+
setPointData({
|
|
66
|
+
info: [],
|
|
67
|
+
infosCompare: []
|
|
68
|
+
});
|
|
69
|
+
if (nodeSetting?.showType) if (nodeSetting?.showType === 2 && chartWidth / transformedData.length > 30) if (transformedData.some((item)=>item?.nodeLen > 2)) setPadding([
|
|
70
|
+
10,
|
|
71
|
+
0,
|
|
72
|
+
40,
|
|
73
|
+
0
|
|
74
|
+
]);
|
|
75
|
+
else transformedData.some((item)=>item?.nodeLen === 2) ? setPadding([
|
|
76
|
+
10,
|
|
77
|
+
0,
|
|
78
|
+
24,
|
|
79
|
+
0
|
|
80
|
+
]) : setPadding([
|
|
81
|
+
20,
|
|
82
|
+
0,
|
|
83
|
+
10,
|
|
84
|
+
0
|
|
85
|
+
]);
|
|
86
|
+
else setPadding([
|
|
87
|
+
20,
|
|
88
|
+
0,
|
|
89
|
+
10,
|
|
90
|
+
0
|
|
91
|
+
]);
|
|
92
|
+
else setPadding([
|
|
93
|
+
20,
|
|
94
|
+
0,
|
|
95
|
+
10,
|
|
96
|
+
0
|
|
97
|
+
]);
|
|
98
|
+
}, [
|
|
99
|
+
chartWidth,
|
|
100
|
+
transformedData,
|
|
101
|
+
nodeSetting
|
|
102
|
+
]);
|
|
103
|
+
const getChartKey = ()=>`${nodeSetting?.showType}${y}${z}${x}`;
|
|
104
|
+
const NodeDetail = businessComponents?.NodeDetail;
|
|
105
|
+
const NodeGeom = businessComponents?.NodeGeom;
|
|
106
|
+
return /*#__PURE__*/ jsxs(Chart, {
|
|
107
|
+
height: height,
|
|
108
|
+
data: transformedData,
|
|
109
|
+
...mergedConfig.baseChartConfig,
|
|
110
|
+
onPlotClick: (e, chart)=>{
|
|
111
|
+
const value = chart.getTooltipItems({
|
|
112
|
+
x: e.x,
|
|
113
|
+
y: e.y
|
|
114
|
+
});
|
|
115
|
+
onChartClick && onChartClick(value[0]);
|
|
116
|
+
},
|
|
117
|
+
onGetG2Instance: (chart)=>{
|
|
118
|
+
chartIns = chart;
|
|
119
|
+
},
|
|
120
|
+
scale: scale,
|
|
121
|
+
appendPadding: padding,
|
|
122
|
+
onPointMouseover: (e)=>{
|
|
123
|
+
if (1 === nodeSetting.showType) {
|
|
124
|
+
setPointP({
|
|
125
|
+
x: e.data.x,
|
|
126
|
+
y: e.data.y
|
|
127
|
+
});
|
|
128
|
+
setPointData(e.data.data.nodeInfos || {
|
|
129
|
+
info: [],
|
|
130
|
+
infosCompare: []
|
|
131
|
+
});
|
|
132
|
+
}
|
|
133
|
+
},
|
|
134
|
+
onAfterrender: (_e, chart)=>{
|
|
135
|
+
if (2 === nodeSetting.showType) {
|
|
136
|
+
setChartWidth(chart.coordinateBBox.width);
|
|
137
|
+
setChartOffset(chart.coordinateBBox.x);
|
|
138
|
+
}
|
|
139
|
+
},
|
|
140
|
+
children: [
|
|
141
|
+
/*#__PURE__*/ jsx(Legend, {
|
|
142
|
+
custom: true,
|
|
143
|
+
allowAllCanceled: true,
|
|
144
|
+
position: nodeSetting.showType ? 'top' : 'bottom',
|
|
145
|
+
items: [
|
|
146
|
+
{
|
|
147
|
+
value: y,
|
|
148
|
+
name: getIndicatorName(safeIndicatorMap, y),
|
|
149
|
+
marker: {
|
|
150
|
+
symbol: 'circle',
|
|
151
|
+
style: {
|
|
152
|
+
fill: mergedConfig.theme.colors[0],
|
|
153
|
+
r: 5
|
|
154
|
+
}
|
|
155
|
+
}
|
|
156
|
+
},
|
|
157
|
+
{
|
|
158
|
+
value: z,
|
|
159
|
+
name: `${getIndicatorName(safeIndicatorMap, z)} `,
|
|
160
|
+
marker: {
|
|
161
|
+
symbol: 'hyphen',
|
|
162
|
+
style: {
|
|
163
|
+
stroke: mergedConfig.theme.combineColors?.[0] || '#FF8C00',
|
|
164
|
+
r: 5,
|
|
165
|
+
lineWidth: 3
|
|
166
|
+
}
|
|
167
|
+
}
|
|
168
|
+
}
|
|
169
|
+
],
|
|
170
|
+
onChange: (ev)=>{
|
|
171
|
+
const item = ev?.item || {};
|
|
172
|
+
const value = item.value;
|
|
173
|
+
const checked = !item.unchecked;
|
|
174
|
+
const geoms = chartIns?.geometries || [];
|
|
175
|
+
for(let i = 0; i < geoms.length; i++){
|
|
176
|
+
const geom = geoms[i];
|
|
177
|
+
if (geom.getYScale().field === value) if (checked) geom.show();
|
|
178
|
+
else geom.hide();
|
|
179
|
+
}
|
|
180
|
+
}
|
|
181
|
+
}),
|
|
182
|
+
/*#__PURE__*/ jsx(Interval, {
|
|
183
|
+
position: `${x}*${y}`,
|
|
184
|
+
style: {
|
|
185
|
+
cursor: 'pointer'
|
|
186
|
+
},
|
|
187
|
+
tooltip: [
|
|
188
|
+
`${x}*${y}`,
|
|
189
|
+
(_name, value)=>({
|
|
190
|
+
name: getIndicatorName(safeIndicatorMap, y),
|
|
191
|
+
value: formatter.formatIndicator(value, safeIndicatorMap[y])
|
|
192
|
+
})
|
|
193
|
+
]
|
|
194
|
+
}),
|
|
195
|
+
/*#__PURE__*/ jsx(Line, {
|
|
196
|
+
position: `${x}*${z}`,
|
|
197
|
+
style: {
|
|
198
|
+
cursor: 'pointer'
|
|
199
|
+
},
|
|
200
|
+
color: mergedConfig.theme.combineColors?.[0] || '#FF8C00',
|
|
201
|
+
shape: "smooth",
|
|
202
|
+
tooltip: [
|
|
203
|
+
`${x}*${z}`,
|
|
204
|
+
(_name, value)=>({
|
|
205
|
+
name: getIndicatorName(safeIndicatorMap, z),
|
|
206
|
+
value: formatter.formatIndicator(value, safeIndicatorMap[z])
|
|
207
|
+
})
|
|
208
|
+
]
|
|
209
|
+
}),
|
|
210
|
+
/*#__PURE__*/ jsx(Tooltip, {
|
|
211
|
+
shared: true,
|
|
212
|
+
showCrosshairs: true,
|
|
213
|
+
domStyles: {
|
|
214
|
+
'g2-tooltip-value': {
|
|
215
|
+
fontWeight: 'bold'
|
|
216
|
+
}
|
|
217
|
+
}
|
|
218
|
+
}),
|
|
219
|
+
/*#__PURE__*/ jsx(Axis, {
|
|
220
|
+
name: y,
|
|
221
|
+
label: {
|
|
222
|
+
formatter: (val)=>getAxisFormat(val, safeIndicatorMap, y)
|
|
223
|
+
}
|
|
224
|
+
}),
|
|
225
|
+
/*#__PURE__*/ jsx(Axis, {
|
|
226
|
+
name: z,
|
|
227
|
+
label: {
|
|
228
|
+
formatter: (val)=>getAxisFormat(val, safeIndicatorMap, z)
|
|
229
|
+
}
|
|
230
|
+
}),
|
|
231
|
+
/*#__PURE__*/ jsx(Axis, {
|
|
232
|
+
grid: null,
|
|
233
|
+
name: x,
|
|
234
|
+
label: {
|
|
235
|
+
autoEllipsis: true
|
|
236
|
+
}
|
|
237
|
+
}),
|
|
238
|
+
transformedData.some((item)=>item?.nodeInfos?.info?.length > 0 || item?.nodeInfos?.infosCompare?.length > 0) && /*#__PURE__*/ jsxs(Fragment, {
|
|
239
|
+
children: [
|
|
240
|
+
1 === nodeSetting.showType && NodeGeom && /*#__PURE__*/ jsx(NodeGeom, {
|
|
241
|
+
pointData: pointData,
|
|
242
|
+
pointP: pointP
|
|
243
|
+
}),
|
|
244
|
+
2 === nodeSetting.showType && NodeDetail && (0 === chartOffset || chartOffset) && /*#__PURE__*/ jsx(NodeDetail, {
|
|
245
|
+
chartWidth: chartWidth,
|
|
246
|
+
chartOffset: chartOffset,
|
|
247
|
+
dvRows: transformedData
|
|
248
|
+
})
|
|
249
|
+
]
|
|
250
|
+
})
|
|
251
|
+
]
|
|
252
|
+
}, getChartKey());
|
|
253
|
+
};
|
|
254
|
+
const composite_BarLineChart = /*#__PURE__*/ memo(BarLineChart);
|
|
255
|
+
export { composite_BarLineChart as default };
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 柱状折线对比组合图(周末高亮版本)
|
|
3
|
+
*/
|
|
4
|
+
import React from 'react';
|
|
5
|
+
import type { BaseChartProps } from '../../core/ChartTypes';
|
|
6
|
+
interface BarLineCompareWeekendProps extends BaseChartProps {
|
|
7
|
+
indicators: string[];
|
|
8
|
+
}
|
|
9
|
+
declare const _default: React.NamedExoticComponent<BarLineCompareWeekendProps>;
|
|
10
|
+
export default _default;
|