@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,620 @@
|
|
|
1
|
+
import { Fragment, jsx, jsxs } from "react/jsx-runtime";
|
|
2
|
+
import { memo, useEffect, useMemo, useRef, useState } from "react";
|
|
3
|
+
import { Axis, Chart, Coordinate, Interval, Legend, Line, Tooltip, View } from "bizcharts";
|
|
4
|
+
import lib from "@antv/data-set/lib";
|
|
5
|
+
import { useChartContext } from "../../core/ChartContext.js";
|
|
6
|
+
import { mergeChartConfig } from "../../core/ChartConfig.js";
|
|
7
|
+
import { calTextWidth, calculateBarWidth, createStripePatternCanvas, getAxisFormat, getAxisHorPaddingByText, getChartKey, markerStyle, truncateText } from "../../utils/chartHelpers.js";
|
|
8
|
+
import { transformIndicatorList } from "../../utils/dataTransform.js";
|
|
9
|
+
import { getIndicatorCompareName } from "../../utils/indicatorHelpers.js";
|
|
10
|
+
import AuxiliaryLine from "../shared/AuxiliaryLine.js";
|
|
11
|
+
import XAxisBackground from "../shared/XAxisBackground.js";
|
|
12
|
+
import { NodeDetail } from "../shared/NodeDetail.js";
|
|
13
|
+
import { NodeGeom } from "../shared/NodeGeom.js";
|
|
14
|
+
import { CompareChange } from "@moonton/publish-components";
|
|
15
|
+
const STRIPE_PATTERN_THRESHOLD = 10;
|
|
16
|
+
const GroupCompare = ({ height = 300, data, x = "", y = "", indicatorMap, onChartClick, indicators = [], timeRange, graphType, legend = "", config, nodeSetting = {
|
|
17
|
+
showType: 0,
|
|
18
|
+
type: []
|
|
19
|
+
}, auxiliaryLineData, highlightDate = [] })=>{
|
|
20
|
+
const { formatter, dataTransform, config: contextConfig } = useChartContext();
|
|
21
|
+
const mergedConfig = useMemo(()=>mergeChartConfig(contextConfig, {}), [
|
|
22
|
+
contextConfig
|
|
23
|
+
]);
|
|
24
|
+
const safeIndicatorMap = indicatorMap || contextConfig.indicatorMap || {};
|
|
25
|
+
const themeColors = mergedConfig.theme.colors;
|
|
26
|
+
const BAR_PADDING_RIGHT = mergedConfig.layout.barPaddingRight || 10;
|
|
27
|
+
const HOR_BAR_PADDING_RIGHT = mergedConfig.layout.horBarPaddingRight || 50;
|
|
28
|
+
const { isDescend = false, isLegend = true, isHorizontal = false, isDataTag = false, isHighlight = true } = config || {};
|
|
29
|
+
const [chartInsWidth, setChartInsWidth] = useState(0);
|
|
30
|
+
const [axisHorPadding, setAxisHorPadding] = useState(0);
|
|
31
|
+
const [mainBarSize, setMainBarSize] = useState(void 0);
|
|
32
|
+
const [backgroundHeight, setBackgroundHeight] = useState(1000);
|
|
33
|
+
const legendMapRef = useRef({});
|
|
34
|
+
const isHor = useMemo(()=>("string" == typeof graphType ? graphType.includes("bar") : 100 === graphType) && isHorizontal, [
|
|
35
|
+
graphType,
|
|
36
|
+
isHorizontal
|
|
37
|
+
]);
|
|
38
|
+
const chartType = useMemo(()=>{
|
|
39
|
+
if ("string" == typeof graphType) return graphType.includes("bar") ? 100 : 200;
|
|
40
|
+
return graphType;
|
|
41
|
+
}, [
|
|
42
|
+
graphType
|
|
43
|
+
]);
|
|
44
|
+
const [pointP, setPointP] = useState({
|
|
45
|
+
x: 0,
|
|
46
|
+
y: 0
|
|
47
|
+
});
|
|
48
|
+
const [pointData, setPointData] = useState({
|
|
49
|
+
info: [],
|
|
50
|
+
infosCompare: []
|
|
51
|
+
});
|
|
52
|
+
const [chartWidth, setChatWidth] = useState(0);
|
|
53
|
+
const [chartOffset, setChartOffset] = useState(0);
|
|
54
|
+
const [padding, setPadding] = useState([
|
|
55
|
+
10,
|
|
56
|
+
0
|
|
57
|
+
]);
|
|
58
|
+
let transformData = data;
|
|
59
|
+
if (isDescend) {
|
|
60
|
+
const compareData = data.filter((item)=>item["groupType"]?.includes("compare"));
|
|
61
|
+
const basicData = data.filter((item)=>!item["groupType"]?.includes("compare"));
|
|
62
|
+
basicData.sort((a, b)=>{
|
|
63
|
+
if ("" === a["groupValue"]) return isHor ? -1 : 1;
|
|
64
|
+
if ("" === b["groupValue"]) return isHor ? 1 : -1;
|
|
65
|
+
return isHor ? a["groupValue"] - b["groupValue"] : b["groupValue"] - a["groupValue"];
|
|
66
|
+
});
|
|
67
|
+
transformData = basicData.concat(compareData);
|
|
68
|
+
}
|
|
69
|
+
const yAxis = "groupValue";
|
|
70
|
+
const ds = new lib();
|
|
71
|
+
const dv = ds.createView().source(transformData);
|
|
72
|
+
if (legend) {
|
|
73
|
+
dv.transform({
|
|
74
|
+
type: "map",
|
|
75
|
+
callback (row) {
|
|
76
|
+
row[yAxis] = "" !== row[yAxis] ? +row[yAxis] : "-";
|
|
77
|
+
row["compareTime"] = row["compareTime"] || "对比时间";
|
|
78
|
+
return row;
|
|
79
|
+
}
|
|
80
|
+
});
|
|
81
|
+
transformData = dv.rows;
|
|
82
|
+
} else {
|
|
83
|
+
legend = "groupType";
|
|
84
|
+
transformData = transformIndicatorList(indicators, data)[y] || [];
|
|
85
|
+
}
|
|
86
|
+
transformData = transformData.map((item)=>{
|
|
87
|
+
const processedItem = dataTransform.processNodeInfo(item, contextConfig.nodeMap);
|
|
88
|
+
return {
|
|
89
|
+
...item,
|
|
90
|
+
...processedItem
|
|
91
|
+
};
|
|
92
|
+
});
|
|
93
|
+
const yValues = useMemo(()=>transformData.filter((item)=>"-" !== item[yAxis] && void 0 !== item[yAxis] && null !== item[yAxis] && "" !== item[yAxis]).map((item)=>Number(item[yAxis])).filter((val)=>!isNaN(val)), [
|
|
94
|
+
transformData,
|
|
95
|
+
yAxis
|
|
96
|
+
]);
|
|
97
|
+
let maxY = Math.max(...transformData.filter((item)=>"-" !== item[yAxis]).map((item)=>item[yAxis]));
|
|
98
|
+
if (auxiliaryLineData?.length) {
|
|
99
|
+
const maxAuxiliaryLine = Math.max(...auxiliaryLineData.map((item)=>+item.value));
|
|
100
|
+
if (maxAuxiliaryLine > maxY) maxY = maxAuxiliaryLine;
|
|
101
|
+
}
|
|
102
|
+
const horPaddingRight = useMemo(()=>calTextWidth(formatter.formatIndicator(maxY, safeIndicatorMap[y]), 12) - 10, [
|
|
103
|
+
maxY,
|
|
104
|
+
formatter,
|
|
105
|
+
safeIndicatorMap,
|
|
106
|
+
y
|
|
107
|
+
]);
|
|
108
|
+
const nodeShowType = useMemo(()=>nodeSetting?.showType ?? 0, [
|
|
109
|
+
nodeSetting?.showType
|
|
110
|
+
]);
|
|
111
|
+
useEffect(()=>{
|
|
112
|
+
setPointP({
|
|
113
|
+
x: 0,
|
|
114
|
+
y: 0
|
|
115
|
+
});
|
|
116
|
+
setPointData({
|
|
117
|
+
info: [],
|
|
118
|
+
infosCompare: []
|
|
119
|
+
});
|
|
120
|
+
const showTypePaddingRight = isHor && isDataTag ? horPaddingRight : HOR_BAR_PADDING_RIGHT;
|
|
121
|
+
if (nodeShowType) if (2 === nodeShowType && chartWidth / (transformData.length / 2) > 30) if (transformData.some((item)=>item && "nodeLen" in item && item.nodeLen > 2)) setPadding([
|
|
122
|
+
10,
|
|
123
|
+
showTypePaddingRight,
|
|
124
|
+
40,
|
|
125
|
+
20
|
|
126
|
+
]);
|
|
127
|
+
else transformData.some((item)=>item && "nodeLen" in item && 2 == item.nodeLen) ? setPadding([
|
|
128
|
+
10,
|
|
129
|
+
showTypePaddingRight,
|
|
130
|
+
24,
|
|
131
|
+
20
|
|
132
|
+
]) : setPadding([
|
|
133
|
+
10,
|
|
134
|
+
showTypePaddingRight,
|
|
135
|
+
10,
|
|
136
|
+
20
|
|
137
|
+
]);
|
|
138
|
+
else setPadding([
|
|
139
|
+
10,
|
|
140
|
+
showTypePaddingRight,
|
|
141
|
+
10,
|
|
142
|
+
20
|
|
143
|
+
]);
|
|
144
|
+
else setPadding(100 === chartType ? [
|
|
145
|
+
20,
|
|
146
|
+
isHor && isDataTag ? horPaddingRight : BAR_PADDING_RIGHT,
|
|
147
|
+
12,
|
|
148
|
+
10
|
|
149
|
+
] : [
|
|
150
|
+
20,
|
|
151
|
+
10,
|
|
152
|
+
0,
|
|
153
|
+
10
|
|
154
|
+
]);
|
|
155
|
+
}, [
|
|
156
|
+
chartWidth,
|
|
157
|
+
transformData.length,
|
|
158
|
+
isHor,
|
|
159
|
+
isDataTag,
|
|
160
|
+
horPaddingRight,
|
|
161
|
+
nodeShowType,
|
|
162
|
+
chartType,
|
|
163
|
+
BAR_PADDING_RIGHT,
|
|
164
|
+
HOR_BAR_PADDING_RIGHT
|
|
165
|
+
]);
|
|
166
|
+
const maxYValue = useMemo(()=>yValues.length > 0 ? Math.max(...yValues) : 0, [
|
|
167
|
+
yValues
|
|
168
|
+
]);
|
|
169
|
+
useEffect(()=>{
|
|
170
|
+
if (maxY > maxYValue) setPadding((pre)=>[
|
|
171
|
+
isHor ? 10 : 25,
|
|
172
|
+
pre[1],
|
|
173
|
+
pre[2],
|
|
174
|
+
pre[3]
|
|
175
|
+
]);
|
|
176
|
+
}, [
|
|
177
|
+
maxY,
|
|
178
|
+
maxYValue,
|
|
179
|
+
isHor
|
|
180
|
+
]);
|
|
181
|
+
useEffect(()=>{
|
|
182
|
+
if (isHorizontal) {
|
|
183
|
+
const calculatedPadding = getAxisHorPaddingByText(maxY, safeIndicatorMap, y) - 22;
|
|
184
|
+
setAxisHorPadding(calculatedPadding);
|
|
185
|
+
}
|
|
186
|
+
}, [
|
|
187
|
+
maxY,
|
|
188
|
+
isHorizontal,
|
|
189
|
+
safeIndicatorMap,
|
|
190
|
+
y
|
|
191
|
+
]);
|
|
192
|
+
const filterFn = useMemo(()=>(item)=>highlightDate?.includes(item.groupName) ?? false, [
|
|
193
|
+
highlightDate
|
|
194
|
+
]);
|
|
195
|
+
const chartInsRef = useRef(null);
|
|
196
|
+
const stripePatternRef = useRef(null);
|
|
197
|
+
const themeColor0 = useMemo(()=>themeColors[0], [
|
|
198
|
+
themeColors
|
|
199
|
+
]);
|
|
200
|
+
useEffect(()=>{
|
|
201
|
+
const offscreen = document.createElement("canvas");
|
|
202
|
+
const ctx = offscreen.getContext("2d");
|
|
203
|
+
if (!ctx) return;
|
|
204
|
+
const dataCount = transformData.length;
|
|
205
|
+
const spaceUnit = dataCount > STRIPE_PATTERN_THRESHOLD ? 12 : 24;
|
|
206
|
+
const sourceCanvas = createStripePatternCanvas(themeColor0, spaceUnit);
|
|
207
|
+
const pattern = ctx.createPattern(sourceCanvas, "repeat");
|
|
208
|
+
if (pattern) stripePatternRef.current = pattern;
|
|
209
|
+
}, [
|
|
210
|
+
transformData.length,
|
|
211
|
+
themeColor0
|
|
212
|
+
]);
|
|
213
|
+
return /*#__PURE__*/ jsxs(Chart, {
|
|
214
|
+
height: height,
|
|
215
|
+
data: transformData,
|
|
216
|
+
...mergedConfig.baseChartConfig,
|
|
217
|
+
onGetG2Instance: (c)=>{
|
|
218
|
+
chartInsRef.current = c;
|
|
219
|
+
setChartInsWidth(c.width);
|
|
220
|
+
},
|
|
221
|
+
onPlotClick: (e, chart)=>{
|
|
222
|
+
const value = chart.getTooltipItems({
|
|
223
|
+
x: e.x,
|
|
224
|
+
y: e.y
|
|
225
|
+
});
|
|
226
|
+
onChartClick && onChartClick(value[0]);
|
|
227
|
+
},
|
|
228
|
+
appendPadding: padding,
|
|
229
|
+
onPointMouseover: (e, _chart)=>{
|
|
230
|
+
if (1 == nodeSetting.showType) {
|
|
231
|
+
setPointP({
|
|
232
|
+
x: e.data.x,
|
|
233
|
+
y: e.data.y
|
|
234
|
+
});
|
|
235
|
+
setPointData(e.data.data.nodeInfos);
|
|
236
|
+
}
|
|
237
|
+
},
|
|
238
|
+
onAfterrender: (_e, chart)=>{
|
|
239
|
+
if (2 == nodeSetting.showType) {
|
|
240
|
+
setChatWidth(chart.coordinateBBox.width);
|
|
241
|
+
setChartOffset(chart.coordinateBBox.x);
|
|
242
|
+
}
|
|
243
|
+
const estimatedBarWidth = calculateBarWidth(chart, transformData, x, 0.5);
|
|
244
|
+
if (void 0 !== estimatedBarWidth) setMainBarSize(estimatedBarWidth);
|
|
245
|
+
const coordinateHeight = chart.coordinateBBox.height;
|
|
246
|
+
if (coordinateHeight && coordinateHeight > 0) setBackgroundHeight(coordinateHeight);
|
|
247
|
+
},
|
|
248
|
+
scale: {
|
|
249
|
+
[yAxis]: {
|
|
250
|
+
type: "linear-strict",
|
|
251
|
+
max: maxY,
|
|
252
|
+
nice: true
|
|
253
|
+
}
|
|
254
|
+
},
|
|
255
|
+
children: [
|
|
256
|
+
/*#__PURE__*/ jsx(XAxisBackground, {
|
|
257
|
+
x: x,
|
|
258
|
+
data: transformData,
|
|
259
|
+
isHighlight: isHighlight,
|
|
260
|
+
filterFn: filterFn,
|
|
261
|
+
dataLength: transformData.length,
|
|
262
|
+
mainBarSize: mainBarSize,
|
|
263
|
+
backgroundHeight: backgroundHeight,
|
|
264
|
+
isHorizontal: isHorizontal
|
|
265
|
+
}),
|
|
266
|
+
100 === chartType ? /*#__PURE__*/ jsx(Interval, {
|
|
267
|
+
position: `${x}*${yAxis}`,
|
|
268
|
+
style: [
|
|
269
|
+
"groupType",
|
|
270
|
+
(groupType)=>{
|
|
271
|
+
const isCompareY = groupType === `${y}_compare`;
|
|
272
|
+
if (isCompareY && stripePatternRef.current) return {
|
|
273
|
+
cursor: "pointer",
|
|
274
|
+
fill: stripePatternRef.current
|
|
275
|
+
};
|
|
276
|
+
return {
|
|
277
|
+
cursor: "pointer"
|
|
278
|
+
};
|
|
279
|
+
}
|
|
280
|
+
],
|
|
281
|
+
color: [
|
|
282
|
+
"groupType",
|
|
283
|
+
(groupType)=>{
|
|
284
|
+
if (!groupType || "string" != typeof groupType) return themeColors[0];
|
|
285
|
+
const baseKey = groupType.replace(/_compare.*/, "");
|
|
286
|
+
if (baseKey === y) return themeColors[0];
|
|
287
|
+
const idx = (indicators || []).indexOf(baseKey);
|
|
288
|
+
return themeColors[idx >= 0 ? idx : 1];
|
|
289
|
+
}
|
|
290
|
+
],
|
|
291
|
+
adjust: [
|
|
292
|
+
{
|
|
293
|
+
type: "dodge",
|
|
294
|
+
marginRatio: 0
|
|
295
|
+
}
|
|
296
|
+
],
|
|
297
|
+
label: [
|
|
298
|
+
yAxis,
|
|
299
|
+
(v)=>{
|
|
300
|
+
const formatted = isDataTag ? formatter.formatIndicator(v, safeIndicatorMap[y]) : void 0;
|
|
301
|
+
return {
|
|
302
|
+
content: formatted || "",
|
|
303
|
+
offset: isHorizontal ? 5 : 10
|
|
304
|
+
};
|
|
305
|
+
}
|
|
306
|
+
]
|
|
307
|
+
}) : /*#__PURE__*/ jsx(Line, {
|
|
308
|
+
position: `${x}*${yAxis}`,
|
|
309
|
+
style: [
|
|
310
|
+
"groupType",
|
|
311
|
+
(groupType)=>{
|
|
312
|
+
if (groupType.includes("_compare")) return {
|
|
313
|
+
lineDash: [
|
|
314
|
+
4,
|
|
315
|
+
4
|
|
316
|
+
]
|
|
317
|
+
};
|
|
318
|
+
}
|
|
319
|
+
],
|
|
320
|
+
state: {
|
|
321
|
+
active: {
|
|
322
|
+
style: (element)=>{
|
|
323
|
+
if ("dash" === element.getModel().shape) return {
|
|
324
|
+
lineDash: [
|
|
325
|
+
4,
|
|
326
|
+
4
|
|
327
|
+
],
|
|
328
|
+
lineWidth: 3
|
|
329
|
+
};
|
|
330
|
+
return {
|
|
331
|
+
lineWidth: 3
|
|
332
|
+
};
|
|
333
|
+
}
|
|
334
|
+
}
|
|
335
|
+
},
|
|
336
|
+
color: [
|
|
337
|
+
"groupType",
|
|
338
|
+
(groupType)=>{
|
|
339
|
+
if (!groupType || "string" != typeof groupType) return themeColors[0];
|
|
340
|
+
const baseKey = groupType.replace(/_compare.*/, "");
|
|
341
|
+
if (baseKey === y) return themeColors[0];
|
|
342
|
+
const idx = (indicators || []).indexOf(baseKey);
|
|
343
|
+
return themeColors[idx >= 0 ? idx : 1];
|
|
344
|
+
}
|
|
345
|
+
],
|
|
346
|
+
shape: [
|
|
347
|
+
legend,
|
|
348
|
+
(groupType)=>{
|
|
349
|
+
if (groupType.includes("_compare")) return "dash";
|
|
350
|
+
return "line";
|
|
351
|
+
}
|
|
352
|
+
],
|
|
353
|
+
label: [
|
|
354
|
+
yAxis,
|
|
355
|
+
(v)=>{
|
|
356
|
+
const formatted = isDataTag ? formatter.formatIndicator(v, safeIndicatorMap[y]) : void 0;
|
|
357
|
+
return {
|
|
358
|
+
content: formatted || ""
|
|
359
|
+
};
|
|
360
|
+
}
|
|
361
|
+
]
|
|
362
|
+
}),
|
|
363
|
+
/*#__PURE__*/ jsx(Coordinate, {
|
|
364
|
+
transpose: isHor
|
|
365
|
+
}),
|
|
366
|
+
/*#__PURE__*/ jsx(Tooltip, {
|
|
367
|
+
shared: true,
|
|
368
|
+
showCrosshairs: true,
|
|
369
|
+
children: (title, items)=>{
|
|
370
|
+
let indicatorName = "";
|
|
371
|
+
return /*#__PURE__*/ jsxs("div", {
|
|
372
|
+
style: {
|
|
373
|
+
padding: "10px 0"
|
|
374
|
+
},
|
|
375
|
+
children: [
|
|
376
|
+
title,
|
|
377
|
+
items && /*#__PURE__*/ jsxs(Fragment, {
|
|
378
|
+
children: [
|
|
379
|
+
/*#__PURE__*/ jsx("div", {
|
|
380
|
+
style: {
|
|
381
|
+
margin: "10px 0"
|
|
382
|
+
},
|
|
383
|
+
children: items.map((it, index)=>{
|
|
384
|
+
indicatorName = it.name.split("_")[0];
|
|
385
|
+
return /*#__PURE__*/ jsxs("div", {
|
|
386
|
+
style: {
|
|
387
|
+
display: "flex",
|
|
388
|
+
justifyContent: "space-between",
|
|
389
|
+
marginBottom: "10px"
|
|
390
|
+
},
|
|
391
|
+
children: [
|
|
392
|
+
/*#__PURE__*/ jsxs("span", {
|
|
393
|
+
children: [
|
|
394
|
+
/*#__PURE__*/ jsx("span", {
|
|
395
|
+
style: 100 === chartType ? markerStyle(it.color, it.name.includes("_compare")) : markerStyle(it.color, false)
|
|
396
|
+
}),
|
|
397
|
+
it.name.includes("_") ? `${getIndicatorCompareName(safeIndicatorMap, it.name)}(${it.data.compareTime})` : getIndicatorCompareName(safeIndicatorMap, it.name)
|
|
398
|
+
]
|
|
399
|
+
}),
|
|
400
|
+
/*#__PURE__*/ jsx("span", {
|
|
401
|
+
style: {
|
|
402
|
+
fontWeight: "bold",
|
|
403
|
+
paddingLeft: "10px"
|
|
404
|
+
},
|
|
405
|
+
children: formatter.formatIndicator(it.data.groupValue, safeIndicatorMap[it.name.split("_")[0]])
|
|
406
|
+
})
|
|
407
|
+
]
|
|
408
|
+
}, index);
|
|
409
|
+
})
|
|
410
|
+
}),
|
|
411
|
+
/*#__PURE__*/ jsxs("div", {
|
|
412
|
+
style: {
|
|
413
|
+
marginLeft: "16px",
|
|
414
|
+
display: "flex",
|
|
415
|
+
justifyContent: "space-between"
|
|
416
|
+
},
|
|
417
|
+
children: [
|
|
418
|
+
`相比变化 `,
|
|
419
|
+
/*#__PURE__*/ jsx("span", {
|
|
420
|
+
style: {
|
|
421
|
+
fontWeight: "bold"
|
|
422
|
+
},
|
|
423
|
+
children: /*#__PURE__*/ jsx(CompareChange, {
|
|
424
|
+
value: items[0].data.change,
|
|
425
|
+
fontSize: 12
|
|
426
|
+
})
|
|
427
|
+
})
|
|
428
|
+
]
|
|
429
|
+
}),
|
|
430
|
+
auxiliaryLineData && auxiliaryLineData.map((item, index)=>/*#__PURE__*/ jsxs("div", {
|
|
431
|
+
style: {
|
|
432
|
+
marginLeft: "16px",
|
|
433
|
+
marginTop: "10px",
|
|
434
|
+
display: "flex",
|
|
435
|
+
justifyContent: "space-between"
|
|
436
|
+
},
|
|
437
|
+
children: [
|
|
438
|
+
/*#__PURE__*/ jsxs("div", {
|
|
439
|
+
children: [
|
|
440
|
+
item.name,
|
|
441
|
+
":"
|
|
442
|
+
]
|
|
443
|
+
}),
|
|
444
|
+
/*#__PURE__*/ jsx("div", {
|
|
445
|
+
children: formatter.formatIndicator(item.value, safeIndicatorMap[indicatorName])
|
|
446
|
+
})
|
|
447
|
+
]
|
|
448
|
+
}, index))
|
|
449
|
+
]
|
|
450
|
+
})
|
|
451
|
+
]
|
|
452
|
+
});
|
|
453
|
+
}
|
|
454
|
+
}),
|
|
455
|
+
auxiliaryLineData?.length && auxiliaryLineData?.length > 0 && /*#__PURE__*/ jsxs(View, {
|
|
456
|
+
data: transformData,
|
|
457
|
+
scale: {
|
|
458
|
+
[yAxis]: {
|
|
459
|
+
type: "linear-strict",
|
|
460
|
+
max: maxY,
|
|
461
|
+
nice: true
|
|
462
|
+
}
|
|
463
|
+
},
|
|
464
|
+
padding: [
|
|
465
|
+
0,
|
|
466
|
+
0,
|
|
467
|
+
0,
|
|
468
|
+
isHor ? 0 : -axisHorPadding
|
|
469
|
+
],
|
|
470
|
+
children: [
|
|
471
|
+
/*#__PURE__*/ jsx(Axis, {
|
|
472
|
+
name: yAxis,
|
|
473
|
+
visible: false
|
|
474
|
+
}),
|
|
475
|
+
/*#__PURE__*/ jsx(Axis, {
|
|
476
|
+
name: x,
|
|
477
|
+
visible: false
|
|
478
|
+
}),
|
|
479
|
+
100 === chartType ? /*#__PURE__*/ jsx(Interval, {
|
|
480
|
+
position: `${x}*${yAxis}`,
|
|
481
|
+
tooltip: false,
|
|
482
|
+
style: {
|
|
483
|
+
fill: "transparent",
|
|
484
|
+
fillOpacity: 0,
|
|
485
|
+
stroke: "transparent",
|
|
486
|
+
strokeOpacity: 0
|
|
487
|
+
}
|
|
488
|
+
}) : /*#__PURE__*/ jsx(Line, {
|
|
489
|
+
position: `${x}*${yAxis}`,
|
|
490
|
+
tooltip: false,
|
|
491
|
+
style: {
|
|
492
|
+
stroke: "transparent",
|
|
493
|
+
strokeOpacity: 0
|
|
494
|
+
}
|
|
495
|
+
}),
|
|
496
|
+
auxiliaryLineData?.map((item, index)=>/*#__PURE__*/ jsx(AuxiliaryLine, {
|
|
497
|
+
name: item.name,
|
|
498
|
+
value: item.value,
|
|
499
|
+
isHorizontal: isHor
|
|
500
|
+
}, index))
|
|
501
|
+
]
|
|
502
|
+
}, `${axisHorPadding}${isHor}`),
|
|
503
|
+
/*#__PURE__*/ jsx(Axis, {
|
|
504
|
+
name: yAxis,
|
|
505
|
+
visible: true,
|
|
506
|
+
label: {
|
|
507
|
+
formatter (val) {
|
|
508
|
+
return getAxisFormat(val, safeIndicatorMap, y);
|
|
509
|
+
}
|
|
510
|
+
}
|
|
511
|
+
}),
|
|
512
|
+
/*#__PURE__*/ jsx(Axis, {
|
|
513
|
+
grid: null,
|
|
514
|
+
name: x,
|
|
515
|
+
visible: true,
|
|
516
|
+
label: {
|
|
517
|
+
autoEllipsis: true,
|
|
518
|
+
formatter: (text)=>isHor ? truncateText(text, chartInsWidth / 5) : text
|
|
519
|
+
}
|
|
520
|
+
}),
|
|
521
|
+
/*#__PURE__*/ jsx(Legend, {
|
|
522
|
+
items: [
|
|
523
|
+
{
|
|
524
|
+
value: y,
|
|
525
|
+
name: y,
|
|
526
|
+
marker: 100 === chartType ? {
|
|
527
|
+
symbol: "circle",
|
|
528
|
+
style: {
|
|
529
|
+
fill: themeColors[0],
|
|
530
|
+
r: 5
|
|
531
|
+
}
|
|
532
|
+
} : {
|
|
533
|
+
symbol: "hyphen",
|
|
534
|
+
style: {
|
|
535
|
+
stroke: themeColors[0],
|
|
536
|
+
lineWidth: 2
|
|
537
|
+
}
|
|
538
|
+
},
|
|
539
|
+
unchecked: legendMapRef.current?.[y] === false
|
|
540
|
+
},
|
|
541
|
+
{
|
|
542
|
+
value: `${y}`,
|
|
543
|
+
name: `${y}_compare`,
|
|
544
|
+
marker: 100 === chartType ? {
|
|
545
|
+
symbol: "circle",
|
|
546
|
+
style: {
|
|
547
|
+
fill: stripePatternRef.current,
|
|
548
|
+
r: 5
|
|
549
|
+
}
|
|
550
|
+
} : {
|
|
551
|
+
symbol: "hyphen",
|
|
552
|
+
style: {
|
|
553
|
+
stroke: themeColors[0],
|
|
554
|
+
lineWidth: 2,
|
|
555
|
+
lineDash: [
|
|
556
|
+
3,
|
|
557
|
+
1.5,
|
|
558
|
+
3
|
|
559
|
+
]
|
|
560
|
+
}
|
|
561
|
+
},
|
|
562
|
+
unchecked: legendMapRef.current?.[`${y}_compare`] === false
|
|
563
|
+
}
|
|
564
|
+
],
|
|
565
|
+
position: 2 == nodeSetting.showType ? "top" : "bottom",
|
|
566
|
+
offsetY: 100 === chartType ? 0 : 0,
|
|
567
|
+
maxItemWidth: 1,
|
|
568
|
+
itemName: {
|
|
569
|
+
formatter: (text)=>text.includes("_") ? `${getIndicatorCompareName(safeIndicatorMap, text)}(对比时间:${timeRange?.compareStartTime}~${timeRange?.compareEndTime})` : getIndicatorCompareName(safeIndicatorMap, text)
|
|
570
|
+
},
|
|
571
|
+
flipPage: false,
|
|
572
|
+
visible: isLegend,
|
|
573
|
+
name: legend,
|
|
574
|
+
custom: true,
|
|
575
|
+
onChange: (ev)=>{
|
|
576
|
+
if (!ev || !ev.item) return;
|
|
577
|
+
const { item } = ev;
|
|
578
|
+
const legendKey = item.name || item.value;
|
|
579
|
+
if (null == legendKey) return;
|
|
580
|
+
const checked = !item.unchecked;
|
|
581
|
+
if (!legendMapRef.current) legendMapRef.current = {};
|
|
582
|
+
legendMapRef.current[legendKey] = checked;
|
|
583
|
+
const chart = chartInsRef.current;
|
|
584
|
+
if (!chart) return;
|
|
585
|
+
const applyFilter = (target)=>{
|
|
586
|
+
if (!target) return;
|
|
587
|
+
if (!legendMapRef.current) legendMapRef.current = {};
|
|
588
|
+
try {
|
|
589
|
+
target.filter("groupType", (val)=>{
|
|
590
|
+
if (!val || "string" != typeof val) return true;
|
|
591
|
+
const mapValue = legendMapRef.current[val];
|
|
592
|
+
return false !== mapValue;
|
|
593
|
+
});
|
|
594
|
+
} catch (error) {}
|
|
595
|
+
};
|
|
596
|
+
try {
|
|
597
|
+
applyFilter(chart);
|
|
598
|
+
chart.render(true);
|
|
599
|
+
} catch (error) {}
|
|
600
|
+
}
|
|
601
|
+
}),
|
|
602
|
+
transformData.some((item)=>item?.nodeInfos?.info?.length > 0 || item?.nodeInfos?.infosCompare?.length > 0) ? /*#__PURE__*/ jsx(Fragment, {
|
|
603
|
+
children: 1 == nodeSetting.showType && NodeGeom ? /*#__PURE__*/ jsx(NodeGeom, {
|
|
604
|
+
pointData: pointData,
|
|
605
|
+
pointP: pointP
|
|
606
|
+
}) : 2 == nodeSetting.showType && NodeDetail ? 0 == chartOffset || chartOffset ? /*#__PURE__*/ jsx(NodeDetail, {
|
|
607
|
+
chartWidth: chartWidth,
|
|
608
|
+
chartOffset: chartOffset,
|
|
609
|
+
dvRows: transformData,
|
|
610
|
+
ratio: 2
|
|
611
|
+
}) : null : null
|
|
612
|
+
}) : null
|
|
613
|
+
]
|
|
614
|
+
}, getChartKey({
|
|
615
|
+
config,
|
|
616
|
+
nodeSetting
|
|
617
|
+
}));
|
|
618
|
+
};
|
|
619
|
+
const composite_GroupCompare = /*#__PURE__*/ memo(GroupCompare);
|
|
620
|
+
export { composite_GroupCompare as default };
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
export interface AuxiliaryLineProps {
|
|
2
|
+
name?: string;
|
|
3
|
+
value?: number | string | undefined;
|
|
4
|
+
isHorizontal?: boolean;
|
|
5
|
+
axis?: 'left' | 'right';
|
|
6
|
+
}
|
|
7
|
+
declare const _default: import("react").MemoExoticComponent<({ name, axis, value, isHorizontal }: AuxiliaryLineProps) => JSX.Element>;
|
|
8
|
+
export default _default;
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
import { Fragment, jsx, jsxs } from "react/jsx-runtime";
|
|
2
|
+
import { Annotation } from "bizcharts";
|
|
3
|
+
import { memo } from "react";
|
|
4
|
+
const AuxiliaryLine = ({ name = '', axis = 'left', value, isHorizontal })=>{
|
|
5
|
+
if (void 0 === value) return /*#__PURE__*/ jsx(Fragment, {});
|
|
6
|
+
const splitTextToMultiline = (text, maxLength = 5)=>{
|
|
7
|
+
let result = '';
|
|
8
|
+
for(let i = 0; i < text.length; i += maxLength)result += text.substring(i, i + maxLength) + '\n';
|
|
9
|
+
return result.trim();
|
|
10
|
+
};
|
|
11
|
+
const lineProps = {
|
|
12
|
+
start: [
|
|
13
|
+
'start',
|
|
14
|
+
value
|
|
15
|
+
],
|
|
16
|
+
end: [
|
|
17
|
+
'end',
|
|
18
|
+
value
|
|
19
|
+
],
|
|
20
|
+
...!isHorizontal && {
|
|
21
|
+
text: {
|
|
22
|
+
position: 'right' === axis ? 'end' : 'start',
|
|
23
|
+
content: splitTextToMultiline(name),
|
|
24
|
+
offsetY: -5,
|
|
25
|
+
offsetX: 'right' === axis ? -65 : 0,
|
|
26
|
+
style: {
|
|
27
|
+
fill: 'rgb(234, 54, 106)',
|
|
28
|
+
shadowBlur: 20,
|
|
29
|
+
shadowColor: 'red',
|
|
30
|
+
shadowOffsetX: 0,
|
|
31
|
+
shadowOffsetY: 0
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
},
|
|
35
|
+
style: {
|
|
36
|
+
stroke: 'rgb(234, 54, 106)'
|
|
37
|
+
}
|
|
38
|
+
};
|
|
39
|
+
return /*#__PURE__*/ jsxs(Fragment, {
|
|
40
|
+
children: [
|
|
41
|
+
/*#__PURE__*/ jsx(Annotation.Line, {
|
|
42
|
+
...lineProps
|
|
43
|
+
}),
|
|
44
|
+
isHorizontal && /*#__PURE__*/ jsx(Annotation.Text, {
|
|
45
|
+
position: [
|
|
46
|
+
'end',
|
|
47
|
+
value
|
|
48
|
+
],
|
|
49
|
+
content: splitTextToMultiline(name),
|
|
50
|
+
offsetX: 3,
|
|
51
|
+
offsetY: name.length > 5 ? 12 : 5,
|
|
52
|
+
style: {
|
|
53
|
+
fill: 'rgb(234, 54, 106)',
|
|
54
|
+
shadowBlur: 20,
|
|
55
|
+
shadowColor: 'red',
|
|
56
|
+
shadowOffsetX: 0,
|
|
57
|
+
shadowOffsetY: 0
|
|
58
|
+
}
|
|
59
|
+
})
|
|
60
|
+
]
|
|
61
|
+
});
|
|
62
|
+
};
|
|
63
|
+
const shared_AuxiliaryLine = /*#__PURE__*/ memo(AuxiliaryLine);
|
|
64
|
+
export { shared_AuxiliaryLine as default };
|