@publishfx/publish-chart 2.1.7 → 2.1.8
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 +9 -0
- package/dist/components/g2/base/G2BarChart.js +3 -1
- package/dist/components/g2/base/G2CombineChart.js +8 -3
- package/dist/components/g2/base/G2LineChart.js +8 -3
- package/dist/components/g2/base/g2Helpers.d.ts +10 -0
- package/dist/components/g2/base/g2Helpers.js +75 -14
- package/dist/components/g2/base/g2bar.d.ts +2 -0
- package/dist/components/g2/base/g2bar.js +10 -52
- package/dist/components/g2/base/g2combine.d.ts +2 -0
- package/dist/components/g2/base/g2combine.js +17 -82
- package/dist/components/g2/base/g2line.d.ts +2 -0
- package/dist/components/g2/base/g2line.js +7 -52
- package/dist/components/g2/shared/G2CompareTooltip.d.ts +1 -0
- package/dist/components/g2/shared/G2CompareTooltip.js +2 -2
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,3 +1,12 @@
|
|
|
1
|
+
**2.1.8** feat(chart): 柱状、折线、组合图的节点单独传递
|
|
2
|
+
- 2026-03-04T11:59:34+08:00 [feat(chart): 柱状、折线、组合图的节点单独传递](http://lf.git.oa.mt/publish_platform/web/publish/commit/5ef7b6c79b51438f7ae49edce74e060e5ffbd595)
|
|
3
|
+
- 2026-03-04T11:45:15+08:00 [fix(chart): 将node信息单独传递](http://lf.git.oa.mt/publish_platform/web/publish/commit/20b4209876bd464ff63674480eb3a308e7007a02)
|
|
4
|
+
- 2026-03-04T00:58:03+08:00 [fix(chart): 辅助线问题统一修复](http://lf.git.oa.mt/publish_platform/web/publish/commit/c40294f244ee7d8036ed1e92594b5e51980b55d0)
|
|
5
|
+
- 2026-03-04T00:18:41+08:00 [fix(chart): 辅助线scale统一设置为key:main](http://lf.git.oa.mt/publish_platform/web/publish/commit/67bf1b6913dd301aa3f1d840909e53bd6c6efcb2)
|
|
6
|
+
- 2026-03-03T23:26:48+08:00 [fix(chart): 组合图对比时间color设置修改](http://lf.git.oa.mt/publish_platform/web/publish/commit/3835d8c1ddc7937550daf45122f335f678e0730b)
|
|
7
|
+
- 2026-03-03T23:01:20+08:00 [fix(chart): inset边距去掉](http://lf.git.oa.mt/publish_platform/web/publish/commit/b96fec0d5939c9836caf5f8ceb51a988410d5e28)
|
|
8
|
+
- 2026-03-03T21:37:11+08:00 [feat(chart): 折线图图例根据indicators排序](http://lf.git.oa.mt/publish_platform/web/publish/commit/2d366548ba1aa170659f9c645f95045f4f510924)
|
|
9
|
+
|
|
1
10
|
**2.1.7** fix(chart): 修复折线图有空数据的异常场景
|
|
2
11
|
- 2026-03-03T17:50:03+08:00 [fix(chart): 修复折线图有空数据的异常场景](http://lf.git.oa.mt/publish_platform/web/publish/commit/3465ede843d4fb156932871cdf042315dbb17096)
|
|
3
12
|
- 2026-03-03T17:38:27+08:00 [fix(chart): 组合图柱数据缺失问题优化](http://lf.git.oa.mt/publish_platform/web/publish/commit/fa55e35a7569b9e7000d2c4dc5d09eee3b60bfff)
|
|
@@ -50,6 +50,7 @@ const G2BarChart = ({ height = 300, data, x = "", y = "", indicatorMap, onChartC
|
|
|
50
50
|
contextConfig.nodeMap
|
|
51
51
|
]);
|
|
52
52
|
console.log("transformedData: bar final", transformedData);
|
|
53
|
+
const nodeData = transformedData.filter((item)=>item.nodeInfos?.info?.length > 0 || item.nodeInfos?.infosCompare?.length > 0);
|
|
53
54
|
const maxY = useMemo(()=>{
|
|
54
55
|
const values = transformedData.filter((item)=>"-" !== item[safeY] && void 0 !== item[safeY] && null !== item[safeY]).map((item)=>Number(item[safeY]) || 0);
|
|
55
56
|
const dataMax = values.length > 0 ? Math.max(...values) : 0;
|
|
@@ -110,6 +111,7 @@ const G2BarChart = ({ height = 300, data, x = "", y = "", indicatorMap, onChartC
|
|
|
110
111
|
}
|
|
111
112
|
const chart = renderG2BarChart(containerRef.current, {
|
|
112
113
|
data: filteredData,
|
|
114
|
+
nodeData,
|
|
113
115
|
x,
|
|
114
116
|
y: safeY,
|
|
115
117
|
maxY,
|
|
@@ -149,7 +151,7 @@ const G2BarChart = ({ height = 300, data, x = "", y = "", indicatorMap, onChartC
|
|
|
149
151
|
},
|
|
150
152
|
auxiliaryLineData: auxiliaryLineData ?? [],
|
|
151
153
|
onNodeListChange: (nodes)=>{
|
|
152
|
-
console.log("g2bar node list:", nodes
|
|
154
|
+
console.log("g2bar node list:", nodes);
|
|
153
155
|
setXYList(nodes);
|
|
154
156
|
},
|
|
155
157
|
timeRange,
|
|
@@ -11,6 +11,7 @@ import useG2TooltipContainer from "../shared/useG2TooltipContainer.js";
|
|
|
11
11
|
import { getIndicatorCompareName } from "../../../utils/indicatorHelpers.js";
|
|
12
12
|
import { renderG2CombineChart } from "./g2combine.js";
|
|
13
13
|
import { G2BarLegend } from "./G2BarLegend.js";
|
|
14
|
+
import { sortByIndicators } from "./g2Helpers.js";
|
|
14
15
|
const transformDataToGroupBarLineFormat = (data, x = "groupName", y = "", indicators)=>{
|
|
15
16
|
if (!data || 0 === data.length) return [];
|
|
16
17
|
return data.map((item)=>{
|
|
@@ -109,6 +110,7 @@ const G2CombineChart = ({ height = 300, data, x = "", y = "", z = "", indicatorM
|
|
|
109
110
|
isDescend
|
|
110
111
|
]);
|
|
111
112
|
console.log("G2CombineChart transformedData:", transformedData, leftData, rightData);
|
|
113
|
+
const nodeData = transformedData.filter((item)=>item.nodeInfos?.info?.length > 0 || item.nodeInfos?.infosCompare?.length > 0);
|
|
112
114
|
const { maxY } = useMemo(()=>{
|
|
113
115
|
const key = isGroupRef.current ? "total" : safeY;
|
|
114
116
|
const yValues = transformedData.filter((item)=>"-" !== item[key] && void 0 !== item[key] && null !== item[key]).map((item)=>Number(item[key]) || 0);
|
|
@@ -134,8 +136,9 @@ const G2CombineChart = ({ height = 300, data, x = "", y = "", z = "", indicatorM
|
|
|
134
136
|
return;
|
|
135
137
|
}
|
|
136
138
|
const groupTypes = Array.from(new Set(transformedData.map((d)=>d.groupType.replace("_compare", "") + "_" + d.isCombine).filter((v)=>null != v)));
|
|
137
|
-
const
|
|
138
|
-
const
|
|
139
|
+
const sortedGroupTypes = sortByIndicators(groupTypes, indicators);
|
|
140
|
+
const lineGroupTypeArr = sortedGroupTypes.filter((v)=>"true" === v.split("_")[1]);
|
|
141
|
+
const items = sortedGroupTypes.map((id, index)=>{
|
|
139
142
|
const colorIndex = index;
|
|
140
143
|
const indicatorId = id.split("_")[0];
|
|
141
144
|
const isCombine = "true" === id.split("_")[1];
|
|
@@ -160,7 +163,8 @@ const G2CombineChart = ({ height = 300, data, x = "", y = "", z = "", indicatorM
|
|
|
160
163
|
}, [
|
|
161
164
|
transformedData,
|
|
162
165
|
safeIndicatorMap,
|
|
163
|
-
themeColors
|
|
166
|
+
themeColors,
|
|
167
|
+
indicators
|
|
164
168
|
]);
|
|
165
169
|
const filterLeftData = useMemo(()=>{
|
|
166
170
|
if (!activeIds.length) return leftData;
|
|
@@ -202,6 +206,7 @@ const G2CombineChart = ({ height = 300, data, x = "", y = "", z = "", indicatorM
|
|
|
202
206
|
console.log("canvasMarginBottom:", canvasMarginBottom);
|
|
203
207
|
const chart = renderG2CombineChart(containerRef.current, {
|
|
204
208
|
data: filteredData,
|
|
209
|
+
nodeData,
|
|
205
210
|
x,
|
|
206
211
|
y: safeY,
|
|
207
212
|
z,
|
|
@@ -7,6 +7,7 @@ import { DataAdapter } from "../../../adapters/DataAdapter.js";
|
|
|
7
7
|
import { NodePopover } from "../../shared/NodePopover.js";
|
|
8
8
|
import { NodeDetail } from "../../shared/NodeDetail.js";
|
|
9
9
|
import { transformIndicatorList } from "../../../utils/dataTransform.js";
|
|
10
|
+
import { sortByIndicators } from "./g2Helpers.js";
|
|
10
11
|
import G2CompareTooltip from "../shared/G2CompareTooltip.js";
|
|
11
12
|
import useG2TooltipContainer from "../shared/useG2TooltipContainer.js";
|
|
12
13
|
import { getIndicatorCompareName } from "../../../utils/indicatorHelpers.js";
|
|
@@ -52,6 +53,8 @@ const G2LineChart = ({ height = 300, data, x = "", y = "", z = "", indicatorMap,
|
|
|
52
53
|
dataTransform,
|
|
53
54
|
contextConfig.nodeMap
|
|
54
55
|
]);
|
|
56
|
+
const nodeData = transformedData.filter((item)=>item.nodeInfos?.info?.length > 0 || item.nodeInfos?.infosCompare?.length > 0);
|
|
57
|
+
console.log('nodeData:', nodeData);
|
|
55
58
|
const { minY, maxY } = useMemo(()=>{
|
|
56
59
|
const dataValues = transformedData.filter((item)=>"-" !== item[safeY] && void 0 !== item[safeY] && null !== item[safeY]).map((item)=>Number(item[safeY]));
|
|
57
60
|
const compareValues = transformedData.filter((item)=>"-" !== item["subGroupValue"] && null != item["subGroupValue"]).map((item)=>Number(item["subGroupValue"]));
|
|
@@ -73,7 +76,6 @@ const G2LineChart = ({ height = 300, data, x = "", y = "", z = "", indicatorMap,
|
|
|
73
76
|
safeY,
|
|
74
77
|
auxiliaryLineData
|
|
75
78
|
]);
|
|
76
|
-
console.log('minY, maxY:', minY, maxY);
|
|
77
79
|
const formatAxis = useCallback((val)=>getAxisFormat(val, safeIndicatorMap, safeLegend), [
|
|
78
80
|
safeIndicatorMap,
|
|
79
81
|
safeLegend
|
|
@@ -85,7 +87,8 @@ const G2LineChart = ({ height = 300, data, x = "", y = "", z = "", indicatorMap,
|
|
|
85
87
|
return;
|
|
86
88
|
}
|
|
87
89
|
const groupTypes = Array.from(new Set(transformedData.map((d)=>d.groupType).filter((v)=>null != v)));
|
|
88
|
-
const
|
|
90
|
+
const sortedGroupTypes = sortByIndicators(groupTypes, indicators);
|
|
91
|
+
const items = sortedGroupTypes.map((id, index)=>{
|
|
89
92
|
const colorIndex = isCompare ? Math.floor(index / 2) : index;
|
|
90
93
|
return {
|
|
91
94
|
id: String(id),
|
|
@@ -106,7 +109,8 @@ const G2LineChart = ({ height = 300, data, x = "", y = "", z = "", indicatorMap,
|
|
|
106
109
|
}, [
|
|
107
110
|
transformedData,
|
|
108
111
|
safeIndicatorMap,
|
|
109
|
-
themeColors
|
|
112
|
+
themeColors,
|
|
113
|
+
indicators
|
|
110
114
|
]);
|
|
111
115
|
const filteredData = useMemo(()=>{
|
|
112
116
|
if (!activeIds.length) return transformedData;
|
|
@@ -125,6 +129,7 @@ const G2LineChart = ({ height = 300, data, x = "", y = "", z = "", indicatorMap,
|
|
|
125
129
|
console.log("G2LineChart", x, y, minY, maxY);
|
|
126
130
|
const chart = renderG2LineChart(containerRef.current, {
|
|
127
131
|
data: filteredData,
|
|
132
|
+
nodeData,
|
|
128
133
|
x,
|
|
129
134
|
y: safeY,
|
|
130
135
|
minY,
|
|
@@ -194,6 +194,7 @@ export declare function getMainView(chart: Chart): import("@antv/g2/lib/api/exte
|
|
|
194
194
|
'composition.view': any;
|
|
195
195
|
}>;
|
|
196
196
|
export interface ScaleYLinearOptions {
|
|
197
|
+
key?: string;
|
|
197
198
|
field?: string;
|
|
198
199
|
domainMin?: number;
|
|
199
200
|
domainMax?: number;
|
|
@@ -296,4 +297,13 @@ export interface GetColorByGroupTypeOptions {
|
|
|
296
297
|
*/
|
|
297
298
|
export declare function getColorByGroupType(groupType: string, options: GetColorByGroupTypeOptions): string;
|
|
298
299
|
export declare function applyHighlightDate(view: any, x: string, data: any, highlightDate: string[], isHighlight: boolean): void;
|
|
300
|
+
export declare function applyNodeData(view: any, nodeData: any[], x: string, y: string): {
|
|
301
|
+
pointP: {
|
|
302
|
+
x: number;
|
|
303
|
+
y: number;
|
|
304
|
+
};
|
|
305
|
+
pointData: any;
|
|
306
|
+
color: string;
|
|
307
|
+
}[];
|
|
299
308
|
export declare function adjustDomainMax(domainMin: number, domainMax: number): number;
|
|
309
|
+
export declare const sortByIndicators: (arr: string[], indicators: string[]) => string[];
|
|
@@ -14,7 +14,7 @@ function getMainView(chart) {
|
|
|
14
14
|
return layer.view();
|
|
15
15
|
}
|
|
16
16
|
function applyScaleYLinear(view, options = {}) {
|
|
17
|
-
const { field = 'y', domainMin = 0, domainMax, nice = true, clamp = true, tickCount = 5, minLimit, maxLimit, tickMethod } = options;
|
|
17
|
+
const { field = 'y', domainMin = 0, domainMax, nice = true, clamp = true, tickCount = 5, minLimit, maxLimit, tickMethod, key } = options;
|
|
18
18
|
view.scale({
|
|
19
19
|
[field]: {
|
|
20
20
|
type: 'linear',
|
|
@@ -25,6 +25,7 @@ function applyScaleYLinear(view, options = {}) {
|
|
|
25
25
|
clamp,
|
|
26
26
|
nice,
|
|
27
27
|
tickCount,
|
|
28
|
+
key,
|
|
28
29
|
...null != minLimit && {
|
|
29
30
|
minLimit
|
|
30
31
|
},
|
|
@@ -148,18 +149,19 @@ function applyAuxiliaryLineY(view, lines, options = {}) {
|
|
|
148
149
|
console.log('applyAuxiliaryLineY:', lines);
|
|
149
150
|
const { stroke = '#F4664A', strokeOpacity = 1, labelMaxLength = 5 } = options;
|
|
150
151
|
lines.forEach((auxLine)=>{
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
tick: false
|
|
156
|
-
}).label({
|
|
152
|
+
console.log('lines:', auxLine);
|
|
153
|
+
view.lineY().encode('y', auxLine.value).style('stroke', stroke).style('strokeOpacity', strokeOpacity).style('lineWidth', 1).style('shadowColor', 'transparent').scale('y', {
|
|
154
|
+
key: auxLine?.axis === 'right' ? 'line' : 'main'
|
|
155
|
+
}).axis('x', false).label({
|
|
157
156
|
dx: 0,
|
|
158
|
-
dy:
|
|
159
|
-
text: splitTextToMultiline(auxLine.name, labelMaxLength, '
|
|
157
|
+
dy: 0,
|
|
158
|
+
text: splitTextToMultiline(auxLine.name, labelMaxLength, '\n'),
|
|
160
159
|
position: auxLine?.axis === 'right' ? 'bottom-right' : 'bottom-left',
|
|
161
|
-
style: {
|
|
162
|
-
|
|
160
|
+
style: {
|
|
161
|
+
fill: stroke,
|
|
162
|
+
shadowColor: 'transparent',
|
|
163
|
+
fillOpacity: 1
|
|
164
|
+
}
|
|
163
165
|
});
|
|
164
166
|
});
|
|
165
167
|
}
|
|
@@ -183,7 +185,7 @@ function applyHighlightDate(view, x, data, highlightDate, isHighlight) {
|
|
|
183
185
|
domainMax: 100,
|
|
184
186
|
independent: true
|
|
185
187
|
}).tooltip(false).axis('y', {
|
|
186
|
-
position: '
|
|
188
|
+
position: 'top',
|
|
187
189
|
title: false,
|
|
188
190
|
grid: false,
|
|
189
191
|
label: false,
|
|
@@ -200,16 +202,75 @@ function applyHighlightDate(view, x, data, highlightDate, isHighlight) {
|
|
|
200
202
|
domainMax: 100,
|
|
201
203
|
independent: true
|
|
202
204
|
}).tooltip(true).axis('y', {
|
|
205
|
+
position: 'top',
|
|
203
206
|
title: false,
|
|
204
207
|
grid: false,
|
|
205
208
|
label: false,
|
|
206
209
|
tick: false
|
|
207
210
|
}).style({
|
|
208
211
|
stroke: 'transparent',
|
|
209
|
-
strokeOpacity:
|
|
212
|
+
strokeOpacity: 1
|
|
210
213
|
});
|
|
211
214
|
}
|
|
215
|
+
function applyNodeData(view, nodeData, x, y) {
|
|
216
|
+
const nodeList = [];
|
|
217
|
+
nodeData.forEach((item)=>{
|
|
218
|
+
view.shape().data([
|
|
219
|
+
{
|
|
220
|
+
[x]: item[x],
|
|
221
|
+
[y]: 0
|
|
222
|
+
}
|
|
223
|
+
]).encode('x', x).encode('y', y).tooltip(false).scale('y', {
|
|
224
|
+
key: 'main'
|
|
225
|
+
}).style({
|
|
226
|
+
render: ({ x: px, y: py }, context)=>{
|
|
227
|
+
const { document } = context;
|
|
228
|
+
const g = document.createElement('g', {});
|
|
229
|
+
const { paddingLeft = 24, marginLeft = 12 } = context?.coordinate?.options || {};
|
|
230
|
+
const adjustLeft = paddingLeft + marginLeft;
|
|
231
|
+
if (item.nodeInfos?.info?.length > 0 || item.nodeInfos?.infosCompare?.length > 0) {
|
|
232
|
+
nodeList.push({
|
|
233
|
+
pointP: {
|
|
234
|
+
x: px + adjustLeft,
|
|
235
|
+
y: py
|
|
236
|
+
},
|
|
237
|
+
pointData: item.nodeInfos || {},
|
|
238
|
+
color: item.color
|
|
239
|
+
});
|
|
240
|
+
const c1 = document.createElement('circle', {
|
|
241
|
+
style: {
|
|
242
|
+
cx: px,
|
|
243
|
+
cy: py,
|
|
244
|
+
r: 2,
|
|
245
|
+
fill: 'white'
|
|
246
|
+
}
|
|
247
|
+
});
|
|
248
|
+
const c2 = document.createElement('circle', {
|
|
249
|
+
style: {
|
|
250
|
+
cx: px,
|
|
251
|
+
cy: py,
|
|
252
|
+
r: 5,
|
|
253
|
+
fill: item.color
|
|
254
|
+
}
|
|
255
|
+
});
|
|
256
|
+
g.appendChild(c2);
|
|
257
|
+
g.appendChild(c1);
|
|
258
|
+
}
|
|
259
|
+
return g;
|
|
260
|
+
}
|
|
261
|
+
});
|
|
262
|
+
});
|
|
263
|
+
return nodeList;
|
|
264
|
+
}
|
|
212
265
|
function adjustDomainMax(domainMin, domainMax) {
|
|
213
266
|
return domainMax === domainMin ? domainMin > 0 ? 1.1 * domainMax : domainMax + 1 : domainMax;
|
|
214
267
|
}
|
|
215
|
-
|
|
268
|
+
const sortByIndicators = (arr, indicators)=>arr.sort((a, b)=>{
|
|
269
|
+
const baseA = a.split('_')[0];
|
|
270
|
+
const baseB = b.split('_')[0];
|
|
271
|
+
const indexA = indicators.indexOf(baseA);
|
|
272
|
+
const indexB = indicators.indexOf(baseB);
|
|
273
|
+
if (-1 !== indexA && -1 !== indexB) return indexA - indexB;
|
|
274
|
+
return 0;
|
|
275
|
+
});
|
|
276
|
+
export { adjustDomainMax, applyAuxiliaryLineY, applyAxisX, applyAxisY, applyHighlightDate, applyLegendColor, applyNodeData, applyScaleYLinear, createChart, getColorByGroupType, getMainView, sortByIndicators };
|
|
@@ -3,6 +3,8 @@ import type { ChartTimeRange } from '../../../core/ChartTypes';
|
|
|
3
3
|
export interface RenderG2BarChartOptions {
|
|
4
4
|
/** 已转换后的数据:约定包含 groupName、groupType、groupValue 等字段 */
|
|
5
5
|
data: any[];
|
|
6
|
+
/** 节点数据 */
|
|
7
|
+
nodeData: any[];
|
|
6
8
|
/** X 轴字段,如 groupName */
|
|
7
9
|
x: string;
|
|
8
10
|
/** Y 轴字段,如 groupValue / cost */
|
|
@@ -1,8 +1,10 @@
|
|
|
1
1
|
import { lines } from "@antv/g-pattern";
|
|
2
|
-
import { applyAuxiliaryLineY, applyAxisX, applyAxisY, applyHighlightDate, applyScaleYLinear, createChart, getColorByGroupType, getMainView } from "./g2Helpers.js";
|
|
2
|
+
import { applyAuxiliaryLineY, applyAxisX, applyAxisY, applyHighlightDate, applyNodeData, applyScaleYLinear, createChart, getColorByGroupType, getMainView } from "./g2Helpers.js";
|
|
3
3
|
const Y_AXIS_FIELD = 'groupValue';
|
|
4
|
+
const CLOSE_NODE_DEBUG = false;
|
|
5
|
+
const CLOSE_HIGHLIGHT_DEBUG = false;
|
|
4
6
|
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, isClickable = false, legend, formatLabel, height = 300, tooltipRender, auxiliaryLineData = [], onNodeListChange, onChartRender } = options;
|
|
7
|
+
const { data, nodeData, 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
8
|
const colorOpts = {
|
|
7
9
|
themeColors,
|
|
8
10
|
primaryKey: y,
|
|
@@ -30,13 +32,11 @@ function renderG2BarChart(container, options) {
|
|
|
30
32
|
});
|
|
31
33
|
view.data(data);
|
|
32
34
|
applyScaleYLinear(view, {
|
|
33
|
-
field: 'y',
|
|
34
35
|
domainMin: 0,
|
|
35
36
|
domainMax: maxY,
|
|
36
|
-
|
|
37
|
-
clamp: true
|
|
37
|
+
key: 'main'
|
|
38
38
|
});
|
|
39
|
-
applyHighlightDate(view, x, data, highlightDate, isHighlight);
|
|
39
|
+
if (!CLOSE_HIGHLIGHT_DEBUG) applyHighlightDate(view, x, data, highlightDate, isHighlight);
|
|
40
40
|
console.log('g2bar data:', data, y);
|
|
41
41
|
const interval = view.interval().encode('x', x).encode('y', y).encode('color', 'groupType').transform({
|
|
42
42
|
type: 'dodgeX',
|
|
@@ -145,52 +145,11 @@ function renderG2BarChart(container, options) {
|
|
|
145
145
|
bounding: tooltipBounding
|
|
146
146
|
});
|
|
147
147
|
applyAuxiliaryLineY(view, auxiliaryLineData);
|
|
148
|
-
const nodeList = [];
|
|
149
148
|
console.log('nodeList data:', data);
|
|
150
|
-
|
|
151
|
-
view
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
[y]: 0
|
|
155
|
-
}
|
|
156
|
-
]).encode('x', x).encode('y', y).tooltip(false).style({
|
|
157
|
-
render: ({ x: px, y: py }, context)=>{
|
|
158
|
-
const { document } = context;
|
|
159
|
-
const g = document.createElement('g', {});
|
|
160
|
-
const { paddingLeft = 24, marginLeft = 12 } = context?.coordinate?.options || {};
|
|
161
|
-
const adjustLeft = paddingLeft + marginLeft;
|
|
162
|
-
if (item.nodeInfos?.info?.length > 0 || item.nodeInfos?.infosCompare?.length > 0) {
|
|
163
|
-
nodeList.push({
|
|
164
|
-
pointP: {
|
|
165
|
-
x: px + adjustLeft,
|
|
166
|
-
y: py
|
|
167
|
-
},
|
|
168
|
-
pointData: item.nodeInfos || {},
|
|
169
|
-
color: item.color
|
|
170
|
-
});
|
|
171
|
-
const c1 = document.createElement('circle', {
|
|
172
|
-
style: {
|
|
173
|
-
cx: px,
|
|
174
|
-
cy: py,
|
|
175
|
-
r: 2,
|
|
176
|
-
fill: 'white'
|
|
177
|
-
}
|
|
178
|
-
});
|
|
179
|
-
const c2 = document.createElement('circle', {
|
|
180
|
-
style: {
|
|
181
|
-
cx: px,
|
|
182
|
-
cy: py,
|
|
183
|
-
r: 5,
|
|
184
|
-
fill: item.color
|
|
185
|
-
}
|
|
186
|
-
});
|
|
187
|
-
g.appendChild(c2);
|
|
188
|
-
g.appendChild(c1);
|
|
189
|
-
}
|
|
190
|
-
return g;
|
|
191
|
-
}
|
|
192
|
-
});
|
|
193
|
-
});
|
|
149
|
+
if (!CLOSE_NODE_DEBUG) {
|
|
150
|
+
const nodeList = applyNodeData(view, nodeData, x, y);
|
|
151
|
+
onNodeListChange?.(nodeList);
|
|
152
|
+
}
|
|
194
153
|
if (isDataTag && formatLabel) interval.label({
|
|
195
154
|
text: (d)=>formatLabel(d),
|
|
196
155
|
position: isHorizontal ? 'right' : 'top',
|
|
@@ -208,7 +167,6 @@ function renderG2BarChart(container, options) {
|
|
|
208
167
|
let hasEmittedNodeList = false;
|
|
209
168
|
chart.on('afterrender', (_e)=>{
|
|
210
169
|
if (hasEmittedNodeList) return;
|
|
211
|
-
if (onNodeListChange) onNodeListChange(nodeList);
|
|
212
170
|
console.log('chart.coordinateBBox:', chart.getContext(), view.getCoordinate());
|
|
213
171
|
const views = chart.getContext()?.views;
|
|
214
172
|
const viewCoordinate = views?.[0]?.layout;
|
|
@@ -8,6 +8,8 @@ import { type AuxiliaryLineItem } from "./g2Helpers";
|
|
|
8
8
|
export interface RenderG2CombineChartOptions {
|
|
9
9
|
/** 已转换后的数据:约定包含 groupName、groupType、groupValue 等字段 */
|
|
10
10
|
data: any[];
|
|
11
|
+
/** 节点数据 */
|
|
12
|
+
nodeData: any[];
|
|
11
13
|
/** X 轴字段,如 groupName */
|
|
12
14
|
x: string;
|
|
13
15
|
/** 柱状图 Y 字段,如 groupValue 或某指标字段 */
|
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
import { lines } from "@antv/g-pattern";
|
|
2
|
-
import { applyAuxiliaryLineY, applyAxisX, applyHighlightDate, createChart, getMainView } from "./g2Helpers.js";
|
|
2
|
+
import { applyAuxiliaryLineY, applyAxisX, applyHighlightDate, applyNodeData, applyScaleYLinear, createChart, getMainView } from "./g2Helpers.js";
|
|
3
3
|
import { getIndicatorCompareName } from "../../../utils/indicatorHelpers.js";
|
|
4
4
|
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, x, y, z: _z, maxY, themeColors, indicatorMap: _indicatorMap, formatAxis, formatLineAxis, isDataTag = true, isCombineDataTag = true, isLegend: _isLegend = false, isCompare = false, formatLabel, highlightDate = [], height = 300, isHighlight = true, isClickable = false, indicators = [], tooltipRender, auxiliaryLineData = [], onNodeListChange, lineColors, onChartRender, isGroup, legendItems = [], indicatorId } = options;
|
|
8
|
+
const { data, nodeData, x, y, z: _z, maxY, themeColors, indicatorMap: _indicatorMap, formatAxis, formatLineAxis, isDataTag = true, isCombineDataTag = true, isLegend: _isLegend = false, isCompare = false, formatLabel, highlightDate = [], height = 300, isHighlight = true, isClickable = false, indicators = [], tooltipRender, auxiliaryLineData = [], onNodeListChange, lineColors, onChartRender, isGroup, legendItems = [], indicatorId } = options;
|
|
9
9
|
const chart = createChart({
|
|
10
10
|
container,
|
|
11
11
|
height,
|
|
@@ -52,14 +52,15 @@ function renderG2CombineChart(container, options) {
|
|
|
52
52
|
}).style({
|
|
53
53
|
columnWidthRatio: 0.6,
|
|
54
54
|
insetLeft: (_d, index, _data, _column)=>{
|
|
55
|
+
console.log('insetLeft:', index, isCompare);
|
|
55
56
|
if (isGroup) return 0;
|
|
56
|
-
if (isCompare) return index % 2 === 0 ?
|
|
57
|
-
return
|
|
57
|
+
if (isCompare) return index % 2 === 0 ? 0 : 0;
|
|
58
|
+
return 0;
|
|
58
59
|
},
|
|
59
60
|
insetRight: (_d, index, _data, _column)=>{
|
|
60
61
|
if (isGroup) return 0;
|
|
61
|
-
if (isCompare) return index % 2 === 1 ?
|
|
62
|
-
return
|
|
62
|
+
if (isCompare) return index % 2 === 1 ? 0 : 0;
|
|
63
|
+
return 0;
|
|
63
64
|
},
|
|
64
65
|
fill: (datum)=>{
|
|
65
66
|
const groupType = String(datum.groupType ?? '');
|
|
@@ -81,17 +82,15 @@ function renderG2CombineChart(container, options) {
|
|
|
81
82
|
cursor: isClickable ? 'pointer' : 'default',
|
|
82
83
|
stroke: 'transparent'
|
|
83
84
|
});
|
|
84
|
-
|
|
85
|
-
type: 'linear',
|
|
85
|
+
const chartScale = {
|
|
86
86
|
domainMin: 0,
|
|
87
87
|
domainMax: finalIntervalMax,
|
|
88
|
-
|
|
89
|
-
clamp: true,
|
|
90
|
-
key: 'bar',
|
|
88
|
+
key: 'main',
|
|
91
89
|
tickMethod: (min, max)=>Array.from({
|
|
92
90
|
length: 6
|
|
93
91
|
}, (_, i)=>min + (max - min) * i / 5)
|
|
94
|
-
}
|
|
92
|
+
};
|
|
93
|
+
applyScaleYLinear(interval, chartScale);
|
|
95
94
|
interval.axis('y', {
|
|
96
95
|
position: 'left',
|
|
97
96
|
title: false,
|
|
@@ -186,7 +185,6 @@ function renderG2CombineChart(container, options) {
|
|
|
186
185
|
];
|
|
187
186
|
const groupType = String(datum?.groupType ?? '');
|
|
188
187
|
const index = groupTypeArr.findIndex((item)=>item === groupType);
|
|
189
|
-
console.log('line: groupTypeArr:', groupTypeArr, groupType, index, lineColors, getIndicatorCompareName(_indicatorMap, datum['groupType']), datum['groupType']);
|
|
190
188
|
return {
|
|
191
189
|
value: datum[LINE_Y_FIELD],
|
|
192
190
|
name: getIndicatorCompareName(_indicatorMap, datum['groupType']),
|
|
@@ -199,18 +197,15 @@ function renderG2CombineChart(container, options) {
|
|
|
199
197
|
}
|
|
200
198
|
]
|
|
201
199
|
});
|
|
202
|
-
|
|
203
|
-
type: 'linear',
|
|
200
|
+
const chartSideScale = {
|
|
204
201
|
domainMin: 0,
|
|
205
202
|
domainMax: finalLineMax,
|
|
206
|
-
nice: true,
|
|
207
|
-
clamp: true,
|
|
208
203
|
key: 'line',
|
|
209
|
-
independent: true,
|
|
210
204
|
tickMethod: (min, max)=>Array.from({
|
|
211
205
|
length: 6
|
|
212
206
|
}, (_, i)=>min + (max - min) * i / 5)
|
|
213
|
-
}
|
|
207
|
+
};
|
|
208
|
+
applyScaleYLinear(line, chartSideScale);
|
|
214
209
|
line.axis('y', {
|
|
215
210
|
position: 'right',
|
|
216
211
|
title: false,
|
|
@@ -267,7 +262,7 @@ function renderG2CombineChart(container, options) {
|
|
|
267
262
|
(datum)=>datum.groupType.includes('_compare') ? {
|
|
268
263
|
name: datum['groupType'].replace('_compare', '_change'),
|
|
269
264
|
indicatorId: datum['groupType'].replace('_compare', ''),
|
|
270
|
-
color: '
|
|
265
|
+
color: 'transparent',
|
|
271
266
|
value: datum?.change,
|
|
272
267
|
isChange: true,
|
|
273
268
|
isCombine: true,
|
|
@@ -361,68 +356,8 @@ function renderG2CombineChart(container, options) {
|
|
|
361
356
|
tipBoxShadow: '0 3px 6px -4px rgba(0, 0, 0, 1)'
|
|
362
357
|
});
|
|
363
358
|
applyAuxiliaryLineY(view, auxiliaryLineData);
|
|
364
|
-
const nodeList =
|
|
365
|
-
|
|
366
|
-
data.forEach((item)=>{
|
|
367
|
-
view.shape().data([
|
|
368
|
-
{
|
|
369
|
-
[x]: item[x],
|
|
370
|
-
[y]: 0
|
|
371
|
-
}
|
|
372
|
-
]).encode('x', x).encode('y', y).tooltip(false).scale('y', {
|
|
373
|
-
key: 'node',
|
|
374
|
-
domainMin: 0,
|
|
375
|
-
domainMax: 1,
|
|
376
|
-
nice: true,
|
|
377
|
-
clamp: true
|
|
378
|
-
}).axis('y', {
|
|
379
|
-
grid: false,
|
|
380
|
-
title: false,
|
|
381
|
-
tick: false,
|
|
382
|
-
label: false,
|
|
383
|
-
gridStrokeOpacity: 1,
|
|
384
|
-
gridLineDash: [
|
|
385
|
-
0,
|
|
386
|
-
0
|
|
387
|
-
]
|
|
388
|
-
}).style({
|
|
389
|
-
render: ({ x: px, y: py }, context)=>{
|
|
390
|
-
const { document } = context;
|
|
391
|
-
const g = document.createElement('g', {});
|
|
392
|
-
const { paddingLeft = 24, marginLeft = 12 } = context?.coordinate?.options || {};
|
|
393
|
-
const adjustLeft = paddingLeft + marginLeft;
|
|
394
|
-
if (item.nodeInfos?.info?.length > 0 || item.nodeInfos?.infosCompare?.length > 0) {
|
|
395
|
-
nodeList.push({
|
|
396
|
-
pointP: {
|
|
397
|
-
x: px + adjustLeft,
|
|
398
|
-
y: py
|
|
399
|
-
},
|
|
400
|
-
pointData: item.nodeInfos || {},
|
|
401
|
-
color: item.color
|
|
402
|
-
});
|
|
403
|
-
const c1 = document.createElement('circle', {
|
|
404
|
-
style: {
|
|
405
|
-
cx: px,
|
|
406
|
-
cy: py,
|
|
407
|
-
r: 2,
|
|
408
|
-
fill: 'white'
|
|
409
|
-
}
|
|
410
|
-
});
|
|
411
|
-
const c2 = document.createElement('circle', {
|
|
412
|
-
style: {
|
|
413
|
-
cx: px,
|
|
414
|
-
cy: py,
|
|
415
|
-
r: 5,
|
|
416
|
-
fill: item.color
|
|
417
|
-
}
|
|
418
|
-
});
|
|
419
|
-
g.appendChild(c2);
|
|
420
|
-
g.appendChild(c1);
|
|
421
|
-
}
|
|
422
|
-
return g;
|
|
423
|
-
}
|
|
424
|
-
});
|
|
425
|
-
});
|
|
359
|
+
const nodeList = applyNodeData(view, nodeData, x, 'groupValue');
|
|
360
|
+
onNodeListChange?.(nodeList);
|
|
426
361
|
if (formatLabel) {
|
|
427
362
|
if (isDataTag) {
|
|
428
363
|
const groupedByX = intervalData.reduce((acc, item)=>{
|
|
@@ -7,6 +7,8 @@ import { ChartTimeRange } from '../../../core/ChartTypes';
|
|
|
7
7
|
export interface RenderG2LineChartOptions {
|
|
8
8
|
/** 已转换后的数据(含 groupValue,groupType 可能带 _compare) */
|
|
9
9
|
data: any[];
|
|
10
|
+
/** 节点数据 */
|
|
11
|
+
nodeData: any[];
|
|
10
12
|
/** X 轴字段,如 groupName */
|
|
11
13
|
x: string;
|
|
12
14
|
/** 主指标 key,用于取色与图例 */
|
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import { applyAuxiliaryLineY, applyAxisX, applyAxisY, applyHighlightDate, applyScaleYLinear, createChart, getColorByGroupType, getMainView } from "./g2Helpers.js";
|
|
1
|
+
import { applyAuxiliaryLineY, applyAxisX, applyAxisY, applyHighlightDate, applyNodeData, applyScaleYLinear, createChart, getColorByGroupType, getMainView } from "./g2Helpers.js";
|
|
2
2
|
const Y_AXIS_FIELD = 'groupValue';
|
|
3
3
|
function renderG2LineChart(container, options) {
|
|
4
|
-
const { data, x, y, minY, maxY, timeRange: _timeRange, themeColors, indicators = [], indicatorMap: _indicatorMap = {}, formatAxis, highlightDate = [], auxiliaryLineData = [], isDataTag = false, isLegend = true, isHighlight = true, formatLabel, height = 300, legendLength: _legendLength, legendSize: _legendSize, tooltipRender, onNodeListChange, onChartRender } = options;
|
|
4
|
+
const { data, nodeData, x, y, minY, maxY, timeRange: _timeRange, themeColors, indicators = [], indicatorMap: _indicatorMap = {}, formatAxis, highlightDate = [], auxiliaryLineData = [], isDataTag = false, isLegend = true, isHighlight = true, formatLabel, height = 300, legendLength: _legendLength, legendSize: _legendSize, tooltipRender, onNodeListChange, onChartRender } = options;
|
|
5
5
|
console.log('g2line data:', data, x, y);
|
|
6
6
|
const colorOpts = {
|
|
7
7
|
themeColors,
|
|
@@ -23,11 +23,9 @@ function renderG2LineChart(container, options) {
|
|
|
23
23
|
view.data(data);
|
|
24
24
|
const domainMin = minY ?? 0;
|
|
25
25
|
applyScaleYLinear(view, {
|
|
26
|
-
field: 'y',
|
|
27
26
|
domainMin,
|
|
28
27
|
domainMax: maxY,
|
|
29
|
-
|
|
30
|
-
clamp: true
|
|
28
|
+
key: 'main'
|
|
31
29
|
});
|
|
32
30
|
applyHighlightDate(view, x, data, highlightDate, isHighlight);
|
|
33
31
|
console.log('g2linets:', x, Y_AXIS_FIELD, data, indicators);
|
|
@@ -80,7 +78,8 @@ function renderG2LineChart(container, options) {
|
|
|
80
78
|
indicatorId: datum['groupType'].replace('_compare', ''),
|
|
81
79
|
value: datum?.change,
|
|
82
80
|
isChange: true,
|
|
83
|
-
color: 'transparent'
|
|
81
|
+
color: 'transparent',
|
|
82
|
+
hidden: indicators?.length > 1
|
|
84
83
|
})
|
|
85
84
|
]
|
|
86
85
|
});
|
|
@@ -133,52 +132,8 @@ function renderG2LineChart(container, options) {
|
|
|
133
132
|
tipBoxShadow: '0 3px 6px -4px rgba(0, 0, 0, 1)'
|
|
134
133
|
});
|
|
135
134
|
applyAuxiliaryLineY(view, auxiliaryLineData);
|
|
136
|
-
const nodeList =
|
|
137
|
-
|
|
138
|
-
data.forEach((item)=>{
|
|
139
|
-
view.shape().data([
|
|
140
|
-
{
|
|
141
|
-
[x]: item[x],
|
|
142
|
-
[y]: 0
|
|
143
|
-
}
|
|
144
|
-
]).encode('x', x).encode('y', y).tooltip(false).style({
|
|
145
|
-
render: ({ x: px, y: py }, context)=>{
|
|
146
|
-
const { document } = context;
|
|
147
|
-
const g = document.createElement('g', {});
|
|
148
|
-
const { paddingLeft = 24, marginLeft = 12 } = context?.coordinate?.options || {};
|
|
149
|
-
const adjustLeft = paddingLeft + marginLeft;
|
|
150
|
-
if (item.nodeInfos?.info?.length > 0 || item.nodeInfos?.infosCompare?.length > 0) {
|
|
151
|
-
nodeList.push({
|
|
152
|
-
pointP: {
|
|
153
|
-
x: px + adjustLeft,
|
|
154
|
-
y: py
|
|
155
|
-
},
|
|
156
|
-
pointData: item.nodeInfos || {},
|
|
157
|
-
color: item.color
|
|
158
|
-
});
|
|
159
|
-
const c1 = document.createElement('circle', {
|
|
160
|
-
style: {
|
|
161
|
-
cx: px,
|
|
162
|
-
cy: py,
|
|
163
|
-
r: 2,
|
|
164
|
-
fill: 'white'
|
|
165
|
-
}
|
|
166
|
-
});
|
|
167
|
-
const c2 = document.createElement('circle', {
|
|
168
|
-
style: {
|
|
169
|
-
cx: px,
|
|
170
|
-
cy: py,
|
|
171
|
-
r: 5,
|
|
172
|
-
fill: item.color
|
|
173
|
-
}
|
|
174
|
-
});
|
|
175
|
-
g.appendChild(c2);
|
|
176
|
-
g.appendChild(c1);
|
|
177
|
-
}
|
|
178
|
-
return g;
|
|
179
|
-
}
|
|
180
|
-
});
|
|
181
|
-
});
|
|
135
|
+
const nodeList = applyNodeData(view, nodeData, x, y);
|
|
136
|
+
onNodeListChange?.(nodeList);
|
|
182
137
|
if (isDataTag && formatLabel) {
|
|
183
138
|
line.label({
|
|
184
139
|
dy: -10,
|
|
@@ -13,14 +13,14 @@ const G2CompareTooltip = ({ isGroupBar = false, title, items, safeIndicatorMap,
|
|
|
13
13
|
/*#__PURE__*/ jsx("div", {
|
|
14
14
|
children: title
|
|
15
15
|
}),
|
|
16
|
-
items?.map(({ color, value, isChange, compareTime, indicatorId, name, percent }, index)=>{
|
|
16
|
+
items?.map(({ color, value, isChange, compareTime, indicatorId, name, percent, hidden }, index)=>{
|
|
17
17
|
let isFirst = false;
|
|
18
18
|
if (0 === index) auxiIndicatorId = indicatorId ?? "";
|
|
19
19
|
if (color && !uniqueColors.includes(color)) {
|
|
20
20
|
isFirst = true;
|
|
21
21
|
uniqueColors.push(color);
|
|
22
22
|
}
|
|
23
|
-
return /*#__PURE__*/ jsxs("div", {
|
|
23
|
+
return !hidden && /*#__PURE__*/ jsxs("div", {
|
|
24
24
|
style: {
|
|
25
25
|
display: "flex",
|
|
26
26
|
justifyContent: "space-between",
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@publishfx/publish-chart",
|
|
3
|
-
"version": "2.1.
|
|
3
|
+
"version": "2.1.8",
|
|
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": [
|