@publishfx/publish-chart 2.0.3 → 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.
Files changed (40) hide show
  1. package/CHANGELOG.md +29 -0
  2. package/dist/adapters/DataAdapter.d.ts +7 -3
  3. package/dist/adapters/DataAdapter.js +61 -0
  4. package/dist/components/g2/base/G2BarChart.d.ts +4 -3
  5. package/dist/components/g2/base/G2BarChart.js +194 -53
  6. package/dist/components/g2/base/G2BarLegend.d.ts +17 -0
  7. package/dist/components/g2/base/G2BarLegend.js +196 -0
  8. package/dist/components/g2/base/G2CombineChart.d.ts +9 -0
  9. package/dist/components/g2/base/G2CombineChart.js +305 -0
  10. package/dist/components/g2/base/G2GroupBarChart.d.ts +9 -0
  11. package/dist/components/g2/base/G2GroupBarChart.js +227 -0
  12. package/dist/components/g2/base/G2IndicatorCardChart.d.ts +43 -0
  13. package/dist/components/g2/base/G2IndicatorCardChart.js +156 -0
  14. package/dist/components/g2/base/G2LineChart.d.ts +4 -3
  15. package/dist/components/g2/base/G2LineChart.js +207 -104
  16. package/dist/components/g2/base/G2PieChart.d.ts +9 -0
  17. package/dist/components/g2/base/G2PieChart.js +189 -0
  18. package/dist/components/g2/base/g2Helpers.d.ts +293 -0
  19. package/dist/components/g2/base/g2Helpers.js +167 -0
  20. package/dist/components/g2/base/g2bar.d.ts +64 -0
  21. package/dist/components/g2/base/g2bar.js +191 -0
  22. package/dist/components/g2/base/g2combine.d.ts +71 -0
  23. package/dist/components/g2/base/g2combine.js +322 -0
  24. package/dist/components/g2/base/g2groupbar.d.ts +69 -0
  25. package/dist/components/g2/base/g2groupbar.js +188 -0
  26. package/dist/components/g2/base/g2line.d.ts +77 -0
  27. package/dist/components/g2/base/g2line.js +208 -0
  28. package/dist/components/g2/shared/G2CompareTooltip.d.ts +23 -0
  29. package/dist/components/g2/shared/G2CompareTooltip.js +93 -0
  30. package/dist/components/g2/shared/useG2TooltipContainer.d.ts +1 -0
  31. package/dist/components/g2/shared/useG2TooltipContainer.js +16 -0
  32. package/dist/components/shared/NodeDetail.js +1 -1
  33. package/dist/components/shared/NodePopover.d.ts +1 -0
  34. package/dist/components/shared/NodePopover.js +3 -2
  35. package/dist/core/ChartTypes.d.ts +4 -0
  36. package/dist/index.d.ts +5 -0
  37. package/dist/index.js +5 -1
  38. package/dist/utils/chartHelpers.d.ts +1 -1
  39. package/dist/utils/chartHelpers.js +2 -2
  40. package/package.json +15 -13
package/CHANGELOG.md CHANGED
@@ -1,3 +1,32 @@
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
+
1
30
  **2.0.3** feat(chart): G2GaugeChart设置value文本的颜色和阈值保持一致
2
31
  - 2026-02-05T15:06:47+08:00 [feat(chart): G2GaugeChart设置value文本的颜色和阈值保持一致](http://lf.git.oa.mt/publish_platform/web/publish/commit/6b80990920484818132164048278789e6f6aa740)
3
32
 
@@ -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
- * 复用现有架构,仅在渲染层面使用 G2@5 API
3
+ * 绘制逻辑复用 g2bar.renderG2BarChart,数据与 React 层(Context、Tooltip)在此组件内处理
4
+ * 支持单指标柱状、横向/纵向、升序/降序、数据标签、图例、辅助线
4
5
  */
5
- import React from 'react';
6
- import type { BaseChartProps } from '../../../core/ChartTypes';
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 { Chart } from "@antv/g2";
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
- const G2BarChart = ({ height = 300, data, x = '', y = '', indicatorMap, onChartClick, legend = '', config })=>{
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
- const result = DataAdapter.transform(data, 'bar', {
14
- type: 'bar',
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
- y,
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)=>'-' !== item[y] && void 0 !== item[y] && null !== item[y]).map((item)=>Number(item[y]) || 0);
32
- return values.length > 0 ? Math.max(...values) : 0;
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
- y
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) chartRef.current.destroy();
42
- const chart = new Chart({
43
- container: containerRef.current,
44
- autoFit: true,
45
- height: height
46
- });
47
- chart.data(transformedData);
48
- if (isHorizontal) chart.coordinate({
49
- transform: [
50
- {
51
- type: 'transpose'
52
- }
53
- ]
54
- });
55
- chart.scale({
56
- [y]: {
57
- nice: true,
58
- min: 0,
59
- max: maxY
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
- [x]: {
62
- type: 'cat'
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
- transformedData,
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
- chartConfig.isLegend,
184
+ themeColors,
94
185
  safeIndicatorMap,
95
186
  formatter,
187
+ formatAxis,
188
+ highlightDate,
189
+ auxiliaryLineData,
96
190
  onChartClick
97
191
  ]);
98
- return /*#__PURE__*/ jsx("div", {
99
- ref: containerRef,
192
+ console.log("xyList:", xyList);
193
+ return /*#__PURE__*/ jsxs("div", {
100
194
  style: {
101
- width: '100%',
102
- height: `${height}px`
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>;
@@ -0,0 +1,196 @@
1
+ import { jsx, jsxs } from "react/jsx-runtime";
2
+ import { useEffect, useMemo, useRef, useState } from "react";
3
+ import { Tooltip } from "@arco-design/web-react";
4
+ const G2BarLegend = ({ items, activeIds, onChange, pageSize: pageSizeProp, maxLabelChars = 8, style })=>{
5
+ console.log("G2BarLegend items:", items, activeIds);
6
+ const [page, setPage] = useState(1);
7
+ const [autoPageSize, setAutoPageSize] = useState(pageSizeProp || items.length || 1);
8
+ const containerRef = useRef(null);
9
+ useEffect(()=>{
10
+ if (pageSizeProp) return void setAutoPageSize(pageSizeProp);
11
+ const computePageSize = ()=>{
12
+ const container = containerRef.current;
13
+ if (!container || !items.length) return void setAutoPageSize(items.length || 1);
14
+ const width = container.offsetWidth || 0;
15
+ if (!width) return void setAutoPageSize(items.length || 1);
16
+ const pagerReserveWidth = 80;
17
+ const availableWidth = Math.max(0, width - pagerReserveWidth);
18
+ const estimatedItemWidths = items.map((item)=>{
19
+ const labelLength = item.label ? item.label.length : 0;
20
+ console.log("computePageSize: estimatedItemWidths:", item.label, labelLength);
21
+ const visibleChars = labelLength;
22
+ return 16 + 8 * visibleChars;
23
+ });
24
+ const avgItemWidth = estimatedItemWidths.reduce((sum, w)=>sum + w, 0) / estimatedItemWidths.length;
25
+ if (!avgItemWidth || !isFinite(avgItemWidth)) return void setAutoPageSize(items.length || 1);
26
+ const computed = Math.max(1, Math.floor(availableWidth / avgItemWidth));
27
+ console.log("computePageSize: computed:", computed, availableWidth, avgItemWidth, estimatedItemWidths);
28
+ setAutoPageSize(computed);
29
+ setPage((p)=>Math.min(p, Math.max(1, Math.ceil(items.length / computed))));
30
+ };
31
+ computePageSize();
32
+ window.addEventListener("resize", computePageSize);
33
+ return ()=>{
34
+ window.removeEventListener("resize", computePageSize);
35
+ };
36
+ }, [
37
+ items,
38
+ pageSizeProp,
39
+ maxLabelChars
40
+ ]);
41
+ const total = items.length;
42
+ const pageCount = Math.max(1, Math.ceil(total / autoPageSize));
43
+ const visibleItems = useMemo(()=>{
44
+ const start = (page - 1) * autoPageSize;
45
+ const end = start + autoPageSize;
46
+ return items.slice(start, end);
47
+ }, [
48
+ items,
49
+ page,
50
+ autoPageSize
51
+ ]);
52
+ const handleToggle = (id)=>{
53
+ const isActive = activeIds.includes(id);
54
+ const nextSet = new Set(isActive ? activeIds.filter((x)=>x !== id) : [
55
+ ...activeIds,
56
+ id
57
+ ]);
58
+ const next = items.map((item)=>item.id).filter((itemId)=>nextSet.has(itemId));
59
+ onChange(next);
60
+ };
61
+ const handlePrev = ()=>{
62
+ setPage((p)=>p > 1 ? p - 1 : p);
63
+ };
64
+ const handleNext = ()=>{
65
+ setPage((p)=>p < pageCount ? p + 1 : p);
66
+ };
67
+ return /*#__PURE__*/ jsxs("div", {
68
+ ref: containerRef,
69
+ style: {
70
+ display: "flex",
71
+ alignItems: "center",
72
+ justifyContent: "center",
73
+ gap: 8,
74
+ fontSize: 12,
75
+ color: "#4e5969",
76
+ ...style
77
+ },
78
+ children: [
79
+ /*#__PURE__*/ jsx("div", {
80
+ style: {
81
+ display: "flex",
82
+ flexWrap: "nowrap",
83
+ gap: 8,
84
+ maxWidth: "100%",
85
+ overflow: "hidden"
86
+ },
87
+ children: visibleItems.map((item)=>{
88
+ const isActive = activeIds.includes(item.id);
89
+ const baseColor = item.isCompare ? items.find((i)=>!i.isCompare)?.color : item.color;
90
+ const displayLabel = item.label;
91
+ const compareBg = `repeating-linear-gradient(-45deg,${baseColor} 0,${baseColor} 2px,#ffffff 2px, #ffffff 4px)`;
92
+ let marker = null;
93
+ marker = "square" === item.symbol ? /*#__PURE__*/ jsx("span", {
94
+ style: {
95
+ width: 10,
96
+ height: 10,
97
+ background: item.isCompare ? compareBg : item.color,
98
+ marginRight: 4
99
+ }
100
+ }) : "line" === item.symbol ? /*#__PURE__*/ jsx("span", {
101
+ style: {
102
+ width: 10,
103
+ height: 1,
104
+ borderBottom: item.isCompare ? `2px dotted ${item.color}` : `2px solid ${item.color}`,
105
+ marginRight: 4
106
+ }
107
+ }) : /*#__PURE__*/ jsx("span", {
108
+ style: {
109
+ width: 10,
110
+ height: 10,
111
+ borderRadius: "50%",
112
+ marginRight: 4,
113
+ boxSizing: "border-box",
114
+ background: item.isCompare ? compareBg : item.color
115
+ }
116
+ });
117
+ return /*#__PURE__*/ jsxs("div", {
118
+ onClick: ()=>handleToggle(item.id),
119
+ style: {
120
+ display: "inline-flex",
121
+ alignItems: "center",
122
+ padding: "2px 6px",
123
+ borderRadius: 4,
124
+ cursor: "pointer",
125
+ userSelect: "none",
126
+ opacity: isActive ? 1 : 0.5
127
+ },
128
+ children: [
129
+ marker,
130
+ /*#__PURE__*/ jsx(Tooltip, {
131
+ content: item.label,
132
+ disabled: true,
133
+ children: /*#__PURE__*/ jsx("span", {
134
+ style: {
135
+ overflow: "hidden",
136
+ textOverflow: "ellipsis",
137
+ whiteSpace: "nowrap"
138
+ },
139
+ children: displayLabel
140
+ })
141
+ })
142
+ ]
143
+ }, item.id);
144
+ })
145
+ }),
146
+ pageCount > 1 && /*#__PURE__*/ jsxs("div", {
147
+ style: {
148
+ display: "inline-flex",
149
+ alignItems: "center",
150
+ gap: 4,
151
+ marginLeft: 8,
152
+ whiteSpace: "nowrap"
153
+ },
154
+ children: [
155
+ /*#__PURE__*/ jsx("button", {
156
+ type: "button",
157
+ onClick: handlePrev,
158
+ disabled: 1 === page,
159
+ style: {
160
+ border: "1px solid #d0d4db",
161
+ backgroundColor: "#fff",
162
+ borderRadius: 2,
163
+ padding: "0 4px",
164
+ cursor: 1 === page ? "not-allowed" : "pointer"
165
+ },
166
+ children: "<"
167
+ }),
168
+ /*#__PURE__*/ jsxs("span", {
169
+ style: {
170
+ fontSize: 12
171
+ },
172
+ children: [
173
+ page,
174
+ "/",
175
+ pageCount
176
+ ]
177
+ }),
178
+ /*#__PURE__*/ jsx("button", {
179
+ type: "button",
180
+ onClick: handleNext,
181
+ disabled: page === pageCount,
182
+ style: {
183
+ border: "1px solid #d0d4db",
184
+ backgroundColor: "#fff",
185
+ borderRadius: 2,
186
+ padding: "0 4px",
187
+ cursor: page === pageCount ? "not-allowed" : "pointer"
188
+ },
189
+ children: ">"
190
+ })
191
+ ]
192
+ })
193
+ ]
194
+ });
195
+ };
196
+ export { G2BarLegend };