@publishfx/publish-chart 2.1.22 → 2.1.24

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) {
@@ -152,7 +159,16 @@ class DataAdapter {
152
159
  }
153
160
  });
154
161
  const xKey = config.x ?? 'x';
155
- combinedv.rows.sort((a, b)=>{
162
+ if (config.isDescend) {
163
+ const sortData = tdv.rows.map((item)=>item[xKey]);
164
+ combinedv.rows.sort((a, b)=>{
165
+ const aIndex = sortData.indexOf(a[xKey]);
166
+ const bIndex = sortData.indexOf(b[xKey]);
167
+ if (-1 === aIndex) return 1;
168
+ if (-1 === bIndex) return -1;
169
+ return aIndex - bIndex;
170
+ });
171
+ } else combinedv.rows.sort((a, b)=>{
156
172
  const aIndex = allKeys.has(a[xKey]) ? Array.from(allKeys).indexOf(a[xKey]) : -1;
157
173
  const bIndex = allKeys.has(b[xKey]) ? Array.from(allKeys).indexOf(b[xKey]) : -1;
158
174
  if (-1 === aIndex) return 1;
@@ -123,13 +123,9 @@ const G2CombineChart = ({ height = 300, data, x = "", y = "", z = "", indicatorM
123
123
  safeIndicatorMap,
124
124
  y
125
125
  ]);
126
- const formatLineAxis = useCallback((val)=>{
127
- const indicatorId = indicators?.length > 2 ? "" : safeZ;
128
- return getAxisFormat(val, safeIndicatorMap, indicatorId);
129
- }, [
126
+ const formatLineAxis = useCallback((val)=>getAxisFormat(val, safeIndicatorMap, safeZ), [
130
127
  safeIndicatorMap,
131
- safeZ,
132
- indicators
128
+ safeZ
133
129
  ]);
134
130
  useEffect(()=>{
135
131
  if (!transformedData.length) {
@@ -182,12 +178,12 @@ const G2CombineChart = ({ height = 300, data, x = "", y = "", z = "", indicatorM
182
178
  groupName: key,
183
179
  isCombine: false,
184
180
  groupType: groupType,
185
- groupValue: "",
181
+ groupValue: null,
186
182
  total: 0,
187
183
  percent: ""
188
184
  });
189
185
  });
190
- groupData.sort((a, b)=>xKey.indexOf(a.groupName) - xKey.indexOf(b.groupName));
186
+ if (!isDescend) groupData.sort((a, b)=>xKey.indexOf(a.groupName) - xKey.indexOf(b.groupName));
191
187
  groupResult = groupResult.concat(groupData);
192
188
  });
193
189
  groupResult.forEach((item)=>{
@@ -203,7 +203,6 @@ const G2LineChart = ({ height = 300, data, x = "", y = "", z = "", indicatorMap,
203
203
  };
204
204
  }, [
205
205
  filteredData,
206
- height,
207
206
  x,
208
207
  y,
209
208
  safeLegend,
@@ -146,20 +146,30 @@ function applyLegendColor(view, options = {}) {
146
146
  }
147
147
  function applyAuxiliaryLineY(view, lines, options = {}) {
148
148
  if (!lines?.length) return;
149
- const { stroke = '#F4664A', strokeOpacity = 1, labelMaxLength = 5 } = options;
149
+ const { labelMaxLength = 5 } = options;
150
150
  lines.forEach((auxLine)=>{
151
151
  view.lineY().data([
152
152
  {
153
153
  y: auxLine.value
154
154
  }
155
- ]).encode('y', auxLine.value).style('stroke', stroke).style('strokeOpacity', strokeOpacity).style('lineWidth', 1).style('shadowColor', 'transparent').animate(false).scale('y', {
155
+ ]).encode('y', auxLine.value).style('stroke', 'rgb(234, 54, 106)').style('strokeOpacity', 1).style('opacity', 1).style('lineWidth', 2).style('shadowColor', 'transparent').animate(false).scale('y', {
156
156
  key: auxLine?.axis === 'right' ? 'line' : 'main'
157
157
  }).axis('x', false).label({
158
- dx: 0,
158
+ opacity: 1,
159
+ dx: -20,
159
160
  dy: 0,
160
- text: splitTextToMultiline(auxLine.name, labelMaxLength, '<br />'),
161
+ text: splitTextToMultiline(auxLine.name, labelMaxLength, '\n'),
161
162
  position: auxLine?.axis === 'right' ? 'bottom-right' : 'bottom-left',
162
- 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
+ style: {
164
+ fill: 'red',
165
+ shadowColor: 'red',
166
+ fillOpacity: 1,
167
+ strokeOpacity: 1,
168
+ opacity: 1,
169
+ shadowBlur: 10,
170
+ shadowOffsetX: 0,
171
+ shadowOffsetY: 0
172
+ }
163
173
  });
164
174
  });
165
175
  }
@@ -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', isHorizontal ? 30 : 0).attr('marginBottom', isLegend ? 0 : 16);
22
+ view.attr('marginLeft', 0).attr('marginRight', isHorizontal ? 30 : 30).attr('marginTop', 10).attr('marginBottom', isLegend ? 0 : 16);
23
23
  if (isHorizontal) view.coordinate({
24
24
  transform: [
25
25
  {
@@ -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,9 +130,6 @@ function renderG2BarChart(container, options) {
137
130
  return tooltipRender(title, safeItems ?? []) ?? null;
138
131
  }
139
132
  });
140
- else view.interaction('tooltip', {
141
- bounding: tooltipBounding
142
- });
143
133
  applyAuxiliaryLineY(view, auxiliaryLineData, {
144
134
  labelMaxLength: 5
145
135
  });
@@ -17,7 +17,7 @@ function renderG2CombineChart(container, options) {
17
17
  animate: null
18
18
  });
19
19
  const view = getMainView(chart);
20
- view.attr('insetLeft', 0).attr('insetRight', 0).attr('marginLeft', 0).attr('marginRight', 0).attr('marginBottom', 0).attr('animate', false).animate(false);
20
+ view.attr('marginLeft', 0).attr('marginRight', 30).attr('marginTop', 10).attr('marginBottom', 16).animate(false);
21
21
  view.data(data);
22
22
  const xValueCount = new Set(data.map((d)=>d[x])).size;
23
23
  applyAxisX(view, {
@@ -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: null === datum[BAR_Y_FIELD] ? '-' : datum[BAR_Y_FIELD],
108
108
  name: datum['groupType'],
109
109
  indicatorId,
110
110
  channel: Y_AXIS_FIELD,
@@ -116,7 +116,7 @@ function renderG2CombineChart(container, options) {
116
116
  }
117
117
  ].filter(Boolean) : [
118
118
  (datum)=>datum.groupType.includes('_compare') ? false : {
119
- value: datum[BAR_Y_FIELD],
119
+ value: null === datum[BAR_Y_FIELD] ? '-' : datum[BAR_Y_FIELD],
120
120
  name: datum['groupType'],
121
121
  indicatorId: datum['groupType'],
122
122
  channel: Y_AXIS_FIELD,
@@ -167,7 +167,7 @@ function renderG2CombineChart(container, options) {
167
167
  (datum)=>{
168
168
  const item = legendItems.find((item)=>item.id === `${datum?.groupType}_${datum?.isCombine}`);
169
169
  return {
170
- value: datum[LINE_Y_FIELD],
170
+ value: null === datum[LINE_Y_FIELD] ? '-' : datum[LINE_Y_FIELD],
171
171
  name: getIndicatorCompareName(_indicatorMap, datum['groupType']),
172
172
  indicatorId: datum['groupType'],
173
173
  channel: Y_AXIS_FIELD,
@@ -253,49 +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
- render: (_event, payload)=>{
269
- const { title, items } = payload;
270
- let safeTitle = title.replace(/,.*$/, '');
271
- const baseItems = items.filter((item)=>item.hasOwnProperty('isCombine') && !item.isCombine);
272
- const safeItems = fillMissingIndicator(baseItems, safeTitle, isCompare, isGroup);
273
- const combineItems = items.filter((item)=>item.hasOwnProperty('isCombine') && item.isCombine);
274
- const safeCombineItems = fillMissingIndicator(combineItems, safeTitle, isCompare, isGroup);
275
- const indicatorOrder = new Map(indicators.map((id, i)=>[
276
- id,
277
- i
278
- ]));
279
- const sortedCombineItems = [
280
- ...safeCombineItems
281
- ].sort((a, b)=>{
282
- const orderA = indicatorOrder.get(a.indicatorId) ?? 1 / 0;
283
- const orderB = indicatorOrder.get(b.indicatorId) ?? 1 / 0;
284
- if (orderA !== orderB) return orderA - orderB;
285
- const typeRank = (item)=>{
286
- if (item.isChange) return 2;
287
- if ('compareline' === item.tipType) return 1;
288
- return 0;
289
- };
290
- return typeRank(a) - typeRank(b);
291
- });
292
- return tooltipRender(safeTitle, [
293
- ...safeItems,
294
- ...sortedCombineItems
295
- ]) ?? null;
296
- }
297
- });
298
- }
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
+ });
299
290
  view.legend(false);
300
291
  view.interaction('poptip', {
301
292
  offsetY: -20,
@@ -17,7 +17,7 @@ function renderG2LineChart(container, options) {
17
17
  insetBottom: 0
18
18
  });
19
19
  const view = getMainView(chart);
20
- view.attr('marginLeft', 0).attr('marginRight', 0).attr('marginBottom', isLegend ? 0 : 16);
20
+ view.attr('marginLeft', 0).attr('marginRight', 30).attr('marginTop', 10).attr('marginBottom', isLegend ? 0 : 16).animate(false);
21
21
  view.data(data);
22
22
  const domainMin = minY ?? 0;
23
23
  applyScaleYLinear(view, {
@@ -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) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@publishfx/publish-chart",
3
- "version": "2.1.22",
3
+ "version": "2.1.24",
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": [