@publishfx/publish-chart 2.1.21 → 2.1.23

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.
@@ -122,14 +122,7 @@ class DataAdapter {
122
122
  dv.transform({
123
123
  type: 'map',
124
124
  callback: (row)=>{
125
- row[config.y] = '' !== row[config.y] ? +row[config.y] : '-';
126
- return row;
127
- }
128
- });
129
- tdv.transform({
130
- type: 'map',
131
- callback: (row)=>{
132
- row[config.y] = '' !== row[config.y] ? +row[config.y] : '-';
125
+ row[config.y] = '' !== row[config.y] ? +row[config.y] : null;
133
126
  return row;
134
127
  }
135
128
  });
@@ -145,6 +138,20 @@ class DataAdapter {
145
138
  return row.isCombine;
146
139
  }
147
140
  });
141
+ tdv.transform({
142
+ type: 'map',
143
+ callback: (row)=>{
144
+ row[config.y] = '' !== row[config.y] ? +row[config.y] : null;
145
+ return row;
146
+ }
147
+ });
148
+ combinedv.transform({
149
+ type: 'map',
150
+ callback: (row)=>{
151
+ row[config.y] = '' !== row[config.y] ? +row[config.y] : null;
152
+ return row;
153
+ }
154
+ });
148
155
  if (config.isDescend) tdv.transform({
149
156
  type: 'sort',
150
157
  callback (a, b) {
@@ -144,7 +144,6 @@ const G2BarChart = ({ height = 300, data, x = "", y = "", indicatorMap, onChartC
144
144
  items: safeItems,
145
145
  safeIndicatorMap: safeIndicatorMap,
146
146
  formatter: formatter,
147
- safeLegend: safeLegend,
148
147
  auxiliaryLineData: auxiliaryLineData
149
148
  }), container);
150
149
  return container;
@@ -70,7 +70,6 @@ const G2CombineChart = ({ height = 300, data, x = "", y = "", z = "", indicatorM
70
70
  isGroupRef.current = isGroup;
71
71
  const themeColors = contextConfig?.theme?.colors || [];
72
72
  const safeIndicatorMap = indicatorMap || contextConfig.indicatorMap || {};
73
- const safeLegend = legend || "groupType";
74
73
  const safeZ = z;
75
74
  const safeY = "groupValue";
76
75
  const isCompare = timeRange?.compareStartTime !== "";
@@ -124,13 +123,9 @@ const G2CombineChart = ({ height = 300, data, x = "", y = "", z = "", indicatorM
124
123
  safeIndicatorMap,
125
124
  y
126
125
  ]);
127
- const formatLineAxis = useCallback((val)=>{
128
- const indicatorId = indicators?.length > 2 ? "" : safeZ;
129
- return getAxisFormat(val, safeIndicatorMap, indicatorId);
130
- }, [
126
+ const formatLineAxis = useCallback((val)=>getAxisFormat(val, safeIndicatorMap, safeZ), [
131
127
  safeIndicatorMap,
132
- safeZ,
133
- indicators
128
+ safeZ
134
129
  ]);
135
130
  useEffect(()=>{
136
131
  if (!transformedData.length) {
@@ -183,7 +178,7 @@ const G2CombineChart = ({ height = 300, data, x = "", y = "", z = "", indicatorM
183
178
  groupName: key,
184
179
  isCombine: false,
185
180
  groupType: groupType,
186
- groupValue: "",
181
+ groupValue: null,
187
182
  total: 0,
188
183
  percent: ""
189
184
  });
@@ -257,7 +252,7 @@ const G2CombineChart = ({ height = 300, data, x = "", y = "", z = "", indicatorM
257
252
  isDataTag,
258
253
  isCombineDataTag,
259
254
  isLegend: false,
260
- isCompare,
255
+ isCompare: isCompare && isOldData,
261
256
  isHighlight,
262
257
  isClickable: !!onChartClick,
263
258
  formatLabel: (isDataTag || isCombineDataTag) && !isOldData ? (d)=>{
@@ -282,7 +277,6 @@ const G2CombineChart = ({ height = 300, data, x = "", y = "", z = "", indicatorM
282
277
  items: safeItems,
283
278
  safeIndicatorMap: safeIndicatorMap,
284
279
  formatter: formatter,
285
- safeLegend: safeLegend,
286
280
  auxiliaryLineData: auxiliaryLineData
287
281
  }), container);
288
282
  return container;
@@ -303,8 +297,7 @@ const G2CombineChart = ({ height = 300, data, x = "", y = "", z = "", indicatorM
303
297
  lineColors,
304
298
  legendItems,
305
299
  indicatorId: y,
306
- isGroup: isGroupRef.current,
307
- isTooltipContent
300
+ isGroup: isGroupRef.current
308
301
  });
309
302
  chartRef.current = chart;
310
303
  if (onChartClick) chart.on("plot:click", (_e)=>{
@@ -133,7 +133,6 @@ const G2GroupBarChart = ({ height = 300, data, x = "", y = "", indicatorMap, onC
133
133
  items: safeItems,
134
134
  safeIndicatorMap: safeIndicatorMap,
135
135
  formatter: formatter,
136
- safeLegend: safeLegend,
137
136
  auxiliaryLineData: auxiliaryLineData
138
137
  }), container);
139
138
  return container;
@@ -165,7 +165,6 @@ const G2LineChart = ({ height = 300, data, x = "", y = "", z = "", indicatorMap,
165
165
  items: safeItems,
166
166
  safeIndicatorMap: safeIndicatorMap,
167
167
  formatter: formatter,
168
- safeLegend: safeLegend,
169
168
  auxiliaryLineData: auxiliaryLineData
170
169
  }), container);
171
170
  return container;
@@ -204,7 +203,6 @@ const G2LineChart = ({ height = 300, data, x = "", y = "", z = "", indicatorMap,
204
203
  };
205
204
  }, [
206
205
  filteredData,
207
- height,
208
206
  x,
209
207
  y,
210
208
  safeLegend,
@@ -72,6 +72,7 @@ function applyAxisX(mark, options = {}) {
72
72
  labelAutoRotate: false,
73
73
  labelFontSize: fontSize,
74
74
  labelFontColor: '#000',
75
+ size: isHorizontal ? Math.min(180, Math.floor(containerWidth / 5)) : 30,
75
76
  labelAutoEllipsis: {
76
77
  type: 'ellipsis',
77
78
  minLength: 80,
@@ -147,14 +148,20 @@ function applyAuxiliaryLineY(view, lines, options = {}) {
147
148
  if (!lines?.length) return;
148
149
  const { stroke = '#F4664A', strokeOpacity = 1, labelMaxLength = 5 } = options;
149
150
  lines.forEach((auxLine)=>{
150
- view.lineY().encode('y', auxLine.value).style('stroke', stroke).style('strokeOpacity', strokeOpacity).style('lineWidth', 1).style('shadowColor', 'transparent').animate(false).scale('y', {
151
+ view.lineY().data([
152
+ {
153
+ y: auxLine.value
154
+ }
155
+ ]).encode('y', auxLine.value).style('stroke', stroke).style('strokeOpacity', strokeOpacity).style('lineWidth', 1).style('shadowColor', 'transparent').animate(false).scale('y', {
151
156
  key: auxLine?.axis === 'right' ? 'line' : 'main'
152
157
  }).axis('x', false).label({
158
+ opacity: 1,
153
159
  dx: 0,
154
160
  dy: 0,
155
161
  text: splitTextToMultiline(auxLine.name, labelMaxLength, '<br />'),
156
162
  position: auxLine?.axis === 'right' ? 'bottom-right' : 'bottom-left',
157
- render: (text)=>`<div style="background-color: transparent; padding: 5px; border-radius: 5px;font-size: 14px;position: absolute;left: ${auxLine?.axis === 'right' ? '-105px' : '0px'}; top: -24px; width: 100px;color: ${stroke}; font-family: 'PingFang SC', 'Microsoft YaHei', sans-serif;">${text}</div>`
163
+ render: (text)=>`<div style="background-color: transparent; padding: 5px; border-radius: 5px;font-size: 12px;position: absolute;left: ${auxLine?.axis === 'right' ? '-105px' : '0px'}; top: ${auxLine?.name?.length > 5 ? '-38px' : '-24px'} ; width: 100px; line-height: 14px; color: ${stroke}; text-shadow: 0 0 10px red;
164
+ font-family: 'PingFang SC', 'Microsoft YaHei', sans-serif;">${text}</div>`
158
165
  });
159
166
  });
160
167
  }
@@ -19,7 +19,7 @@ function renderG2BarChart(container, options) {
19
19
  insetBottom: 0
20
20
  });
21
21
  const view = getMainView(chart);
22
- view.attr('marginLeft', 0).attr('marginRight', 0).attr('marginBottom', isLegend ? 0 : 16);
22
+ view.attr('marginLeft', 0).attr('marginRight', isHorizontal ? 30 : 0).attr('marginBottom', isLegend ? 0 : 16);
23
23
  if (isHorizontal) view.coordinate({
24
24
  transform: [
25
25
  {
@@ -79,8 +79,8 @@ function renderG2BarChart(container, options) {
79
79
  });
80
80
  view.legend(false);
81
81
  view.interaction('poptip', {
82
- offsetY: -20,
83
- offsetX: 0,
82
+ offsetY: -50,
83
+ offsetX: -10,
84
84
  tipBackgroundColor: '#fcfcfc',
85
85
  tipColor: '#333',
86
86
  tipBorderRadius: '6px',
@@ -114,18 +114,11 @@ function renderG2BarChart(container, options) {
114
114
  }) : null
115
115
  ].filter(Boolean)
116
116
  });
117
- const tooltipBounding = {
118
- x: 0,
119
- y: 0,
120
- width: container.clientWidth || container.offsetWidth,
121
- height: container.clientHeight || container.offsetHeight
122
- };
123
117
  if (tooltipRender) view.interaction('tooltip', {
124
118
  shared: true,
125
119
  crosshairsY: true,
126
120
  wait: 100,
127
121
  marker: false,
128
- bounding: tooltipBounding,
129
122
  render: (_event, payload)=>{
130
123
  const { title, items } = payload;
131
124
  const lastIsChange = items.filter((item)=>item.isChange);
@@ -137,10 +130,9 @@ function renderG2BarChart(container, options) {
137
130
  return tooltipRender(title, safeItems ?? []) ?? null;
138
131
  }
139
132
  });
140
- else view.interaction('tooltip', {
141
- bounding: tooltipBounding
133
+ applyAuxiliaryLineY(view, auxiliaryLineData, {
134
+ labelMaxLength: 5
142
135
  });
143
- applyAuxiliaryLineY(view, auxiliaryLineData);
144
136
  const nodeResult = applyNodeData(view, nodeData, x, y);
145
137
  if (isDataTag && formatLabel) interval.label({
146
138
  style: {
@@ -158,6 +150,15 @@ function renderG2BarChart(container, options) {
158
150
  }
159
151
  ]
160
152
  });
153
+ view.labelTransform([
154
+ {
155
+ type: 'exceedAdjust',
156
+ bounds: 'main'
157
+ },
158
+ {
159
+ type: 'overlapHide'
160
+ }
161
+ ]);
161
162
  chart.render();
162
163
  let hasEmittedNodeList = false;
163
164
  chart.on('afterrender', (_e)=>{
@@ -87,8 +87,6 @@ export interface RenderG2CombineChartOptions {
87
87
  }>;
88
88
  /** 当前指标 id(用于 tooltip 展示) */
89
89
  indicatorId?: string;
90
- /** 是否将 tooltip 挂载到 body(用于可视化看板、编辑看板场景,避免被父容器裁剪) */
91
- isTooltipContent?: boolean;
92
90
  }
93
91
  /**
94
92
  * 在容器上渲染 G2 柱状 + 折线组合图,返回 Chart 实例便于 destroy/更新
@@ -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, nodeData, x, z: _z, maxLeft, maxRight, themeColors, indicatorMap: _indicatorMap, formatAxis, formatLineAxis, isDataTag = true, isCombineDataTag = true, isLegend: _isLegend = false, isCompare = false, formatLabel, highlightDate = [], isHighlight = true, isClickable = false, indicators = [], tooltipRender, auxiliaryLineData = [], onNodeListChange, lineColors, onChartRender, isGroup, legendItems = [], indicatorId, isTooltipContent = false } = options;
8
+ const { data, nodeData, x, z: _z, maxLeft, maxRight, themeColors, indicatorMap: _indicatorMap, formatAxis, formatLineAxis, isDataTag = true, isCombineDataTag = true, isLegend: _isLegend = false, isCompare = false, formatLabel, highlightDate = [], isHighlight = true, isClickable = false, indicators = [], tooltipRender, auxiliaryLineData = [], onNodeListChange, lineColors, onChartRender, isGroup, legendItems = [], indicatorId } = options;
9
9
  const chart = createChart({
10
10
  container,
11
11
  autoFit: true
@@ -104,7 +104,7 @@ function renderG2CombineChart(container, options) {
104
104
  const groupType = String(datum.groupType ?? '');
105
105
  const index = legendItems.findIndex((item)=>item.id === `${groupType}_${datum.isCombine}`);
106
106
  return {
107
- value: datum[Y_AXIS_FIELD],
107
+ value: datum[BAR_Y_FIELD],
108
108
  name: datum['groupType'],
109
109
  indicatorId,
110
110
  channel: Y_AXIS_FIELD,
@@ -253,52 +253,40 @@ function renderG2CombineChart(container, options) {
253
253
  } : false
254
254
  ].filter(Boolean)
255
255
  });
256
- if (tooltipRender) {
257
- const tooltipBounding = {
258
- x: 0,
259
- y: 0,
260
- width: container.clientWidth || container.offsetWidth,
261
- height: container.clientHeight || container.offsetHeight
262
- };
263
- view.interaction('tooltip', {
264
- shared: true,
265
- crosshairsY: true,
266
- marker: false,
267
- bounding: tooltipBounding,
268
- ...isTooltipContent ? {
269
- mount: 'body'
270
- } : {},
271
- render: (_event, payload)=>{
272
- const { title, items } = payload;
273
- let safeTitle = title.replace(/,.*$/, '');
274
- const baseItems = items.filter((item)=>item.hasOwnProperty('isCombine') && !item.isCombine);
275
- const safeItems = fillMissingIndicator(baseItems, safeTitle, isCompare, isGroup);
276
- const combineItems = items.filter((item)=>item.hasOwnProperty('isCombine') && item.isCombine);
277
- const safeCombineItems = fillMissingIndicator(combineItems, safeTitle, isCompare, isGroup);
278
- const indicatorOrder = new Map(indicators.map((id, i)=>[
279
- id,
280
- i
281
- ]));
282
- const sortedCombineItems = [
283
- ...safeCombineItems
284
- ].sort((a, b)=>{
285
- const orderA = indicatorOrder.get(a.indicatorId) ?? 1 / 0;
286
- const orderB = indicatorOrder.get(b.indicatorId) ?? 1 / 0;
287
- if (orderA !== orderB) return orderA - orderB;
288
- const typeRank = (item)=>{
289
- if (item.isChange) return 2;
290
- if ('compareline' === item.tipType) return 1;
291
- return 0;
292
- };
293
- return typeRank(a) - typeRank(b);
294
- });
295
- return tooltipRender(safeTitle, [
296
- ...safeItems,
297
- ...sortedCombineItems
298
- ]) ?? null;
299
- }
300
- });
301
- }
256
+ if (tooltipRender) view.interaction('tooltip', {
257
+ shared: true,
258
+ crosshairsY: true,
259
+ marker: false,
260
+ render: (_event, payload)=>{
261
+ const { title, items } = payload;
262
+ let safeTitle = title.replace(/,.*$/, '');
263
+ const baseItems = items.filter((item)=>item.hasOwnProperty('isCombine') && !item.isCombine);
264
+ const safeItems = fillMissingIndicator(baseItems, safeTitle, isCompare, isGroup);
265
+ const combineItems = items.filter((item)=>item.hasOwnProperty('isCombine') && item.isCombine);
266
+ const safeCombineItems = fillMissingIndicator(combineItems, safeTitle, isCompare, isGroup);
267
+ const indicatorOrder = new Map(indicators.map((id, i)=>[
268
+ id,
269
+ i
270
+ ]));
271
+ const sortedCombineItems = [
272
+ ...safeCombineItems
273
+ ].sort((a, b)=>{
274
+ const orderA = indicatorOrder.get(a.indicatorId) ?? 1 / 0;
275
+ const orderB = indicatorOrder.get(b.indicatorId) ?? 1 / 0;
276
+ if (orderA !== orderB) return orderA - orderB;
277
+ const typeRank = (item)=>{
278
+ if (item.isChange) return 2;
279
+ if ('compareline' === item.tipType) return 1;
280
+ return 0;
281
+ };
282
+ return typeRank(a) - typeRank(b);
283
+ });
284
+ return tooltipRender(safeTitle, [
285
+ ...safeItems,
286
+ ...sortedCombineItems
287
+ ]) ?? null;
288
+ }
289
+ });
302
290
  view.legend(false);
303
291
  view.interaction('poptip', {
304
292
  offsetY: -20,
@@ -79,16 +79,9 @@ function renderG2LineChart(container, options) {
79
79
  })
80
80
  ]
81
81
  });
82
- const tooltipBounding = {
83
- x: 0,
84
- y: 0,
85
- width: container.clientWidth || container.offsetWidth,
86
- height: container.clientHeight || container.offsetHeight
87
- };
88
82
  if (tooltipRender) view.interaction('tooltip', {
89
83
  shared: true,
90
84
  marker: false,
91
- bounding: tooltipBounding,
92
85
  render: (_event, payload)=>{
93
86
  const { title, items } = payload;
94
87
  if (indicators.length) {
@@ -16,7 +16,6 @@ interface Props {
16
16
  items: Item[];
17
17
  safeIndicatorMap: any;
18
18
  formatter: any;
19
- safeLegend: string;
20
19
  auxiliaryLineData?: AuxiliaryLineData[];
21
20
  }
22
21
  declare const _default: import("react").NamedExoticComponent<Props>;
@@ -2,7 +2,7 @@ import { jsx, jsxs } from "react/jsx-runtime";
2
2
  import { memo } from "react";
3
3
  import { CompareChange } from "@publishfx/publish-components";
4
4
  import { getIndicatorCompareName } from "../../../utils/indicatorHelpers.js";
5
- const G2CompareTooltip = ({ isGroupBar = false, title, items, safeIndicatorMap, formatter, safeLegend, auxiliaryLineData })=>{
5
+ const G2CompareTooltip = ({ isGroupBar = false, title, items, safeIndicatorMap, formatter, auxiliaryLineData })=>{
6
6
  let auxiIndicatorId = '';
7
7
  let combineIndicatorId = '';
8
8
  const uniqueColors = [];
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@publishfx/publish-chart",
3
- "version": "2.1.21",
3
+ "version": "2.1.23",
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": [