@publishfx/publish-chart 2.1.2 → 2.1.3

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,4 +1,13 @@
1
- **2.1.1** feat(chart): 柱状图支持crossharisY
1
+ **2.1.3** fix(chart): 组合图分组时inset置为0
2
+ - 2026-02-28T23:48:20+08:00 [fix(chart): 组合图分组时inset置为0](http://lf.git.oa.mt/publish_platform/web/publish/commit/047e02d3cfbce21101277f48e904864163b2a02c)
3
+ - 2026-02-28T22:42:20+08:00 [feat(chart): 组合图tooltip数据调整](http://lf.git.oa.mt/publish_platform/web/publish/commit/f79461050699b0755c8837e26b035083ec980cf1)
4
+ - 2026-02-28T20:42:35+08:00 [feat(chart): 组合图默认值](http://lf.git.oa.mt/publish_platform/web/publish/commit/97613e165dc16ff1d415e01facafa11db4125a24)
5
+ - 2026-02-28T20:42:08+08:00 [feat(chart): 组合图tooltips](http://lf.git.oa.mt/publish_platform/web/publish/commit/910af4376c2149ed44816d3eae4a3188f2601f54)
6
+ - 2026-02-28T20:31:15+08:00 [feat(chart): 组合图增加着重日功能](http://lf.git.oa.mt/publish_platform/web/publish/commit/f88ce5905022454d3ac611cd16de73f6ae8c8d12)
7
+ - 2026-02-28T20:08:16+08:00 [feat(chart): 设置着重interval的ratio为0.6](http://lf.git.oa.mt/publish_platform/web/publish/commit/057cb33eabe87d077b46b6271eea63a5e2879640)
8
+ - 2026-02-28T20:02:39+08:00 [fix(chart): 修复组合图的ts错误](http://lf.git.oa.mt/publish_platform/web/publish/commit/a01f19528e46ee13d39f6de85c8ffc5fa9405ec5)
9
+ - 2026-02-28T19:10:04+08:00 [feat(chart): 组合图支持分组](http://lf.git.oa.mt/publish_platform/web/publish/commit/525c1bbe47027ca3c4550adfea1c36e43c4dad34)
10
+ - 2026-02-28T18:45:52+08:00 [feat(chart): 着重日逻辑优化](http://lf.git.oa.mt/publish_platform/web/publish/commit/3d57801fccaf67f69d3c08d19cc750fa36a2fa42)
2
11
  - 2026-02-28T18:37:26+08:00 [feat(chart): 柱状图支持crossharisY](http://lf.git.oa.mt/publish_platform/web/publish/commit/b77a0932f1710144915d209c0186640bafdff492)
3
12
 
4
13
  **2.1.1** feat(chart): 柱状图支持crossharisY
@@ -35,7 +35,7 @@ class DataAdapter {
35
35
  callback: (a, b)=>{
36
36
  if ('-' === a[config.y]) return config.isHorizontal ? -1 : 1;
37
37
  if ('-' === b[config.y]) return config.isHorizontal ? 1 : -1;
38
- return config.isHorizontal ? a[config.y] - b[config.y] : b[config.y] - a[config.y];
38
+ return b[config.y] - a[config.y];
39
39
  }
40
40
  });
41
41
  }
@@ -137,11 +137,13 @@ const G2CombineChart = ({ height = 300, data, x = "", y = "", z = "", indicatorM
137
137
  return;
138
138
  }
139
139
  const groupTypes = Array.from(new Set(transformedData.map((d)=>d.groupType.replace("_compare", "") + "_" + d.isCombine).filter((v)=>null != v)));
140
+ const lineGroupTypeArr = groupTypes.filter((v)=>"true" === v.split("_")[1]);
140
141
  const items = groupTypes.map((id, index)=>{
141
142
  const colorIndex = index;
142
143
  const indicatorId = id.split("_")[0];
143
144
  const isCombine = "true" === id.split("_")[1];
144
- const color = isGroup ? themeColors[colorIndex] || themeColors[0] : 0 === colorIndex ? themeColors[colorIndex] : lineColors[colorIndex - 1];
145
+ const lineGroupTypeIndex = lineGroupTypeArr.indexOf(id);
146
+ const color = isGroup ? isCombine ? lineColors[lineGroupTypeIndex] || lineColors[0] : themeColors[colorIndex] || themeColors[0] : 0 === colorIndex ? themeColors[colorIndex] : lineColors[colorIndex - 1];
145
147
  return {
146
148
  id,
147
149
  label: isGroup ? isCombine ? getIndicatorCompareName(safeIndicatorMap, String(indicatorId)) : indicatorId : getIndicatorCompareName(safeIndicatorMap, String(indicatorId)) + (String(indicatorId).includes("_compare") ? `(对比时间:${timeRange?.compareStartTime}~${timeRange?.compareEndTime})` : ""),
@@ -195,7 +197,7 @@ const G2CombineChart = ({ height = 300, data, x = "", y = "", z = "", indicatorM
195
197
  height: height - canvasMarginBottom,
196
198
  formatLabel: isDataTag ? (d)=>{
197
199
  const indicatorId = d.groupType.split("_")[0];
198
- return "-" === formatter.formatIndicator(d.groupValue, safeIndicatorMap[indicatorId]) ? "" : formatter.formatIndicator(d.groupValue, safeIndicatorMap[indicatorId]);
200
+ return isGroup ? d.isCombine ? "-" === formatter.formatIndicator(d.groupValue, safeIndicatorMap[z]) ? "" : formatter.formatIndicator(d.groupValue, safeIndicatorMap[z]) : "-" === formatter.formatIndicator(d['total'], safeIndicatorMap[y]) ? "" : formatter.formatIndicator(d['total'], safeIndicatorMap[y]) : "-" === formatter.formatIndicator(d.groupValue, safeIndicatorMap[indicatorId]) ? "" : formatter.formatIndicator(d.groupValue, safeIndicatorMap[indicatorId]);
199
201
  } : void 0,
200
202
  indicators,
201
203
  tooltipRender: (title, items)=>{
@@ -207,7 +209,7 @@ const G2CombineChart = ({ height = 300, data, x = "", y = "", z = "", indicatorM
207
209
  }));
208
210
  safeItems = safeItems.filter((i)=>i.indicatorId);
209
211
  react_dom.render(/*#__PURE__*/ jsx(G2CompareTooltip, {
210
- isGroupBar: true,
212
+ isGroupBar: isGroup,
211
213
  title: title,
212
214
  items: safeItems,
213
215
  safeIndicatorMap: safeIndicatorMap,
@@ -153,11 +153,14 @@ function applyHighlightDate(view, x, data, highlightDate, isHighlight) {
153
153
  domainMax: 100,
154
154
  independent: true
155
155
  }).tooltip(false).axis('y', {
156
+ position: 'right',
156
157
  title: false,
157
158
  grid: false,
158
- label: false
159
+ label: false,
160
+ tick: false
159
161
  });
160
162
  highlightInterval.style({
163
+ columnWidthRatio: 0.6,
161
164
  fill: '#cccccc',
162
165
  fillOpacity: isHighlight ? 0.3 : 0
163
166
  });
@@ -169,7 +172,8 @@ function applyHighlightDate(view, x, data, highlightDate, isHighlight) {
169
172
  }).tooltip(true).axis('y', {
170
173
  title: false,
171
174
  grid: false,
172
- label: false
175
+ label: false,
176
+ tick: false
173
177
  }).style({
174
178
  stroke: 'transparent',
175
179
  strokeOpacity: 0
@@ -45,10 +45,12 @@ function renderG2BarChart(container, options) {
45
45
  interval.style({
46
46
  columnWidthRatio: 0.6,
47
47
  insetLeft: (_d, index, _data, _column)=>{
48
+ if (isHorizontal) return 0;
48
49
  if (isCompare) return index % 2 === 0 ? 4 : 0;
49
50
  return 4;
50
51
  },
51
52
  insetRight: (_d, index, _data, _column)=>{
53
+ if (isHorizontal) return 0;
52
54
  if (isCompare) return index % 2 === 1 ? 4 : 0;
53
55
  return 4;
54
56
  },
@@ -1,5 +1,6 @@
1
1
  import { lines } from "@antv/g-pattern";
2
- import { applyAxisX, createChart, getMainView } from "./g2Helpers.js";
2
+ import { applyAxisX, applyHighlightDate, createChart, getMainView } from "./g2Helpers.js";
3
+ import { getIndicatorCompareName } from "../../../utils/indicatorHelpers.js";
3
4
  const Y_AXIS_FIELD = 'groupValue';
4
5
  const BAR_Y_FIELD = 'barValue';
5
6
  const LINE_Y_FIELD = 'lineValue';
@@ -21,17 +22,12 @@ function renderG2CombineChart(container, options) {
21
22
  view.data(data);
22
23
  applyAxisX(view, {
23
24
  title: false,
24
- grid: true,
25
- gridStroke: '#333',
26
- gridLineWidth: 50,
27
- gridLineDash: [
28
- 1000
29
- ],
30
- gridFilter: highlightDate.length > 0 && isHighlight ? (val)=>highlightDate.includes(val?.label) : ()=>false
25
+ grid: false
31
26
  });
32
27
  const barColor = themeColors[0] ?? "#5B8FF9";
33
- console.log('tooltip: themeColors:', themeColors[0], barColor);
28
+ console.log('tooltip: themeColors:', themeColors[0], barColor, isGroup);
34
29
  console.log('renderG2CombineChart interval data:', data.filter((item)=>!item.isCombine));
30
+ applyHighlightDate(view, x, data, highlightDate, isHighlight);
35
31
  const intervalData = data.filter((item)=>!item.isCombine).map((item)=>({
36
32
  ...item,
37
33
  [BAR_Y_FIELD]: item[Y_AXIS_FIELD]
@@ -44,9 +40,20 @@ function renderG2CombineChart(container, options) {
44
40
  type: 'stackY',
45
41
  reverse: true
46
42
  } : {
47
- type: 'dodgeX'
43
+ type: 'dodgeX',
44
+ padding: 0
48
45
  }).style({
49
- columnWidthRatio: 0.5,
46
+ columnWidthRatio: 0.6,
47
+ insetLeft: (_d, index, _data, _column)=>{
48
+ if (isGroup) return 0;
49
+ if (isCompare) return index % 2 === 0 ? 4 : 0;
50
+ return 4;
51
+ },
52
+ insetRight: (_d, index, _data, _column)=>{
53
+ if (isGroup) return 0;
54
+ if (isCompare) return index % 2 === 1 ? 4 : 0;
55
+ return 4;
56
+ },
50
57
  fill: (datum)=>{
51
58
  const groupType = String(datum.groupType ?? '');
52
59
  const index = legendItems.findIndex((item)=>item.id === `${groupType}_${datum.isCombine}`);
@@ -102,7 +109,8 @@ function renderG2CombineChart(container, options) {
102
109
  indicatorId,
103
110
  channel: Y_AXIS_FIELD,
104
111
  color: themeColors[index % themeColors.length] ?? themeColors[0] ?? "#5B8FF9",
105
- percent: `${(100 * Number(datum.percent)).toFixed(2)}%`
112
+ percent: `${(100 * Number(datum.percent)).toFixed(2)}%`,
113
+ isCombine: false
106
114
  };
107
115
  }
108
116
  ].filter(Boolean) : [
@@ -111,7 +119,8 @@ function renderG2CombineChart(container, options) {
111
119
  name: datum['groupType'],
112
120
  indicatorId: datum['groupType'],
113
121
  channel: Y_AXIS_FIELD,
114
- color: barColor || 'transparent'
122
+ color: barColor || 'transparent',
123
+ isCombine: false
115
124
  },
116
125
  isCompare ? (datum)=>datum.groupType.includes('_compare') ? {
117
126
  value: datum[BAR_Y_FIELD],
@@ -119,14 +128,16 @@ function renderG2CombineChart(container, options) {
119
128
  name: datum['groupType'],
120
129
  indicatorId: datum['groupType'].replace('_compare', ''),
121
130
  channel: Y_AXIS_FIELD,
122
- color: barColor || 'transparent'
131
+ color: barColor || 'transparent',
132
+ isCombine: false
123
133
  } : false : false,
124
134
  isCompare ? (datum)=>datum.groupType.includes('_compare') ? {
125
135
  name: datum['groupType'].replace('_compare', '_change'),
126
136
  indicatorId: datum['groupType'].replace('_compare', ''),
127
137
  value: datum?.change,
128
138
  isChange: true,
129
- color: 'transparent'
139
+ color: 'transparent',
140
+ isCombine: false
130
141
  } : false : false
131
142
  ].filter(Boolean)
132
143
  });
@@ -139,6 +150,7 @@ function renderG2CombineChart(container, options) {
139
150
  ...item,
140
151
  [LINE_Y_FIELD]: item[Y_AXIS_FIELD]
141
152
  }));
153
+ console.log('compareLineData:', compareLineData);
142
154
  const lineMaxY = lineData.reduce((max, item)=>Math.max(max, item[LINE_Y_FIELD]), 0);
143
155
  const compareLineMaxY = compareLineData.reduce((max, item)=>Math.max(max, item[LINE_Y_FIELD]), 0);
144
156
  const lineFinalMaxY = Math.max(lineMaxY, compareLineMaxY);
@@ -146,20 +158,35 @@ function renderG2CombineChart(container, options) {
146
158
  const line = view.line().data(lineData).encode("x", x).encode("y", LINE_Y_FIELD).encode('color', 'groupType').style({
147
159
  lineWidth: 2,
148
160
  stroke: (datum)=>{
161
+ const groupTypeSet = new Set(lineData.map((item)=>item.groupType));
162
+ const groupTypeArr = [
163
+ ...groupTypeSet
164
+ ];
149
165
  const groupType = String(datum[0]?.groupType ?? '');
150
- const color = lineColors[indicators.slice(1).indexOf(String(groupType)) ?? 0];
166
+ const index = groupTypeArr.findIndex((item)=>item === groupType);
167
+ const color = isGroup ? lineColors[index] || lineColors[0] : lineColors[indicators.slice(1).indexOf(String(groupType)) ?? 0];
151
168
  return color;
152
169
  }
153
170
  });
154
171
  line.tooltip({
155
172
  items: [
156
- (datum)=>({
173
+ (datum)=>{
174
+ const groupTypeSet = new Set(lineData.map((item)=>item.groupType));
175
+ const groupTypeArr = [
176
+ ...groupTypeSet
177
+ ];
178
+ const groupType = String(datum[0]?.groupType ?? '');
179
+ const index = groupTypeArr.findIndex((item)=>item === groupType);
180
+ return {
157
181
  value: datum[LINE_Y_FIELD],
158
- name: datum['groupType'],
182
+ name: isGroup ? getIndicatorCompareName(_indicatorMap, datum['groupType']) : datum['groupType'],
159
183
  indicatorId: datum['groupType'],
160
184
  channel: Y_AXIS_FIELD,
161
- color: lineColors[indicators.slice(1).indexOf(String(datum['groupType'])) ?? 0] || 'transparent'
162
- })
185
+ color: isGroup ? lineColors[index] || lineColors[0] : lineColors[indicators.slice(1).indexOf(String(datum['groupType'])) ?? 0] || 'transparent',
186
+ isCombine: true,
187
+ tipType: 'line'
188
+ };
189
+ }
163
190
  ]
164
191
  });
165
192
  line.scale('y', {
@@ -209,32 +236,45 @@ function renderG2CombineChart(container, options) {
209
236
  console.log('hasCompareData:', hasCompareData, data);
210
237
  if (hasCompareData) compareLine.tooltip({
211
238
  items: [
212
- (datum)=>({
239
+ (datum)=>datum.groupType.includes('_compare') ? {
213
240
  value: datum[LINE_Y_FIELD],
214
241
  compareTime: datum?.compareTime,
215
242
  name: datum['groupType'],
216
243
  indicatorId: datum['groupType'].replace('_compare', ''),
217
244
  channel: Y_AXIS_FIELD,
218
- color: lineColors[indicators.slice(1).indexOf(String(datum['groupType'])) ?? 0] || 'transparent'
219
- }),
220
- (datum)=>({
245
+ color: lineColors[indicators.slice(1).indexOf(String(datum['groupType'])) ?? 0] || 'transparent',
246
+ isCombine: true,
247
+ tipType: 'compareline'
248
+ } : false,
249
+ (datum)=>datum.groupType.includes('_compare') ? {
221
250
  name: datum['groupType'].replace('_compare', '_change'),
222
251
  indicatorId: datum['groupType'].replace('_compare', ''),
252
+ color: 'blue',
223
253
  value: datum?.change,
224
254
  isChange: true,
225
- color: 'transparent'
226
- })
227
- ]
255
+ isCombine: true,
256
+ tipType: 'compareline'
257
+ } : false
258
+ ].filter(Boolean)
228
259
  });
229
- if (tooltipRender) line.interaction('tooltip', {
260
+ if (tooltipRender) view.interaction('tooltip', {
230
261
  shared: true,
231
262
  crosshairsY: true,
232
263
  marker: false,
233
264
  render: (_event, payload)=>{
234
265
  const { title, items } = payload;
266
+ const baseItems = items.filter((item)=>!item.isCombine);
267
+ const combineItems = items.filter((item)=>item.isCombine);
235
268
  console.log('tooltipRender:', title, items, indicators);
269
+ if (isGroup) return tooltipRender(title, [
270
+ ...baseItems,
271
+ ...combineItems
272
+ ]) ?? null;
236
273
  if (indicators.length) {
237
- const groupedItems = indicators.map((indicator)=>items.filter((i)=>i.indicatorId === String(indicator)));
274
+ const groupedItems = indicators.map((indicator, index)=>{
275
+ if (0 === index) return items.filter((i)=>!i.isCombine).filter((i)=>i.indicatorId === String(indicator));
276
+ return items.filter((i)=>i.isCombine).filter((i)=>i.indicatorId === String(indicator));
277
+ });
238
278
  console.log(groupedItems.flat(), 'tooltip groupedItems');
239
279
  const sortedItems = groupedItems.map((group)=>[
240
280
  group.filter((i)=>i.name === i.indicatorId),
@@ -244,8 +284,9 @@ function renderG2CombineChart(container, options) {
244
284
  console.log(sortedItems, 'tooltip sortedItems');
245
285
  const formatItems = sortedItems.map((item)=>({
246
286
  ...item,
247
- color: lineColors[indicators.slice(1).indexOf(String(item?.indicatorId)) ?? 0] || barColor || 'transparent'
287
+ color: item.isCombine ? lineColors[indicators.slice(1).indexOf(String(item?.indicatorId)) ?? 0] || barColor || 'transparent' : barColor || 'transparent'
248
288
  }));
289
+ console.log(formatItems, 'tooltip formatItems');
249
290
  return tooltipRender(title, formatItems ?? []) ?? null;
250
291
  }
251
292
  }
@@ -314,11 +355,27 @@ function renderG2CombineChart(container, options) {
314
355
  });
315
356
  });
316
357
  if (isDataTag && formatLabel) {
358
+ const groupedByX = intervalData.reduce((acc, item)=>{
359
+ const key = item[x];
360
+ if (!acc[key]) acc[key] = [];
361
+ acc[key].push(item);
362
+ return acc;
363
+ }, {});
364
+ const lastItemsInEachStack = new Set();
365
+ Object.values(groupedByX).forEach((group)=>{
366
+ group.sort((a, b)=>a[y] - b[y]);
367
+ const lastItem = group[group.length - 1];
368
+ lastItemsInEachStack.add(lastItem);
369
+ });
317
370
  interval.label({
318
- dy: -10,
371
+ dy: isGroup ? -16 : -10,
319
372
  dx: -10,
320
373
  offset: 0,
321
- text: (d)=>formatLabel(d)
374
+ text: (d)=>{
375
+ if (!isGroup) return formatLabel(d);
376
+ if (lastItemsInEachStack.has(d)) return formatLabel(d);
377
+ return '';
378
+ }
322
379
  });
323
380
  line.label({
324
381
  dy: -10,
@@ -30,10 +30,10 @@ function renderG2LineChart(container, options) {
30
30
  clamp: true
31
31
  });
32
32
  applyHighlightDate(view, x, data, highlightDate, isHighlight);
33
- console.log('g2linets:', x, Y_AXIS_FIELD, data);
34
- const line = view.line().data(data.filter((item)=>!item.groupType.includes('_compare'))).encode('x', x).encode('y', Y_AXIS_FIELD).encode('color', 'groupType').style({
33
+ console.log('g2linets:', x, Y_AXIS_FIELD, data, indicators);
34
+ const line = view.line().data(data.filter((item)=>!item.groupType.includes('_compare'))).encode('x', x).encode('y', Y_AXIS_FIELD).encode('color', 'groupType').encode('series', 'groupType').style({
35
35
  lineWidth: 2,
36
- stroke: (_datum, index)=>themeColors[index] ?? themeColors[0]
36
+ stroke: (datum)=>getColorByGroupType(datum[0]?.groupType ?? '', colorOpts)
37
37
  });
38
38
  const compareLine = view.line().data(data.filter((item)=>item.groupType.includes('_compare'))).encode('x', x).encode('y', Y_AXIS_FIELD).encode('color', 'groupType').style({
39
39
  lineDash: [
@@ -41,7 +41,7 @@ function renderG2LineChart(container, options) {
41
41
  4
42
42
  ],
43
43
  lineWidth: 2,
44
- stroke: (_datum, index)=>themeColors[index] ?? themeColors[0]
44
+ stroke: (datum)=>getColorByGroupType(datum[0]?.groupType ?? '', colorOpts)
45
45
  });
46
46
  applyAxisX(view, {
47
47
  grid: false
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@publishfx/publish-chart",
3
- "version": "2.1.2",
3
+ "version": "2.1.3",
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": [