@publishfx/publish-chart 2.1.2 → 2.1.4
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 +14 -1
- package/dist/adapters/DataAdapter.js +1 -1
- package/dist/components/g2/base/G2BarChart.js +5 -1
- package/dist/components/g2/base/G2CombineChart.js +9 -12
- package/dist/components/g2/base/G2LineChart.js +7 -1
- package/dist/components/g2/base/g2Helpers.js +6 -2
- package/dist/components/g2/base/g2bar.d.ts +2 -0
- package/dist/components/g2/base/g2bar.js +5 -2
- package/dist/components/g2/base/g2combine.d.ts +2 -0
- package/dist/components/g2/base/g2combine.js +93 -35
- package/dist/components/g2/base/g2line.js +4 -4
- package/package.json +13 -13
package/CHANGELOG.md
CHANGED
|
@@ -1,4 +1,17 @@
|
|
|
1
|
-
**2.1.
|
|
1
|
+
**2.1.4** feat(chart): 柱状、折线、组合三个图表支持onChartClick
|
|
2
|
+
- 2026-03-02T15:27:33+08:00 [feat(chart): 柱状、折线、组合三个图表支持onChartClick](http://lf.git.oa.mt/publish_platform/web/publish/commit/0cbed83b537a5b0a08f676256b8e69bb9ae0741a)
|
|
3
|
+
- 2026-03-02T14:38:28+08:00 [fix(chart): 组合图针对副轴数据全为0时,Y刻度的处理。](http://lf.git.oa.mt/publish_platform/web/publish/commit/2b262810e33d3660255831fb7ef0e345907841e9)
|
|
4
|
+
|
|
5
|
+
**2.1.3** fix(chart): 组合图分组时inset置为0
|
|
6
|
+
- 2026-02-28T23:48:20+08:00 [fix(chart): 组合图分组时inset置为0](http://lf.git.oa.mt/publish_platform/web/publish/commit/047e02d3cfbce21101277f48e904864163b2a02c)
|
|
7
|
+
- 2026-02-28T22:42:20+08:00 [feat(chart): 组合图tooltip数据调整](http://lf.git.oa.mt/publish_platform/web/publish/commit/f79461050699b0755c8837e26b035083ec980cf1)
|
|
8
|
+
- 2026-02-28T20:42:35+08:00 [feat(chart): 组合图默认值](http://lf.git.oa.mt/publish_platform/web/publish/commit/97613e165dc16ff1d415e01facafa11db4125a24)
|
|
9
|
+
- 2026-02-28T20:42:08+08:00 [feat(chart): 组合图tooltips](http://lf.git.oa.mt/publish_platform/web/publish/commit/910af4376c2149ed44816d3eae4a3188f2601f54)
|
|
10
|
+
- 2026-02-28T20:31:15+08:00 [feat(chart): 组合图增加着重日功能](http://lf.git.oa.mt/publish_platform/web/publish/commit/f88ce5905022454d3ac611cd16de73f6ae8c8d12)
|
|
11
|
+
- 2026-02-28T20:08:16+08:00 [feat(chart): 设置着重interval的ratio为0.6](http://lf.git.oa.mt/publish_platform/web/publish/commit/057cb33eabe87d077b46b6271eea63a5e2879640)
|
|
12
|
+
- 2026-02-28T20:02:39+08:00 [fix(chart): 修复组合图的ts错误](http://lf.git.oa.mt/publish_platform/web/publish/commit/a01f19528e46ee13d39f6de85c8ffc5fa9405ec5)
|
|
13
|
+
- 2026-02-28T19:10:04+08:00 [feat(chart): 组合图支持分组](http://lf.git.oa.mt/publish_platform/web/publish/commit/525c1bbe47027ca3c4550adfea1c36e43c4dad34)
|
|
14
|
+
- 2026-02-28T18:45:52+08:00 [feat(chart): 着重日逻辑优化](http://lf.git.oa.mt/publish_platform/web/publish/commit/3d57801fccaf67f69d3c08d19cc750fa36a2fa42)
|
|
2
15
|
- 2026-02-28T18:37:26+08:00 [feat(chart): 柱状图支持crossharisY](http://lf.git.oa.mt/publish_platform/web/publish/commit/b77a0932f1710144915d209c0186640bafdff492)
|
|
3
16
|
|
|
4
17
|
**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
|
|
38
|
+
return b[config.y] - a[config.y];
|
|
39
39
|
}
|
|
40
40
|
});
|
|
41
41
|
}
|
|
@@ -122,6 +122,7 @@ const G2BarChart = ({ height = 300, data, x = "", y = "", indicatorMap, onChartC
|
|
|
122
122
|
isLegend: !!isCompare,
|
|
123
123
|
isHorizontal,
|
|
124
124
|
isHighlight,
|
|
125
|
+
isClickable: !!onChartClick,
|
|
125
126
|
legend: safeLegend || void 0,
|
|
126
127
|
formatLabel: isDataTag && safeY ? (d)=>{
|
|
127
128
|
const v = d[safeY];
|
|
@@ -160,8 +161,11 @@ const G2BarChart = ({ height = 300, data, x = "", y = "", indicatorMap, onChartC
|
|
|
160
161
|
});
|
|
161
162
|
chartRef.current = chart;
|
|
162
163
|
if (onChartClick) chart.on("element:click", (e)=>{
|
|
164
|
+
console.log('e:', e);
|
|
163
165
|
const datum = e.data?.data;
|
|
164
|
-
if (datum) onChartClick(
|
|
166
|
+
if (datum) onChartClick({
|
|
167
|
+
title: datum[x]
|
|
168
|
+
});
|
|
165
169
|
});
|
|
166
170
|
return ()=>{
|
|
167
171
|
if (chartRef.current) {
|
|
@@ -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
|
|
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})` : ""),
|
|
@@ -192,10 +194,11 @@ const G2CombineChart = ({ height = 300, data, x = "", y = "", z = "", indicatorM
|
|
|
192
194
|
isDataTag,
|
|
193
195
|
isLegend: false,
|
|
194
196
|
isCompare,
|
|
197
|
+
isClickable: !!onChartClick,
|
|
195
198
|
height: height - canvasMarginBottom,
|
|
196
199
|
formatLabel: isDataTag ? (d)=>{
|
|
197
200
|
const indicatorId = d.groupType.split("_")[0];
|
|
198
|
-
return "-" === formatter.formatIndicator(d.groupValue, safeIndicatorMap[indicatorId]) ? "" : formatter.formatIndicator(d.groupValue, safeIndicatorMap[indicatorId]);
|
|
201
|
+
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
202
|
} : void 0,
|
|
200
203
|
indicators,
|
|
201
204
|
tooltipRender: (title, items)=>{
|
|
@@ -207,7 +210,7 @@ const G2CombineChart = ({ height = 300, data, x = "", y = "", z = "", indicatorM
|
|
|
207
210
|
}));
|
|
208
211
|
safeItems = safeItems.filter((i)=>i.indicatorId);
|
|
209
212
|
react_dom.render(/*#__PURE__*/ jsx(G2CompareTooltip, {
|
|
210
|
-
isGroupBar:
|
|
213
|
+
isGroupBar: isGroup,
|
|
211
214
|
title: title,
|
|
212
215
|
items: safeItems,
|
|
213
216
|
safeIndicatorMap: safeIndicatorMap,
|
|
@@ -237,7 +240,9 @@ const G2CombineChart = ({ height = 300, data, x = "", y = "", z = "", indicatorM
|
|
|
237
240
|
chartRef.current = chart;
|
|
238
241
|
if (onChartClick) chart.on("element:click", (e)=>{
|
|
239
242
|
const datum = e.data?.data;
|
|
240
|
-
if (datum) onChartClick(
|
|
243
|
+
if (datum) onChartClick({
|
|
244
|
+
title: datum[x]
|
|
245
|
+
});
|
|
241
246
|
});
|
|
242
247
|
return ()=>{
|
|
243
248
|
if (chartRef.current) {
|
|
@@ -263,14 +268,6 @@ const G2CombineChart = ({ height = 300, data, x = "", y = "", z = "", indicatorM
|
|
|
263
268
|
isGroup,
|
|
264
269
|
legendItems
|
|
265
270
|
]);
|
|
266
|
-
if (!z) return /*#__PURE__*/ jsx("div", {
|
|
267
|
-
style: {
|
|
268
|
-
width: "100%",
|
|
269
|
-
color: "#86909c",
|
|
270
|
-
padding: 16
|
|
271
|
-
},
|
|
272
|
-
children: "请传入 z 作为折线指标字段,以展示柱状+折线组合图。"
|
|
273
|
-
});
|
|
274
271
|
return /*#__PURE__*/ jsxs("div", {
|
|
275
272
|
style: {
|
|
276
273
|
width: "100%",
|
|
@@ -12,7 +12,7 @@ import useG2TooltipContainer from "../shared/useG2TooltipContainer.js";
|
|
|
12
12
|
import { getIndicatorCompareName } from "../../../utils/indicatorHelpers.js";
|
|
13
13
|
import { G2BarLegend } from "./G2BarLegend.js";
|
|
14
14
|
import { renderG2LineChart } from "./g2line.js";
|
|
15
|
-
const G2LineChart = ({ height = 300, data, x = "", y = "", z = "", indicatorMap, onChartClick
|
|
15
|
+
const G2LineChart = ({ height = 300, data, x = "", y = "", z = "", indicatorMap, onChartClick, timeRange, legend = "", config, nodeSetting = {
|
|
16
16
|
showType: 0,
|
|
17
17
|
type: []
|
|
18
18
|
}, auxiliaryLineData, highlightDate, indicators = [] })=>{
|
|
@@ -169,6 +169,12 @@ const G2LineChart = ({ height = 300, data, x = "", y = "", z = "", indicatorMap,
|
|
|
169
169
|
}
|
|
170
170
|
});
|
|
171
171
|
chartRef.current = chart;
|
|
172
|
+
if (onChartClick) chart.on("element:click", (e)=>{
|
|
173
|
+
const datum = e.data?.data;
|
|
174
|
+
if (datum) onChartClick({
|
|
175
|
+
title: datum[x]
|
|
176
|
+
});
|
|
177
|
+
});
|
|
172
178
|
return ()=>{
|
|
173
179
|
if (chartRef.current) {
|
|
174
180
|
chartRef.current.off("element:click");
|
|
@@ -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
|
|
@@ -33,6 +33,8 @@ export interface RenderG2BarChartOptions {
|
|
|
33
33
|
isHighlight?: boolean;
|
|
34
34
|
/** 图例字段名(与 y 不同时表示分组柱),通常为 groupType */
|
|
35
35
|
isCompare?: boolean;
|
|
36
|
+
/** 是否启用点击事件 */
|
|
37
|
+
isClickable?: boolean;
|
|
36
38
|
legend?: string;
|
|
37
39
|
/** 数据标签格式化:formatLabel(datum) */
|
|
38
40
|
formatLabel?: (datum: any) => string;
|
|
@@ -2,7 +2,7 @@ import { lines } from "@antv/g-pattern";
|
|
|
2
2
|
import { applyAuxiliaryLineY, applyAxisX, applyAxisY, applyHighlightDate, applyScaleYLinear, createChart, getColorByGroupType, getMainView } from "./g2Helpers.js";
|
|
3
3
|
const Y_AXIS_FIELD = 'groupValue';
|
|
4
4
|
function renderG2BarChart(container, options) {
|
|
5
|
-
const { data, x, y, maxY, timeRange: _timeRange, themeColors, indicators = [], indicatorMap: _indicatorMap = {}, formatAxis, highlightDate = [], isDataTag = false, isLegend = true, isHorizontal = false, isHighlight = true, isCompare = false, legend, formatLabel, height = 300, tooltipRender, auxiliaryLineData = [], onNodeListChange, onChartRender } = options;
|
|
5
|
+
const { data, x, y, maxY, timeRange: _timeRange, themeColors, indicators = [], indicatorMap: _indicatorMap = {}, formatAxis, highlightDate = [], isDataTag = false, isLegend = true, isHorizontal = false, isHighlight = true, isCompare = false, isClickable = false, legend, formatLabel, height = 300, tooltipRender, auxiliaryLineData = [], onNodeListChange, onChartRender } = options;
|
|
6
6
|
const colorOpts = {
|
|
7
7
|
themeColors,
|
|
8
8
|
primaryKey: y,
|
|
@@ -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
|
},
|
|
@@ -66,7 +68,8 @@ function renderG2BarChart(container, options) {
|
|
|
66
68
|
transform: 'rotate(-30deg)'
|
|
67
69
|
};
|
|
68
70
|
return getColorByGroupType(groupType, colorOpts);
|
|
69
|
-
}
|
|
71
|
+
},
|
|
72
|
+
cursor: isClickable ? 'pointer' : 'default'
|
|
70
73
|
});
|
|
71
74
|
applyAxisX(view, {
|
|
72
75
|
grid: false
|
|
@@ -1,10 +1,11 @@
|
|
|
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';
|
|
6
7
|
function renderG2CombineChart(container, options) {
|
|
7
|
-
const { data, x, y, z: _z, maxY, themeColors, indicatorMap: _indicatorMap, formatAxis, formatLineAxis, isDataTag = false, isLegend: _isLegend = false, isCompare = false, formatLabel, highlightDate = [], height = 300, isHighlight = true, indicators = [], tooltipRender, onNodeListChange, lineColors, onChartRender, isGroup, legendItems = [], indicatorId } = options;
|
|
8
|
+
const { data, x, y, z: _z, maxY, themeColors, indicatorMap: _indicatorMap, formatAxis, formatLineAxis, isDataTag = false, isLegend: _isLegend = false, isCompare = false, formatLabel, highlightDate = [], height = 300, isHighlight = true, isClickable = false, indicators = [], tooltipRender, onNodeListChange, lineColors, onChartRender, isGroup, legendItems = [], indicatorId } = options;
|
|
8
9
|
const chart = createChart({
|
|
9
10
|
container,
|
|
10
11
|
height,
|
|
@@ -21,17 +22,12 @@ function renderG2CombineChart(container, options) {
|
|
|
21
22
|
view.data(data);
|
|
22
23
|
applyAxisX(view, {
|
|
23
24
|
title: false,
|
|
24
|
-
grid:
|
|
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.
|
|
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}`);
|
|
@@ -64,6 +71,7 @@ function renderG2CombineChart(container, options) {
|
|
|
64
71
|
};
|
|
65
72
|
return barColor;
|
|
66
73
|
},
|
|
74
|
+
cursor: isClickable ? 'pointer' : 'default',
|
|
67
75
|
stroke: 'transparent'
|
|
68
76
|
});
|
|
69
77
|
interval.scale('y', {
|
|
@@ -102,7 +110,8 @@ function renderG2CombineChart(container, options) {
|
|
|
102
110
|
indicatorId,
|
|
103
111
|
channel: Y_AXIS_FIELD,
|
|
104
112
|
color: themeColors[index % themeColors.length] ?? themeColors[0] ?? "#5B8FF9",
|
|
105
|
-
percent: `${(100 * Number(datum.percent)).toFixed(2)}
|
|
113
|
+
percent: `${(100 * Number(datum.percent)).toFixed(2)}%`,
|
|
114
|
+
isCombine: false
|
|
106
115
|
};
|
|
107
116
|
}
|
|
108
117
|
].filter(Boolean) : [
|
|
@@ -111,7 +120,8 @@ function renderG2CombineChart(container, options) {
|
|
|
111
120
|
name: datum['groupType'],
|
|
112
121
|
indicatorId: datum['groupType'],
|
|
113
122
|
channel: Y_AXIS_FIELD,
|
|
114
|
-
color: barColor || 'transparent'
|
|
123
|
+
color: barColor || 'transparent',
|
|
124
|
+
isCombine: false
|
|
115
125
|
},
|
|
116
126
|
isCompare ? (datum)=>datum.groupType.includes('_compare') ? {
|
|
117
127
|
value: datum[BAR_Y_FIELD],
|
|
@@ -119,14 +129,16 @@ function renderG2CombineChart(container, options) {
|
|
|
119
129
|
name: datum['groupType'],
|
|
120
130
|
indicatorId: datum['groupType'].replace('_compare', ''),
|
|
121
131
|
channel: Y_AXIS_FIELD,
|
|
122
|
-
color: barColor || 'transparent'
|
|
132
|
+
color: barColor || 'transparent',
|
|
133
|
+
isCombine: false
|
|
123
134
|
} : false : false,
|
|
124
135
|
isCompare ? (datum)=>datum.groupType.includes('_compare') ? {
|
|
125
136
|
name: datum['groupType'].replace('_compare', '_change'),
|
|
126
137
|
indicatorId: datum['groupType'].replace('_compare', ''),
|
|
127
138
|
value: datum?.change,
|
|
128
139
|
isChange: true,
|
|
129
|
-
color: 'transparent'
|
|
140
|
+
color: 'transparent',
|
|
141
|
+
isCombine: false
|
|
130
142
|
} : false : false
|
|
131
143
|
].filter(Boolean)
|
|
132
144
|
});
|
|
@@ -139,27 +151,43 @@ function renderG2CombineChart(container, options) {
|
|
|
139
151
|
...item,
|
|
140
152
|
[LINE_Y_FIELD]: item[Y_AXIS_FIELD]
|
|
141
153
|
}));
|
|
154
|
+
console.log('compareLineData:', compareLineData);
|
|
142
155
|
const lineMaxY = lineData.reduce((max, item)=>Math.max(max, item[LINE_Y_FIELD]), 0);
|
|
143
156
|
const compareLineMaxY = compareLineData.reduce((max, item)=>Math.max(max, item[LINE_Y_FIELD]), 0);
|
|
144
|
-
const lineFinalMaxY = Math.max(lineMaxY, compareLineMaxY);
|
|
157
|
+
const lineFinalMaxY = Math.max(lineMaxY, compareLineMaxY) || 1;
|
|
145
158
|
console.log('lineFinalMaxY:', lineFinalMaxY);
|
|
146
159
|
const line = view.line().data(lineData).encode("x", x).encode("y", LINE_Y_FIELD).encode('color', 'groupType').style({
|
|
147
160
|
lineWidth: 2,
|
|
148
161
|
stroke: (datum)=>{
|
|
162
|
+
const groupTypeSet = new Set(lineData.map((item)=>item.groupType));
|
|
163
|
+
const groupTypeArr = [
|
|
164
|
+
...groupTypeSet
|
|
165
|
+
];
|
|
149
166
|
const groupType = String(datum[0]?.groupType ?? '');
|
|
150
|
-
const
|
|
167
|
+
const index = groupTypeArr.findIndex((item)=>item === groupType);
|
|
168
|
+
const color = isGroup ? lineColors[index] || lineColors[0] : lineColors[indicators.slice(1).indexOf(String(groupType)) ?? 0];
|
|
151
169
|
return color;
|
|
152
170
|
}
|
|
153
171
|
});
|
|
154
172
|
line.tooltip({
|
|
155
173
|
items: [
|
|
156
|
-
(datum)=>
|
|
174
|
+
(datum)=>{
|
|
175
|
+
const groupTypeSet = new Set(lineData.map((item)=>item.groupType));
|
|
176
|
+
const groupTypeArr = [
|
|
177
|
+
...groupTypeSet
|
|
178
|
+
];
|
|
179
|
+
const groupType = String(datum[0]?.groupType ?? '');
|
|
180
|
+
const index = groupTypeArr.findIndex((item)=>item === groupType);
|
|
181
|
+
return {
|
|
157
182
|
value: datum[LINE_Y_FIELD],
|
|
158
|
-
name: datum['groupType'],
|
|
183
|
+
name: isGroup ? getIndicatorCompareName(_indicatorMap, datum['groupType']) : datum['groupType'],
|
|
159
184
|
indicatorId: datum['groupType'],
|
|
160
185
|
channel: Y_AXIS_FIELD,
|
|
161
|
-
color: lineColors[indicators.slice(1).indexOf(String(datum['groupType'])) ?? 0] || 'transparent'
|
|
162
|
-
|
|
186
|
+
color: isGroup ? lineColors[index] || lineColors[0] : lineColors[indicators.slice(1).indexOf(String(datum['groupType'])) ?? 0] || 'transparent',
|
|
187
|
+
isCombine: true,
|
|
188
|
+
tipType: 'line'
|
|
189
|
+
};
|
|
190
|
+
}
|
|
163
191
|
]
|
|
164
192
|
});
|
|
165
193
|
line.scale('y', {
|
|
@@ -168,7 +196,7 @@ function renderG2CombineChart(container, options) {
|
|
|
168
196
|
domainMax: lineFinalMaxY,
|
|
169
197
|
nice: true,
|
|
170
198
|
clamp: true,
|
|
171
|
-
key: '
|
|
199
|
+
key: 'line',
|
|
172
200
|
independent: true,
|
|
173
201
|
tickMethod: (min, max)=>Array.from({
|
|
174
202
|
length: 6
|
|
@@ -209,32 +237,45 @@ function renderG2CombineChart(container, options) {
|
|
|
209
237
|
console.log('hasCompareData:', hasCompareData, data);
|
|
210
238
|
if (hasCompareData) compareLine.tooltip({
|
|
211
239
|
items: [
|
|
212
|
-
(datum)=>({
|
|
240
|
+
(datum)=>datum.groupType.includes('_compare') ? {
|
|
213
241
|
value: datum[LINE_Y_FIELD],
|
|
214
242
|
compareTime: datum?.compareTime,
|
|
215
243
|
name: datum['groupType'],
|
|
216
244
|
indicatorId: datum['groupType'].replace('_compare', ''),
|
|
217
245
|
channel: Y_AXIS_FIELD,
|
|
218
|
-
color: lineColors[indicators.slice(1).indexOf(String(datum['groupType'])) ?? 0] || 'transparent'
|
|
219
|
-
|
|
220
|
-
|
|
246
|
+
color: lineColors[indicators.slice(1).indexOf(String(datum['groupType'])) ?? 0] || 'transparent',
|
|
247
|
+
isCombine: true,
|
|
248
|
+
tipType: 'compareline'
|
|
249
|
+
} : false,
|
|
250
|
+
(datum)=>datum.groupType.includes('_compare') ? {
|
|
221
251
|
name: datum['groupType'].replace('_compare', '_change'),
|
|
222
252
|
indicatorId: datum['groupType'].replace('_compare', ''),
|
|
253
|
+
color: 'blue',
|
|
223
254
|
value: datum?.change,
|
|
224
255
|
isChange: true,
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
256
|
+
isCombine: true,
|
|
257
|
+
tipType: 'compareline'
|
|
258
|
+
} : false
|
|
259
|
+
].filter(Boolean)
|
|
228
260
|
});
|
|
229
|
-
if (tooltipRender)
|
|
261
|
+
if (tooltipRender) view.interaction('tooltip', {
|
|
230
262
|
shared: true,
|
|
231
263
|
crosshairsY: true,
|
|
232
264
|
marker: false,
|
|
233
265
|
render: (_event, payload)=>{
|
|
234
266
|
const { title, items } = payload;
|
|
267
|
+
const baseItems = items.filter((item)=>!item.isCombine);
|
|
268
|
+
const combineItems = items.filter((item)=>item.isCombine);
|
|
235
269
|
console.log('tooltipRender:', title, items, indicators);
|
|
270
|
+
if (isGroup) return tooltipRender(title, [
|
|
271
|
+
...baseItems,
|
|
272
|
+
...combineItems
|
|
273
|
+
]) ?? null;
|
|
236
274
|
if (indicators.length) {
|
|
237
|
-
const groupedItems = indicators.map((indicator)=>
|
|
275
|
+
const groupedItems = indicators.map((indicator, index)=>{
|
|
276
|
+
if (0 === index) return items.filter((i)=>!i.isCombine).filter((i)=>i.indicatorId === String(indicator));
|
|
277
|
+
return items.filter((i)=>i.isCombine).filter((i)=>i.indicatorId === String(indicator));
|
|
278
|
+
});
|
|
238
279
|
console.log(groupedItems.flat(), 'tooltip groupedItems');
|
|
239
280
|
const sortedItems = groupedItems.map((group)=>[
|
|
240
281
|
group.filter((i)=>i.name === i.indicatorId),
|
|
@@ -244,8 +285,9 @@ function renderG2CombineChart(container, options) {
|
|
|
244
285
|
console.log(sortedItems, 'tooltip sortedItems');
|
|
245
286
|
const formatItems = sortedItems.map((item)=>({
|
|
246
287
|
...item,
|
|
247
|
-
color: lineColors[indicators.slice(1).indexOf(String(item?.indicatorId)) ?? 0] || barColor || 'transparent'
|
|
288
|
+
color: item.isCombine ? lineColors[indicators.slice(1).indexOf(String(item?.indicatorId)) ?? 0] || barColor || 'transparent' : barColor || 'transparent'
|
|
248
289
|
}));
|
|
290
|
+
console.log(formatItems, 'tooltip formatItems');
|
|
249
291
|
return tooltipRender(title, formatItems ?? []) ?? null;
|
|
250
292
|
}
|
|
251
293
|
}
|
|
@@ -314,11 +356,27 @@ function renderG2CombineChart(container, options) {
|
|
|
314
356
|
});
|
|
315
357
|
});
|
|
316
358
|
if (isDataTag && formatLabel) {
|
|
359
|
+
const groupedByX = intervalData.reduce((acc, item)=>{
|
|
360
|
+
const key = item[x];
|
|
361
|
+
if (!acc[key]) acc[key] = [];
|
|
362
|
+
acc[key].push(item);
|
|
363
|
+
return acc;
|
|
364
|
+
}, {});
|
|
365
|
+
const lastItemsInEachStack = new Set();
|
|
366
|
+
Object.values(groupedByX).forEach((group)=>{
|
|
367
|
+
group.sort((a, b)=>a[y] - b[y]);
|
|
368
|
+
const lastItem = group[group.length - 1];
|
|
369
|
+
lastItemsInEachStack.add(lastItem);
|
|
370
|
+
});
|
|
317
371
|
interval.label({
|
|
318
|
-
dy: -10,
|
|
372
|
+
dy: isGroup ? -16 : -10,
|
|
319
373
|
dx: -10,
|
|
320
374
|
offset: 0,
|
|
321
|
-
text: (d)=>
|
|
375
|
+
text: (d)=>{
|
|
376
|
+
if (!isGroup) return formatLabel(d);
|
|
377
|
+
if (lastItemsInEachStack.has(d)) return formatLabel(d);
|
|
378
|
+
return '';
|
|
379
|
+
}
|
|
322
380
|
});
|
|
323
381
|
line.label({
|
|
324
382
|
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: (
|
|
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: (
|
|
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.
|
|
3
|
+
"version": "2.1.4",
|
|
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": [
|
|
@@ -24,20 +24,10 @@
|
|
|
24
24
|
"CHANGELOG.md",
|
|
25
25
|
"README.md"
|
|
26
26
|
],
|
|
27
|
-
"scripts": {
|
|
28
|
-
"build": "rslib build",
|
|
29
|
-
"dev": "rslib build --watch",
|
|
30
|
-
"lint": "eslint src --ext .ts,.tsx",
|
|
31
|
-
"lint:fix": "eslint src --ext .ts,.tsx --fix",
|
|
32
|
-
"test": "jest",
|
|
33
|
-
"test:watch": "jest --watch",
|
|
34
|
-
"test:coverage": "jest --coverage"
|
|
35
|
-
},
|
|
36
27
|
"devDependencies": {
|
|
37
28
|
"@antv/data-set": "^0.11.8",
|
|
38
29
|
"@antv/g-pattern": "^2.0.42",
|
|
39
30
|
"@antv/g2": "^5.3.0",
|
|
40
|
-
"@publishfx/publish-components": "workspace:^",
|
|
41
31
|
"@types/jest": "^29.5.12",
|
|
42
32
|
"@types/lodash": "^4.17.20",
|
|
43
33
|
"@types/react": "^18.3.18",
|
|
@@ -55,7 +45,8 @@
|
|
|
55
45
|
"react-dom": "^18.3.1",
|
|
56
46
|
"styled-components": "^5.3.11",
|
|
57
47
|
"ts-jest": "^29.1.2",
|
|
58
|
-
"typescript": "^5.9.3"
|
|
48
|
+
"typescript": "^5.9.3",
|
|
49
|
+
"@publishfx/publish-components": "^2.1.0"
|
|
59
50
|
},
|
|
60
51
|
"peerDependencies": {
|
|
61
52
|
"@antv/data-set": "^0.11.8",
|
|
@@ -71,5 +62,14 @@
|
|
|
71
62
|
"publishConfig": {
|
|
72
63
|
"access": "public",
|
|
73
64
|
"registry": "https://registry.npmjs.org/"
|
|
65
|
+
},
|
|
66
|
+
"scripts": {
|
|
67
|
+
"build": "rslib build",
|
|
68
|
+
"dev": "rslib build --watch",
|
|
69
|
+
"lint": "eslint src --ext .ts,.tsx",
|
|
70
|
+
"lint:fix": "eslint src --ext .ts,.tsx --fix",
|
|
71
|
+
"test": "jest",
|
|
72
|
+
"test:watch": "jest --watch",
|
|
73
|
+
"test:coverage": "jest --coverage"
|
|
74
74
|
}
|
|
75
|
-
}
|
|
75
|
+
}
|