@publishfx/publish-chart 2.1.3 → 2.1.4

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 CHANGED
@@ -1,3 +1,7 @@
1
+ **2.1.4** feat(chart): 柱状、折线、组合三个图表支持onChartClick
2
+ - 2026-03-02T15:27:33+08:00 [feat(chart): 柱状、折线、组合三个图表支持onChartClick](http://lf.git.oa.mt/publish_platform/web/publish/commit/0cbed83b537a5b0a08f676256b8e69bb9ae0741a)
3
+ - 2026-03-02T14:38:28+08:00 [fix(chart): 组合图针对副轴数据全为0时,Y刻度的处理。](http://lf.git.oa.mt/publish_platform/web/publish/commit/2b262810e33d3660255831fb7ef0e345907841e9)
4
+
1
5
  **2.1.3** fix(chart): 组合图分组时inset置为0
2
6
  - 2026-02-28T23:48:20+08:00 [fix(chart): 组合图分组时inset置为0](http://lf.git.oa.mt/publish_platform/web/publish/commit/047e02d3cfbce21101277f48e904864163b2a02c)
3
7
  - 2026-02-28T22:42:20+08:00 [feat(chart): 组合图tooltip数据调整](http://lf.git.oa.mt/publish_platform/web/publish/commit/f79461050699b0755c8837e26b035083ec980cf1)
@@ -122,6 +122,7 @@ const G2BarChart = ({ height = 300, data, x = "", y = "", indicatorMap, onChartC
122
122
  isLegend: !!isCompare,
123
123
  isHorizontal,
124
124
  isHighlight,
125
+ isClickable: !!onChartClick,
125
126
  legend: safeLegend || void 0,
126
127
  formatLabel: isDataTag && safeY ? (d)=>{
127
128
  const v = d[safeY];
@@ -160,8 +161,11 @@ const G2BarChart = ({ height = 300, data, x = "", y = "", indicatorMap, onChartC
160
161
  });
161
162
  chartRef.current = chart;
162
163
  if (onChartClick) chart.on("element:click", (e)=>{
164
+ console.log('e:', e);
163
165
  const datum = e.data?.data;
164
- if (datum) onChartClick(datum);
166
+ if (datum) onChartClick({
167
+ title: datum[x]
168
+ });
165
169
  });
166
170
  return ()=>{
167
171
  if (chartRef.current) {
@@ -194,6 +194,7 @@ const G2CombineChart = ({ height = 300, data, x = "", y = "", z = "", indicatorM
194
194
  isDataTag,
195
195
  isLegend: false,
196
196
  isCompare,
197
+ isClickable: !!onChartClick,
197
198
  height: height - canvasMarginBottom,
198
199
  formatLabel: isDataTag ? (d)=>{
199
200
  const indicatorId = d.groupType.split("_")[0];
@@ -239,7 +240,9 @@ const G2CombineChart = ({ height = 300, data, x = "", y = "", z = "", indicatorM
239
240
  chartRef.current = chart;
240
241
  if (onChartClick) chart.on("element:click", (e)=>{
241
242
  const datum = e.data?.data;
242
- if (datum) onChartClick(datum);
243
+ if (datum) onChartClick({
244
+ title: datum[x]
245
+ });
243
246
  });
244
247
  return ()=>{
245
248
  if (chartRef.current) {
@@ -265,14 +268,6 @@ const G2CombineChart = ({ height = 300, data, x = "", y = "", z = "", indicatorM
265
268
  isGroup,
266
269
  legendItems
267
270
  ]);
268
- if (!z) return /*#__PURE__*/ jsx("div", {
269
- style: {
270
- width: "100%",
271
- color: "#86909c",
272
- padding: 16
273
- },
274
- children: "请传入 z 作为折线指标字段,以展示柱状+折线组合图。"
275
- });
276
271
  return /*#__PURE__*/ jsxs("div", {
277
272
  style: {
278
273
  width: "100%",
@@ -12,7 +12,7 @@ import useG2TooltipContainer from "../shared/useG2TooltipContainer.js";
12
12
  import { getIndicatorCompareName } from "../../../utils/indicatorHelpers.js";
13
13
  import { G2BarLegend } from "./G2BarLegend.js";
14
14
  import { renderG2LineChart } from "./g2line.js";
15
- const G2LineChart = ({ height = 300, data, x = "", y = "", z = "", indicatorMap, onChartClick: _onChartClick, timeRange, legend = "", config, nodeSetting = {
15
+ const G2LineChart = ({ height = 300, data, x = "", y = "", z = "", indicatorMap, onChartClick, timeRange, legend = "", config, nodeSetting = {
16
16
  showType: 0,
17
17
  type: []
18
18
  }, auxiliaryLineData, highlightDate, indicators = [] })=>{
@@ -169,6 +169,12 @@ const G2LineChart = ({ height = 300, data, x = "", y = "", z = "", indicatorMap,
169
169
  }
170
170
  });
171
171
  chartRef.current = chart;
172
+ if (onChartClick) chart.on("element:click", (e)=>{
173
+ const datum = e.data?.data;
174
+ if (datum) onChartClick({
175
+ title: datum[x]
176
+ });
177
+ });
172
178
  return ()=>{
173
179
  if (chartRef.current) {
174
180
  chartRef.current.off("element:click");
@@ -33,6 +33,8 @@ export interface RenderG2BarChartOptions {
33
33
  isHighlight?: boolean;
34
34
  /** 图例字段名(与 y 不同时表示分组柱),通常为 groupType */
35
35
  isCompare?: boolean;
36
+ /** 是否启用点击事件 */
37
+ isClickable?: boolean;
36
38
  legend?: string;
37
39
  /** 数据标签格式化:formatLabel(datum) */
38
40
  formatLabel?: (datum: any) => string;
@@ -2,7 +2,7 @@ import { lines } from "@antv/g-pattern";
2
2
  import { applyAuxiliaryLineY, applyAxisX, applyAxisY, applyHighlightDate, applyScaleYLinear, createChart, getColorByGroupType, getMainView } from "./g2Helpers.js";
3
3
  const Y_AXIS_FIELD = 'groupValue';
4
4
  function renderG2BarChart(container, options) {
5
- const { data, x, y, maxY, timeRange: _timeRange, themeColors, indicators = [], indicatorMap: _indicatorMap = {}, formatAxis, highlightDate = [], isDataTag = false, isLegend = true, isHorizontal = false, isHighlight = true, isCompare = false, legend, formatLabel, height = 300, tooltipRender, auxiliaryLineData = [], onNodeListChange, onChartRender } = options;
5
+ const { data, x, y, maxY, timeRange: _timeRange, themeColors, indicators = [], indicatorMap: _indicatorMap = {}, formatAxis, highlightDate = [], isDataTag = false, isLegend = true, isHorizontal = false, isHighlight = true, isCompare = false, isClickable = false, legend, formatLabel, height = 300, tooltipRender, auxiliaryLineData = [], onNodeListChange, onChartRender } = options;
6
6
  const colorOpts = {
7
7
  themeColors,
8
8
  primaryKey: y,
@@ -68,7 +68,8 @@ function renderG2BarChart(container, options) {
68
68
  transform: 'rotate(-30deg)'
69
69
  };
70
70
  return getColorByGroupType(groupType, colorOpts);
71
- }
71
+ },
72
+ cursor: isClickable ? 'pointer' : 'default'
72
73
  });
73
74
  applyAxisX(view, {
74
75
  grid: false
@@ -33,6 +33,8 @@ export interface RenderG2CombineChartOptions {
33
33
  isHighlight?: boolean;
34
34
  /** 是否启用对比期 */
35
35
  isCompare?: boolean;
36
+ /** 是否启用点击事件 */
37
+ isClickable?: boolean;
36
38
  /** 数据标签格式化:formatLabel(datum) */
37
39
  formatLabel?: (datum: any) => string;
38
40
  /** 图表高度 */
@@ -5,7 +5,7 @@ const Y_AXIS_FIELD = 'groupValue';
5
5
  const BAR_Y_FIELD = 'barValue';
6
6
  const LINE_Y_FIELD = 'lineValue';
7
7
  function renderG2CombineChart(container, options) {
8
- const { data, x, y, z: _z, maxY, themeColors, indicatorMap: _indicatorMap, formatAxis, formatLineAxis, isDataTag = false, isLegend: _isLegend = false, isCompare = false, formatLabel, highlightDate = [], height = 300, isHighlight = true, indicators = [], tooltipRender, onNodeListChange, lineColors, onChartRender, isGroup, legendItems = [], indicatorId } = options;
8
+ const { data, x, y, z: _z, maxY, themeColors, indicatorMap: _indicatorMap, formatAxis, formatLineAxis, isDataTag = false, isLegend: _isLegend = false, isCompare = false, formatLabel, highlightDate = [], height = 300, isHighlight = true, isClickable = false, indicators = [], tooltipRender, onNodeListChange, lineColors, onChartRender, isGroup, legendItems = [], indicatorId } = options;
9
9
  const chart = createChart({
10
10
  container,
11
11
  height,
@@ -71,6 +71,7 @@ function renderG2CombineChart(container, options) {
71
71
  };
72
72
  return barColor;
73
73
  },
74
+ cursor: isClickable ? 'pointer' : 'default',
74
75
  stroke: 'transparent'
75
76
  });
76
77
  interval.scale('y', {
@@ -153,7 +154,7 @@ function renderG2CombineChart(container, options) {
153
154
  console.log('compareLineData:', compareLineData);
154
155
  const lineMaxY = lineData.reduce((max, item)=>Math.max(max, item[LINE_Y_FIELD]), 0);
155
156
  const compareLineMaxY = compareLineData.reduce((max, item)=>Math.max(max, item[LINE_Y_FIELD]), 0);
156
- const lineFinalMaxY = Math.max(lineMaxY, compareLineMaxY);
157
+ const lineFinalMaxY = Math.max(lineMaxY, compareLineMaxY) || 1;
157
158
  console.log('lineFinalMaxY:', lineFinalMaxY);
158
159
  const line = view.line().data(lineData).encode("x", x).encode("y", LINE_Y_FIELD).encode('color', 'groupType').style({
159
160
  lineWidth: 2,
@@ -195,7 +196,7 @@ function renderG2CombineChart(container, options) {
195
196
  domainMax: lineFinalMaxY,
196
197
  nice: true,
197
198
  clamp: true,
198
- key: 'bar',
199
+ key: 'line',
199
200
  independent: true,
200
201
  tickMethod: (min, max)=>Array.from({
201
202
  length: 6
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@publishfx/publish-chart",
3
- "version": "2.1.3",
3
+ "version": "2.1.4",
4
4
  "description": "A React chart component library for the Publish platform, including BarChart, LineChart, BarLineChart and other visualization components",
5
5
  "type": "module",
6
6
  "keywords": [
@@ -24,20 +24,10 @@
24
24
  "CHANGELOG.md",
25
25
  "README.md"
26
26
  ],
27
- "scripts": {
28
- "build": "rslib build",
29
- "dev": "rslib build --watch",
30
- "lint": "eslint src --ext .ts,.tsx",
31
- "lint:fix": "eslint src --ext .ts,.tsx --fix",
32
- "test": "jest",
33
- "test:watch": "jest --watch",
34
- "test:coverage": "jest --coverage"
35
- },
36
27
  "devDependencies": {
37
28
  "@antv/data-set": "^0.11.8",
38
29
  "@antv/g-pattern": "^2.0.42",
39
30
  "@antv/g2": "^5.3.0",
40
- "@publishfx/publish-components": "workspace:^",
41
31
  "@types/jest": "^29.5.12",
42
32
  "@types/lodash": "^4.17.20",
43
33
  "@types/react": "^18.3.18",
@@ -55,7 +45,8 @@
55
45
  "react-dom": "^18.3.1",
56
46
  "styled-components": "^5.3.11",
57
47
  "ts-jest": "^29.1.2",
58
- "typescript": "^5.9.3"
48
+ "typescript": "^5.9.3",
49
+ "@publishfx/publish-components": "^2.1.0"
59
50
  },
60
51
  "peerDependencies": {
61
52
  "@antv/data-set": "^0.11.8",
@@ -71,5 +62,14 @@
71
62
  "publishConfig": {
72
63
  "access": "public",
73
64
  "registry": "https://registry.npmjs.org/"
65
+ },
66
+ "scripts": {
67
+ "build": "rslib build",
68
+ "dev": "rslib build --watch",
69
+ "lint": "eslint src --ext .ts,.tsx",
70
+ "lint:fix": "eslint src --ext .ts,.tsx --fix",
71
+ "test": "jest",
72
+ "test:watch": "jest --watch",
73
+ "test:coverage": "jest --coverage"
74
74
  }
75
- }
75
+ }