@publishfx/publish-chart 2.0.2 → 2.1.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/CHANGELOG.md +32 -0
- package/README.md +6 -6
- package/dist/adapters/DataAdapter.d.ts +7 -3
- package/dist/adapters/DataAdapter.js +61 -0
- package/dist/components/g2/base/G2BarChart.d.ts +4 -3
- package/dist/components/g2/base/G2BarChart.js +194 -53
- package/dist/components/g2/base/G2BarLegend.d.ts +17 -0
- package/dist/components/g2/base/G2BarLegend.js +196 -0
- package/dist/components/g2/base/G2CombineChart.d.ts +9 -0
- package/dist/components/g2/base/G2CombineChart.js +305 -0
- package/dist/components/g2/base/G2GaugeChart.js +3 -1
- package/dist/components/g2/base/G2GroupBarChart.d.ts +9 -0
- package/dist/components/g2/base/G2GroupBarChart.js +227 -0
- package/dist/components/g2/base/G2IndicatorCardChart.d.ts +43 -0
- package/dist/components/g2/base/G2IndicatorCardChart.js +156 -0
- package/dist/components/g2/base/G2LineChart.d.ts +4 -3
- package/dist/components/g2/base/G2LineChart.js +207 -104
- package/dist/components/g2/base/G2PieChart.d.ts +9 -0
- package/dist/components/g2/base/G2PieChart.js +189 -0
- package/dist/components/g2/base/g2Helpers.d.ts +293 -0
- package/dist/components/g2/base/g2Helpers.js +167 -0
- package/dist/components/g2/base/g2bar.d.ts +64 -0
- package/dist/components/g2/base/g2bar.js +191 -0
- package/dist/components/g2/base/g2combine.d.ts +71 -0
- package/dist/components/g2/base/g2combine.js +322 -0
- package/dist/components/g2/base/g2groupbar.d.ts +69 -0
- package/dist/components/g2/base/g2groupbar.js +188 -0
- package/dist/components/g2/base/g2line.d.ts +77 -0
- package/dist/components/g2/base/g2line.js +208 -0
- package/dist/components/g2/shared/G2CompareTooltip.d.ts +23 -0
- package/dist/components/g2/shared/G2CompareTooltip.js +93 -0
- package/dist/components/g2/shared/useG2TooltipContainer.d.ts +1 -0
- package/dist/components/g2/shared/useG2TooltipContainer.js +16 -0
- package/dist/components/shared/NodeDetail.js +1 -1
- package/dist/components/shared/NodePopover.d.ts +1 -0
- package/dist/components/shared/NodePopover.js +3 -2
- package/dist/core/ChartTypes.d.ts +4 -0
- package/dist/index.d.ts +5 -0
- package/dist/index.js +5 -1
- package/dist/utils/chartHelpers.d.ts +1 -1
- package/dist/utils/chartHelpers.js +2 -2
- package/package.json +15 -13
package/CHANGELOG.md
CHANGED
|
@@ -1,3 +1,35 @@
|
|
|
1
|
+
**2.1.0** fix(chart): ts错误修复
|
|
2
|
+
- 2026-02-28T16:06:24+08:00 [fix(chart): ts错误修复](http://lf.git.oa.mt/publish_platform/web/publish/commit/7a070b0f77b3ff41450fce0884f8713ebd58f4b2)
|
|
3
|
+
- 2026-02-28T15:53:07+08:00 [fix(chart): 柱状图和折线图的图例分别设置为square和line](http://lf.git.oa.mt/publish_platform/web/publish/commit/a11ccf463d4fad84ae0d4b84672bc1db79951bb1)
|
|
4
|
+
- 2026-02-28T15:40:18+08:00 [feat(chart): 折线图和组合图支持节点详情](http://lf.git.oa.mt/publish_platform/web/publish/commit/73593a0644bc956772395a307f6e73f43b80a159)
|
|
5
|
+
- 2026-02-28T15:19:08+08:00 [fix(chart): 节点详情Dom结构修改](http://lf.git.oa.mt/publish_platform/web/publish/commit/0e8de83391883c976bf9a4aaaff161679f845c09)
|
|
6
|
+
- 2026-02-28T15:17:44+08:00 [feat: 堆积图数据标签&高亮](http://lf.git.oa.mt/publish_platform/web/publish/commit/867b4341e71a8703f31b4c1808b7d57e0a58c480)
|
|
7
|
+
- 2026-02-28T15:09:33+08:00 [feat(chart): 新增柱状图节点详情支持](http://lf.git.oa.mt/publish_platform/web/publish/commit/fd94eacc4618f04704caf4c61c8e914900ceb688)
|
|
8
|
+
- 2026-02-28T12:22:23+08:00 [feat(chart): 着重显示的逻辑联动tooltipRender的数据处理](http://lf.git.oa.mt/publish_platform/web/publish/commit/934e5a798d8424327aa13a3d739fb03cc00935f4)
|
|
9
|
+
- 2026-02-28T12:12:29+08:00 [feat(chart): 新增高亮日期辅助函数](http://lf.git.oa.mt/publish_platform/web/publish/commit/539ccc99d93680497fa770ea5c08c80b119eb098)
|
|
10
|
+
- 2026-02-28T00:08:09+08:00 [feat(chart): 组合图tooltip修正](http://lf.git.oa.mt/publish_platform/web/publish/commit/12ac7885e508cf26a1b8322a6c048c25accfba54)
|
|
11
|
+
- 2026-02-27T22:50:37+08:00 [feat(chart): G2Combine组合图支持双轴展示](http://lf.git.oa.mt/publish_platform/web/publish/commit/8c4428edecd5922f75746c168fd76da68364c690)
|
|
12
|
+
- 2026-02-27T21:46:47+08:00 [feat: 堆积图](http://lf.git.oa.mt/publish_platform/web/publish/commit/55e60330c83cc19e548bbb91c9ed0837d39a9282)
|
|
13
|
+
- 2026-02-27T20:58:12+08:00 [feat(chart): 图例组件支持symbol符号](http://lf.git.oa.mt/publish_platform/web/publish/commit/06435b768d54913aacf12280ff9e7b2e782fb7cb)
|
|
14
|
+
- 2026-02-27T20:44:47+08:00 [fix(chart): G2Combine组合图的图例逻辑修改成线上一致](http://lf.git.oa.mt/publish_platform/web/publish/commit/ff7d39e61c9945aa9c1db61d319a7ae3d0cba23b)
|
|
15
|
+
- 2026-02-27T19:49:23+08:00 [fix(chart): 组合图补充节点逻辑](http://lf.git.oa.mt/publish_platform/web/publish/commit/05ab21057b5c7695e559ab664c8e2135fd8b7f49)
|
|
16
|
+
- 2026-02-27T19:45:55+08:00 [feat(chart): G2CombineChart组合图初步提交](http://lf.git.oa.mt/publish_platform/web/publish/commit/36e1d93d3d9714c8899e23bb86a829c22ce24aab)
|
|
17
|
+
- 2026-02-27T16:10:00+08:00 [fix(chart): 修复折线图高亮参数支持](http://lf.git.oa.mt/publish_platform/web/publish/commit/691e792838831d92d2b1229ee500dab30b5af913)
|
|
18
|
+
- 2026-02-27T16:01:24+08:00 [fix(chart): 辅助线使用自定义render渲染](http://lf.git.oa.mt/publish_platform/web/publish/commit/a9285296553ccb0c1c7e52a2365a1bd6c386d26b)
|
|
19
|
+
- 2026-02-27T15:57:34+08:00 [feat(chart): 更新G2LineChart组件](http://lf.git.oa.mt/publish_platform/web/publish/commit/c7c25e369fcebf1c04f1c9487d0de0dc7b533ef3)
|
|
20
|
+
- 2026-02-26T23:33:58+08:00 [fix(chart): G2BarChart的图例文案保持一致](http://lf.git.oa.mt/publish_platform/web/publish/commit/01b0ae29d1deccb600163cefb983788c38e0948d)
|
|
21
|
+
- 2026-02-26T22:58:27+08:00 [feat(chart): 增加G2BarChart柱状图](http://lf.git.oa.mt/publish_platform/web/publish/commit/b69d46602f28d3f68531f516a162ea6717a21ffc)
|
|
22
|
+
- 2026-02-26T22:32:20+08:00 [feat(chart): G2版本Tooltip渲染函数更新](http://lf.git.oa.mt/publish_platform/web/publish/commit/2788488cdbe38561ec19b8f1fab814f0292029ed)
|
|
23
|
+
- 2026-02-11T23:23:12+08:00 [feat(chart): 新增G2PieChart饼图和G2IndicatorCardChart指标卡图表组件](http://lf.git.oa.mt/publish_platform/web/publish/commit/42e516b980dbccc39def106611af29eea64e42de)
|
|
24
|
+
- 2026-02-11T20:19:51+08:00 [feat(chart): legend](http://lf.git.oa.mt/publish_platform/web/publish/commit/dc1957c73dbd91107ba6ca2f8e4f2aefbedb4b36)
|
|
25
|
+
- 2026-02-10T16:31:05+08:00 [feat(chart): tooltip优化](http://lf.git.oa.mt/publish_platform/web/publish/commit/6a486017fcaf23bd478d269b4e74962347e316ba)
|
|
26
|
+
- 2026-02-10T15:55:53+08:00 [feat(chart): tooltips](http://lf.git.oa.mt/publish_platform/web/publish/commit/bceab306e7ff2dd855a789982b9df37292bca2fe)
|
|
27
|
+
- 2026-02-06T20:03:25+08:00 [feat: 节点信息&对比时间](http://lf.git.oa.mt/publish_platform/web/publish/commit/893949661301676195b1dba1a9531678da50f926)
|
|
28
|
+
- 2026-02-05T18:38:44+08:00 [feat: 着重日功能](http://lf.git.oa.mt/publish_platform/web/publish/commit/a50195b6cc5d0f6645151194fa8d6e856e5af69a)
|
|
29
|
+
|
|
30
|
+
**2.0.3** feat(chart): G2GaugeChart设置value文本的颜色和阈值保持一致
|
|
31
|
+
- 2026-02-05T15:06:47+08:00 [feat(chart): G2GaugeChart设置value文本的颜色和阈值保持一致](http://lf.git.oa.mt/publish_platform/web/publish/commit/6b80990920484818132164048278789e6f6aa740)
|
|
32
|
+
|
|
1
33
|
**2.0.2** feat(chart): 优化G2GaugeChart组件,仅基于数据驱动UI,不涉及业务逻辑
|
|
2
34
|
- 2026-02-05T14:07:11+08:00 [feat(chart): 优化G2GaugeChart组件,仅基于数据驱动UI,不涉及业务逻辑](http://lf.git.oa.mt/publish_platform/web/publish/commit/ad3728038c692c40a03dcb6a38f7b77b0952cccc)
|
|
3
35
|
|
package/README.md
CHANGED
|
@@ -1,13 +1,13 @@
|
|
|
1
|
-
# @
|
|
1
|
+
# @publishfx/publish-chart
|
|
2
2
|
|
|
3
3
|
基于新架构设计的 React 图表组件库,支持离线分析模块使用的所有图表类型。
|
|
4
4
|
|
|
5
5
|
## 安装
|
|
6
6
|
|
|
7
7
|
```bash
|
|
8
|
-
npm install @
|
|
8
|
+
npm install @publishfx/publish-chart
|
|
9
9
|
# 或
|
|
10
|
-
pnpm add @
|
|
10
|
+
pnpm add @publishfx/publish-chart
|
|
11
11
|
```
|
|
12
12
|
|
|
13
13
|
## 特性
|
|
@@ -30,7 +30,7 @@ import {
|
|
|
30
30
|
defaultChartConfig,
|
|
31
31
|
createFormatterService,
|
|
32
32
|
createDataTransformService
|
|
33
|
-
} from '@
|
|
33
|
+
} from '@publishfx/publish-chart';
|
|
34
34
|
|
|
35
35
|
const chartServices = {
|
|
36
36
|
formatter: createFormatterService(),
|
|
@@ -53,7 +53,7 @@ const chartServices = {
|
|
|
53
53
|
如果你只需要自定义业务组件,其他服务使用库的默认配置,可以这样:
|
|
54
54
|
|
|
55
55
|
```tsx
|
|
56
|
-
import { ChartProvider } from '@
|
|
56
|
+
import { ChartProvider } from '@publishfx/publish-chart';
|
|
57
57
|
|
|
58
58
|
// 只定义 businessComponents,其他使用默认值
|
|
59
59
|
const chartServices = {
|
|
@@ -73,7 +73,7 @@ const chartServices = {
|
|
|
73
73
|
### 2. 使用图表组件
|
|
74
74
|
|
|
75
75
|
```tsx
|
|
76
|
-
import { BarChart, LineChart, BarLineChart } from '@
|
|
76
|
+
import { BarChart, LineChart, BarLineChart } from '@publishfx/publish-chart';
|
|
77
77
|
|
|
78
78
|
<BarChart
|
|
79
79
|
data={data}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
export interface TransformConfig {
|
|
2
|
-
type: 'bar' | 'line' | 'barLine' | 'groupCompare';
|
|
2
|
+
type: 'bar' | 'groupBar' | 'line' | 'barLine' | 'groupCompare';
|
|
3
3
|
x?: string;
|
|
4
4
|
y?: string;
|
|
5
5
|
z?: string;
|
|
@@ -15,9 +15,13 @@ export declare class DataAdapter {
|
|
|
15
15
|
*/
|
|
16
16
|
static transform(data: any[], transformType: TransformConfig['type'], config: TransformConfig): any[];
|
|
17
17
|
/**
|
|
18
|
-
|
|
19
|
-
|
|
18
|
+
* 柱状图数据转换
|
|
19
|
+
*/
|
|
20
20
|
private static transformForBar;
|
|
21
|
+
/**
|
|
22
|
+
* 堆积图数据转换
|
|
23
|
+
*/
|
|
24
|
+
private static transformForGroupBar;
|
|
21
25
|
/**
|
|
22
26
|
* 折线图数据转换
|
|
23
27
|
*/
|
|
@@ -5,6 +5,8 @@ class DataAdapter {
|
|
|
5
5
|
switch(transformType){
|
|
6
6
|
case 'bar':
|
|
7
7
|
return this.transformForBar(data, config);
|
|
8
|
+
case 'groupBar':
|
|
9
|
+
return this.transformForGroupBar(data, config);
|
|
8
10
|
case 'line':
|
|
9
11
|
return this.transformForLine(data, config);
|
|
10
12
|
case 'barLine':
|
|
@@ -37,6 +39,65 @@ class DataAdapter {
|
|
|
37
39
|
}
|
|
38
40
|
return dv.rows;
|
|
39
41
|
}
|
|
42
|
+
static transformForGroupBar(data, config) {
|
|
43
|
+
const ds = new lib();
|
|
44
|
+
const dv = ds.createView().source(data);
|
|
45
|
+
const tdv = ds.createView().source(data);
|
|
46
|
+
if (config.y && config.x) {
|
|
47
|
+
dv.transform({
|
|
48
|
+
type: 'map',
|
|
49
|
+
callback: (row)=>{
|
|
50
|
+
row[config.y] = '' !== row[config.y] ? +row[config.y] : '-';
|
|
51
|
+
return row;
|
|
52
|
+
}
|
|
53
|
+
});
|
|
54
|
+
tdv.transform({
|
|
55
|
+
type: 'map',
|
|
56
|
+
callback: (row)=>{
|
|
57
|
+
row[config.y] = '' !== row[config.y] ? +row[config.y] : '-';
|
|
58
|
+
return row;
|
|
59
|
+
}
|
|
60
|
+
});
|
|
61
|
+
tdv.transform({
|
|
62
|
+
type: 'filter',
|
|
63
|
+
callback (row) {
|
|
64
|
+
return !row[config.y] || '-' !== row[config.y];
|
|
65
|
+
}
|
|
66
|
+
});
|
|
67
|
+
tdv.transform({
|
|
68
|
+
type: 'aggregate',
|
|
69
|
+
fields: [
|
|
70
|
+
config.y
|
|
71
|
+
],
|
|
72
|
+
groupBy: [
|
|
73
|
+
config.x
|
|
74
|
+
],
|
|
75
|
+
operations: [
|
|
76
|
+
'sum'
|
|
77
|
+
],
|
|
78
|
+
as: [
|
|
79
|
+
'total'
|
|
80
|
+
]
|
|
81
|
+
});
|
|
82
|
+
tdv.transform({
|
|
83
|
+
type: 'sort',
|
|
84
|
+
callback (a, b) {
|
|
85
|
+
return b.total - a.total;
|
|
86
|
+
}
|
|
87
|
+
});
|
|
88
|
+
const xKey = config.x ?? 'x';
|
|
89
|
+
const sortData = tdv.rows.map((item)=>item[xKey]);
|
|
90
|
+
if (config.isDescend) dv.transform({
|
|
91
|
+
type: 'sort',
|
|
92
|
+
callback (a, b) {
|
|
93
|
+
if (-1 === sortData.indexOf(a[xKey])) return config.isHorizontal ? -1 : 1;
|
|
94
|
+
if (-1 === sortData.indexOf(b[xKey])) return config.isHorizontal ? 1 : -1;
|
|
95
|
+
return config.isHorizontal ? sortData.indexOf(b[xKey]) - sortData.indexOf(a[xKey]) : sortData.indexOf(a[xKey]) - sortData.indexOf(b[xKey]);
|
|
96
|
+
}
|
|
97
|
+
});
|
|
98
|
+
}
|
|
99
|
+
return dv.rows;
|
|
100
|
+
}
|
|
40
101
|
static transformForLine(data, config) {
|
|
41
102
|
const ds = new lib();
|
|
42
103
|
const dv = ds.createView().source(data);
|
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* G2@5 基础柱状图组件
|
|
3
|
-
*
|
|
3
|
+
* 绘制逻辑复用 g2bar.renderG2BarChart,数据与 React 层(Context、Tooltip)在此组件内处理
|
|
4
|
+
* 支持单指标柱状、横向/纵向、升序/降序、数据标签、图例、辅助线
|
|
4
5
|
*/
|
|
5
|
-
import React from
|
|
6
|
-
import type { BaseChartProps } from
|
|
6
|
+
import React from "react";
|
|
7
|
+
import type { BaseChartProps } from "../../../core/ChartTypes";
|
|
7
8
|
declare const G2BarChart: React.FC<BaseChartProps>;
|
|
8
9
|
export default G2BarChart;
|
|
@@ -1,19 +1,41 @@
|
|
|
1
|
-
import { jsx } from "react/jsx-runtime";
|
|
2
|
-
import { useEffect, useMemo, useRef } from "react";
|
|
3
|
-
import
|
|
1
|
+
import { jsx, jsxs } from "react/jsx-runtime";
|
|
2
|
+
import { useCallback, useEffect, useMemo, useRef, useState } from "react";
|
|
3
|
+
import react_dom from "react-dom";
|
|
4
4
|
import { useChartContext } from "../../../core/ChartContext.js";
|
|
5
|
+
import { getAxisFormat } from "../../../utils/chartHelpers.js";
|
|
5
6
|
import { DataAdapter } from "../../../adapters/DataAdapter.js";
|
|
6
|
-
|
|
7
|
+
import { NodePopover } from "../../shared/NodePopover.js";
|
|
8
|
+
import { NodeDetail } from "../../shared/NodeDetail.js";
|
|
9
|
+
import { transformIndicatorList } from "../../../utils/dataTransform.js";
|
|
10
|
+
import G2CompareTooltip from "../shared/G2CompareTooltip.js";
|
|
11
|
+
import useG2TooltipContainer from "../shared/useG2TooltipContainer.js";
|
|
12
|
+
import { renderG2BarChart } from "./g2bar.js";
|
|
13
|
+
import { getIndicatorCompareName } from "../../../utils/indicatorHelpers.js";
|
|
14
|
+
import { G2BarLegend } from "./G2BarLegend.js";
|
|
15
|
+
const G2BarChart = ({ height = 300, data, x = "", y = "", indicatorMap, onChartClick, legend = "", config, nodeSetting = {
|
|
16
|
+
showType: 0,
|
|
17
|
+
type: []
|
|
18
|
+
}, auxiliaryLineData, highlightDate = [], indicators = [], timeRange })=>{
|
|
19
|
+
console.log("props data:", data, nodeSetting, "x:", x, "y:", y, "legend:", legend, "indicators:", indicators, timeRange);
|
|
7
20
|
const { formatter, dataTransform, config: contextConfig } = useChartContext();
|
|
21
|
+
const tooltipContainerRef = useG2TooltipContainer();
|
|
22
|
+
const themeColors = contextConfig?.theme?.colors || [];
|
|
8
23
|
const safeIndicatorMap = indicatorMap || contextConfig.indicatorMap || {};
|
|
9
|
-
const safeLegend = legend || y;
|
|
24
|
+
const safeLegend = "groupType" !== legend ? legend || y : y;
|
|
25
|
+
const isCompare = timeRange?.compareStartTime !== "";
|
|
26
|
+
const safeY = "groupValue";
|
|
10
27
|
const chartConfig = config || {};
|
|
11
|
-
const { isDataTag = false, isDescend = false, isHorizontal = false } = chartConfig;
|
|
28
|
+
const { isDataTag = false, isDescend = false, isHorizontal = false, isLegend = true, isHighlight = true } = chartConfig;
|
|
12
29
|
const transformedData = useMemo(()=>{
|
|
13
|
-
|
|
14
|
-
|
|
30
|
+
console.log("transformedData: bar ---", legend, data, indicators);
|
|
31
|
+
if (!legend) {
|
|
32
|
+
let result = transformIndicatorList(indicators, data);
|
|
33
|
+
data = result[y] || [];
|
|
34
|
+
}
|
|
35
|
+
const result = DataAdapter.transform(data, "bar", {
|
|
36
|
+
type: "bar",
|
|
15
37
|
x,
|
|
16
|
-
y,
|
|
38
|
+
y: safeY,
|
|
17
39
|
isDescend,
|
|
18
40
|
isHorizontal
|
|
19
41
|
});
|
|
@@ -21,86 +43,205 @@ const G2BarChart = ({ height = 300, data, x = '', y = '', indicatorMap, onChartC
|
|
|
21
43
|
}, [
|
|
22
44
|
data,
|
|
23
45
|
x,
|
|
24
|
-
|
|
46
|
+
safeY,
|
|
25
47
|
isDescend,
|
|
26
48
|
isHorizontal,
|
|
27
49
|
dataTransform,
|
|
28
50
|
contextConfig.nodeMap
|
|
29
51
|
]);
|
|
52
|
+
console.log("transformedData: bar final", transformedData);
|
|
30
53
|
const maxY = useMemo(()=>{
|
|
31
|
-
const values = transformedData.filter((item)=>
|
|
32
|
-
|
|
54
|
+
const values = transformedData.filter((item)=>"-" !== item[safeY] && void 0 !== item[safeY] && null !== item[safeY]).map((item)=>Number(item[safeY]) || 0);
|
|
55
|
+
const dataMax = values.length > 0 ? Math.max(...values) : 0;
|
|
56
|
+
const auxValues = auxiliaryLineData?.length ? auxiliaryLineData.map((item)=>item.value) : [];
|
|
57
|
+
const maxAux = auxValues.length ? Math.max(...auxValues) : dataMax;
|
|
58
|
+
return Math.max(dataMax, maxAux);
|
|
33
59
|
}, [
|
|
34
60
|
transformedData,
|
|
35
|
-
|
|
61
|
+
safeY,
|
|
62
|
+
auxiliaryLineData
|
|
63
|
+
]);
|
|
64
|
+
const formatAxis = useCallback((val)=>getAxisFormat(val, safeIndicatorMap, safeLegend), [
|
|
65
|
+
safeIndicatorMap,
|
|
66
|
+
safeLegend
|
|
36
67
|
]);
|
|
68
|
+
const [xyList, setXYList] = useState([]);
|
|
69
|
+
const [activeIds, setActiveIds] = useState([]);
|
|
70
|
+
const [legendItems, setLegendItems] = useState([]);
|
|
37
71
|
const containerRef = useRef(null);
|
|
38
72
|
const chartRef = useRef(null);
|
|
73
|
+
const [viewWidth, setViewWidth] = useState(0);
|
|
74
|
+
const [viewOffset, setViewOffset] = useState(0);
|
|
75
|
+
useEffect(()=>{
|
|
76
|
+
if (!transformedData.length) {
|
|
77
|
+
setLegendItems([]);
|
|
78
|
+
setActiveIds([]);
|
|
79
|
+
return;
|
|
80
|
+
}
|
|
81
|
+
const groupTypes = Array.from(new Set(transformedData.map((d)=>d.groupType).filter((v)=>null != v)));
|
|
82
|
+
const items = groupTypes.map((id, index)=>({
|
|
83
|
+
id: String(id),
|
|
84
|
+
label: getIndicatorCompareName(safeIndicatorMap, String(id)) + (id.includes("_compare") ? `(对比时间:${timeRange?.compareStartTime}~${timeRange?.compareEndTime})` : ""),
|
|
85
|
+
color: themeColors[index % themeColors.length] ?? themeColors[0] ?? "#5B8FF9",
|
|
86
|
+
isCompare: String(id).includes("_compare"),
|
|
87
|
+
symbol: "square"
|
|
88
|
+
}));
|
|
89
|
+
setLegendItems(items);
|
|
90
|
+
if (!activeIds.length) setActiveIds(items.map((i)=>i.id));
|
|
91
|
+
}, [
|
|
92
|
+
transformedData,
|
|
93
|
+
safeIndicatorMap,
|
|
94
|
+
themeColors,
|
|
95
|
+
activeIds.length
|
|
96
|
+
]);
|
|
97
|
+
const filteredData = useMemo(()=>{
|
|
98
|
+
if (!activeIds.length) return transformedData;
|
|
99
|
+
return transformedData.filter((d)=>d.groupType ? activeIds.includes(String(d.groupType)) : true);
|
|
100
|
+
}, [
|
|
101
|
+
transformedData,
|
|
102
|
+
activeIds
|
|
103
|
+
]);
|
|
104
|
+
const canvasMarginBottom = legendItems.length > 1 ? 2 === nodeSetting.showType ? 32 : 16 : 0;
|
|
39
105
|
useEffect(()=>{
|
|
40
106
|
if (!containerRef.current || !transformedData.length) return;
|
|
41
|
-
if (chartRef.current)
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
]
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
107
|
+
if (chartRef.current) {
|
|
108
|
+
chartRef.current.destroy();
|
|
109
|
+
chartRef.current = null;
|
|
110
|
+
}
|
|
111
|
+
const chart = renderG2BarChart(containerRef.current, {
|
|
112
|
+
data: filteredData,
|
|
113
|
+
x,
|
|
114
|
+
y: safeY,
|
|
115
|
+
maxY,
|
|
116
|
+
themeColors,
|
|
117
|
+
indicatorMap: safeIndicatorMap,
|
|
118
|
+
formatAxis,
|
|
119
|
+
highlightDate: highlightDate ?? [],
|
|
120
|
+
isCompare,
|
|
121
|
+
isDataTag,
|
|
122
|
+
isLegend: !!isCompare,
|
|
123
|
+
isHorizontal,
|
|
124
|
+
isHighlight,
|
|
125
|
+
legend: safeLegend || void 0,
|
|
126
|
+
formatLabel: isDataTag && safeY ? (d)=>{
|
|
127
|
+
const v = d[safeY];
|
|
128
|
+
return "-" === v || null == v ? "" : formatter.formatIndicator(v, safeIndicatorMap[safeLegend]);
|
|
129
|
+
} : void 0,
|
|
130
|
+
height: height - canvasMarginBottom,
|
|
131
|
+
tooltipRender: (title, items)=>{
|
|
132
|
+
const container = tooltipContainerRef.current;
|
|
133
|
+
if (!container) return null;
|
|
134
|
+
let safeItems = items.map((i)=>({
|
|
135
|
+
...i,
|
|
136
|
+
color: i.color || "transparent"
|
|
137
|
+
}));
|
|
138
|
+
safeItems = safeItems.filter((i)=>i.indicatorId);
|
|
139
|
+
react_dom.render(/*#__PURE__*/ jsx(G2CompareTooltip, {
|
|
140
|
+
title: title,
|
|
141
|
+
items: safeItems,
|
|
142
|
+
safeIndicatorMap: safeIndicatorMap,
|
|
143
|
+
formatter: formatter,
|
|
144
|
+
safeLegend: safeLegend,
|
|
145
|
+
auxiliaryLineData: auxiliaryLineData
|
|
146
|
+
}), container);
|
|
147
|
+
return container;
|
|
60
148
|
},
|
|
61
|
-
[
|
|
62
|
-
|
|
149
|
+
auxiliaryLineData: auxiliaryLineData ?? [],
|
|
150
|
+
onNodeListChange: (nodes)=>{
|
|
151
|
+
console.log("g2bar node list:", nodes, nodes[0], nodes[1]);
|
|
152
|
+
setXYList(nodes);
|
|
153
|
+
},
|
|
154
|
+
timeRange,
|
|
155
|
+
onChartRender: (chartProps)=>{
|
|
156
|
+
console.log("chartProps:", chartProps);
|
|
157
|
+
setViewWidth(chartProps.layout.innerWidth);
|
|
158
|
+
setViewOffset(chartProps.layout.paddingLeft + chartProps.layout.marginLeft);
|
|
63
159
|
}
|
|
64
160
|
});
|
|
65
|
-
if (safeLegend && false !== chartConfig.isLegend) chart.legend(safeLegend, {
|
|
66
|
-
position: 'top'
|
|
67
|
-
});
|
|
68
|
-
chart.interaction('poptip', true);
|
|
69
|
-
const interval = chart.interval().encode('x', x).encode('y', y);
|
|
70
|
-
if (safeLegend) interval.encode('color', safeLegend);
|
|
71
|
-
if (isDataTag) interval.label({
|
|
72
|
-
text: (d)=>formatter.formatIndicator(d[y], safeIndicatorMap[y]),
|
|
73
|
-
position: isHorizontal ? 'right' : 'top',
|
|
74
|
-
offset: 5
|
|
75
|
-
});
|
|
76
|
-
chart.render();
|
|
77
161
|
chartRef.current = chart;
|
|
162
|
+
if (onChartClick) chart.on("element:click", (e)=>{
|
|
163
|
+
const datum = e.data?.data;
|
|
164
|
+
if (datum) onChartClick(datum);
|
|
165
|
+
});
|
|
78
166
|
return ()=>{
|
|
79
167
|
if (chartRef.current) {
|
|
168
|
+
chartRef.current.off("element:click");
|
|
80
169
|
chartRef.current.destroy();
|
|
81
170
|
chartRef.current = null;
|
|
82
171
|
}
|
|
83
172
|
};
|
|
84
173
|
}, [
|
|
85
|
-
|
|
174
|
+
filteredData,
|
|
86
175
|
height,
|
|
87
176
|
x,
|
|
88
177
|
y,
|
|
89
178
|
safeLegend,
|
|
90
179
|
isHorizontal,
|
|
91
180
|
isDataTag,
|
|
181
|
+
isLegend,
|
|
182
|
+
isHighlight,
|
|
92
183
|
maxY,
|
|
93
|
-
|
|
184
|
+
themeColors,
|
|
94
185
|
safeIndicatorMap,
|
|
95
186
|
formatter,
|
|
187
|
+
formatAxis,
|
|
188
|
+
highlightDate,
|
|
189
|
+
auxiliaryLineData,
|
|
96
190
|
onChartClick
|
|
97
191
|
]);
|
|
98
|
-
|
|
99
|
-
|
|
192
|
+
console.log("xyList:", xyList);
|
|
193
|
+
return /*#__PURE__*/ jsxs("div", {
|
|
100
194
|
style: {
|
|
101
|
-
width:
|
|
102
|
-
|
|
103
|
-
}
|
|
195
|
+
width: "100%",
|
|
196
|
+
position: "relative"
|
|
197
|
+
},
|
|
198
|
+
children: [
|
|
199
|
+
isLegend && legendItems.length > 1 && 2 === nodeSetting.showType && /*#__PURE__*/ jsx(G2BarLegend, {
|
|
200
|
+
items: legendItems,
|
|
201
|
+
activeIds: activeIds,
|
|
202
|
+
onChange: setActiveIds,
|
|
203
|
+
style: {
|
|
204
|
+
marginBottom: 8
|
|
205
|
+
}
|
|
206
|
+
}),
|
|
207
|
+
/*#__PURE__*/ jsx("div", {
|
|
208
|
+
ref: containerRef,
|
|
209
|
+
style: {
|
|
210
|
+
width: "100%",
|
|
211
|
+
height: `${height - canvasMarginBottom}px`
|
|
212
|
+
}
|
|
213
|
+
}),
|
|
214
|
+
isLegend && legendItems.length > 1 && 2 !== nodeSetting.showType && /*#__PURE__*/ jsx(G2BarLegend, {
|
|
215
|
+
items: legendItems,
|
|
216
|
+
activeIds: activeIds,
|
|
217
|
+
onChange: setActiveIds,
|
|
218
|
+
style: {
|
|
219
|
+
marginBottom: 8
|
|
220
|
+
}
|
|
221
|
+
}),
|
|
222
|
+
2 !== nodeSetting.showType ? /*#__PURE__*/ jsx("div", {
|
|
223
|
+
children: xyList?.map((item, index)=>/*#__PURE__*/ jsx(NodePopover, {
|
|
224
|
+
style: {
|
|
225
|
+
position: "absolute",
|
|
226
|
+
top: item.pointP?.y + 10,
|
|
227
|
+
left: item.pointP?.x,
|
|
228
|
+
width: 12,
|
|
229
|
+
height: 12,
|
|
230
|
+
borderRadius: "50%",
|
|
231
|
+
transform: "translate(-50%, 0%)",
|
|
232
|
+
background: item?.color,
|
|
233
|
+
zIndex: 999
|
|
234
|
+
},
|
|
235
|
+
pointP: item.pointP,
|
|
236
|
+
pointData: item.pointData
|
|
237
|
+
}, index))
|
|
238
|
+
}) : /*#__PURE__*/ jsx(NodeDetail, {
|
|
239
|
+
chartWidth: viewWidth,
|
|
240
|
+
chartOffset: viewOffset,
|
|
241
|
+
dvRows: transformedData,
|
|
242
|
+
ratio: isCompare ? 2 : 1
|
|
243
|
+
})
|
|
244
|
+
]
|
|
104
245
|
});
|
|
105
246
|
};
|
|
106
247
|
const base_G2BarChart = G2BarChart;
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import React from "react";
|
|
2
|
+
export type G2BarLegendItem = {
|
|
3
|
+
id: string;
|
|
4
|
+
label: string;
|
|
5
|
+
color: string;
|
|
6
|
+
isCompare?: boolean;
|
|
7
|
+
symbol?: "square" | "circle" | "line";
|
|
8
|
+
};
|
|
9
|
+
export type G2BarLegendProps = {
|
|
10
|
+
items: G2BarLegendItem[];
|
|
11
|
+
activeIds: string[];
|
|
12
|
+
onChange: (nextActiveIds: string[]) => void;
|
|
13
|
+
pageSize?: number;
|
|
14
|
+
maxLabelChars?: number;
|
|
15
|
+
style?: React.CSSProperties;
|
|
16
|
+
};
|
|
17
|
+
export declare const G2BarLegend: React.FC<G2BarLegendProps>;
|