@publishfx/publish-chart 2.1.10 → 2.1.12

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,14 @@
1
+ **2.1.11** fix(chart): 组合图去掉主轴过滤逻辑,以支持tooltip展示
2
+ - 2026-03-04T20:56:34+08:00 [fix(chart): 组合图去掉主轴过滤逻辑,以支持tooltip展示](http://lf.git.oa.mt/publish_platform/web/publish/commit/215222fb1ae535a52aea475d3a8447cdc61dfa19)
3
+ - 2026-03-04T20:30:34+08:00 [fix(chart): 组合图数据处理逻辑优化](http://lf.git.oa.mt/publish_platform/web/publish/commit/bab29eb2897d1b7b60877c234d8cc14b4d79b9a9)
4
+ - 2026-03-04T20:22:30+08:00 [feat(chart): 柱状图切换指标空白问题](http://lf.git.oa.mt/publish_platform/web/publish/commit/2e37e53f1322968e7a1e384bf148d7fd213fb7c2)
5
+ - 2026-03-04T19:14:10+08:00 [feat(chart): 坐标轴label透明度](http://lf.git.oa.mt/publish_platform/web/publish/commit/47436b58d55a8c770a8374b70cf974db86e4aecc)
6
+ - 2026-03-04T18:25:28+08:00 [feat(chart): 多指标折线图组合图y轴格式化](http://lf.git.oa.mt/publish_platform/web/publish/commit/e1577f958143c2d2e338adb73e4a6ac3193cb08f)
7
+ - 2026-03-04T17:55:18+08:00 [fix(chart): 修复之前异常数据处理导致的组合图分组tooltip数据错误的问题](http://lf.git.oa.mt/publish_platform/web/publish/commit/62982adf8ce4ce3b04cc8fc6703e2fce05b43984)
8
+ - 2026-03-04T17:53:43+08:00 [fix(chart): 组合图折线图触发下钻](http://lf.git.oa.mt/publish_platform/web/publish/commit/51cabfb3e90b990db03b04ab6e6c039d9c7d3239)
9
+ - 2026-03-04T17:34:02+08:00 [fix(chart): 修复剩余数据全为0时的Y轴异常问题](http://lf.git.oa.mt/publish_platform/web/publish/commit/0d64328b1c38b71ad0289579592870fa20bc37b1)
10
+ - 2026-03-04T17:13:55+08:00 [fix(chart): 辅助线分左右,分别影响主、副轴的刻度尺](http://lf.git.oa.mt/publish_platform/web/publish/commit/0c91a39b4fe8ff1b13999766e8f6f90dce85f37e)
11
+
1
12
  **2.1.10** fix(chart): 修复剩余数据全为0时的Y轴异常问题
2
13
  - 2026-03-04T17:34:02+08:00 [fix(chart): 修复剩余数据全为0时的Y轴异常问题](http://lf.git.oa.mt/publish_platform/web/publish/commit/0d64328b1c38b71ad0289579592870fa20bc37b1)
3
14
  - 2026-03-04T17:13:55+08:00 [fix(chart): 辅助线分左右,分别影响主、副轴的刻度尺](http://lf.git.oa.mt/publish_platform/web/publish/commit/0c91a39b4fe8ff1b13999766e8f6f90dce85f37e)
@@ -6,6 +6,7 @@ export interface TransformConfig {
6
6
  isDescend?: boolean;
7
7
  isHorizontal?: boolean;
8
8
  isGroup?: boolean;
9
+ isOld?: boolean;
9
10
  }
10
11
  /**
11
12
  * 数据适配器类
@@ -144,12 +144,8 @@ class DataAdapter {
144
144
  return row.isCombine;
145
145
  }
146
146
  });
147
- tdv.transform({
148
- type: 'filter',
149
- callback (row) {
150
- return !row[config.y] || '-' !== row[config.y];
151
- }
152
- });
147
+ console.log('tdv:', tdv.rows);
148
+ console.log('tdv:', tdv.rows);
153
149
  if (config.isDescend) tdv.transform({
154
150
  type: 'sort',
155
151
  callback (a, b) {
@@ -88,12 +88,11 @@ const G2BarChart = ({ height = 300, data, x = "", y = "", indicatorMap, onChartC
88
88
  symbol: "square"
89
89
  }));
90
90
  setLegendItems(items);
91
- if (!activeIds.length) setActiveIds(items.map((i)=>i.id));
91
+ setActiveIds(items.map((i)=>i.id));
92
92
  }, [
93
93
  transformedData,
94
94
  safeIndicatorMap,
95
- themeColors,
96
- activeIds.length
95
+ themeColors
97
96
  ]);
98
97
  const filteredData = useMemo(()=>{
99
98
  if (!activeIds.length) return transformedData;
@@ -66,6 +66,7 @@ const G2CombineChart = ({ height = 300, data, x = "", y = "", z = "", indicatorM
66
66
  const tooltipContainerRef = useG2TooltipContainer();
67
67
  const isGroupRef = useRef(isGroup);
68
68
  const [isOldData, setIsOldData] = useState(false);
69
+ const currentTooltipTitleRef = useRef(null);
69
70
  isGroupRef.current = isGroup;
70
71
  console.log("G2CombineChart props:", data, x, y, z, indicators, legend, config, nodeSetting);
71
72
  const themeColors = contextConfig?.theme?.colors || [];
@@ -85,6 +86,7 @@ const G2CombineChart = ({ height = 300, data, x = "", y = "", z = "", indicatorM
85
86
  let result = transformDataToGroupBarLineFormat(data, x, y, indicators);
86
87
  data = result;
87
88
  setIsOldData(true);
89
+ console.log('tdv data:', data);
88
90
  }
89
91
  console.log("G2CombineChart renderG2CombineChart transformedData2:", data);
90
92
  const { transformedData, leftData, rightData } = DataAdapter.transform(data, "barLine", {
@@ -93,7 +95,8 @@ const G2CombineChart = ({ height = 300, data, x = "", y = "", z = "", indicatorM
93
95
  y: safeY,
94
96
  z,
95
97
  isDescend,
96
- isGroup: isGroupRef.current
98
+ isGroup: isGroupRef.current,
99
+ isOld: !legend
97
100
  });
98
101
  return {
99
102
  transformedData: transformedData.map((item)=>dataTransform.processNodeInfo(item, contextConfig.nodeMap)),
@@ -125,9 +128,13 @@ const G2CombineChart = ({ height = 300, data, x = "", y = "", z = "", indicatorM
125
128
  safeIndicatorMap,
126
129
  y
127
130
  ]);
128
- const formatLineAxis = useCallback((val)=>getAxisFormat(val, safeIndicatorMap, safeZ), [
131
+ const formatLineAxis = useCallback((val)=>{
132
+ const indicatorId = indicators?.length > 1 ? '' : safeZ;
133
+ return getAxisFormat(val, safeIndicatorMap, indicatorId);
134
+ }, [
129
135
  safeIndicatorMap,
130
- safeZ
136
+ safeZ,
137
+ indicators
131
138
  ]);
132
139
  useEffect(()=>{
133
140
  if (!transformedData.length) {
@@ -170,7 +177,7 @@ const G2CombineChart = ({ height = 300, data, x = "", y = "", z = "", indicatorM
170
177
  if (!activeIds.length) return leftData;
171
178
  const result = leftData.filter((d)=>d.groupType ? activeIds.includes(String(d.groupType.replace("_compare", "") + "_" + d.isCombine)) : true);
172
179
  if (isGroupRef.current) result.forEach((item)=>{
173
- item.total = result.filter((d)=>d.groupName === item.groupName).reduce((acc, d)=>acc + d.groupValue, 0);
180
+ item.total = result.filter((d)=>d.groupName === item.groupName).reduce((acc, d)=>acc + ('' === d.groupValue ? 0 : d.groupValue), 0);
174
181
  });
175
182
  return result;
176
183
  }, [
@@ -230,6 +237,7 @@ const G2CombineChart = ({ height = 300, data, x = "", y = "", z = "", indicatorM
230
237
  } : void 0,
231
238
  indicators,
232
239
  tooltipRender: (title, items)=>{
240
+ currentTooltipTitleRef.current = title;
233
241
  const container = tooltipContainerRef.current;
234
242
  if (!container) return null;
235
243
  let safeItems = items.map((i)=>({
@@ -267,15 +275,18 @@ const G2CombineChart = ({ height = 300, data, x = "", y = "", z = "", indicatorM
267
275
  isGroup: isGroupRef.current
268
276
  });
269
277
  chartRef.current = chart;
270
- if (onChartClick) chart.on("element:click", (e)=>{
271
- const datum = e.data?.data;
272
- if (datum) onChartClick({
273
- title: datum[x]
274
- });
278
+ if (onChartClick) chart.on("plot:click", (_e)=>{
279
+ const tooltipTitle = currentTooltipTitleRef.current;
280
+ if (null != tooltipTitle) {
281
+ console.log('使用 tooltip title 触发下钻:', tooltipTitle);
282
+ onChartClick({
283
+ title: tooltipTitle
284
+ });
285
+ }
275
286
  });
276
287
  return ()=>{
277
288
  if (chartRef.current) {
278
- chartRef.current.off("element:click");
289
+ chartRef.current.off("plot:click");
279
290
  chartRef.current.destroy();
280
291
  chartRef.current = null;
281
292
  }
@@ -76,9 +76,13 @@ const G2LineChart = ({ height = 300, data, x = "", y = "", z = "", indicatorMap,
76
76
  safeY,
77
77
  auxiliaryLineData
78
78
  ]);
79
- const formatAxis = useCallback((val)=>getAxisFormat(val, safeIndicatorMap, safeLegend), [
79
+ const formatAxis = useCallback((val)=>{
80
+ const indicatorId = indicators?.length > 1 ? '' : safeLegend;
81
+ return getAxisFormat(val, safeIndicatorMap, indicatorId);
82
+ }, [
80
83
  safeIndicatorMap,
81
- safeLegend
84
+ safeLegend,
85
+ indicators
82
86
  ]);
83
87
  useEffect(()=>{
84
88
  if (!transformedData.length) {
@@ -82,6 +82,7 @@ function applyAxisX(mark, options = {}) {
82
82
  },
83
83
  labelAlign: 'horizontal',
84
84
  labelDx: (_datum, _index, _data)=>0,
85
+ labelOpacity: 0.6,
85
86
  ...axisFilter && {
86
87
  tickFilter: axisFilter('tick'),
87
88
  labelFilter: axisFilter('label')
@@ -96,6 +97,7 @@ function applyAxisY(mark, options = {}) {
96
97
  mark.axis('y', {
97
98
  title,
98
99
  labelAutoRotate,
100
+ labelOpacity: 0.6,
99
101
  grid,
100
102
  gridStroke,
101
103
  gridLineWidth,
@@ -38,8 +38,12 @@ function renderG2CombineChart(container, options) {
38
38
  console.log('renderG2CombineChart interval data:', intervalData);
39
39
  const intervalMaxY = intervalData.reduce((max, item)=>{
40
40
  const key = isGroup ? "total" : BAR_Y_FIELD;
41
+ console.log('intervalMaxY item:', key, item[key], intervalData);
42
+ if ('-' === item[key] || void 0 === item[key] || null === item[key] || '' === item[key]) return max;
41
43
  return Math.max(max, item[key]);
42
44
  }, 0);
45
+ console.log('intervalMaxY:', intervalMaxY);
46
+ console.log('tdv:', intervalMaxY);
43
47
  const auxLeftValues = auxiliaryLineData?.length ? auxiliaryLineData.filter((item)=>'left' === item.axis).map((item)=>item.value) : [];
44
48
  const maxAuxLeft = auxLeftValues.length ? Math.max(...auxLeftValues) : 0;
45
49
  const auxRightValues = auxiliaryLineData?.length ? auxiliaryLineData.filter((item)=>'right' === item.axis).map((item)=>item.value) : [];
@@ -104,7 +108,8 @@ function renderG2CombineChart(container, options) {
104
108
  0,
105
109
  0
106
110
  ],
107
- labelFormatter: formatAxis
111
+ labelFormatter: formatAxis,
112
+ labelOpacity: 0.6
108
113
  });
109
114
  console.log('tooltip:', barColor, isCompare);
110
115
  interval.tooltip({
@@ -120,7 +125,8 @@ function renderG2CombineChart(container, options) {
120
125
  channel: Y_AXIS_FIELD,
121
126
  color: themeColors[index % themeColors.length] ?? themeColors[0] ?? "#5B8FF9",
122
127
  percent: `${(100 * Number(datum.percent)).toFixed(2)}%`,
123
- isCombine: false
128
+ isCombine: false,
129
+ x: datum[x]
124
130
  };
125
131
  }
126
132
  ].filter(Boolean) : [
@@ -140,7 +146,8 @@ function renderG2CombineChart(container, options) {
140
146
  indicatorId: datum['groupType'].replace('_compare', ''),
141
147
  channel: Y_AXIS_FIELD,
142
148
  color: barColor || 'transparent',
143
- isCombine: false
149
+ isCombine: false,
150
+ x: datum[x]
144
151
  } : false : false,
145
152
  isCompare ? (datum)=>datum.groupType.includes('_compare') ? {
146
153
  name: datum['groupType'].replace('_compare', '_change'),
@@ -148,7 +155,8 @@ function renderG2CombineChart(container, options) {
148
155
  value: datum?.change,
149
156
  isChange: true,
150
157
  color: 'transparent',
151
- isCombine: false
158
+ isCombine: false,
159
+ x: datum[x]
152
160
  } : false : false
153
161
  ].filter(Boolean)
154
162
  });
@@ -156,14 +164,20 @@ function renderG2CombineChart(container, options) {
156
164
  ...item,
157
165
  [LINE_Y_FIELD]: item[Y_AXIS_FIELD]
158
166
  }));
159
- console.log('renderG2CombineChart: line data:', lineData);
167
+ console.log('renderG2CombineChart: line data:', data);
160
168
  const compareLineData = data.filter((item)=>item.isCombine && item.groupType.includes('_compare')).filter((item)=>'' !== item[Y_AXIS_FIELD]).map((item)=>({
161
169
  ...item,
162
170
  [LINE_Y_FIELD]: item[Y_AXIS_FIELD]
163
171
  }));
164
172
  console.log('compareLineData:', compareLineData);
165
- const lineMaxY = lineData.reduce((max, item)=>Math.max(max, item[LINE_Y_FIELD]), 0);
166
- const compareLineMaxY = compareLineData.reduce((max, item)=>Math.max(max, item[LINE_Y_FIELD]), 0);
173
+ const lineMaxY = lineData.reduce((max, item)=>{
174
+ if ('-' === item[LINE_Y_FIELD] || void 0 === item[LINE_Y_FIELD] || null === item[LINE_Y_FIELD] || '' === item[LINE_Y_FIELD]) return max;
175
+ return Math.max(max, item[LINE_Y_FIELD]);
176
+ }, 0);
177
+ const compareLineMaxY = compareLineData.reduce((max, item)=>{
178
+ if ('-' === item[LINE_Y_FIELD] || void 0 === item[LINE_Y_FIELD] || null === item[LINE_Y_FIELD] || '' === item[LINE_Y_FIELD]) return max;
179
+ return Math.max(max, item[LINE_Y_FIELD]);
180
+ }, 0);
167
181
  const lineFinalMaxY = Math.max(lineMaxY, compareLineMaxY) || 1;
168
182
  const finalLineMax = Math.max(lineFinalMaxY, maxAuxRight);
169
183
  console.log('lineData:', lineData);
@@ -212,7 +226,8 @@ function renderG2CombineChart(container, options) {
212
226
  0
213
227
  ],
214
228
  tickOpacity: 0,
215
- labelFormatter: formatLineAxis
229
+ labelFormatter: formatLineAxis,
230
+ labelOpacity: 0.6
216
231
  });
217
232
  console.log('renderG2CombineChart: compare line data:', compareLineData);
218
233
  const compareLine = view.line().data(compareLineData).encode('x', x).encode('y', LINE_Y_FIELD).encode('color', 'groupType').style({
@@ -267,96 +282,102 @@ function renderG2CombineChart(container, options) {
267
282
  } : false
268
283
  ].filter(Boolean)
269
284
  });
270
- if (tooltipRender) view.interaction('tooltip', {
271
- shared: true,
272
- crosshairsY: true,
273
- marker: false,
274
- render: (event, payload)=>{
275
- const { title, items } = payload;
276
- console.log('tooltipRender:', title, items);
277
- let safeTitle = title.replace(/,.*$/, '');
278
- const baseItems = items.filter((item)=>!item.isCombine);
279
- const safeItems = baseItems.map((item)=>{
280
- if (item.x !== safeTitle) return {
281
- ...item,
282
- value: '-'
283
- };
284
- return item;
285
- });
286
- const combineItems = items.filter((item)=>item.isCombine);
287
- const safeCombineItems = combineItems.map((item)=>{
288
- if (item.x !== safeTitle) return {
289
- ...item,
290
- value: '-'
291
- };
292
- return item;
293
- });
294
- const indicatorOrder = new Map(indicators.map((id, i)=>[
295
- id,
296
- i
297
- ]));
298
- const sortedCombineItems = [
299
- ...safeCombineItems
300
- ].sort((a, b)=>{
301
- const orderA = indicatorOrder.get(a.indicatorId) ?? 1 / 0;
302
- const orderB = indicatorOrder.get(b.indicatorId) ?? 1 / 0;
303
- if (orderA !== orderB) return orderA - orderB;
304
- const typeRank = (item)=>{
305
- if (item.isChange) return 2;
306
- if ('compareline' === item.tipType) return 1;
307
- return 0;
308
- };
309
- return typeRank(a) - typeRank(b);
310
- });
311
- const content = tooltipRender(safeTitle, [
312
- ...safeItems,
313
- ...sortedCombineItems
314
- ]) ?? null;
315
- if (content) {
316
- const domEvent = event?.event ?? event;
317
- const clientX = domEvent?.clientX ?? domEvent?.x ?? 0;
318
- const clientY = domEvent?.clientY ?? domEvent?.y ?? 0;
319
- const rect = container.getBoundingClientRect();
320
- const offsetX = 12;
321
- const offsetY = 12;
322
- const applyClamp = ()=>{
323
- let el = content;
324
- while(el && el.parentElement){
325
- const p = el.parentElement;
326
- if (p.classList?.contains('g2-tooltip')) {
285
+ if (tooltipRender) {
286
+ const intervalSort = (item)=>{
287
+ if (item.isChange) return 2;
288
+ if (item.name.includes('_compare')) return 1;
289
+ return 0;
290
+ };
291
+ view.interaction('tooltip', {
292
+ shared: true,
293
+ crosshairsY: true,
294
+ marker: false,
295
+ render: (event, payload)=>{
296
+ const { title, items } = payload;
297
+ let safeTitle = title.replace(/,.*$/, '');
298
+ const baseItems = items.filter((item)=>!item.isCombine);
299
+ const safeItems = baseItems.map((item)=>{
300
+ if (item.x !== safeTitle) return {
301
+ ...item,
302
+ value: '-'
303
+ };
304
+ return item;
305
+ }).sort(intervalSort);
306
+ const combineItems = items.filter((item)=>item.isCombine);
307
+ const safeCombineItems = combineItems.map((item)=>{
308
+ if (item.x !== safeTitle) return {
309
+ ...item,
310
+ value: '-'
311
+ };
312
+ return item;
313
+ });
314
+ const indicatorOrder = new Map(indicators.map((id, i)=>[
315
+ id,
316
+ i
317
+ ]));
318
+ const sortedCombineItems = [
319
+ ...safeCombineItems
320
+ ].sort((a, b)=>{
321
+ const orderA = indicatorOrder.get(a.indicatorId) ?? 1 / 0;
322
+ const orderB = indicatorOrder.get(b.indicatorId) ?? 1 / 0;
323
+ if (orderA !== orderB) return orderA - orderB;
324
+ const typeRank = (item)=>{
325
+ if (item.isChange) return 2;
326
+ if ('compareline' === item.tipType) return 1;
327
+ return 0;
328
+ };
329
+ return typeRank(a) - typeRank(b);
330
+ });
331
+ const content = tooltipRender(safeTitle, [
332
+ ...safeItems,
333
+ ...sortedCombineItems
334
+ ]) ?? null;
335
+ if (content) {
336
+ const domEvent = event?.event ?? event;
337
+ const clientX = domEvent?.clientX ?? domEvent?.x ?? 0;
338
+ const clientY = domEvent?.clientY ?? domEvent?.y ?? 0;
339
+ const rect = container.getBoundingClientRect();
340
+ const offsetX = 12;
341
+ const offsetY = 12;
342
+ const applyClamp = ()=>{
343
+ let el = content;
344
+ while(el && el.parentElement){
345
+ const p = el.parentElement;
346
+ if (p.classList?.contains('g2-tooltip')) {
347
+ el = p;
348
+ break;
349
+ }
327
350
  el = p;
328
- break;
329
351
  }
330
- el = p;
331
- }
332
- const wrapper = el && el.classList?.contains('g2-tooltip') ? el : null;
333
- if (!wrapper) return;
334
- const wRect = wrapper.getBoundingClientRect();
335
- const tooltipW = wRect.width || 260;
336
- const tooltipH = wRect.height || 300;
337
- const minLeft = rect.left;
338
- const maxLeft = rect.right - tooltipW;
339
- const minTop = rect.top;
340
- const maxTop = rect.bottom - tooltipH;
341
- const desiredLeft = clientX + offsetX;
342
- const desiredTop = clientY + offsetY;
343
- const left = Math.min(Math.max(desiredLeft, minLeft), Math.max(maxLeft, minLeft));
344
- const top = Math.min(Math.max(desiredTop, minTop), Math.max(maxTop, minTop));
345
- wrapper.style.position = 'fixed';
346
- wrapper.style.left = `${left}px`;
347
- wrapper.style.top = `${top}px`;
348
- wrapper.style.transform = 'translate(0px, 0px)';
349
- wrapper.style.pointerEvents = 'none';
350
- wrapper.style.zIndex = '9999';
351
- };
352
- try {
353
- applyClamp();
354
- requestAnimationFrame(applyClamp);
355
- } catch {}
352
+ const wrapper = el && el.classList?.contains('g2-tooltip') ? el : null;
353
+ if (!wrapper) return;
354
+ const wRect = wrapper.getBoundingClientRect();
355
+ const tooltipW = wRect.width || 260;
356
+ const tooltipH = wRect.height || 300;
357
+ const minLeft = rect.left;
358
+ const maxLeft = rect.right - tooltipW;
359
+ const minTop = rect.top;
360
+ const maxTop = rect.bottom - tooltipH;
361
+ const desiredLeft = clientX + offsetX;
362
+ const desiredTop = clientY + offsetY;
363
+ const left = Math.min(Math.max(desiredLeft, minLeft), Math.max(maxLeft, minLeft));
364
+ const top = Math.min(Math.max(desiredTop, minTop), Math.max(maxTop, minTop));
365
+ wrapper.style.position = 'fixed';
366
+ wrapper.style.left = `${left}px`;
367
+ wrapper.style.top = `${top}px`;
368
+ wrapper.style.transform = 'translate(0px, 0px)';
369
+ wrapper.style.pointerEvents = 'none';
370
+ wrapper.style.zIndex = '9999';
371
+ };
372
+ try {
373
+ applyClamp();
374
+ requestAnimationFrame(applyClamp);
375
+ } catch {}
376
+ }
377
+ return content;
356
378
  }
357
- return content;
358
- }
359
- });
379
+ });
380
+ }
360
381
  view.legend(false);
361
382
  view.interaction('poptip', {
362
383
  offsetY: -20,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@publishfx/publish-chart",
3
- "version": "2.1.10",
3
+ "version": "2.1.12",
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": [