@publishfx/publish-chart 2.1.28 → 2.1.30
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/dist/adapters/DataAdapter.js +9 -5
- package/dist/components/g2/base/g2Helpers.d.ts +2 -0
- package/dist/components/g2/base/g2Helpers.js +11 -8
- package/dist/components/g2/base/g2bar.js +5 -3
- package/dist/components/g2/base/g2combine.js +3 -1
- package/dist/components/g2/base/g2line.js +3 -1
- package/dist/components/g2/shared/G2CompareTooltip.d.ts +1 -0
- package/dist/components/g2/shared/G2CompareTooltip.js +2 -1
- package/package.json +1 -1
|
@@ -1,4 +1,8 @@
|
|
|
1
1
|
import lib from "@antv/data-set/lib";
|
|
2
|
+
const parseDataValue = (value, defaultStr = '-')=>{
|
|
3
|
+
if ('' !== value && '-' !== value && null != value && 'NaN' !== value) return +value;
|
|
4
|
+
return defaultStr;
|
|
5
|
+
};
|
|
2
6
|
class DataAdapter {
|
|
3
7
|
static transform(data, transformType, config) {
|
|
4
8
|
if (!data || 0 === data.length) return [];
|
|
@@ -24,7 +28,7 @@ class DataAdapter {
|
|
|
24
28
|
dv.transform({
|
|
25
29
|
type: 'map',
|
|
26
30
|
callback: (row)=>{
|
|
27
|
-
row[config.y] =
|
|
31
|
+
row[config.y] = parseDataValue(row[config.y], null);
|
|
28
32
|
return row;
|
|
29
33
|
}
|
|
30
34
|
});
|
|
@@ -106,7 +110,7 @@ class DataAdapter {
|
|
|
106
110
|
if (config.y) dv.transform({
|
|
107
111
|
type: 'map',
|
|
108
112
|
callback: (row)=>{
|
|
109
|
-
row[config.y] =
|
|
113
|
+
row[config.y] = parseDataValue(row[config.y]);
|
|
110
114
|
return row;
|
|
111
115
|
}
|
|
112
116
|
});
|
|
@@ -122,7 +126,7 @@ class DataAdapter {
|
|
|
122
126
|
dv.transform({
|
|
123
127
|
type: 'map',
|
|
124
128
|
callback: (row)=>{
|
|
125
|
-
row[config.y] =
|
|
129
|
+
row[config.y] = parseDataValue(row[config.y], null);
|
|
126
130
|
return row;
|
|
127
131
|
}
|
|
128
132
|
});
|
|
@@ -141,14 +145,14 @@ class DataAdapter {
|
|
|
141
145
|
tdv.transform({
|
|
142
146
|
type: 'map',
|
|
143
147
|
callback: (row)=>{
|
|
144
|
-
row[config.y] =
|
|
148
|
+
row[config.y] = parseDataValue(row[config.y], null);
|
|
145
149
|
return row;
|
|
146
150
|
}
|
|
147
151
|
});
|
|
148
152
|
combinedv.transform({
|
|
149
153
|
type: 'map',
|
|
150
154
|
callback: (row)=>{
|
|
151
|
-
row[config.y] =
|
|
155
|
+
row[config.y] = parseDataValue(row[config.y], null);
|
|
152
156
|
return row;
|
|
153
157
|
}
|
|
154
158
|
});
|
|
@@ -228,6 +228,8 @@ export interface ApplyAxisXOptions {
|
|
|
228
228
|
containerWidth?: number;
|
|
229
229
|
/** 单个标签最大显示字符数,超出截断。默认 6 */
|
|
230
230
|
maxLabelChars?: number;
|
|
231
|
+
/** 单个标签最小显示宽度,默认 90 */
|
|
232
|
+
minLabelWidth?: number;
|
|
231
233
|
}
|
|
232
234
|
/** 配置 X 轴,挂载在 mark 上(如 line / interval) */
|
|
233
235
|
export declare function applyAxisX(mark: any, options?: ApplyAxisXOptions): void;
|
|
@@ -37,12 +37,12 @@ function applyScaleYLinear(view, options = {}) {
|
|
|
37
37
|
}
|
|
38
38
|
});
|
|
39
39
|
}
|
|
40
|
-
function calcAxisInterval(dataCount, containerWidth, maxLabelChars, fontSize) {
|
|
40
|
+
function calcAxisInterval(dataCount, containerWidth, maxLabelChars, fontSize, minLabelWidth = 90) {
|
|
41
41
|
if (dataCount <= 1) return 1;
|
|
42
42
|
const charWidth = 0.55 * fontSize;
|
|
43
|
-
const ellipsisWidth = Math.min(maxLabelChars * charWidth,
|
|
43
|
+
const ellipsisWidth = Math.min(maxLabelChars * charWidth, minLabelWidth);
|
|
44
44
|
const slotWidth = ellipsisWidth + 8;
|
|
45
|
-
const plotWidth = 0.
|
|
45
|
+
const plotWidth = 0.95 * containerWidth;
|
|
46
46
|
const maxLabels = Math.max(Math.floor(plotWidth / slotWidth), 2);
|
|
47
47
|
return Math.max(Math.ceil(dataCount / maxLabels), 1);
|
|
48
48
|
}
|
|
@@ -55,10 +55,10 @@ function createAxisFilter(type, interval, _dataCount) {
|
|
|
55
55
|
function applyAxisX(mark, options = {}) {
|
|
56
56
|
const { title = false, isHorizontal = false, grid = true, gridStroke = '#333', gridLineWidth = 50, gridLineDash = [
|
|
57
57
|
1000
|
|
58
|
-
], gridFilter, dataCount = 0, containerWidth = 0, maxLabelChars = 30 } = options;
|
|
58
|
+
], gridFilter, dataCount = 0, containerWidth = 0, maxLabelChars = 30, minLabelWidth = 90 } = options;
|
|
59
59
|
const fontSize = 12;
|
|
60
60
|
const needSampling = dataCount > 0 && containerWidth > 0;
|
|
61
|
-
const interval = needSampling ? calcAxisInterval(dataCount, containerWidth, maxLabelChars, fontSize) : 1;
|
|
61
|
+
const interval = needSampling ? calcAxisInterval(dataCount, containerWidth, maxLabelChars, fontSize, minLabelWidth) : 1;
|
|
62
62
|
const axisFilter = needSampling && interval > 1 ? (type)=>createAxisFilter(type, interval, dataCount) : null;
|
|
63
63
|
mark.axis('x', {
|
|
64
64
|
title,
|
|
@@ -294,21 +294,24 @@ function fillMissingIndicator(baseItems, safeTitle, isCompare, isGroup = false)
|
|
|
294
294
|
name: indicatorId,
|
|
295
295
|
value: '-',
|
|
296
296
|
x: safeTitle,
|
|
297
|
-
color: color
|
|
297
|
+
color: color,
|
|
298
|
+
dataType: 'manual'
|
|
298
299
|
});
|
|
299
300
|
if (!baseItems.find((item)=>item.indicatorId === indicatorId && item.name === indicatorId + '_compare')) baseItems.push({
|
|
300
301
|
indicatorId: indicatorId,
|
|
301
302
|
name: indicatorId + '_compare',
|
|
302
303
|
tipType: 'compareline',
|
|
303
304
|
value: '-',
|
|
304
|
-
x: safeTitle
|
|
305
|
+
x: safeTitle,
|
|
306
|
+
dataType: 'manual'
|
|
305
307
|
});
|
|
306
308
|
if (!baseItems.find((item)=>item.indicatorId === indicatorId && item.name === indicatorId + '_change')) baseItems.push({
|
|
307
309
|
indicatorId: indicatorId,
|
|
308
310
|
name: indicatorId + '_change',
|
|
309
311
|
isChange: true,
|
|
310
312
|
value: '-',
|
|
311
|
-
x: safeTitle
|
|
313
|
+
x: safeTitle,
|
|
314
|
+
dataType: 'manual'
|
|
312
315
|
});
|
|
313
316
|
}
|
|
314
317
|
});
|
|
@@ -34,6 +34,7 @@ function renderG2BarChart(container, options) {
|
|
|
34
34
|
key: 'main'
|
|
35
35
|
});
|
|
36
36
|
if (!CLOSE_HIGHLIGHT_DEBUG) applyHighlightDate(view, x, data, highlightDate, isHighlight);
|
|
37
|
+
const minLabelWidth = data.some((d)=>d.groupName.length < 3) ? 30 : 90;
|
|
37
38
|
const interval = view.interval().encode('x', x).encode('y', y).encode('color', 'groupType').transform({
|
|
38
39
|
type: 'dodgeX',
|
|
39
40
|
padding: isHorizontal ? 0.2 : 0
|
|
@@ -72,7 +73,8 @@ function renderG2BarChart(container, options) {
|
|
|
72
73
|
grid: false,
|
|
73
74
|
isHorizontal,
|
|
74
75
|
dataCount: xValueCount,
|
|
75
|
-
containerWidth: container.clientWidth
|
|
76
|
+
containerWidth: container.clientWidth,
|
|
77
|
+
minLabelWidth
|
|
76
78
|
});
|
|
77
79
|
applyAxisY(view, {
|
|
78
80
|
labelFormatter: formatAxis
|
|
@@ -91,14 +93,14 @@ function renderG2BarChart(container, options) {
|
|
|
91
93
|
interval.tooltip({
|
|
92
94
|
items: [
|
|
93
95
|
(datum)=>({
|
|
94
|
-
value: datum[Y_AXIS_FIELD],
|
|
96
|
+
value: null === datum[Y_AXIS_FIELD] ? '-' : datum[Y_AXIS_FIELD],
|
|
95
97
|
name: datum['groupType'],
|
|
96
98
|
indicatorId: datum['groupType'],
|
|
97
99
|
channel: Y_AXIS_FIELD,
|
|
98
100
|
color: getColorByGroupType(datum['groupType'], colorOpts) || 'transparent'
|
|
99
101
|
}),
|
|
100
102
|
isCompare ? (datum)=>({
|
|
101
|
-
value: datum[Y_AXIS_FIELD],
|
|
103
|
+
value: null === datum[Y_AXIS_FIELD] ? '-' : datum[Y_AXIS_FIELD],
|
|
102
104
|
compareTime: datum?.compareTime,
|
|
103
105
|
name: datum['groupType'],
|
|
104
106
|
indicatorId: datum['groupType'].replace('_compare', ''),
|
|
@@ -16,6 +16,7 @@ function renderG2CombineChart(container, options) {
|
|
|
16
16
|
insetBottom: 0,
|
|
17
17
|
animate: null
|
|
18
18
|
});
|
|
19
|
+
const minLabelWidth = data.some((d)=>d.groupName.length < 3) ? 30 : 90;
|
|
19
20
|
const view = getMainView(chart);
|
|
20
21
|
view.attr('marginLeft', 0).attr('marginRight', 30).attr('marginTop', 16).attr('marginBottom', 0).animate(false);
|
|
21
22
|
view.data(data);
|
|
@@ -24,7 +25,8 @@ function renderG2CombineChart(container, options) {
|
|
|
24
25
|
title: false,
|
|
25
26
|
grid: false,
|
|
26
27
|
dataCount: xValueCount,
|
|
27
|
-
containerWidth: container.clientWidth
|
|
28
|
+
containerWidth: container.clientWidth,
|
|
29
|
+
minLabelWidth
|
|
28
30
|
});
|
|
29
31
|
const barColor = themeColors[0] ?? "#5B8FF9";
|
|
30
32
|
applyHighlightDate(view, x, data, highlightDate, isHighlight);
|
|
@@ -16,6 +16,7 @@ function renderG2LineChart(container, options) {
|
|
|
16
16
|
paddingBottom: 0,
|
|
17
17
|
insetBottom: 0
|
|
18
18
|
});
|
|
19
|
+
const minLabelWidth = data.some((d)=>d.groupName.length < 3) ? 30 : 90;
|
|
19
20
|
const view = getMainView(chart);
|
|
20
21
|
view.attr('marginLeft', 0).attr('marginRight', 30).attr('marginTop', 10).attr('marginBottom', isLegend ? 0 : 16).animate(false);
|
|
21
22
|
view.data(data);
|
|
@@ -42,7 +43,8 @@ function renderG2LineChart(container, options) {
|
|
|
42
43
|
applyAxisX(view, {
|
|
43
44
|
grid: false,
|
|
44
45
|
dataCount: xValueCount,
|
|
45
|
-
containerWidth: container.clientWidth
|
|
46
|
+
containerWidth: container.clientWidth,
|
|
47
|
+
minLabelWidth
|
|
46
48
|
});
|
|
47
49
|
applyAxisY(view, {
|
|
48
50
|
labelFormatter: formatAxis
|
|
@@ -14,7 +14,7 @@ const G2CompareTooltip = ({ isGroupBar = false, title, items, safeIndicatorMap,
|
|
|
14
14
|
/*#__PURE__*/ jsx("div", {
|
|
15
15
|
children: title
|
|
16
16
|
}),
|
|
17
|
-
items?.map(({ color, value, isChange, compareTime, indicatorId, name, percent, hidden, isCombine }, index)=>{
|
|
17
|
+
items?.map(({ color, value, isChange, compareTime, indicatorId, name, percent, hidden, isCombine, dataType }, index)=>{
|
|
18
18
|
if (isCombine) combineIndicatorId = indicatorId ?? "";
|
|
19
19
|
let isFirst = false;
|
|
20
20
|
if (0 === index) auxiIndicatorId = indicatorId ?? "";
|
|
@@ -22,6 +22,7 @@ const G2CompareTooltip = ({ isGroupBar = false, title, items, safeIndicatorMap,
|
|
|
22
22
|
isFirst = true;
|
|
23
23
|
uniqueColors.push(color);
|
|
24
24
|
}
|
|
25
|
+
if (combineIndicatorId === auxiIndicatorId && '-' === value && 'manual' === dataType) return null;
|
|
25
26
|
return !hidden && /*#__PURE__*/ jsxs("div", {
|
|
26
27
|
style: {
|
|
27
28
|
display: "flex",
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@publishfx/publish-chart",
|
|
3
|
-
"version": "2.1.
|
|
3
|
+
"version": "2.1.30",
|
|
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": [
|