@publishfx/publish-chart 2.1.38 → 2.1.42

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,9 @@
1
+ **2.1.41** feat(chart): 分组对比折线图自定义图例与tooltip交互优化 f-6719092744
2
+ - 2026-06-16T16:45:08+08:00 [feat(chart): 分组对比折线图自定义图例与tooltip交互优化 f-6719092744](http://lf.git.oa.mt/publish_platform/web/publish/commit/446f1dcea5fa50c1db96a395747bf26a5213a2f5)
3
+
4
+ **2.1.39** feat(chart): 分组对比折线图自定义图例与tooltip交互优化 f-6719092744
5
+ - 2026-06-16T16:45:08+08:00 [feat(chart): 分组对比折线图自定义图例与tooltip交互优化 f-6719092744](http://lf.git.oa.mt/publish_platform/web/publish/commit/446f1dcea5fa50c1db96a395747bf26a5213a2f5)
6
+
1
7
  **2.1.38** feat(chart): 分组对比折线图自定义图例逻辑优化 f-6719092744
2
8
  - 2026-06-16T14:36:13+08:00 [feat(chart): 分组对比折线图自定义图例逻辑优化 f-6719092744](http://lf.git.oa.mt/publish_platform/web/publish/commit/a03eaf696cb567384e0e888cb2cd1a86046ecae3)
3
9
  - 2026-06-09T11:58:41+08:00 [feat(chart): 撤销组合图tooltip优化 f-6854368983](http://lf.git.oa.mt/publish_platform/web/publish/commit/1b7e955aa4ff680ce2bad27c3709306d3f12c7d3)
@@ -1,5 +1,5 @@
1
1
  import { jsx, jsxs } from "react/jsx-runtime";
2
- import react, { memo, useEffect, useMemo, useState } from "react";
2
+ import react, { memo, useEffect, useMemo, useRef, useState } from "react";
3
3
  import { Axis, Chart, Legend, Line, Tooltip, View } from "bizcharts";
4
4
  import styled_components from "styled-components";
5
5
  import lib from "@antv/data-set/lib";
@@ -56,6 +56,8 @@ const GroupLineCompare = ({ height, data, x = 'groupName', y = '', legend = 'gro
56
56
  const [colorMap, setColorMap] = useState({});
57
57
  const [checkedLegendItems, setCheckedLegendItems] = useState(new Set());
58
58
  const [legendItems, setLegendItems] = useState([]);
59
+ const prevLegendItemsRef = useRef([]);
60
+ const isFirstRenderRef = useRef(true);
59
61
  const [padding, setPadding] = useState([
60
62
  20,
61
63
  10,
@@ -124,6 +126,17 @@ const GroupLineCompare = ({ height, data, x = 'groupName', y = '', legend = 'gro
124
126
  maxY,
125
127
  transformData
126
128
  ]);
129
+ useEffect(()=>{
130
+ if (transformData.length > 0) {
131
+ const groupTypeSet = new Set();
132
+ transformData.forEach((item)=>{
133
+ groupTypeSet.add(item.groupType);
134
+ });
135
+ setCheckedLegendItems(groupTypeSet);
136
+ }
137
+ }, [
138
+ isLegend
139
+ ]);
127
140
  useEffect(()=>{
128
141
  const groupTypeSet = new Set();
129
142
  transformData.forEach((item)=>{
@@ -155,7 +168,22 @@ const GroupLineCompare = ({ height, data, x = 'groupName', y = '', legend = 'gro
155
168
  }));
156
169
  setColorMap(colorMap);
157
170
  setLegendItems(legendItems);
158
- setCheckedLegendItems(groupTypeSet);
171
+ setCheckedLegendItems((prev)=>{
172
+ if (isFirstRenderRef.current) {
173
+ isFirstRenderRef.current = false;
174
+ return groupTypeSet;
175
+ }
176
+ const prevLegendNames = new Set(prevLegendItemsRef.current.map((item)=>item.name));
177
+ const next = new Set();
178
+ groupTypeSet.forEach((item)=>{
179
+ const baseItem = item.endsWith('_compare') ? item.replace('_compare', '') : item;
180
+ if (prevLegendNames.has(baseItem)) {
181
+ if (prev.has(baseItem)) next.add(item);
182
+ } else next.add(item);
183
+ });
184
+ return next;
185
+ });
186
+ prevLegendItemsRef.current = legendItems;
159
187
  }, [
160
188
  transformData
161
189
  ]);
@@ -220,6 +248,13 @@ const GroupLineCompare = ({ height, data, x = 'groupName', y = '', legend = 'gro
220
248
  transformData,
221
249
  x
222
250
  ]);
251
+ const finalLegendItems = useMemo(()=>legendItems.map((item)=>({
252
+ ...item,
253
+ unchecked: !checkedLegendItems.has(item.name)
254
+ })), [
255
+ legendItems,
256
+ checkedLegendItems
257
+ ]);
223
258
  return /*#__PURE__*/ jsxs(Chart, {
224
259
  height: height || 300,
225
260
  data: transformData,
@@ -302,17 +337,19 @@ const GroupLineCompare = ({ height, data, x = 'groupName', y = '', legend = 'gro
302
337
  }),
303
338
  /*#__PURE__*/ jsx(Tooltip, {
304
339
  shared: true,
305
- showCrosshairs: true,
340
+ showCrosshairs: checkedLegendItems.size > 0,
306
341
  children: (title, items)=>{
307
- const originItems = items?.filter((item)=>!item.name.includes('_compare'));
342
+ if (0 === checkedLegendItems.size) return null;
343
+ const activeItems = items?.filter((item)=>checkedLegendItems.has(item.name)) || [];
344
+ const originItems = activeItems.filter((item)=>!item.name.includes('_compare'));
308
345
  return /*#__PURE__*/ jsx("div", {
309
346
  style: {
310
347
  padding: '10px 0'
311
348
  },
312
- children: items?.length ? /*#__PURE__*/ jsxs(StyledTooltip, {
349
+ children: originItems.length > 0 && /*#__PURE__*/ jsxs(StyledTooltip, {
313
350
  children: [
314
- originItems?.map((it, index)=>{
315
- const compareItem = items.find((item)=>item.name === `${it.name}_compare`) || {};
351
+ originItems.map((it, index)=>{
352
+ const compareItem = activeItems.find((item)=>item.name === `${it.name}_compare`) || {};
316
353
  return /*#__PURE__*/ jsxs(react.Fragment, {
317
354
  children: [
318
355
  !index && /*#__PURE__*/ jsxs("div", {
@@ -400,7 +437,7 @@ const GroupLineCompare = ({ height, data, x = 'groupName', y = '', legend = 'gro
400
437
  ]
401
438
  }, index))
402
439
  ]
403
- }) : title
440
+ })
404
441
  });
405
442
  }
406
443
  }),
@@ -442,8 +479,7 @@ const GroupLineCompare = ({ height, data, x = 'groupName', y = '', legend = 'gro
442
479
  custom: true,
443
480
  position: "bottom-left",
444
481
  name: legend,
445
- items: legendItems,
446
- filter: (name)=>checkedLegendItems.has(name),
482
+ items: finalLegendItems,
447
483
  onChange: (e)=>{
448
484
  const { unchecked, name } = e.item;
449
485
  setCheckedLegendItems((prev)=>{
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@publishfx/publish-chart",
3
- "version": "2.1.38",
3
+ "version": "2.1.42",
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": [