@publishfx/publish-chart 1.3.1 → 1.4.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.
@@ -0,0 +1,310 @@
1
+ import { Fragment, jsx, jsxs } from "react/jsx-runtime";
2
+ import { memo, useEffect, useMemo, useState } from "react";
3
+ import { Axis, Chart, Legend, Line, Tooltip, View } from "bizcharts";
4
+ import lib from "@antv/data-set/lib";
5
+ import { calculateBarWidth, getAxisFormat, getAxisHorPaddingByText } from "../../utils/chartHelpers.js";
6
+ import { defaultChartConfig, nodeMap } from "../../core/ChartConfig.js";
7
+ import { formatIndicatorV2 } from "../../utils/formatters.js";
8
+ import AuxiliaryLine from "../shared/AuxiliaryLine.js";
9
+ import { NodeGeom } from "../shared/NodeGeom.js";
10
+ import XAxisBackground from "../shared/XAxisBackground.js";
11
+ const GroupLine = ({ height, data, x = 'groupName', y = '', legend = 'groupType', indicatorMap, config, auxiliaryLineData, nodeSetting = {
12
+ showType: 0,
13
+ type: []
14
+ }, highlightDate })=>{
15
+ const yAxis = 'groupValue';
16
+ const { isDataTag = true, isLegend = true, isHighlight = true } = config || {};
17
+ const [axisHorPadding, setAxisHorPadding] = useState(0);
18
+ const [padding, setPadding] = useState([
19
+ 20,
20
+ 10,
21
+ 10,
22
+ 0
23
+ ]);
24
+ const [mainBarSize, setMainBarSize] = useState(void 0);
25
+ const ds = new lib();
26
+ const dv = ds.createView().source(data);
27
+ if ('' !== y) {
28
+ dv.transform({
29
+ type: 'map',
30
+ callback (row) {
31
+ row[yAxis] = '' !== row[yAxis] ? +row[yAxis] : '-';
32
+ return row;
33
+ }
34
+ });
35
+ dv.transform({
36
+ type: 'filter',
37
+ callback (row) {
38
+ return '-' !== row[yAxis];
39
+ }
40
+ });
41
+ }
42
+ const transformData = dv.rows;
43
+ let maxY = Math.max(...dv.rows.filter((item)=>'-' !== item[yAxis]).map((item)=>+item[yAxis]));
44
+ if (auxiliaryLineData?.length) {
45
+ const maxAuxiliaryLine = Math.max(...auxiliaryLineData.map((item)=>+item.value));
46
+ if (maxAuxiliaryLine > maxY) maxY = maxAuxiliaryLine;
47
+ }
48
+ dv.rows.forEach((item)=>{
49
+ const infos = [
50
+ ...item?.nodeInfos?.info || [],
51
+ ...item?.nodeInfos?.infosCompare || []
52
+ ];
53
+ const len = infos.length || 0;
54
+ item.nodeLen = len;
55
+ if (0 === len) return;
56
+ item.node = 0;
57
+ item.color = 1 == len ? nodeMap.get(infos[0].type)?.color : 'l (0) 0:#32C5FF 0.44:#B620E0 0.99:#F7B500';
58
+ });
59
+ const [pointP, setPointP] = useState({
60
+ x: 0,
61
+ y: 0
62
+ });
63
+ const [pointData, setPointData] = useState({
64
+ info: [],
65
+ infosCompare: []
66
+ });
67
+ useEffect(()=>{
68
+ setPointP({
69
+ x: 0,
70
+ y: 0
71
+ });
72
+ setPointData({
73
+ info: [],
74
+ infosCompare: []
75
+ });
76
+ }, [
77
+ data
78
+ ]);
79
+ useEffect(()=>{
80
+ if (maxY > Math.max(...dv.rows.filter((item)=>'-' !== item[yAxis]).map((item)=>+item[yAxis]))) setPadding((pre)=>[
81
+ 25,
82
+ pre[1],
83
+ pre[2],
84
+ pre[3]
85
+ ]);
86
+ }, [
87
+ data,
88
+ maxY
89
+ ]);
90
+ const filterFn = useMemo(()=>(item)=>highlightDate?.includes(item.groupName) ?? false, [
91
+ highlightDate
92
+ ]);
93
+ const nodeViewData = useMemo(()=>{
94
+ const uniqueMap = new Map();
95
+ transformData.forEach((item)=>{
96
+ const hasNode = (item?.nodeInfos?.info?.length || 0) > 0 || (item?.nodeInfos?.infosCompare?.length || 0) > 0;
97
+ if (hasNode && !uniqueMap.has(item.groupName)) uniqueMap.set(item.groupName, {
98
+ groupName: item.groupName,
99
+ node: 0,
100
+ nodeInfos: item.nodeInfos,
101
+ color: item.color,
102
+ [legend]: 'NodeEvent'
103
+ });
104
+ });
105
+ return Array.from(uniqueMap.values());
106
+ }, [
107
+ transformData
108
+ ]);
109
+ return /*#__PURE__*/ jsxs(Chart, {
110
+ height: height || 300,
111
+ data: transformData,
112
+ ...defaultChartConfig.baseChartConfig,
113
+ appendPadding: padding,
114
+ scale: {
115
+ [yAxis]: {
116
+ type: 'linear',
117
+ max: maxY,
118
+ nice: true
119
+ }
120
+ },
121
+ onPointMouseover: (e)=>{
122
+ if (1 == nodeSetting.showType) {
123
+ setPointP({
124
+ x: e.data.x,
125
+ y: e.data.y
126
+ });
127
+ setPointData(e.data.data.nodeInfos);
128
+ }
129
+ },
130
+ onAfterrender: (chart)=>{
131
+ const estimatedBarWidth = calculateBarWidth(chart, transformData, x, 0.5);
132
+ if (void 0 !== estimatedBarWidth) setMainBarSize(estimatedBarWidth);
133
+ },
134
+ children: [
135
+ /*#__PURE__*/ jsx(XAxisBackground, {
136
+ x: x,
137
+ data: transformData,
138
+ isHighlight: isHighlight,
139
+ filterFn: filterFn,
140
+ dataLength: transformData.length,
141
+ mainBarSize: mainBarSize
142
+ }),
143
+ /*#__PURE__*/ jsx(Line, {
144
+ position: `${x}*${yAxis}`,
145
+ style: {
146
+ cursor: 'pointer'
147
+ },
148
+ color: legend,
149
+ label: [
150
+ yAxis,
151
+ (v)=>({
152
+ content: isDataTag ? formatIndicatorV2(v, indicatorMap[y]) : ''
153
+ })
154
+ ]
155
+ }),
156
+ /*#__PURE__*/ jsx(Tooltip, {
157
+ shared: true,
158
+ showCrosshairs: true,
159
+ children: (title, items)=>/*#__PURE__*/ jsxs("div", {
160
+ style: {
161
+ padding: '10px 0'
162
+ },
163
+ children: [
164
+ title,
165
+ items && /*#__PURE__*/ jsxs(Fragment, {
166
+ children: [
167
+ /*#__PURE__*/ jsx("div", {
168
+ children: items.map((it, index)=>/*#__PURE__*/ jsxs("div", {
169
+ style: {
170
+ display: 'flex',
171
+ justifyContent: 'space-between',
172
+ marginTop: '10px'
173
+ },
174
+ children: [
175
+ /*#__PURE__*/ jsxs("span", {
176
+ children: [
177
+ /*#__PURE__*/ jsx("span", {
178
+ style: {
179
+ width: '8px',
180
+ height: '8px',
181
+ backgroundColor: it.color,
182
+ display: 'inline-block',
183
+ borderRadius: '50%',
184
+ marginRight: '8px'
185
+ }
186
+ }),
187
+ it.name,
188
+ ":"
189
+ ]
190
+ }),
191
+ /*#__PURE__*/ jsx("span", {
192
+ style: {
193
+ fontWeight: 'bold',
194
+ paddingLeft: '10px'
195
+ },
196
+ children: formatIndicatorV2(it.value, indicatorMap[y])
197
+ })
198
+ ]
199
+ }, index))
200
+ }),
201
+ auxiliaryLineData && auxiliaryLineData.map((item, index)=>/*#__PURE__*/ jsxs("div", {
202
+ style: {
203
+ marginLeft: '16px',
204
+ marginTop: '10px',
205
+ display: 'flex',
206
+ justifyContent: 'space-between'
207
+ },
208
+ children: [
209
+ /*#__PURE__*/ jsxs("div", {
210
+ children: [
211
+ item.name,
212
+ ":"
213
+ ]
214
+ }),
215
+ /*#__PURE__*/ jsx("div", {
216
+ children: formatIndicatorV2(item.value, indicatorMap[y])
217
+ })
218
+ ]
219
+ }, index))
220
+ ]
221
+ })
222
+ ]
223
+ })
224
+ }),
225
+ auxiliaryLineData?.length > 0 && /*#__PURE__*/ jsxs(View, {
226
+ data: dv.rows,
227
+ scale: {
228
+ [yAxis]: {
229
+ type: 'linear',
230
+ max: maxY,
231
+ nice: true
232
+ }
233
+ },
234
+ padding: [
235
+ 0,
236
+ 0,
237
+ 0,
238
+ -axisHorPadding
239
+ ],
240
+ children: [
241
+ /*#__PURE__*/ jsx(Axis, {
242
+ name: yAxis,
243
+ visible: false
244
+ }),
245
+ /*#__PURE__*/ jsx(Axis, {
246
+ name: x,
247
+ visible: false
248
+ }),
249
+ /*#__PURE__*/ jsx(Line, {
250
+ position: `${x}*${yAxis}`,
251
+ visible: false
252
+ }),
253
+ auxiliaryLineData.map((item, index)=>/*#__PURE__*/ jsx(AuxiliaryLine, {
254
+ name: item.name,
255
+ value: item.value
256
+ }, index))
257
+ ]
258
+ }, axisHorPadding),
259
+ /*#__PURE__*/ jsx(Legend, {
260
+ position: "bottom-left",
261
+ maxItemWidth: 1,
262
+ visible: isLegend,
263
+ itemHeight: 14,
264
+ name: legend
265
+ }),
266
+ /*#__PURE__*/ jsx(Legend, {
267
+ name: "color",
268
+ visible: false
269
+ }),
270
+ /*#__PURE__*/ jsx(Axis, {
271
+ name: yAxis,
272
+ label: {
273
+ formatter (val) {
274
+ setAxisHorPadding(getAxisHorPaddingByText(val, indicatorMap, y) - 22);
275
+ return getAxisFormat(val, indicatorMap, y);
276
+ }
277
+ }
278
+ }),
279
+ nodeViewData.length > 0 && 1 == nodeSetting.showType && /*#__PURE__*/ jsxs(View, {
280
+ data: nodeViewData,
281
+ scale: {
282
+ node: {
283
+ min: 0,
284
+ max: 1
285
+ },
286
+ groupName: {
287
+ type: 'cat'
288
+ }
289
+ },
290
+ children: [
291
+ /*#__PURE__*/ jsx(Axis, {
292
+ name: "node",
293
+ visible: false
294
+ }),
295
+ /*#__PURE__*/ jsx(Legend, {
296
+ name: "color",
297
+ visible: false
298
+ }),
299
+ /*#__PURE__*/ jsx(NodeGeom, {
300
+ pointData: pointData,
301
+ pointP: pointP,
302
+ isLegend: isLegend
303
+ })
304
+ ]
305
+ })
306
+ ]
307
+ }, nodeSetting?.showType + JSON.stringify(config));
308
+ };
309
+ const composite_GroupLine = /*#__PURE__*/ memo(GroupLine);
310
+ export { composite_GroupLine as default };
@@ -0,0 +1,3 @@
1
+ import React from 'react';
2
+ declare const _default: React.MemoExoticComponent<({ height, data, x, y, legend, indicatorMap, config, auxiliaryLineData, nodeSetting, highlightDate, }: any) => JSX.Element>;
3
+ export default _default;