onesight-charts 1.4.2 → 1.4.3
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.
|
@@ -55,37 +55,13 @@ function CommonBar(props) {
|
|
|
55
55
|
}
|
|
56
56
|
} = props;
|
|
57
57
|
const [total, setTotal] = (0, import_react.useState)(0);
|
|
58
|
-
|
|
58
|
+
const chart = (0, import_react.useRef)(null);
|
|
59
59
|
const [currentPage, setCurrentPage] = (0, import_react.useState)(1);
|
|
60
60
|
const chartRef = (0, import_react.useRef)(null);
|
|
61
61
|
const prevDepsRef = (0, import_react.useRef)(null);
|
|
62
62
|
const tooltipClassNameRef = (0, import_react.useRef)(
|
|
63
63
|
`onesight-chart-common-bar-tooltip-${Date.now()}-${Math.random().toString(36).substr(2, 9)}`
|
|
64
64
|
);
|
|
65
|
-
(0, import_react.useEffect)(() => {
|
|
66
|
-
const currentDeps = JSON.stringify({ currentPage, data });
|
|
67
|
-
const prevDeps = prevDepsRef.current;
|
|
68
|
-
if (prevDeps !== null && currentDeps === prevDeps) {
|
|
69
|
-
return;
|
|
70
|
-
}
|
|
71
|
-
prevDepsRef.current = currentDeps;
|
|
72
|
-
let copyData = JSON.parse(JSON.stringify(data));
|
|
73
|
-
let splice_data = copyData.slice(
|
|
74
|
-
(currentPage - 1) * number,
|
|
75
|
-
currentPage * number
|
|
76
|
-
);
|
|
77
|
-
if (data.length) {
|
|
78
|
-
setTotal(Math.ceil(data.length / number));
|
|
79
|
-
}
|
|
80
|
-
init2(splice_data);
|
|
81
|
-
callbackGetPage(currentPage);
|
|
82
|
-
setTimeout(() => {
|
|
83
|
-
bindClickEvents();
|
|
84
|
-
}, 0);
|
|
85
|
-
return () => {
|
|
86
|
-
unbindClickEvents();
|
|
87
|
-
};
|
|
88
|
-
}, [currentPage, data, bindClickEvents, unbindClickEvents]);
|
|
89
65
|
const paginationCb = (currData, page) => {
|
|
90
66
|
setCurrentPage(page);
|
|
91
67
|
};
|
|
@@ -94,15 +70,13 @@ function CommonBar(props) {
|
|
|
94
70
|
const tooltipElement = event.target.closest(
|
|
95
71
|
`.${tooltipClassNameRef.current}`
|
|
96
72
|
);
|
|
97
|
-
if (!tooltipElement)
|
|
73
|
+
if (!tooltipElement)
|
|
98
74
|
return;
|
|
99
|
-
}
|
|
100
75
|
const seriesNameElement = event.target.closest(".item");
|
|
101
76
|
if (seriesNameElement) {
|
|
102
77
|
const seriesItem = seriesNameElement.getAttribute("data-series-item");
|
|
103
|
-
if (!seriesItem)
|
|
78
|
+
if (!seriesItem)
|
|
104
79
|
return;
|
|
105
|
-
}
|
|
106
80
|
const seriesData = JSON.parse(seriesItem);
|
|
107
81
|
handleClick && handleClick("tooltipType", seriesData);
|
|
108
82
|
}
|
|
@@ -121,6 +95,35 @@ function CommonBar(props) {
|
|
|
121
95
|
chartElement.removeEventListener("click", onChartClick);
|
|
122
96
|
}
|
|
123
97
|
}, [onChartClick]);
|
|
98
|
+
(0, import_react.useEffect)(() => {
|
|
99
|
+
const currentDeps = JSON.stringify({ currentPage, data });
|
|
100
|
+
const prevDeps = prevDepsRef.current;
|
|
101
|
+
if (prevDeps !== null && currentDeps === prevDeps)
|
|
102
|
+
return;
|
|
103
|
+
prevDepsRef.current = currentDeps;
|
|
104
|
+
const copyData = JSON.parse(JSON.stringify(data));
|
|
105
|
+
const splice_data = copyData.slice(
|
|
106
|
+
(currentPage - 1) * number,
|
|
107
|
+
currentPage * number
|
|
108
|
+
);
|
|
109
|
+
if (data.length)
|
|
110
|
+
setTotal(Math.ceil(data.length / number));
|
|
111
|
+
init2(splice_data);
|
|
112
|
+
callbackGetPage(currentPage);
|
|
113
|
+
setTimeout(() => {
|
|
114
|
+
bindClickEvents();
|
|
115
|
+
}, 0);
|
|
116
|
+
return () => {
|
|
117
|
+
unbindClickEvents();
|
|
118
|
+
};
|
|
119
|
+
}, [
|
|
120
|
+
currentPage,
|
|
121
|
+
data,
|
|
122
|
+
bindClickEvents,
|
|
123
|
+
unbindClickEvents,
|
|
124
|
+
number,
|
|
125
|
+
callbackGetPage
|
|
126
|
+
]);
|
|
124
127
|
function toggleAxisPointer(myChart, show) {
|
|
125
128
|
myChart.setOption({
|
|
126
129
|
tooltip: {
|
|
@@ -136,35 +139,30 @@ function CommonBar(props) {
|
|
|
136
139
|
return String(jsonString).replace(/&/g, "&").replace(/"/g, """).replace(/'/g, "'").replace(/</g, "<").replace(/>/g, ">");
|
|
137
140
|
}
|
|
138
141
|
const calculateWidth = (len) => {
|
|
139
|
-
if (len === 1 || len === 2 || len === 3)
|
|
142
|
+
if (len === 1 || len === 2 || len === 3)
|
|
140
143
|
return 42;
|
|
141
|
-
|
|
144
|
+
if (len === 4)
|
|
142
145
|
return 40;
|
|
143
|
-
|
|
146
|
+
if (len === 5)
|
|
144
147
|
return 32;
|
|
145
|
-
|
|
148
|
+
if (len === 6)
|
|
146
149
|
return 26;
|
|
147
|
-
|
|
150
|
+
if (len === 7)
|
|
148
151
|
return 24;
|
|
149
|
-
|
|
152
|
+
if (len === 8)
|
|
150
153
|
return 20;
|
|
151
|
-
|
|
154
|
+
if (len === 9)
|
|
152
155
|
return 18;
|
|
153
|
-
|
|
156
|
+
if (len === 10)
|
|
154
157
|
return 16;
|
|
155
|
-
|
|
158
|
+
return 16;
|
|
156
159
|
};
|
|
157
160
|
function setBarData(myChart, newData) {
|
|
158
161
|
if (!myChart)
|
|
159
162
|
return;
|
|
160
163
|
myChart.setOption(
|
|
161
164
|
{
|
|
162
|
-
series: [
|
|
163
|
-
// 背景柱(seriesIndex 0)保持不变
|
|
164
|
-
{},
|
|
165
|
-
// 前景柱(seriesIndex 1)换成新数组
|
|
166
|
-
{ data: newData }
|
|
167
|
-
]
|
|
165
|
+
series: [{}, { data: newData }]
|
|
168
166
|
},
|
|
169
167
|
false
|
|
170
168
|
);
|
|
@@ -180,14 +178,10 @@ function CommonBar(props) {
|
|
|
180
178
|
fontWeight: 500,
|
|
181
179
|
lineHeight: 20,
|
|
182
180
|
align: "right",
|
|
183
|
-
// 文本宽度 = 总宽 - 图标宽度 - 间距
|
|
184
|
-
// width: Math.max(0, maxLabelWidth - ICON_SIZE - ICON_GAP),
|
|
185
181
|
overflow: "truncate",
|
|
186
182
|
ellipsis: "...",
|
|
187
|
-
// 如果没有任何图标,则不需要左边距
|
|
188
183
|
padding: hasAnyIcon ? [0, 0, 0, ICON_GAP] : [0, 0, 0, 0]
|
|
189
184
|
},
|
|
190
|
-
// 为没有图标的项目创建一个空的样式
|
|
191
185
|
noIcon: {
|
|
192
186
|
width: 0,
|
|
193
187
|
height: 0
|
|
@@ -200,15 +194,10 @@ function CommonBar(props) {
|
|
|
200
194
|
height: ICON_SIZE,
|
|
201
195
|
align: "right",
|
|
202
196
|
borderRadius: 4,
|
|
203
|
-
// 这里用图片作为文本块的背景
|
|
204
197
|
backgroundColor: { image: row.platformIcon }
|
|
205
|
-
// 建议传绝对路径或 public 下的路径
|
|
206
198
|
};
|
|
207
199
|
} else {
|
|
208
|
-
rich[`icon${i}`] = {
|
|
209
|
-
width: 0,
|
|
210
|
-
height: 0
|
|
211
|
-
};
|
|
200
|
+
rich[`icon${i}`] = { width: 0, height: 0 };
|
|
212
201
|
}
|
|
213
202
|
});
|
|
214
203
|
return rich;
|
|
@@ -221,9 +210,8 @@ function CommonBar(props) {
|
|
|
221
210
|
if (!labelText)
|
|
222
211
|
return "";
|
|
223
212
|
const fullRect = echarts.format.getTextRect(labelText, font);
|
|
224
|
-
if (fullRect.width <= maxWidthPx)
|
|
213
|
+
if (fullRect.width <= maxWidthPx)
|
|
225
214
|
return labelText;
|
|
226
|
-
}
|
|
227
215
|
const DOT = "...";
|
|
228
216
|
const dotW = echarts.format.getTextRect(DOT, font).width;
|
|
229
217
|
let prefixLen = 1;
|
|
@@ -239,9 +227,8 @@ function CommonBar(props) {
|
|
|
239
227
|
best = candidate;
|
|
240
228
|
bestW = w;
|
|
241
229
|
prefixLen++;
|
|
242
|
-
if (prefixLen % 2 === 0)
|
|
230
|
+
if (prefixLen % 2 === 0)
|
|
243
231
|
suffixLen++;
|
|
244
|
-
}
|
|
245
232
|
} else {
|
|
246
233
|
break;
|
|
247
234
|
}
|
|
@@ -260,39 +247,12 @@ function CommonBar(props) {
|
|
|
260
247
|
let fadedData = null;
|
|
261
248
|
let lastIndex = null;
|
|
262
249
|
const axisData = currentData.map((item) => item.format || item.name || "-");
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
label: {
|
|
270
|
-
// 负数就把文字放左边,正数/0 放右边
|
|
271
|
-
position: (item == null ? void 0 : item.proportion) < 0 ? "left" : "right"
|
|
272
|
-
},
|
|
273
|
-
itemStyle: (item == null ? void 0 : item.proportion) ? { color: itemColor } : { color: "rgba(29, 169, 160, 0)" }
|
|
274
|
-
};
|
|
275
|
-
} else {
|
|
276
|
-
return {
|
|
277
|
-
name: item.name || "-",
|
|
278
|
-
value: item.value || 0,
|
|
279
|
-
label: {
|
|
280
|
-
// 负数就把文字放左边,正数/0 放右边
|
|
281
|
-
position: item.value < 0 ? "left" : "right"
|
|
282
|
-
},
|
|
283
|
-
itemStyle: item.value ? { color: itemColor } : { color: "rgba(29, 169, 160, 0)" }
|
|
284
|
-
};
|
|
285
|
-
}
|
|
286
|
-
});
|
|
287
|
-
const originalData = seriesData.map((d) => ({
|
|
288
|
-
...d,
|
|
289
|
-
itemStyle: { ...d.itemStyle || {}, opacity: 1 }
|
|
290
|
-
}));
|
|
291
|
-
let maxDataValue = Math.max(
|
|
292
|
-
...currentData.map(
|
|
293
|
-
(item) => showProportion ? item == null ? void 0 : item.proportion : item.value
|
|
294
|
-
)
|
|
295
|
-
);
|
|
250
|
+
const yIconFlag = (_a = data == null ? void 0 : data[0]) == null ? void 0 : _a.platformIcon;
|
|
251
|
+
const valueAccessor = (item) => showProportion ? (item == null ? void 0 : item.proportion) || 0 : item.value || 0;
|
|
252
|
+
const maxDataValue = Math.max(...currentData.map(valueAccessor));
|
|
253
|
+
const minDataValue = Math.min(...currentData.map(valueAccessor));
|
|
254
|
+
const hasNegative = minDataValue < 0;
|
|
255
|
+
const allNegative = maxDataValue < 0;
|
|
296
256
|
const ySample = axisData.reduce(
|
|
297
257
|
(a, b) => a.length > b.length ? a : b,
|
|
298
258
|
""
|
|
@@ -313,12 +273,9 @@ function CommonBar(props) {
|
|
|
313
273
|
sampleText,
|
|
314
274
|
"14px sans-serif"
|
|
315
275
|
).width;
|
|
316
|
-
const
|
|
317
|
-
const
|
|
318
|
-
const
|
|
319
|
-
const minDataValue = Math.min(...currentData.map(valueAccessor));
|
|
320
|
-
const hasNegative = minDataValue < 0;
|
|
321
|
-
const allNegative = maxDataValue < 0;
|
|
276
|
+
const LABEL_DISTANCE = 5;
|
|
277
|
+
const SAFE_PX = 12;
|
|
278
|
+
const extra = 15 + LABEL_DISTANCE + SAFE_PX;
|
|
322
279
|
let bgValue;
|
|
323
280
|
if (allNegative) {
|
|
324
281
|
bgValue = 0;
|
|
@@ -326,7 +283,7 @@ function CommonBar(props) {
|
|
|
326
283
|
bgValue = maxDataValue * barAreaWidth / (barAreaWidth - labelWidth - extra);
|
|
327
284
|
} else {
|
|
328
285
|
const overflowPx = labelWidth + extra - barAreaWidth;
|
|
329
|
-
const unitPerPx = maxDataValue / barAreaWidth;
|
|
286
|
+
const unitPerPx = maxDataValue / Math.max(barAreaWidth, 1);
|
|
330
287
|
bgValue = maxDataValue + overflowPx * unitPerPx;
|
|
331
288
|
}
|
|
332
289
|
let minBgValue = 0;
|
|
@@ -365,7 +322,7 @@ function CommonBar(props) {
|
|
|
365
322
|
negativeBarAreaWidth - minLabelWidth - minExtra
|
|
366
323
|
);
|
|
367
324
|
const dataPerPixel = absMinDataValue / availableBarWidth;
|
|
368
|
-
const labelSpaceInData = (minLabelWidth + minExtra) * dataPerPixel;
|
|
325
|
+
const labelSpaceInData = (minLabelWidth + minExtra) * dataPerPixel * 1.3;
|
|
369
326
|
minBgValue = -(absMinDataValue + labelSpaceInData);
|
|
370
327
|
if (maxDataValue > 0 && !allNegative) {
|
|
371
328
|
const positiveBarAreaWidth = barAreaWidth - negativeBarAreaWidth;
|
|
@@ -378,22 +335,48 @@ function CommonBar(props) {
|
|
|
378
335
|
}
|
|
379
336
|
}
|
|
380
337
|
}
|
|
338
|
+
const MIN_BAR_PX = 4;
|
|
339
|
+
const safeBarAreaWidth = Math.max(1, barAreaWidth);
|
|
340
|
+
let axisSpan = bgValue - minBgValue;
|
|
341
|
+
axisSpan = Math.max(axisSpan, 1);
|
|
342
|
+
let minVisibleValue = axisSpan * (MIN_BAR_PX / safeBarAreaWidth);
|
|
343
|
+
minVisibleValue = Math.max(minVisibleValue, 1);
|
|
344
|
+
if (hasNegative) {
|
|
345
|
+
minBgValue = Math.min(minBgValue, -minVisibleValue * 1.1);
|
|
346
|
+
axisSpan = Math.max(bgValue - minBgValue, 1);
|
|
347
|
+
minVisibleValue = Math.max(axisSpan * (MIN_BAR_PX / safeBarAreaWidth), 1);
|
|
348
|
+
}
|
|
349
|
+
const seriesData = currentData.map((item) => {
|
|
350
|
+
const itemColor = item.color || barColor;
|
|
351
|
+
const raw = valueAccessor(item);
|
|
352
|
+
const displayValue = raw === 0 ? 0 : Math.sign(raw) * Math.max(Math.abs(raw), minVisibleValue);
|
|
353
|
+
return {
|
|
354
|
+
name: item.name || "-",
|
|
355
|
+
rawValue: raw,
|
|
356
|
+
value: displayValue,
|
|
357
|
+
label: {
|
|
358
|
+
position: raw < 0 ? "left" : "right"
|
|
359
|
+
},
|
|
360
|
+
itemStyle: raw ? { color: itemColor } : { color: "rgba(29, 169, 160, 0)" }
|
|
361
|
+
};
|
|
362
|
+
});
|
|
363
|
+
const originalData = seriesData.map((d) => ({
|
|
364
|
+
...d,
|
|
365
|
+
itemStyle: { ...d.itemStyle || {}, opacity: 1 }
|
|
366
|
+
}));
|
|
381
367
|
let option = {
|
|
382
368
|
tooltip: {
|
|
383
369
|
className: `onesight-chart-common-bar-tooltip ${tooltipClassNameRef.current}`,
|
|
384
370
|
trigger: "axis",
|
|
385
371
|
enterable: true,
|
|
386
|
-
// showContent: true,
|
|
387
|
-
// alwaysShowContent: true,
|
|
388
|
-
// hideDelay: 1000000000,
|
|
389
372
|
padding: 0,
|
|
390
373
|
position: (point, params, dom) => {
|
|
391
374
|
const tooltipHeight = (dom == null ? void 0 : dom.offsetHeight) || 0;
|
|
392
375
|
const currentHeight = myDom.offsetHeight;
|
|
393
|
-
|
|
376
|
+
const len = axisData.length > 10 ? 10 : axisData.length;
|
|
394
377
|
let yValue = 0;
|
|
395
378
|
if (tooltipHeight) {
|
|
396
|
-
|
|
379
|
+
const dataIndex = params[0].dataIndex;
|
|
397
380
|
yValue = currentHeight / len * dataIndex - tooltipHeight - 12;
|
|
398
381
|
}
|
|
399
382
|
return [290 - (278 + 2) / 2, yValue];
|
|
@@ -401,82 +384,68 @@ function CommonBar(props) {
|
|
|
401
384
|
axisPointer: {
|
|
402
385
|
type: "shadow",
|
|
403
386
|
z: 1,
|
|
404
|
-
shadowStyle: {
|
|
405
|
-
color: "rgba(243,244,244,1)"
|
|
406
|
-
},
|
|
387
|
+
shadowStyle: { color: "rgba(243,244,244,1)" },
|
|
407
388
|
clickable: true
|
|
408
389
|
},
|
|
409
390
|
formatter: (res) => {
|
|
410
391
|
var _a2, _b;
|
|
411
|
-
if (!res.some((i) => i.value !== void 0 && i.value !== null))
|
|
392
|
+
if (!res.some((i) => i.value !== void 0 && i.value !== null))
|
|
412
393
|
return "";
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
let triangleWidth = 280;
|
|
394
|
+
const dataArr = [res[1]];
|
|
395
|
+
const currentColor = ((_a2 = res[1]) == null ? void 0 : _a2.color) || "#1DA9A0";
|
|
396
|
+
const triangleWidth = 280;
|
|
417
397
|
const dataIndex = (_b = res[1]) == null ? void 0 : _b.dataIndex;
|
|
418
398
|
const originalItem = currentData[dataIndex];
|
|
419
399
|
return `<div class='onesight-chart-common-bar-tooltip-box' style="width:278px;position: relative;">
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
|
|
400
|
+
${isTooltipTitleShow ? `<div class="tooltip-head">${res[0].format || res[0].name}</div>` : ""}
|
|
401
|
+
<div class='tooltip-body'>
|
|
402
|
+
${dataArr.map((item) => {
|
|
403
|
+
var _a3;
|
|
404
|
+
const raw = ((_a3 = item == null ? void 0 : item.data) == null ? void 0 : _a3.rawValue) !== void 0 ? item.data.rawValue : item.value;
|
|
425
405
|
const itemWithAlias = {
|
|
426
406
|
...item,
|
|
427
407
|
alias: originalItem == null ? void 0 : originalItem.alias,
|
|
428
408
|
alias2: originalItem == null ? void 0 : originalItem.alias2,
|
|
429
|
-
aliasArray: originalItem == null ? void 0 : originalItem.aliasArray
|
|
409
|
+
aliasArray: originalItem == null ? void 0 : originalItem.aliasArray,
|
|
410
|
+
rawValue: raw
|
|
430
411
|
};
|
|
431
412
|
const escapedJson = escapeHtmlAttribute(
|
|
432
413
|
JSON.stringify(itemWithAlias)
|
|
433
414
|
);
|
|
434
415
|
return `<div class='item' data-series-item="${escapedJson}" key='${item.seriesName}'>
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
|
|
442
|
-
|
|
443
|
-
</span>
|
|
444
|
-
</div>
|
|
445
|
-
</div>`;
|
|
416
|
+
<div class='l'>
|
|
417
|
+
<span style="display:inline-block;width: 14px;vertical-align: middle;height: 14px;background-color:${currentColor};border-radius: 4px;margin-bottom: 2px;margin-right:6px"></span>
|
|
418
|
+
<span>${tooltipItemName ? res[0].format || res[0].name : tipName}</span>
|
|
419
|
+
</div>
|
|
420
|
+
<div class='r' style="padding-left:6px;">
|
|
421
|
+
<span class='num'>${showProportion ? (0, import_chartUtils.computeFloat)(raw) : (0, import_chartUtils.changeDataTypeEn)(raw)}</span>
|
|
422
|
+
</div>
|
|
423
|
+
</div>`;
|
|
446
424
|
}).join("")}
|
|
447
|
-
|
|
448
|
-
|
|
449
|
-
|
|
425
|
+
</div>
|
|
426
|
+
<div class='triangle-down' style='width:${triangleWidth}px'></div>
|
|
427
|
+
</div>`;
|
|
450
428
|
}
|
|
451
429
|
},
|
|
452
430
|
animation: true,
|
|
453
431
|
animationEasing: "cubicInOut",
|
|
454
432
|
animationEasingUpdate: "cubicInOut",
|
|
455
|
-
legend: {
|
|
456
|
-
show: false
|
|
457
|
-
},
|
|
433
|
+
legend: { show: false },
|
|
458
434
|
grid: {
|
|
459
435
|
top: 0,
|
|
460
|
-
// bottom: 30,
|
|
461
436
|
bottom: 0,
|
|
462
437
|
left: 12,
|
|
463
|
-
right:
|
|
438
|
+
right: 0,
|
|
464
439
|
containLabel: true
|
|
465
440
|
},
|
|
466
441
|
xAxis: {
|
|
467
442
|
type: "value",
|
|
468
443
|
max: bgValue,
|
|
469
|
-
min:
|
|
444
|
+
min: minBgValue,
|
|
470
445
|
show: false,
|
|
471
|
-
axisLine: {
|
|
472
|
-
|
|
473
|
-
},
|
|
474
|
-
axisLabel: {
|
|
475
|
-
show: false
|
|
476
|
-
},
|
|
477
|
-
splitLine: {
|
|
478
|
-
show: false
|
|
479
|
-
},
|
|
446
|
+
axisLine: { show: false },
|
|
447
|
+
axisLabel: { show: false },
|
|
448
|
+
splitLine: { show: false },
|
|
480
449
|
boundaryGap: false
|
|
481
450
|
},
|
|
482
451
|
yAxis: {
|
|
@@ -491,27 +460,13 @@ function CommonBar(props) {
|
|
|
491
460
|
show: true,
|
|
492
461
|
interval: 0,
|
|
493
462
|
rotate: 0,
|
|
494
|
-
// width: 188,
|
|
495
463
|
overflow: "truncate",
|
|
496
464
|
ellipsis: "...",
|
|
497
|
-
// formatter: function (value, index) {
|
|
498
|
-
// // 检查当前项是否有 platformIcon
|
|
499
|
-
// if (yIconFlag) {
|
|
500
|
-
// return `{icon${index}|} {label|${value}}`;
|
|
501
|
-
// } else {
|
|
502
|
-
// return value;
|
|
503
|
-
// }
|
|
504
|
-
// },
|
|
505
465
|
formatter: function(value, index) {
|
|
506
466
|
var _a2;
|
|
507
467
|
const rowHasIcon = !!(yIconFlag && ((_a2 = currentData[index]) == null ? void 0 : _a2.platformIcon));
|
|
508
468
|
const maxPx = getMaxTextWidthForRow(rowHasIcon);
|
|
509
|
-
const finalText = middleEllipsis(
|
|
510
|
-
value,
|
|
511
|
-
maxPx,
|
|
512
|
-
"14px sans-serif"
|
|
513
|
-
// 跟 axisLabel 字体保持一致
|
|
514
|
-
);
|
|
469
|
+
const finalText = middleEllipsis(value, maxPx, "14px sans-serif");
|
|
515
470
|
if (yIconFlag) {
|
|
516
471
|
return `{icon${index}|} {label|${finalText}}`;
|
|
517
472
|
} else {
|
|
@@ -519,82 +474,55 @@ function CommonBar(props) {
|
|
|
519
474
|
}
|
|
520
475
|
}
|
|
521
476
|
},
|
|
522
|
-
axisTick: {
|
|
523
|
-
|
|
524
|
-
},
|
|
525
|
-
axisLine: {
|
|
526
|
-
show: false
|
|
527
|
-
},
|
|
528
|
-
splitLine: {
|
|
529
|
-
show: false
|
|
530
|
-
},
|
|
477
|
+
axisTick: { show: false },
|
|
478
|
+
axisLine: { show: false },
|
|
479
|
+
splitLine: { show: false },
|
|
531
480
|
data: axisData
|
|
532
481
|
},
|
|
533
482
|
series: [
|
|
534
483
|
{
|
|
535
|
-
// === 背景柱系列 ===
|
|
536
|
-
// 需要背景柱的原因是让柱状条加上后面的数字标签的和不超过悬浮上去的阴影的长度
|
|
537
484
|
name: "背景条",
|
|
538
485
|
type: "bar",
|
|
539
|
-
// 让它在最底层
|
|
540
486
|
z: 1,
|
|
541
|
-
// 不需要点击/hover 交互
|
|
542
487
|
silent: true,
|
|
543
|
-
// 让柱子和后面的柱子重叠在同一个类目位置
|
|
544
488
|
barGap: "-100%",
|
|
545
|
-
emphasis: {
|
|
546
|
-
|
|
547
|
-
},
|
|
548
|
-
// 柱子的样式
|
|
549
|
-
itemStyle: {
|
|
550
|
-
color: "rgba(0, 0, 0, 0)"
|
|
551
|
-
// 背景色可自定义
|
|
552
|
-
},
|
|
553
|
-
// 这里的 data 根据正负数使用不同的背景值
|
|
489
|
+
emphasis: { disabled: true },
|
|
490
|
+
itemStyle: { color: "rgba(0, 0, 0, 0)" },
|
|
554
491
|
data: currentData.map((item) => {
|
|
555
|
-
const
|
|
556
|
-
return
|
|
492
|
+
const v = valueAccessor(item);
|
|
493
|
+
return v < 0 ? minBgValue : bgValue;
|
|
557
494
|
}),
|
|
558
|
-
// 根据你需要的柱宽
|
|
559
|
-
// barMaxWidth: 42,
|
|
560
|
-
// barMinWidth: 16,
|
|
561
495
|
barWidth: calculateWidth(seriesData.length),
|
|
496
|
+
// 这里留着也无所谓,但“最小可见长度”由方案B控制
|
|
562
497
|
barMinHeight: 4,
|
|
498
|
+
barMinWidth: 4,
|
|
563
499
|
cursor: "pointer",
|
|
564
500
|
animation: false,
|
|
565
501
|
showBackground: false
|
|
566
|
-
// 这层本身不再需要 showBackground
|
|
567
502
|
},
|
|
568
503
|
{
|
|
569
504
|
type: "bar",
|
|
570
|
-
// showBackground: true,
|
|
571
505
|
label: {
|
|
572
506
|
show: true,
|
|
573
|
-
// position: 'right',
|
|
574
507
|
fontWeight: 400,
|
|
575
508
|
fontSize: 14,
|
|
576
509
|
color: "#515E5F",
|
|
577
510
|
distance: 5,
|
|
578
511
|
formatter: (params) => {
|
|
579
|
-
|
|
580
|
-
|
|
581
|
-
|
|
582
|
-
return (0, import_chartUtils.numberFormatNull)(params.value);
|
|
583
|
-
}
|
|
512
|
+
var _a2;
|
|
513
|
+
const raw = ((_a2 = params == null ? void 0 : params.data) == null ? void 0 : _a2.rawValue) ?? params.value;
|
|
514
|
+
return showProportion ? (0, import_chartUtils.computeFloat)(raw) : (0, import_chartUtils.numberFormatNull)(raw);
|
|
584
515
|
}
|
|
585
516
|
},
|
|
586
|
-
emphasis: {
|
|
587
|
-
disabled: true
|
|
588
|
-
},
|
|
517
|
+
emphasis: { disabled: true },
|
|
589
518
|
itemStyle: {
|
|
590
519
|
borderColor: "rgba(0,0,0,0)",
|
|
591
520
|
borderWidth: 0,
|
|
592
521
|
borderType: "solid"
|
|
593
522
|
},
|
|
594
|
-
// barMaxWidth: 42,
|
|
595
|
-
// barMinWidth: 16,
|
|
596
523
|
barWidth: calculateWidth(seriesData.length),
|
|
597
524
|
barMinHeight: 4,
|
|
525
|
+
barMinWidth: 4,
|
|
598
526
|
cursor: "pointer",
|
|
599
527
|
animation: false,
|
|
600
528
|
data: seriesData
|
|
@@ -605,8 +533,8 @@ function CommonBar(props) {
|
|
|
605
533
|
option.yAxis.axisLabel.rich = makeYAxisRich(currentData);
|
|
606
534
|
}
|
|
607
535
|
myChart.getZr().on("click", function(params) {
|
|
608
|
-
|
|
609
|
-
|
|
536
|
+
const pointInPixel = [params.offsetX, params.offsetY];
|
|
537
|
+
const dataCoord = myChart.convertFromPixel(
|
|
610
538
|
{ seriesIndex: 0 },
|
|
611
539
|
pointInPixel
|
|
612
540
|
);
|
|
@@ -663,9 +591,7 @@ function CommonBar(props) {
|
|
|
663
591
|
(0, import_chartUtils.dealBarPath)(myDom, true);
|
|
664
592
|
});
|
|
665
593
|
myChart.setOption(option, true);
|
|
666
|
-
const element = document.querySelector(
|
|
667
|
-
`.${tooltipClassNameRef.current}`
|
|
668
|
-
);
|
|
594
|
+
const element = document.querySelector(`.${tooltipClassNameRef.current}`);
|
|
669
595
|
if (element) {
|
|
670
596
|
element.addEventListener("mouseleave", function(event) {
|
|
671
597
|
if (event && element.offsetHeight && event.offsetY < element.offsetHeight - 2) {
|