@publishfx/publish-chart 2.1.10 → 2.1.11

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,11 @@ 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('tdv 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('tdv:', intervalMaxY);
43
46
  const auxLeftValues = auxiliaryLineData?.length ? auxiliaryLineData.filter((item)=>'left' === item.axis).map((item)=>item.value) : [];
44
47
  const maxAuxLeft = auxLeftValues.length ? Math.max(...auxLeftValues) : 0;
45
48
  const auxRightValues = auxiliaryLineData?.length ? auxiliaryLineData.filter((item)=>'right' === item.axis).map((item)=>item.value) : [];
@@ -104,7 +107,8 @@ function renderG2CombineChart(container, options) {
104
107
  0,
105
108
  0
106
109
  ],
107
- labelFormatter: formatAxis
110
+ labelFormatter: formatAxis,
111
+ labelOpacity: 0.6
108
112
  });
109
113
  console.log('tooltip:', barColor, isCompare);
110
114
  interval.tooltip({
@@ -120,7 +124,8 @@ function renderG2CombineChart(container, options) {
120
124
  channel: Y_AXIS_FIELD,
121
125
  color: themeColors[index % themeColors.length] ?? themeColors[0] ?? "#5B8FF9",
122
126
  percent: `${(100 * Number(datum.percent)).toFixed(2)}%`,
123
- isCombine: false
127
+ isCombine: false,
128
+ x: datum[x]
124
129
  };
125
130
  }
126
131
  ].filter(Boolean) : [
@@ -140,7 +145,8 @@ function renderG2CombineChart(container, options) {
140
145
  indicatorId: datum['groupType'].replace('_compare', ''),
141
146
  channel: Y_AXIS_FIELD,
142
147
  color: barColor || 'transparent',
143
- isCombine: false
148
+ isCombine: false,
149
+ x: datum[x]
144
150
  } : false : false,
145
151
  isCompare ? (datum)=>datum.groupType.includes('_compare') ? {
146
152
  name: datum['groupType'].replace('_compare', '_change'),
@@ -148,7 +154,8 @@ function renderG2CombineChart(container, options) {
148
154
  value: datum?.change,
149
155
  isChange: true,
150
156
  color: 'transparent',
151
- isCombine: false
157
+ isCombine: false,
158
+ x: datum[x]
152
159
  } : false : false
153
160
  ].filter(Boolean)
154
161
  });
@@ -156,14 +163,20 @@ function renderG2CombineChart(container, options) {
156
163
  ...item,
157
164
  [LINE_Y_FIELD]: item[Y_AXIS_FIELD]
158
165
  }));
159
- console.log('renderG2CombineChart: line data:', lineData);
166
+ console.log('renderG2CombineChart: line data:', data);
160
167
  const compareLineData = data.filter((item)=>item.isCombine && item.groupType.includes('_compare')).filter((item)=>'' !== item[Y_AXIS_FIELD]).map((item)=>({
161
168
  ...item,
162
169
  [LINE_Y_FIELD]: item[Y_AXIS_FIELD]
163
170
  }));
164
171
  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);
172
+ const lineMaxY = lineData.reduce((max, item)=>{
173
+ if ('-' === item[LINE_Y_FIELD] || void 0 === item[LINE_Y_FIELD] || null === item[LINE_Y_FIELD] || '' === item[LINE_Y_FIELD]) return max;
174
+ return Math.max(max, item[LINE_Y_FIELD]);
175
+ }, 0);
176
+ const compareLineMaxY = compareLineData.reduce((max, item)=>{
177
+ if ('-' === item[LINE_Y_FIELD] || void 0 === item[LINE_Y_FIELD] || null === item[LINE_Y_FIELD] || '' === item[LINE_Y_FIELD]) return max;
178
+ return Math.max(max, item[LINE_Y_FIELD]);
179
+ }, 0);
167
180
  const lineFinalMaxY = Math.max(lineMaxY, compareLineMaxY) || 1;
168
181
  const finalLineMax = Math.max(lineFinalMaxY, maxAuxRight);
169
182
  console.log('lineData:', lineData);
@@ -212,7 +225,8 @@ function renderG2CombineChart(container, options) {
212
225
  0
213
226
  ],
214
227
  tickOpacity: 0,
215
- labelFormatter: formatLineAxis
228
+ labelFormatter: formatLineAxis,
229
+ labelOpacity: 0.6
216
230
  });
217
231
  console.log('renderG2CombineChart: compare line data:', compareLineData);
218
232
  const compareLine = view.line().data(compareLineData).encode('x', x).encode('y', LINE_Y_FIELD).encode('color', 'groupType').style({
@@ -267,96 +281,102 @@ function renderG2CombineChart(container, options) {
267
281
  } : false
268
282
  ].filter(Boolean)
269
283
  });
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')) {
284
+ if (tooltipRender) {
285
+ const intervalSort = (item)=>{
286
+ if (item.isChange) return 2;
287
+ if (item.name.includes('_compare')) return 1;
288
+ return 0;
289
+ };
290
+ view.interaction('tooltip', {
291
+ shared: true,
292
+ crosshairsY: true,
293
+ marker: false,
294
+ render: (event, payload)=>{
295
+ const { title, items } = payload;
296
+ let safeTitle = title.replace(/,.*$/, '');
297
+ const baseItems = items.filter((item)=>!item.isCombine);
298
+ const safeItems = baseItems.map((item)=>{
299
+ if (item.x !== safeTitle) return {
300
+ ...item,
301
+ value: '-'
302
+ };
303
+ return item;
304
+ }).sort(intervalSort);
305
+ const combineItems = items.filter((item)=>item.isCombine);
306
+ const safeCombineItems = combineItems.map((item)=>{
307
+ if (item.x !== safeTitle) return {
308
+ ...item,
309
+ value: '-'
310
+ };
311
+ return item;
312
+ });
313
+ const indicatorOrder = new Map(indicators.map((id, i)=>[
314
+ id,
315
+ i
316
+ ]));
317
+ const sortedCombineItems = [
318
+ ...safeCombineItems
319
+ ].sort((a, b)=>{
320
+ const orderA = indicatorOrder.get(a.indicatorId) ?? 1 / 0;
321
+ const orderB = indicatorOrder.get(b.indicatorId) ?? 1 / 0;
322
+ if (orderA !== orderB) return orderA - orderB;
323
+ const typeRank = (item)=>{
324
+ if (item.isChange) return 2;
325
+ if ('compareline' === item.tipType) return 1;
326
+ return 0;
327
+ };
328
+ return typeRank(a) - typeRank(b);
329
+ });
330
+ const content = tooltipRender(safeTitle, [
331
+ ...safeItems,
332
+ ...sortedCombineItems
333
+ ]) ?? null;
334
+ if (content) {
335
+ const domEvent = event?.event ?? event;
336
+ const clientX = domEvent?.clientX ?? domEvent?.x ?? 0;
337
+ const clientY = domEvent?.clientY ?? domEvent?.y ?? 0;
338
+ const rect = container.getBoundingClientRect();
339
+ const offsetX = 12;
340
+ const offsetY = 12;
341
+ const applyClamp = ()=>{
342
+ let el = content;
343
+ while(el && el.parentElement){
344
+ const p = el.parentElement;
345
+ if (p.classList?.contains('g2-tooltip')) {
346
+ el = p;
347
+ break;
348
+ }
327
349
  el = p;
328
- break;
329
350
  }
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 {}
351
+ const wrapper = el && el.classList?.contains('g2-tooltip') ? el : null;
352
+ if (!wrapper) return;
353
+ const wRect = wrapper.getBoundingClientRect();
354
+ const tooltipW = wRect.width || 260;
355
+ const tooltipH = wRect.height || 300;
356
+ const minLeft = rect.left;
357
+ const maxLeft = rect.right - tooltipW;
358
+ const minTop = rect.top;
359
+ const maxTop = rect.bottom - tooltipH;
360
+ const desiredLeft = clientX + offsetX;
361
+ const desiredTop = clientY + offsetY;
362
+ const left = Math.min(Math.max(desiredLeft, minLeft), Math.max(maxLeft, minLeft));
363
+ const top = Math.min(Math.max(desiredTop, minTop), Math.max(maxTop, minTop));
364
+ wrapper.style.position = 'fixed';
365
+ wrapper.style.left = `${left}px`;
366
+ wrapper.style.top = `${top}px`;
367
+ wrapper.style.transform = 'translate(0px, 0px)';
368
+ wrapper.style.pointerEvents = 'none';
369
+ wrapper.style.zIndex = '9999';
370
+ };
371
+ try {
372
+ applyClamp();
373
+ requestAnimationFrame(applyClamp);
374
+ } catch {}
375
+ }
376
+ return content;
356
377
  }
357
- return content;
358
- }
359
- });
378
+ });
379
+ }
360
380
  view.legend(false);
361
381
  view.interaction('poptip', {
362
382
  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.11",
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": [