@ant-design/agentic-ui 2.1.0 → 2.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/dist/History/components/HistoryEmpty.d.ts +17 -0
- package/dist/History/components/HistoryEmpty.js +50 -0
- package/dist/History/components/HistoryEmptyIcon.d.ts +5 -0
- package/dist/History/components/HistoryEmptyIcon.js +1214 -0
- package/dist/History/components/HistoryList.d.ts +1 -0
- package/dist/History/components/HistoryList.js +6 -0
- package/dist/History/components/SearchComponent.js +10 -4
- package/dist/History/components/index.d.ts +1 -0
- package/dist/History/components/index.js +2 -0
- package/dist/History/index.js +39 -27
- package/dist/History/style.js +12 -0
- package/dist/History/types/index.d.ts +2 -2
- package/dist/Hooks/useIntersectionOnce.d.ts +5 -0
- package/dist/Hooks/useIntersectionOnce.js +79 -0
- package/dist/Hooks/useLanguage.d.ts +2 -0
- package/dist/I18n/locales.d.ts +2 -0
- package/dist/I18n/locales.js +4 -0
- package/dist/MarkdownEditor/editor/parser/parserMarkdownToSlateNode.js +31 -3
- package/dist/MarkdownEditor/editor/parser/remarkParse.js +2 -2
- package/dist/MarkdownEditor/editor/utils/markdownToHtml.js +4 -4
- package/dist/MarkdownInputField/MarkdownInputField.js +24 -20
- package/dist/Plugins/chart/AreaChart/index.js +20 -9
- package/dist/Plugins/chart/BarChart/index.js +12 -1
- package/dist/Plugins/chart/ChartMark/Area.js +21 -10
- package/dist/Plugins/chart/ChartMark/Bar.js +19 -8
- package/dist/Plugins/chart/ChartMark/Column.js +19 -8
- package/dist/Plugins/chart/ChartMark/Line.js +20 -9
- package/dist/Plugins/chart/ChartMark/Pie.js +12 -1
- package/dist/Plugins/chart/ChartRender.js +183 -48
- package/dist/Plugins/chart/DonutChart/index.js +12 -1
- package/dist/Plugins/chart/FunnelChart/index.d.ts +2 -0
- package/dist/Plugins/chart/FunnelChart/index.js +69 -18
- package/dist/Plugins/chart/LineChart/index.js +20 -9
- package/dist/Plugins/chart/RadarChart/index.js +19 -8
- package/dist/Plugins/chart/ScatterChart/index.js +12 -1
- package/dist/Plugins/chart/loadChartRuntime.d.ts +18 -0
- package/dist/Plugins/chart/loadChartRuntime.js +91 -0
- package/dist/Plugins/defaultPlugins.d.ts +3 -0
- package/dist/Plugins/defaultPlugins.js +2 -0
- package/dist/Plugins/katex/InlineKatex.js +3 -2
- package/dist/Plugins/mermaid/Mermaid.d.ts +5 -2
- package/dist/Plugins/mermaid/Mermaid.js +130 -38
- package/dist/Plugins/mermaid/index.js +1 -1
- package/dist/TaskList/index.js +2 -8
- package/dist/TaskList/style.js +1 -7
- package/package.json +3 -3
|
@@ -12,15 +12,26 @@ import React, { useImperativeHandle, useRef } from "react";
|
|
|
12
12
|
import { Bar as ChartBar } from "react-chartjs-2";
|
|
13
13
|
import { stringFormatNumber } from "../utils";
|
|
14
14
|
import { Container } from "./Container";
|
|
15
|
-
|
|
16
|
-
CategoryScale,
|
|
17
|
-
LinearScale,
|
|
18
|
-
BarElement,
|
|
19
|
-
Title,
|
|
20
|
-
Tooltip,
|
|
21
|
-
Legend
|
|
22
|
-
);
|
|
15
|
+
var chartMarkBarRegistered = false;
|
|
23
16
|
var Bar = (props) => {
|
|
17
|
+
React.useMemo(() => {
|
|
18
|
+
if (chartMarkBarRegistered) {
|
|
19
|
+
return void 0;
|
|
20
|
+
}
|
|
21
|
+
if (typeof window === "undefined") {
|
|
22
|
+
return void 0;
|
|
23
|
+
}
|
|
24
|
+
ChartJS.register(
|
|
25
|
+
CategoryScale,
|
|
26
|
+
LinearScale,
|
|
27
|
+
BarElement,
|
|
28
|
+
Title,
|
|
29
|
+
Tooltip,
|
|
30
|
+
Legend
|
|
31
|
+
);
|
|
32
|
+
chartMarkBarRegistered = true;
|
|
33
|
+
return void 0;
|
|
34
|
+
}, []);
|
|
24
35
|
const chartRef = React.useRef(void 0);
|
|
25
36
|
const htmlRef = useRef(null);
|
|
26
37
|
const barChartRef = useRef(null);
|
|
@@ -12,15 +12,26 @@ import React, { useImperativeHandle, useRef } from "react";
|
|
|
12
12
|
import { Bar as ChartBar } from "react-chartjs-2";
|
|
13
13
|
import { stringFormatNumber } from "../utils";
|
|
14
14
|
import { Container } from "./Container";
|
|
15
|
-
|
|
16
|
-
CategoryScale,
|
|
17
|
-
LinearScale,
|
|
18
|
-
BarElement,
|
|
19
|
-
Title,
|
|
20
|
-
Tooltip,
|
|
21
|
-
Legend
|
|
22
|
-
);
|
|
15
|
+
var chartMarkColumnRegistered = false;
|
|
23
16
|
var Column = (props) => {
|
|
17
|
+
React.useMemo(() => {
|
|
18
|
+
if (chartMarkColumnRegistered) {
|
|
19
|
+
return void 0;
|
|
20
|
+
}
|
|
21
|
+
if (typeof window === "undefined") {
|
|
22
|
+
return void 0;
|
|
23
|
+
}
|
|
24
|
+
ChartJS.register(
|
|
25
|
+
CategoryScale,
|
|
26
|
+
LinearScale,
|
|
27
|
+
BarElement,
|
|
28
|
+
Title,
|
|
29
|
+
Tooltip,
|
|
30
|
+
Legend
|
|
31
|
+
);
|
|
32
|
+
chartMarkColumnRegistered = true;
|
|
33
|
+
return void 0;
|
|
34
|
+
}, []);
|
|
24
35
|
const chartRef = React.useRef(void 0);
|
|
25
36
|
const htmlRef = useRef(null);
|
|
26
37
|
const barChartRef = useRef(null);
|
|
@@ -13,16 +13,27 @@ import React, { useImperativeHandle, useRef } from "react";
|
|
|
13
13
|
import { Line as ChartLine } from "react-chartjs-2";
|
|
14
14
|
import { stringFormatNumber } from "../utils";
|
|
15
15
|
import { Container } from "./Container";
|
|
16
|
-
|
|
17
|
-
CategoryScale,
|
|
18
|
-
LinearScale,
|
|
19
|
-
PointElement,
|
|
20
|
-
LineElement,
|
|
21
|
-
Title,
|
|
22
|
-
Tooltip,
|
|
23
|
-
Legend
|
|
24
|
-
);
|
|
16
|
+
var chartMarkLineRegistered = false;
|
|
25
17
|
var Line = (props) => {
|
|
18
|
+
React.useMemo(() => {
|
|
19
|
+
if (chartMarkLineRegistered) {
|
|
20
|
+
return void 0;
|
|
21
|
+
}
|
|
22
|
+
if (typeof window === "undefined") {
|
|
23
|
+
return void 0;
|
|
24
|
+
}
|
|
25
|
+
ChartJS.register(
|
|
26
|
+
CategoryScale,
|
|
27
|
+
LinearScale,
|
|
28
|
+
PointElement,
|
|
29
|
+
LineElement,
|
|
30
|
+
Title,
|
|
31
|
+
Tooltip,
|
|
32
|
+
Legend
|
|
33
|
+
);
|
|
34
|
+
chartMarkLineRegistered = true;
|
|
35
|
+
return void 0;
|
|
36
|
+
}, []);
|
|
26
37
|
const chartRef = React.useRef(void 0);
|
|
27
38
|
const htmlRef = useRef(null);
|
|
28
39
|
const lineChartRef = useRef(null);
|
|
@@ -4,8 +4,19 @@ import React, { useImperativeHandle, useRef } from "react";
|
|
|
4
4
|
import { Doughnut } from "react-chartjs-2";
|
|
5
5
|
import { defaultColorList } from "../const";
|
|
6
6
|
import { Container } from "./Container";
|
|
7
|
-
|
|
7
|
+
var chartMarkPieRegistered = false;
|
|
8
8
|
var Pie = (props) => {
|
|
9
|
+
React.useMemo(() => {
|
|
10
|
+
if (chartMarkPieRegistered) {
|
|
11
|
+
return void 0;
|
|
12
|
+
}
|
|
13
|
+
if (typeof window === "undefined") {
|
|
14
|
+
return void 0;
|
|
15
|
+
}
|
|
16
|
+
ChartJS.register(ArcElement, Tooltip, Legend);
|
|
17
|
+
chartMarkPieRegistered = true;
|
|
18
|
+
return void 0;
|
|
19
|
+
}, []);
|
|
9
20
|
const chartRef = React.useRef(void 0);
|
|
10
21
|
const htmlRef = useRef(null);
|
|
11
22
|
const pieChartRef = useRef(null);
|
|
@@ -21,14 +21,10 @@ import { ProForm, ProFormSelect } from "@ant-design/pro-components";
|
|
|
21
21
|
import { ConfigProvider, Descriptions, Dropdown, Popover, Table } from "antd";
|
|
22
22
|
import React, { useContext, useMemo, useState } from "react";
|
|
23
23
|
import { ActionIconBox } from "../../Components/ActionIconBox";
|
|
24
|
+
import { Loading } from "../../Components/Loading";
|
|
25
|
+
import { useIntersectionOnce } from "../../Hooks/useIntersectionOnce";
|
|
24
26
|
import { I18nContext } from "../../I18n";
|
|
25
|
-
import
|
|
26
|
-
import BarChart from "./BarChart";
|
|
27
|
-
import DonutChart from "./DonutChart";
|
|
28
|
-
import FunnelChart from "./FunnelChart";
|
|
29
|
-
import LineChart from "./LineChart";
|
|
30
|
-
import RadarChart from "./RadarChart";
|
|
31
|
-
import ScatterChart from "./ScatterChart";
|
|
27
|
+
import { loadChartRuntime } from "./loadChartRuntime";
|
|
32
28
|
import { isNotEmpty, toNumber } from "./utils";
|
|
33
29
|
var getChartMap = (i18n) => {
|
|
34
30
|
var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k;
|
|
@@ -95,6 +91,54 @@ var ChartRender = (props) => {
|
|
|
95
91
|
const i18n = useContext(I18nContext);
|
|
96
92
|
const [config, setConfig] = useState(() => props.config);
|
|
97
93
|
const [renderKey, setRenderKey] = useState(0);
|
|
94
|
+
const [runtime, setRuntime] = useState(null);
|
|
95
|
+
const [runtimeError, setRuntimeError] = useState(null);
|
|
96
|
+
const [isRuntimeLoading, setRuntimeLoading] = useState(false);
|
|
97
|
+
const containerRef = React.useRef(null);
|
|
98
|
+
const isIntersecting = useIntersectionOnce(containerRef);
|
|
99
|
+
const renderDescriptionsFallback = React.useMemo(() => {
|
|
100
|
+
var _a;
|
|
101
|
+
const columnCount = ((_a = config == null ? void 0 : config.columns) == null ? void 0 : _a.length) || 0;
|
|
102
|
+
return chartData.length < 2 && columnCount > 8;
|
|
103
|
+
}, [chartData, config == null ? void 0 : config.columns]);
|
|
104
|
+
const shouldLoadRuntime = chartType !== "table" && chartType !== "descriptions" && !renderDescriptionsFallback;
|
|
105
|
+
React.useEffect(() => {
|
|
106
|
+
if (runtime)
|
|
107
|
+
return;
|
|
108
|
+
if (isRuntimeLoading)
|
|
109
|
+
return;
|
|
110
|
+
if (runtimeError)
|
|
111
|
+
return;
|
|
112
|
+
let cancelled = false;
|
|
113
|
+
setRuntimeLoading(true);
|
|
114
|
+
loadChartRuntime().then((module) => {
|
|
115
|
+
if (cancelled)
|
|
116
|
+
return;
|
|
117
|
+
setRuntime(module);
|
|
118
|
+
}).catch((error) => {
|
|
119
|
+
if (cancelled)
|
|
120
|
+
return;
|
|
121
|
+
const message = error instanceof Error ? error.message : String(error);
|
|
122
|
+
setRuntimeError(message);
|
|
123
|
+
}).finally(() => {
|
|
124
|
+
if (cancelled)
|
|
125
|
+
return;
|
|
126
|
+
setRuntimeLoading(false);
|
|
127
|
+
});
|
|
128
|
+
return () => {
|
|
129
|
+
cancelled = true;
|
|
130
|
+
};
|
|
131
|
+
}, [
|
|
132
|
+
shouldLoadRuntime,
|
|
133
|
+
isIntersecting,
|
|
134
|
+
runtime,
|
|
135
|
+
isRuntimeLoading,
|
|
136
|
+
runtimeError
|
|
137
|
+
]);
|
|
138
|
+
const handleRetryRuntime = React.useCallback(() => {
|
|
139
|
+
setRuntime(null);
|
|
140
|
+
setRuntimeError(null);
|
|
141
|
+
}, []);
|
|
98
142
|
const ChartMap = useMemo(() => getChartMap(i18n), [i18n]);
|
|
99
143
|
const getAxisTitles = () => {
|
|
100
144
|
var _a, _b, _c, _d;
|
|
@@ -400,6 +444,116 @@ var ChartRender = (props) => {
|
|
|
400
444
|
)
|
|
401
445
|
);
|
|
402
446
|
}
|
|
447
|
+
if (chartType === "descriptions" || renderDescriptionsFallback) {
|
|
448
|
+
return /* @__PURE__ */ React.createElement(
|
|
449
|
+
"div",
|
|
450
|
+
{
|
|
451
|
+
key: config == null ? void 0 : config.index,
|
|
452
|
+
style: {
|
|
453
|
+
display: "flex",
|
|
454
|
+
flexDirection: "column",
|
|
455
|
+
gap: 8
|
|
456
|
+
}
|
|
457
|
+
},
|
|
458
|
+
chartData.map((row, rowIndex) => {
|
|
459
|
+
var _a2;
|
|
460
|
+
return /* @__PURE__ */ React.createElement(
|
|
461
|
+
Descriptions,
|
|
462
|
+
{
|
|
463
|
+
bordered: true,
|
|
464
|
+
key: `${config == null ? void 0 : config.index}-${rowIndex}`,
|
|
465
|
+
column: {
|
|
466
|
+
xxl: 2,
|
|
467
|
+
xl: 2,
|
|
468
|
+
lg: 2,
|
|
469
|
+
md: 2,
|
|
470
|
+
sm: 1,
|
|
471
|
+
xs: 1
|
|
472
|
+
},
|
|
473
|
+
items: (_a2 = config == null ? void 0 : config.columns) == null ? void 0 : _a2.map((column) => {
|
|
474
|
+
if (!column.title || !column.dataIndex)
|
|
475
|
+
return null;
|
|
476
|
+
return {
|
|
477
|
+
label: column.title || "",
|
|
478
|
+
children: row[column.dataIndex]
|
|
479
|
+
};
|
|
480
|
+
}).filter((item) => !!item)
|
|
481
|
+
}
|
|
482
|
+
);
|
|
483
|
+
})
|
|
484
|
+
);
|
|
485
|
+
}
|
|
486
|
+
console.log(
|
|
487
|
+
"isRuntimeLoading || !isIntersecting",
|
|
488
|
+
isRuntimeLoading || !isIntersecting,
|
|
489
|
+
isIntersecting
|
|
490
|
+
);
|
|
491
|
+
if (!runtime && shouldLoadRuntime) {
|
|
492
|
+
const height = (config == null ? void 0 : config.height) || 240;
|
|
493
|
+
if (runtimeError) {
|
|
494
|
+
return /* @__PURE__ */ React.createElement(
|
|
495
|
+
"div",
|
|
496
|
+
{
|
|
497
|
+
style: {
|
|
498
|
+
minHeight: height,
|
|
499
|
+
display: "flex",
|
|
500
|
+
flexDirection: "column",
|
|
501
|
+
alignItems: "center",
|
|
502
|
+
justifyContent: "center",
|
|
503
|
+
width: "100%",
|
|
504
|
+
gap: 8,
|
|
505
|
+
color: "rgba(239, 68, 68, 0.8)"
|
|
506
|
+
},
|
|
507
|
+
role: "alert"
|
|
508
|
+
},
|
|
509
|
+
/* @__PURE__ */ React.createElement("span", null, runtimeError),
|
|
510
|
+
/* @__PURE__ */ React.createElement(
|
|
511
|
+
"button",
|
|
512
|
+
{
|
|
513
|
+
type: "button",
|
|
514
|
+
onClick: handleRetryRuntime,
|
|
515
|
+
style: {
|
|
516
|
+
padding: "4px 12px",
|
|
517
|
+
borderRadius: "0.5em",
|
|
518
|
+
border: "1px solid rgba(239, 68, 68, 0.5)",
|
|
519
|
+
background: "transparent",
|
|
520
|
+
color: "rgba(239, 68, 68, 0.8)",
|
|
521
|
+
cursor: "pointer"
|
|
522
|
+
}
|
|
523
|
+
},
|
|
524
|
+
"重试加载"
|
|
525
|
+
)
|
|
526
|
+
);
|
|
527
|
+
}
|
|
528
|
+
return /* @__PURE__ */ React.createElement(
|
|
529
|
+
"div",
|
|
530
|
+
{
|
|
531
|
+
style: {
|
|
532
|
+
minHeight: height,
|
|
533
|
+
display: "flex",
|
|
534
|
+
alignItems: "center",
|
|
535
|
+
justifyContent: "center",
|
|
536
|
+
width: "100%",
|
|
537
|
+
color: "#6B7280"
|
|
538
|
+
},
|
|
539
|
+
role: "status",
|
|
540
|
+
"aria-live": "polite"
|
|
541
|
+
},
|
|
542
|
+
isRuntimeLoading || !isIntersecting ? /* @__PURE__ */ React.createElement(Loading, null) : null
|
|
543
|
+
);
|
|
544
|
+
}
|
|
545
|
+
if (!runtime) {
|
|
546
|
+
return null;
|
|
547
|
+
}
|
|
548
|
+
const {
|
|
549
|
+
DonutChart,
|
|
550
|
+
FunnelChart,
|
|
551
|
+
AreaChart,
|
|
552
|
+
BarChart,
|
|
553
|
+
LineChart,
|
|
554
|
+
RadarChart,
|
|
555
|
+
ScatterChart
|
|
556
|
+
} = runtime;
|
|
403
557
|
if (chartType === "pie") {
|
|
404
558
|
return /* @__PURE__ */ React.createElement(
|
|
405
559
|
DonutChart,
|
|
@@ -563,48 +717,29 @@ var ChartRender = (props) => {
|
|
|
563
717
|
}
|
|
564
718
|
);
|
|
565
719
|
}
|
|
566
|
-
if (chartType === "descriptions" || chartData.length < 2 && (config == null ? void 0 : config.columns.length) > 8) {
|
|
567
|
-
return /* @__PURE__ */ React.createElement(
|
|
568
|
-
"div",
|
|
569
|
-
{
|
|
570
|
-
key: config == null ? void 0 : config.index,
|
|
571
|
-
style: {
|
|
572
|
-
display: "flex",
|
|
573
|
-
flexDirection: "column",
|
|
574
|
-
gap: 8
|
|
575
|
-
}
|
|
576
|
-
},
|
|
577
|
-
chartData.map((row) => {
|
|
578
|
-
return /* @__PURE__ */ React.createElement(
|
|
579
|
-
Descriptions,
|
|
580
|
-
{
|
|
581
|
-
bordered: true,
|
|
582
|
-
key: config == null ? void 0 : config.index,
|
|
583
|
-
column: {
|
|
584
|
-
xxl: 2,
|
|
585
|
-
xl: 2,
|
|
586
|
-
lg: 2,
|
|
587
|
-
md: 2,
|
|
588
|
-
sm: 1,
|
|
589
|
-
xs: 1
|
|
590
|
-
},
|
|
591
|
-
items: config == null ? void 0 : config.columns.map((column) => {
|
|
592
|
-
if (!column.title || !column.dataIndex)
|
|
593
|
-
return null;
|
|
594
|
-
return {
|
|
595
|
-
label: column.title || "",
|
|
596
|
-
children: row[column.dataIndex]
|
|
597
|
-
};
|
|
598
|
-
}).filter((item) => !!item)
|
|
599
|
-
}
|
|
600
|
-
);
|
|
601
|
-
})
|
|
602
|
-
);
|
|
603
|
-
}
|
|
604
|
-
}, [chartType, JSON.stringify(chartData), JSON.stringify(config)]);
|
|
605
|
-
if (!chartDom)
|
|
606
720
|
return null;
|
|
607
|
-
|
|
721
|
+
}, [
|
|
722
|
+
chartType,
|
|
723
|
+
JSON.stringify(chartData),
|
|
724
|
+
JSON.stringify(config),
|
|
725
|
+
renderKey,
|
|
726
|
+
toolBar,
|
|
727
|
+
convertDonutData,
|
|
728
|
+
convertFlatData,
|
|
729
|
+
title,
|
|
730
|
+
dataTime,
|
|
731
|
+
filterBy,
|
|
732
|
+
groupBy,
|
|
733
|
+
colorLegend,
|
|
734
|
+
runtime,
|
|
735
|
+
runtimeError,
|
|
736
|
+
isRuntimeLoading,
|
|
737
|
+
isIntersecting,
|
|
738
|
+
shouldLoadRuntime,
|
|
739
|
+
renderDescriptionsFallback,
|
|
740
|
+
handleRetryRuntime
|
|
741
|
+
]);
|
|
742
|
+
return /* @__PURE__ */ React.createElement("div", { ref: containerRef, style: { width: "100%" }, contentEditable: false }, chartDom);
|
|
608
743
|
};
|
|
609
744
|
export {
|
|
610
745
|
ChartRender
|
|
@@ -62,7 +62,7 @@ import {
|
|
|
62
62
|
import LegendView from "./Legend";
|
|
63
63
|
import { createBackgroundArcPlugin, createCenterTextPlugin } from "./plugins";
|
|
64
64
|
import { useStyle } from "./style";
|
|
65
|
-
|
|
65
|
+
var donutChartComponentsRegistered = false;
|
|
66
66
|
var DonutChart = (_a) => {
|
|
67
67
|
var _b = _a, {
|
|
68
68
|
data,
|
|
@@ -102,6 +102,17 @@ var DonutChart = (_a) => {
|
|
|
102
102
|
"statistic"
|
|
103
103
|
]);
|
|
104
104
|
var _a2;
|
|
105
|
+
useMemo(() => {
|
|
106
|
+
if (donutChartComponentsRegistered) {
|
|
107
|
+
return void 0;
|
|
108
|
+
}
|
|
109
|
+
if (typeof window === "undefined") {
|
|
110
|
+
return void 0;
|
|
111
|
+
}
|
|
112
|
+
ChartJS.register(ArcElement, Tooltip, Legend);
|
|
113
|
+
donutChartComponentsRegistered = true;
|
|
114
|
+
return void 0;
|
|
115
|
+
}, []);
|
|
105
116
|
const { isMobile, windowWidth } = useMobile();
|
|
106
117
|
const defaultConfigs = [{ showLegend: true }];
|
|
107
118
|
const finalConfigs = configs || defaultConfigs;
|
|
@@ -44,6 +44,8 @@ export interface FunnelChartProps extends ChartContainerProps {
|
|
|
44
44
|
toolbarExtra?: React.ReactNode;
|
|
45
45
|
/** 是否将过滤器渲染到工具栏 */
|
|
46
46
|
renderFilterInToolbar?: boolean;
|
|
47
|
+
/** 最底层的最小宽度占比(0-1),相对于最顶层的宽度,0-不限制 */
|
|
48
|
+
bottomLayerMinWidth?: number;
|
|
47
49
|
/** ChartStatistic组件配置:object表示单个配置,array表示多个配置 */
|
|
48
50
|
statistic?: StatisticConfigType;
|
|
49
51
|
typeNames?: {
|
|
@@ -53,7 +53,7 @@ import {
|
|
|
53
53
|
import { defaultColorList } from "../const";
|
|
54
54
|
import { findDataPointByXValue, isXValueEqual, toNumber } from "../utils";
|
|
55
55
|
import { useStyle } from "./style";
|
|
56
|
-
|
|
56
|
+
var funnelChartComponentsRegistered = false;
|
|
57
57
|
var FunnelChart = (_a) => {
|
|
58
58
|
var _b = _a, {
|
|
59
59
|
title,
|
|
@@ -70,6 +70,7 @@ var FunnelChart = (_a) => {
|
|
|
70
70
|
showPercent = true,
|
|
71
71
|
toolbarExtra,
|
|
72
72
|
renderFilterInToolbar = false,
|
|
73
|
+
bottomLayerMinWidth = 0,
|
|
73
74
|
typeNames,
|
|
74
75
|
statistic: statisticConfig
|
|
75
76
|
} = _b, props = __objRest(_b, [
|
|
@@ -87,9 +88,21 @@ var FunnelChart = (_a) => {
|
|
|
87
88
|
"showPercent",
|
|
88
89
|
"toolbarExtra",
|
|
89
90
|
"renderFilterInToolbar",
|
|
91
|
+
"bottomLayerMinWidth",
|
|
90
92
|
"typeNames",
|
|
91
93
|
"statistic"
|
|
92
94
|
]);
|
|
95
|
+
useMemo(() => {
|
|
96
|
+
if (funnelChartComponentsRegistered) {
|
|
97
|
+
return void 0;
|
|
98
|
+
}
|
|
99
|
+
if (typeof window === "undefined") {
|
|
100
|
+
return void 0;
|
|
101
|
+
}
|
|
102
|
+
ChartJS.register(CategoryScale, LinearScale, BarElement, Tooltip, Legend);
|
|
103
|
+
funnelChartComponentsRegistered = true;
|
|
104
|
+
return void 0;
|
|
105
|
+
}, []);
|
|
93
106
|
const safeData = Array.isArray(data) ? data : [];
|
|
94
107
|
const statistics = useMemo(() => {
|
|
95
108
|
if (!statisticConfig)
|
|
@@ -100,7 +113,6 @@ var FunnelChart = (_a) => {
|
|
|
100
113
|
typeof window !== "undefined" ? window.innerWidth : 768
|
|
101
114
|
);
|
|
102
115
|
const isMobile = windowWidth <= 768;
|
|
103
|
-
const responsiveWidth = isMobile ? "100%" : width;
|
|
104
116
|
useEffect(() => {
|
|
105
117
|
const handleResize = () => setWindowWidth(window.innerWidth);
|
|
106
118
|
if (typeof window !== "undefined") {
|
|
@@ -170,6 +182,12 @@ var FunnelChart = (_a) => {
|
|
|
170
182
|
}
|
|
171
183
|
return chartHeight;
|
|
172
184
|
}, [height, chartHeight]);
|
|
185
|
+
const originalValues = useMemo(() => {
|
|
186
|
+
return stages.map((x) => {
|
|
187
|
+
const dp = findDataPointByXValue(filteredData, x);
|
|
188
|
+
return toNumber(dp == null ? void 0 : dp.y, 0);
|
|
189
|
+
});
|
|
190
|
+
}, [filteredData, stages]);
|
|
173
191
|
const processedData = useMemo(() => {
|
|
174
192
|
const baseColor = color || defaultColorList[0];
|
|
175
193
|
const labels = stages.map((x) => x.toString());
|
|
@@ -179,7 +197,25 @@ var FunnelChart = (_a) => {
|
|
|
179
197
|
return n;
|
|
180
198
|
});
|
|
181
199
|
const typeName = (typeNames == null ? void 0 : typeNames.name) || "转化";
|
|
182
|
-
const
|
|
200
|
+
const adjustedValues = (() => {
|
|
201
|
+
if (bottomLayerMinWidth <= 0 || bottomLayerMinWidth > 1 || values.length === 0) {
|
|
202
|
+
return values;
|
|
203
|
+
}
|
|
204
|
+
const maxValue = Math.max(...values);
|
|
205
|
+
const minValue = Math.min(...values);
|
|
206
|
+
if (minValue >= maxValue * bottomLayerMinWidth) {
|
|
207
|
+
return values;
|
|
208
|
+
}
|
|
209
|
+
const minWidth = bottomLayerMinWidth * maxValue;
|
|
210
|
+
const range = maxValue - minValue;
|
|
211
|
+
return values.map((v) => {
|
|
212
|
+
if (range === 0)
|
|
213
|
+
return maxValue;
|
|
214
|
+
const normalized = (v - minValue) / range;
|
|
215
|
+
return minWidth + normalized * (maxValue - minWidth);
|
|
216
|
+
});
|
|
217
|
+
})();
|
|
218
|
+
const datasetData = adjustedValues.map(
|
|
183
219
|
(v) => [-v / 2, v / 2]
|
|
184
220
|
);
|
|
185
221
|
const hexToRgb = (hex) => {
|
|
@@ -223,7 +259,7 @@ var FunnelChart = (_a) => {
|
|
|
223
259
|
}
|
|
224
260
|
]
|
|
225
261
|
};
|
|
226
|
-
}, [filteredData, stages]);
|
|
262
|
+
}, [filteredData, stages, bottomLayerMinWidth, color, typeNames]);
|
|
227
263
|
const ratioDisplay = useMemo(() => {
|
|
228
264
|
const formatRaw = (v) => {
|
|
229
265
|
if (v === null || v === void 0)
|
|
@@ -379,15 +415,14 @@ var FunnelChart = (_a) => {
|
|
|
379
415
|
return (it == null ? void 0 : it.label) ? String(it.label) : "";
|
|
380
416
|
},
|
|
381
417
|
label: (ctx) => {
|
|
382
|
-
var _a2, _b2
|
|
383
|
-
const
|
|
384
|
-
const
|
|
385
|
-
const idx = (_c = ctx.dataIndex) != null ? _c : 0;
|
|
418
|
+
var _a2, _b2;
|
|
419
|
+
const idx = (_a2 = ctx.dataIndex) != null ? _a2 : 0;
|
|
420
|
+
const originalValue = (_b2 = originalValues == null ? void 0 : originalValues[idx]) != null ? _b2 : 0;
|
|
386
421
|
const percentStr = ratioDisplay == null ? void 0 : ratioDisplay[idx];
|
|
387
422
|
if (showPercent === false || !percentStr) {
|
|
388
|
-
return `${
|
|
423
|
+
return `${originalValue}`;
|
|
389
424
|
}
|
|
390
|
-
return `${
|
|
425
|
+
return `${originalValue}(${percentStr})`;
|
|
391
426
|
}
|
|
392
427
|
}
|
|
393
428
|
}
|
|
@@ -517,7 +552,7 @@ var FunnelChart = (_a) => {
|
|
|
517
552
|
const maxEnd = Math.max(...ends);
|
|
518
553
|
const padding = 12;
|
|
519
554
|
meta.data.forEach((el, i) => {
|
|
520
|
-
var _a3, _b3, _c;
|
|
555
|
+
var _a3, _b3, _c, _d;
|
|
521
556
|
const raw = ds == null ? void 0 : ds[i];
|
|
522
557
|
if (!raw || !Array.isArray(raw))
|
|
523
558
|
return;
|
|
@@ -527,30 +562,46 @@ var FunnelChart = (_a) => {
|
|
|
527
562
|
const start = Number((_b3 = raw[0]) != null ? _b3 : 0);
|
|
528
563
|
const end = Number((_c = raw[1]) != null ? _c : 0);
|
|
529
564
|
const mid = (start + end) / 2;
|
|
530
|
-
const
|
|
565
|
+
const originalValue = (_d = originalValues == null ? void 0 : originalValues[i]) != null ? _d : 0;
|
|
531
566
|
const cx = (xScale == null ? void 0 : xScale.getPixelForValue) ? xScale.getPixelForValue(mid) : el.x;
|
|
532
567
|
ctx.save();
|
|
533
568
|
ctx.fillStyle = "#fff";
|
|
534
569
|
ctx.textAlign = "center";
|
|
535
|
-
ctx.fillText(String(Math.round(
|
|
570
|
+
ctx.fillText(String(Math.round(originalValue)), cx, y);
|
|
536
571
|
ctx.restore();
|
|
537
572
|
});
|
|
538
573
|
ctx.restore();
|
|
539
574
|
}
|
|
540
575
|
};
|
|
541
|
-
}, [isMobile, axisTextColor]);
|
|
576
|
+
}, [isMobile, axisTextColor, originalValues]);
|
|
577
|
+
const containerClassName = useMemo(() => {
|
|
578
|
+
if (isMobile)
|
|
579
|
+
return "w-full";
|
|
580
|
+
if (typeof width === "number")
|
|
581
|
+
return "";
|
|
582
|
+
if (typeof width === "string" && width === "100%")
|
|
583
|
+
return "w-full";
|
|
584
|
+
return "";
|
|
585
|
+
}, [isMobile, width]);
|
|
586
|
+
const containerStyle = useMemo(() => {
|
|
587
|
+
if (isMobile)
|
|
588
|
+
return void 0;
|
|
589
|
+
if (typeof width === "number")
|
|
590
|
+
return { width };
|
|
591
|
+
if (typeof width === "string" && width !== "100%")
|
|
592
|
+
return { width };
|
|
593
|
+
return void 0;
|
|
594
|
+
}, [isMobile, width]);
|
|
542
595
|
return wrapSSR(
|
|
543
596
|
/* @__PURE__ */ React.createElement(
|
|
544
597
|
ChartContainer,
|
|
545
598
|
{
|
|
546
599
|
baseClassName,
|
|
547
|
-
className,
|
|
600
|
+
className: `${className || ""} ${containerClassName}`.trim(),
|
|
548
601
|
theme,
|
|
549
602
|
isMobile,
|
|
550
603
|
variant: props.variant,
|
|
551
|
-
style:
|
|
552
|
-
width: responsiveWidth
|
|
553
|
-
}
|
|
604
|
+
style: containerStyle
|
|
554
605
|
},
|
|
555
606
|
/* @__PURE__ */ React.createElement(
|
|
556
607
|
ChartToolBar,
|
|
@@ -58,15 +58,7 @@ import {
|
|
|
58
58
|
findDataPointByXValue
|
|
59
59
|
} from "../utils";
|
|
60
60
|
import { useStyle } from "./style";
|
|
61
|
-
|
|
62
|
-
CategoryScale,
|
|
63
|
-
LinearScale,
|
|
64
|
-
PointElement,
|
|
65
|
-
LineElement,
|
|
66
|
-
Filler,
|
|
67
|
-
Tooltip,
|
|
68
|
-
Legend
|
|
69
|
-
);
|
|
61
|
+
var lineChartComponentsRegistered = false;
|
|
70
62
|
var LineChart = (_a) => {
|
|
71
63
|
var _b = _a, {
|
|
72
64
|
title,
|
|
@@ -109,6 +101,25 @@ var LineChart = (_a) => {
|
|
|
109
101
|
"renderFilterInToolbar",
|
|
110
102
|
"statistic"
|
|
111
103
|
]);
|
|
104
|
+
useMemo(() => {
|
|
105
|
+
if (lineChartComponentsRegistered) {
|
|
106
|
+
return void 0;
|
|
107
|
+
}
|
|
108
|
+
if (typeof window === "undefined") {
|
|
109
|
+
return void 0;
|
|
110
|
+
}
|
|
111
|
+
ChartJS.register(
|
|
112
|
+
CategoryScale,
|
|
113
|
+
LinearScale,
|
|
114
|
+
PointElement,
|
|
115
|
+
LineElement,
|
|
116
|
+
Filler,
|
|
117
|
+
Tooltip,
|
|
118
|
+
Legend
|
|
119
|
+
);
|
|
120
|
+
lineChartComponentsRegistered = true;
|
|
121
|
+
return void 0;
|
|
122
|
+
}, []);
|
|
112
123
|
const safeData = Array.isArray(data) ? data : [];
|
|
113
124
|
const [windowWidth, setWindowWidth] = useState(
|
|
114
125
|
typeof window !== "undefined" ? window.innerWidth : 768
|
|
@@ -53,14 +53,7 @@ import {
|
|
|
53
53
|
} from "../components";
|
|
54
54
|
import { defaultColorList } from "../const";
|
|
55
55
|
import { useStyle } from "./style";
|
|
56
|
-
|
|
57
|
-
RadialLinearScale,
|
|
58
|
-
PointElement,
|
|
59
|
-
LineElement,
|
|
60
|
-
Filler,
|
|
61
|
-
Tooltip,
|
|
62
|
-
Legend
|
|
63
|
-
);
|
|
56
|
+
var radarChartComponentsRegistered = false;
|
|
64
57
|
var RadarChart = (_a) => {
|
|
65
58
|
var _b = _a, {
|
|
66
59
|
data,
|
|
@@ -87,6 +80,24 @@ var RadarChart = (_a) => {
|
|
|
87
80
|
"statistic",
|
|
88
81
|
"textMaxWidth"
|
|
89
82
|
]);
|
|
83
|
+
useMemo(() => {
|
|
84
|
+
if (radarChartComponentsRegistered) {
|
|
85
|
+
return void 0;
|
|
86
|
+
}
|
|
87
|
+
if (typeof window === "undefined") {
|
|
88
|
+
return void 0;
|
|
89
|
+
}
|
|
90
|
+
ChartJS.register(
|
|
91
|
+
RadialLinearScale,
|
|
92
|
+
PointElement,
|
|
93
|
+
LineElement,
|
|
94
|
+
Filler,
|
|
95
|
+
Tooltip,
|
|
96
|
+
Legend
|
|
97
|
+
);
|
|
98
|
+
radarChartComponentsRegistered = true;
|
|
99
|
+
return void 0;
|
|
100
|
+
}, []);
|
|
90
101
|
const { getPrefixCls } = useContext(ConfigProvider.ConfigContext);
|
|
91
102
|
const prefixCls = getPrefixCls("radar-chart");
|
|
92
103
|
const { wrapSSR, hashId } = useStyle(prefixCls);
|