@easyv/charts 1.10.14 → 1.10.15
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/change.md +26 -0
- package/config.json +119 -0
- package/lib/components/Chart.js +5 -5
- package/lib/components/Legend.js +207 -16
- package/lib/components/Marquee.js +1 -1
- package/lib/components/PieChart.js +193 -102
- package/lib/formatter/legend.js +78 -26
- package/lib/utils/legendPlacement.js +37 -0
- package/package.json +1 -1
- package/src/components/Chart.js +11 -3
- package/src/components/Legend.js +256 -8
- package/src/components/Marquee.tsx +4 -4
- package/src/components/PieChart.js +161 -102
- package/src/formatter/legend.js +151 -68
- package/src/utils/legendPlacement.js +28 -0
package/src/components/Legend.js
CHANGED
|
@@ -3,6 +3,7 @@
|
|
|
3
3
|
*/
|
|
4
4
|
import React, { memo, useCallback, useState, useEffect, useRef } from "react";
|
|
5
5
|
import { getIcon, sortPie } from "../utils";
|
|
6
|
+
import { parseLegendAlignment } from "../utils/legendPlacement";
|
|
6
7
|
import TextOverflow from "./TextOverflow";
|
|
7
8
|
|
|
8
9
|
const defaultFont = {
|
|
@@ -32,6 +33,7 @@ export default memo(
|
|
|
32
33
|
translate: { x, y },
|
|
33
34
|
},
|
|
34
35
|
loop = {},
|
|
36
|
+
name: { layoutMode } = {},
|
|
35
37
|
font: { italic, bold, ...font } = defaultFont,
|
|
36
38
|
unselect: { opacity = 1 } = {},
|
|
37
39
|
},
|
|
@@ -39,6 +41,11 @@ export default memo(
|
|
|
39
41
|
formatter,
|
|
40
42
|
judge,
|
|
41
43
|
pieClick,
|
|
44
|
+
isPieChart = false,
|
|
45
|
+
chartWidth,
|
|
46
|
+
componentWidth,
|
|
47
|
+
marginLeft = 0,
|
|
48
|
+
marginRight = 0,
|
|
42
49
|
}) => {
|
|
43
50
|
if (!show) return null;
|
|
44
51
|
|
|
@@ -86,11 +93,16 @@ export default memo(
|
|
|
86
93
|
};
|
|
87
94
|
|
|
88
95
|
const _series = sortPie(series, order, columnsSeries);
|
|
89
|
-
const
|
|
96
|
+
const {
|
|
97
|
+
alignment: _alignment,
|
|
98
|
+
position,
|
|
99
|
+
isCenterTopOrBottom,
|
|
100
|
+
isSidePlacement,
|
|
101
|
+
} = parseLegendAlignment(alignment);
|
|
90
102
|
const legendMainAlign =
|
|
91
|
-
|
|
103
|
+
_alignment == "left"
|
|
92
104
|
? "flex-start"
|
|
93
|
-
:
|
|
105
|
+
: _alignment == "center"
|
|
94
106
|
? "center"
|
|
95
107
|
: "flex-end";
|
|
96
108
|
const length = _series.length;
|
|
@@ -204,6 +216,112 @@ export default memo(
|
|
|
204
216
|
return Math.max(maxMeasured, maxCfg);
|
|
205
217
|
});
|
|
206
218
|
|
|
219
|
+
const isPieAdaptive = isPieChart && layoutMode === "Adaptive";
|
|
220
|
+
const isPieFixedWidthGrid =
|
|
221
|
+
isPieChart &&
|
|
222
|
+
(layoutMode === "FixedWidth" ||
|
|
223
|
+
((layoutMode == null || layoutMode === "") &&
|
|
224
|
+
LegendType == "FixedWidth"));
|
|
225
|
+
const isFixedWidth = isPieChart
|
|
226
|
+
? isPieFixedWidthGrid
|
|
227
|
+
: LegendType == "FixedWidth";
|
|
228
|
+
const isSideLegend = isPieAdaptive && isSidePlacement;
|
|
229
|
+
const isTopBottomAdaptive = isPieAdaptive && isCenterTopOrBottom;
|
|
230
|
+
const fullWidth = componentWidth ?? chartWidth ?? 0;
|
|
231
|
+
const legendAreaWidth = Math.max(0, fullWidth - marginLeft - marginRight);
|
|
232
|
+
const sideLegendMaxWidth = isSideLegend
|
|
233
|
+
? Math.max(
|
|
234
|
+
0,
|
|
235
|
+
position === "left" || _alignment === "left"
|
|
236
|
+
? marginLeft
|
|
237
|
+
: marginRight,
|
|
238
|
+
)
|
|
239
|
+
: 0;
|
|
240
|
+
const isSideLegendOnRight =
|
|
241
|
+
isSideLegend &&
|
|
242
|
+
(position === "right" ||
|
|
243
|
+
(_alignment === "right" && position !== "left"));
|
|
244
|
+
const fixedColumnsPerRow = Math.min(
|
|
245
|
+
Math.max(1, Number(gridTemplateColumns) || 1),
|
|
246
|
+
length,
|
|
247
|
+
);
|
|
248
|
+
const isPieTopBottomFixedMultiCol =
|
|
249
|
+
isPieChart &&
|
|
250
|
+
isFixedWidth &&
|
|
251
|
+
isCenterTopOrBottom &&
|
|
252
|
+
fixedColumnsPerRow > 1;
|
|
253
|
+
|
|
254
|
+
const formatterExtra = {
|
|
255
|
+
...config,
|
|
256
|
+
valueMaxWidth,
|
|
257
|
+
percentMaxWidth,
|
|
258
|
+
nameMaxWidth,
|
|
259
|
+
otherData: data,
|
|
260
|
+
columnsSeries,
|
|
261
|
+
fieldColumnKeys,
|
|
262
|
+
fieldsColumnWidths,
|
|
263
|
+
legendPosition: position,
|
|
264
|
+
isPieAdaptive: true,
|
|
265
|
+
...(isSideLegend && sideLegendMaxWidth > 0
|
|
266
|
+
? { adaptiveMaxWidth: sideLegendMaxWidth }
|
|
267
|
+
: {}),
|
|
268
|
+
...(isTopBottomAdaptive ? { chartWidth: legendAreaWidth } : {}),
|
|
269
|
+
};
|
|
270
|
+
|
|
271
|
+
const renderPieSideItem = (series, i) => {
|
|
272
|
+
const {
|
|
273
|
+
type,
|
|
274
|
+
name,
|
|
275
|
+
displayName,
|
|
276
|
+
fieldName,
|
|
277
|
+
icon,
|
|
278
|
+
selected,
|
|
279
|
+
index,
|
|
280
|
+
} = series;
|
|
281
|
+
const _icon = getIcon(type, icon, series?.config?.line?.type);
|
|
282
|
+
return (
|
|
283
|
+
<li
|
|
284
|
+
key={i}
|
|
285
|
+
onClick={onClick(fieldName)}
|
|
286
|
+
data-name={displayName || name}
|
|
287
|
+
data-index={index}
|
|
288
|
+
style={{
|
|
289
|
+
display: "flex",
|
|
290
|
+
width: "max-content",
|
|
291
|
+
maxWidth: sideLegendMaxWidth || undefined,
|
|
292
|
+
opacity: selected === false ? opacity / 100 : 1,
|
|
293
|
+
alignItems: "center",
|
|
294
|
+
cursor: "pointer",
|
|
295
|
+
gap: _icon.gap,
|
|
296
|
+
minWidth: 0,
|
|
297
|
+
overflow: "hidden",
|
|
298
|
+
boxSizing: "border-box",
|
|
299
|
+
}}
|
|
300
|
+
>
|
|
301
|
+
{formatter ? (
|
|
302
|
+
formatter(series, formatterExtra)
|
|
303
|
+
) : (
|
|
304
|
+
<>
|
|
305
|
+
<span style={{ ..._icon, flexShrink: 0 }} />
|
|
306
|
+
<TextOverflow
|
|
307
|
+
type="ellipsis"
|
|
308
|
+
value={displayName || name}
|
|
309
|
+
style={{
|
|
310
|
+
...font,
|
|
311
|
+
fontStyle: italic ? "italic" : "normal",
|
|
312
|
+
fontWeight: bold ? "bold" : "normal",
|
|
313
|
+
minWidth: 0,
|
|
314
|
+
flex: "1 1 0%",
|
|
315
|
+
maxWidth: "100%",
|
|
316
|
+
}}
|
|
317
|
+
speed={speed}
|
|
318
|
+
/>
|
|
319
|
+
</>
|
|
320
|
+
)}
|
|
321
|
+
</li>
|
|
322
|
+
);
|
|
323
|
+
};
|
|
324
|
+
|
|
207
325
|
const stylePieOrAxis = formatter
|
|
208
326
|
? {
|
|
209
327
|
display: "flex",
|
|
@@ -234,7 +352,130 @@ export default memo(
|
|
|
234
352
|
height: loop.show ? height : "auto",
|
|
235
353
|
overflowY: loop.show ? "scroll" : "auto",
|
|
236
354
|
};
|
|
237
|
-
|
|
355
|
+
if (isPieAdaptive && isSideLegend) {
|
|
356
|
+
const pieAdaptiveWrapperStyle = {
|
|
357
|
+
position: "absolute",
|
|
358
|
+
display: "flex",
|
|
359
|
+
flexDirection: "column",
|
|
360
|
+
width: "max-content",
|
|
361
|
+
maxWidth: sideLegendMaxWidth || undefined,
|
|
362
|
+
alignItems: isSideLegendOnRight ? "flex-end" : "flex-start",
|
|
363
|
+
...getPosition(position, _alignment, x, y),
|
|
364
|
+
height: loop.show ? height : "auto",
|
|
365
|
+
overflowY: loop.show ? "scroll" : "auto",
|
|
366
|
+
};
|
|
367
|
+
const pieAdaptiveListStyle = {
|
|
368
|
+
display: "flex",
|
|
369
|
+
flexDirection: "column",
|
|
370
|
+
width: "max-content",
|
|
371
|
+
maxWidth: "100%",
|
|
372
|
+
alignItems: isSideLegendOnRight ? "flex-end" : "flex-start",
|
|
373
|
+
margin: 0,
|
|
374
|
+
padding: 0,
|
|
375
|
+
listStyle: "none",
|
|
376
|
+
gap: `${gridRowGap}px`,
|
|
377
|
+
};
|
|
378
|
+
return (
|
|
379
|
+
<div
|
|
380
|
+
className="__easyv-legend-wrapper"
|
|
381
|
+
style={pieAdaptiveWrapperStyle}
|
|
382
|
+
ref={ref_container}
|
|
383
|
+
>
|
|
384
|
+
<ul style={pieAdaptiveListStyle}>
|
|
385
|
+
{_series.map((series, i) => renderPieSideItem(series, i))}
|
|
386
|
+
</ul>
|
|
387
|
+
</div>
|
|
388
|
+
);
|
|
389
|
+
}
|
|
390
|
+
|
|
391
|
+
if (isTopBottomAdaptive) {
|
|
392
|
+
const topBottomWrapperStyle = {
|
|
393
|
+
position: "absolute",
|
|
394
|
+
width: legendAreaWidth || "100%",
|
|
395
|
+
maxWidth: legendAreaWidth || "100%",
|
|
396
|
+
boxSizing: "border-box",
|
|
397
|
+
...getPosition(position, _alignment, x, y),
|
|
398
|
+
height: loop.show ? height : "auto",
|
|
399
|
+
overflowY: loop.show ? "scroll" : "auto",
|
|
400
|
+
};
|
|
401
|
+
const topBottomListStyle = {
|
|
402
|
+
display: "flex",
|
|
403
|
+
flexDirection: "row",
|
|
404
|
+
flexWrap: "wrap",
|
|
405
|
+
width: "100%",
|
|
406
|
+
maxWidth: "100%",
|
|
407
|
+
boxSizing: "border-box",
|
|
408
|
+
margin: 0,
|
|
409
|
+
padding: 0,
|
|
410
|
+
listStyle: "none",
|
|
411
|
+
justifyContent: legendMainAlign,
|
|
412
|
+
gap: `${gridRowGap}px ${gridColumnGap}px`,
|
|
413
|
+
};
|
|
414
|
+
return (
|
|
415
|
+
<div
|
|
416
|
+
className="__easyv-legend-wrapper"
|
|
417
|
+
style={topBottomWrapperStyle}
|
|
418
|
+
ref={ref_container}
|
|
419
|
+
>
|
|
420
|
+
<ul style={topBottomListStyle}>
|
|
421
|
+
{_series.map((series, i) => {
|
|
422
|
+
const {
|
|
423
|
+
type,
|
|
424
|
+
name,
|
|
425
|
+
displayName,
|
|
426
|
+
fieldName,
|
|
427
|
+
icon,
|
|
428
|
+
selected,
|
|
429
|
+
index,
|
|
430
|
+
} = series;
|
|
431
|
+
const _icon = getIcon(type, icon, series?.config?.line?.type);
|
|
432
|
+
return (
|
|
433
|
+
<li
|
|
434
|
+
key={i}
|
|
435
|
+
onClick={onClick(fieldName)}
|
|
436
|
+
data-name={displayName || name}
|
|
437
|
+
data-index={index}
|
|
438
|
+
style={{
|
|
439
|
+
display: "inline-flex",
|
|
440
|
+
alignItems: "center",
|
|
441
|
+
width: "max-content",
|
|
442
|
+
maxWidth: "100%",
|
|
443
|
+
minWidth: 0,
|
|
444
|
+
overflow: "hidden",
|
|
445
|
+
boxSizing: "border-box",
|
|
446
|
+
opacity: selected === false ? opacity / 100 : 1,
|
|
447
|
+
cursor: "pointer",
|
|
448
|
+
gap: _icon.gap,
|
|
449
|
+
flexShrink: 0,
|
|
450
|
+
}}
|
|
451
|
+
>
|
|
452
|
+
{formatter ? (
|
|
453
|
+
formatter(series, formatterExtra)
|
|
454
|
+
) : (
|
|
455
|
+
<>
|
|
456
|
+
<span style={{ ..._icon, flexShrink: 0 }} />
|
|
457
|
+
<TextOverflow
|
|
458
|
+
type="ellipsis"
|
|
459
|
+
value={displayName || name}
|
|
460
|
+
style={{
|
|
461
|
+
...font,
|
|
462
|
+
fontStyle: italic ? "italic" : "normal",
|
|
463
|
+
fontWeight: bold ? "bold" : "normal",
|
|
464
|
+
minWidth: 0,
|
|
465
|
+
}}
|
|
466
|
+
speed={speed}
|
|
467
|
+
/>
|
|
468
|
+
</>
|
|
469
|
+
)}
|
|
470
|
+
</li>
|
|
471
|
+
);
|
|
472
|
+
})}
|
|
473
|
+
</ul>
|
|
474
|
+
</div>
|
|
475
|
+
);
|
|
476
|
+
}
|
|
477
|
+
|
|
478
|
+
return isFixedWidth ? (
|
|
238
479
|
<div
|
|
239
480
|
className="__easyv-legend-wrapper"
|
|
240
481
|
style={{
|
|
@@ -249,10 +490,17 @@ export default memo(
|
|
|
249
490
|
<ul
|
|
250
491
|
style={{
|
|
251
492
|
display: "grid",
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
493
|
+
rowGap: gridRowGap + "px",
|
|
494
|
+
columnGap:
|
|
495
|
+
(isPieTopBottomFixedMultiCol
|
|
496
|
+
? Math.max(gridColumnGap, 40)
|
|
497
|
+
: gridColumnGap) + "px",
|
|
498
|
+
justifyContent: isPieTopBottomFixedMultiCol
|
|
499
|
+
? legendMainAlign
|
|
500
|
+
: undefined,
|
|
501
|
+
gridTemplateColumns: isPieTopBottomFixedMultiCol
|
|
502
|
+
? `repeat(${fixedColumnsPerRow}, max-content)`
|
|
503
|
+
: `repeat(${fixedColumnsPerRow}, minmax(0, 1fr))`,
|
|
256
504
|
}}
|
|
257
505
|
>
|
|
258
506
|
{_series.map((series, i) => {
|
|
@@ -37,7 +37,7 @@ export default memo(
|
|
|
37
37
|
const startAnimation = (lineWidth: number) => {
|
|
38
38
|
const animation = (timestamp: number) => {
|
|
39
39
|
let frame = Math.round(
|
|
40
|
-
((timestamp * speed_.current) % (lineWidth * 100)) / 100
|
|
40
|
+
((timestamp * speed_.current) % (lineWidth * 100)) / 100,
|
|
41
41
|
);
|
|
42
42
|
target.current.style.transform = `translate(-${frame}px,0px)`;
|
|
43
43
|
target.current.nextSibling.style.transform = `translate(-${frame}px,0px)`;
|
|
@@ -57,7 +57,7 @@ export default memo(
|
|
|
57
57
|
const containerWidth = rootRef.current.clientWidth;
|
|
58
58
|
|
|
59
59
|
if (textWidth <= containerWidth) {
|
|
60
|
-
console.log("文字全部可视");
|
|
60
|
+
// console.log("文字全部可视");
|
|
61
61
|
//表示文字全部可视
|
|
62
62
|
cancelAnimationFrame(timer.current || 0);
|
|
63
63
|
target.current.style.transform = "translate(0px,0px)"; //重置偏移
|
|
@@ -88,7 +88,7 @@ export default memo(
|
|
|
88
88
|
root: rootRef.current,
|
|
89
89
|
rootMargin: "0px 0px 0px 0px",
|
|
90
90
|
threshold: new Array(101).fill(0).map((d, i) => i / 100), //这里设置了[0-1]之间所有的阈值,保证每一帧的变化都能被观察到
|
|
91
|
-
}
|
|
91
|
+
},
|
|
92
92
|
);
|
|
93
93
|
|
|
94
94
|
// 使用ResizeObserver监听元素尺寸变化,这样即使有3D变换也能准确检测
|
|
@@ -142,5 +142,5 @@ export default memo(
|
|
|
142
142
|
})}
|
|
143
143
|
</div>
|
|
144
144
|
);
|
|
145
|
-
})
|
|
145
|
+
}),
|
|
146
146
|
);
|
|
@@ -34,10 +34,21 @@ import { pieLegendFormatter as legendFormatter } from "../formatter";
|
|
|
34
34
|
import ringCss from "../css/piechart.module.css";
|
|
35
35
|
import { useAiDataOfPie } from "../hooks";
|
|
36
36
|
import { PieTooltip } from "./PieTooltip";
|
|
37
|
-
import {
|
|
37
|
+
import { getPieAdaptiveMarginPreset } from "../utils/legendPlacement";
|
|
38
38
|
|
|
39
39
|
const PI = Math.PI;
|
|
40
40
|
|
|
41
|
+
const PIE_ADAPTIVE_MARGINS = {
|
|
42
|
+
right: { marginTop: 24, marginBottom: 24, marginLeft: 0, marginRight: 200 },
|
|
43
|
+
left: { marginTop: 24, marginBottom: 24, marginLeft: 200, marginRight: 0 },
|
|
44
|
+
top: { marginTop: 150, marginBottom: 24, marginLeft: 24, marginRight: 24 },
|
|
45
|
+
bottom: { marginTop: 24, marginBottom: 150, marginLeft: 24, marginRight: 24 },
|
|
46
|
+
hidden: { marginTop: 24, marginBottom: 24, marginLeft: 24, marginRight: 24 },
|
|
47
|
+
};
|
|
48
|
+
|
|
49
|
+
const getPieAdaptiveMargin = (show, alignment) =>
|
|
50
|
+
getPieAdaptiveMarginPreset(show, alignment, PIE_ADAPTIVE_MARGINS);
|
|
51
|
+
|
|
41
52
|
const defaultChart = {
|
|
42
53
|
outerRadius: 1,
|
|
43
54
|
innerRadius: 0,
|
|
@@ -49,111 +60,111 @@ const defaultChart = {
|
|
|
49
60
|
};
|
|
50
61
|
const defaultAngle = { startAngle: 0, endAngle: 360, antiClockwise: false };
|
|
51
62
|
|
|
52
|
-
const nameDy = (showValue, showPercent, mode, dir) => {
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
};
|
|
67
|
-
const valueDy = (value1, mode, dir) => {
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
};
|
|
63
|
+
// const nameDy = (showValue, showPercent, mode, dir) => {
|
|
64
|
+
// if (showValue || showPercent) {
|
|
65
|
+
// if (mode == "vertical") {
|
|
66
|
+
// return dir == 1 ? "1.1em" : "-2.6em";
|
|
67
|
+
// } else {
|
|
68
|
+
// return 0;
|
|
69
|
+
// }
|
|
70
|
+
// } else {
|
|
71
|
+
// if (mode == "vertical") {
|
|
72
|
+
// return dir * 1.1 + "em";
|
|
73
|
+
// } else {
|
|
74
|
+
// return 0;
|
|
75
|
+
// }
|
|
76
|
+
// }
|
|
77
|
+
// };
|
|
78
|
+
// const valueDy = (value1, mode, dir) => {
|
|
79
|
+
// if (value1) {
|
|
80
|
+
// if (mode == "vertical") {
|
|
81
|
+
// return "1.5em";
|
|
82
|
+
// } else {
|
|
83
|
+
// return 0;
|
|
84
|
+
// }
|
|
85
|
+
// } else {
|
|
86
|
+
// if (mode == "vertical") {
|
|
87
|
+
// return dir == 1 ? "1.1em" : "-1.1em";
|
|
88
|
+
// } else {
|
|
89
|
+
// return 0;
|
|
90
|
+
// }
|
|
91
|
+
// }
|
|
92
|
+
// };
|
|
82
93
|
|
|
83
|
-
const percentDy_ = (showName, showValue, mode, dir) => {
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
};
|
|
94
|
+
// const percentDy_ = (showName, showValue, mode, dir) => {
|
|
95
|
+
// if (showValue) {
|
|
96
|
+
// return 0;
|
|
97
|
+
// }
|
|
98
|
+
// if (showName) {
|
|
99
|
+
// if (mode == "vertical") {
|
|
100
|
+
// return "1.5em";
|
|
101
|
+
// } else {
|
|
102
|
+
// return 0;
|
|
103
|
+
// }
|
|
104
|
+
// } else {
|
|
105
|
+
// if (mode == "vertical") {
|
|
106
|
+
// return dir * 1.1 + "em";
|
|
107
|
+
// } else {
|
|
108
|
+
// return 0;
|
|
109
|
+
// }
|
|
110
|
+
// }
|
|
111
|
+
// };
|
|
101
112
|
|
|
102
|
-
const percentX = (showName, showValue, mode, x) => {
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
};
|
|
113
|
+
// const percentX = (showName, showValue, mode, x) => {
|
|
114
|
+
// if (showValue) {
|
|
115
|
+
// return "";
|
|
116
|
+
// }
|
|
117
|
+
// if (showName) {
|
|
118
|
+
// if (mode == "vertical") {
|
|
119
|
+
// return x;
|
|
120
|
+
// } else {
|
|
121
|
+
// return "";
|
|
122
|
+
// }
|
|
123
|
+
// } else {
|
|
124
|
+
// return x;
|
|
125
|
+
// }
|
|
126
|
+
// };
|
|
116
127
|
|
|
117
|
-
const percentDx = (showName, showValue, mode) => {
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
};
|
|
128
|
+
// const percentDx = (showName, showValue, mode) => {
|
|
129
|
+
// if (showValue) {
|
|
130
|
+
// return "0.5em";
|
|
131
|
+
// }
|
|
132
|
+
// if (showName) {
|
|
133
|
+
// if (mode == "vertical") {
|
|
134
|
+
// return 0;
|
|
135
|
+
// } else {
|
|
136
|
+
// return "0.5em";
|
|
137
|
+
// }
|
|
138
|
+
// } else {
|
|
139
|
+
// return 0;
|
|
140
|
+
// }
|
|
141
|
+
// };
|
|
131
142
|
|
|
132
|
-
const percentDy = (showName, showValue, mode) => {
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
};
|
|
143
|
+
// const percentDy = (showName, showValue, mode) => {
|
|
144
|
+
// if (showValue) {
|
|
145
|
+
// return 0;
|
|
146
|
+
// }
|
|
147
|
+
// if (showName) {
|
|
148
|
+
// if (mode == "vertical") {
|
|
149
|
+
// return "1.5em";
|
|
150
|
+
// } else {
|
|
151
|
+
// return 0;
|
|
152
|
+
// }
|
|
153
|
+
// } else {
|
|
154
|
+
// return 0;
|
|
155
|
+
// }
|
|
156
|
+
// };
|
|
146
157
|
|
|
147
|
-
const valueDx = (showName, mode) => {
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
};
|
|
158
|
+
// const valueDx = (showName, mode) => {
|
|
159
|
+
// if (!showName) {
|
|
160
|
+
// return "";
|
|
161
|
+
// }
|
|
162
|
+
// if (mode == "vertical") {
|
|
163
|
+
// return "";
|
|
164
|
+
// } else {
|
|
165
|
+
// return "0.5em";
|
|
166
|
+
// }
|
|
167
|
+
// };
|
|
157
168
|
|
|
158
169
|
const getCoord = (deg, radius) => {
|
|
159
170
|
var x = Math.cos(deg) * radius,
|
|
@@ -254,7 +265,7 @@ const Component = memo(
|
|
|
254
265
|
label,
|
|
255
266
|
legend: { formatter = legendFormatter, ...legend },
|
|
256
267
|
animation: { ringDuration, labelDuration } = {},
|
|
257
|
-
margin: { marginLeft, marginTop },
|
|
268
|
+
margin: { marginLeft, marginTop, marginRight, marginBottom },
|
|
258
269
|
},
|
|
259
270
|
fan: {
|
|
260
271
|
chart = defaultChart,
|
|
@@ -301,7 +312,45 @@ const Component = memo(
|
|
|
301
312
|
height: chartHeight,
|
|
302
313
|
triggerOnRelative,
|
|
303
314
|
onEmit,
|
|
315
|
+
updateConfig,
|
|
304
316
|
} = useContext(chartContext);
|
|
317
|
+
const { show: legendShow, name: { layoutMode: legendLayoutMode } = {} } =
|
|
318
|
+
legend.config;
|
|
319
|
+
const legendAlignment = legend.config?.layout?.alignment;
|
|
320
|
+
const adaptiveMarginPresetKey = useRef("");
|
|
321
|
+
useEffect(() => {
|
|
322
|
+
if (legendLayoutMode !== "Adaptive" || !updateConfig) return;
|
|
323
|
+
const presetKey = `${legendLayoutMode}-${legendShow}-${legendAlignment}`;
|
|
324
|
+
if (adaptiveMarginPresetKey.current === presetKey) return;
|
|
325
|
+
adaptiveMarginPresetKey.current = presetKey;
|
|
326
|
+
const target = getPieAdaptiveMargin(legendShow, legendAlignment);
|
|
327
|
+
updateConfig({
|
|
328
|
+
id,
|
|
329
|
+
type: "config",
|
|
330
|
+
payload: [
|
|
331
|
+
{
|
|
332
|
+
path: ["chart", "margin", "marginTop"],
|
|
333
|
+
field: "value",
|
|
334
|
+
value: target.marginTop,
|
|
335
|
+
},
|
|
336
|
+
{
|
|
337
|
+
path: ["chart", "margin", "marginBottom"],
|
|
338
|
+
field: "value",
|
|
339
|
+
value: target.marginBottom,
|
|
340
|
+
},
|
|
341
|
+
{
|
|
342
|
+
path: ["chart", "margin", "marginLeft"],
|
|
343
|
+
field: "value",
|
|
344
|
+
value: target.marginLeft,
|
|
345
|
+
},
|
|
346
|
+
{
|
|
347
|
+
path: ["chart", "margin", "marginRight"],
|
|
348
|
+
field: "value",
|
|
349
|
+
value: target.marginRight,
|
|
350
|
+
},
|
|
351
|
+
],
|
|
352
|
+
});
|
|
353
|
+
}, [id, updateConfig, legendLayoutMode, legendShow, legendAlignment]);
|
|
305
354
|
const [y, setY] = useState(1);
|
|
306
355
|
const radius = (Math.min(chartWidth, chartHeight) / 2) * outerRadius;
|
|
307
356
|
|
|
@@ -626,6 +675,10 @@ const Component = memo(
|
|
|
626
675
|
<Legend
|
|
627
676
|
{...legend}
|
|
628
677
|
height={chartHeight}
|
|
678
|
+
componentWidth={width}
|
|
679
|
+
marginLeft={marginLeft}
|
|
680
|
+
marginRight={marginRight}
|
|
681
|
+
isPieChart
|
|
629
682
|
columnsSeries={columnsSeries}
|
|
630
683
|
data={data}
|
|
631
684
|
series={_arcs.map((arc) => ({
|
|
@@ -897,6 +950,10 @@ const Component = memo(
|
|
|
897
950
|
<Legend
|
|
898
951
|
{...legend}
|
|
899
952
|
height={chartHeight}
|
|
953
|
+
componentWidth={width}
|
|
954
|
+
marginLeft={marginLeft}
|
|
955
|
+
marginRight={marginRight}
|
|
956
|
+
isPieChart
|
|
900
957
|
data={data}
|
|
901
958
|
columnsSeries={columnsSeries}
|
|
902
959
|
series={_arcs.map((arc) => ({
|
|
@@ -1031,7 +1088,9 @@ const Current = ({
|
|
|
1031
1088
|
value={nameTemp}
|
|
1032
1089
|
speed={speed}
|
|
1033
1090
|
style={{
|
|
1091
|
+
width: "100%",
|
|
1034
1092
|
maxWidth,
|
|
1093
|
+
textAlign: "center",
|
|
1035
1094
|
display: textOverflow == "marquee" ? "flex" : "bolck",
|
|
1036
1095
|
justifyContent: "center",
|
|
1037
1096
|
...getFontStyle(nameFont),
|