Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
"changes": [
{
"comment": "修复瀑布图堆积标签忽略 formatter 配置的问题(#4487)。",
"type": "none",
"packageName": "@visactor/vchart"
}
],
"packageName": "@visactor/vchart",
"email": "dingling112@gmail.com"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
import { assertionError } from '../../../assertions.mjs';
import { verifyRendered, verifySpec } from '../../../helpers.mjs';

/**
* 验证目的:瀑布图堆积标签按 formatter 对变化值保留四位小数。
* 场景条件:第一根柱需要补零,第二根柱需要舍入,且其变化值与累计值不同。
* 覆盖边界:断言垂直瀑布图中两根数据柱的可见标签文本,截图检查标签与柱的布局。
*/
export default {
createSpec() {
return {
type: 'waterfall',
data: {
values: [
{ category: 'A', value: 1.2 },
{ category: 'B', value: 0.12567 }
]
},
xField: 'category',
yField: 'value',
total: { type: 'end', text: 'Total' },
stackLabel: { visible: true, valueType: 'change', formatter: '.4f' }
};
},
async verify(page) {
await verifySpec(page, this.createSpec());
await verifyRendered(page, 'label');

// 从图元读取文本和对应类目,确认格式化使用的是堆积变化值。
const labels = await page.evaluate(() => {
const stage = window.__visualChart.getStage();
return stage
.findAll(
graphic =>
graphic.type === 'text' &&
graphic.attribute.visible !== false &&
['A', 'B'].includes(graphic.attribute.data?.index),
true
)
.map(graphic => [graphic.attribute.data.index, graphic.attribute.text]);
});
const texts = new Map(labels);
if (labels.length !== 2 || texts.get('A') !== '1.2000' || texts.get('B') !== '0.1257') {
throw assertionError(`堆积变化值标签应为 A=1.2000、B=0.1257,实际为 ${JSON.stringify(labels)}`);
}
}
};
5 changes: 5 additions & 0 deletions packages/vchart/__tests__/visual/cases/index.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -766,6 +766,11 @@ export const cases = [
purpose: '瀑布图绝对值堆叠标签与字段总计',
file: './charts/waterfall/waterfall-absolute-label.mjs'
},
{
id: 'waterfall-stack-label-formatter',
purpose: '瀑布图堆积变化值标签的四位小数格式化',
file: './charts/waterfall/waterfall-stack-label-formatter.mjs'
},
{
id: 'waterfall-total-tag',
purpose: '瀑布图仅通过标记字段识别总计',
Expand Down
3 changes: 2 additions & 1 deletion packages/vchart/__tests__/visual/cases/manifest.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"schemaVersion": 1,
"indexDigest": "0f05d547be269348230381c38230b6846f2461dbdb31c85cb8f5e82158ace216",
"indexDigest": "83b7b6fa9376bebe53c3de32a5c1dba74ec1d7c8524f6d1d3578032066ec5d05",
"ids": [
"title-resize-legend-layout",
"injected-stage",
Expand Down Expand Up @@ -158,6 +158,7 @@
"line-end-label",
"waterfall-horizontal-total",
"waterfall-absolute-label",
"waterfall-stack-label-formatter",
"waterfall-total-tag",
"richtext-axis-marker",
"richtext-funnel-label",
Expand Down
2 changes: 1 addition & 1 deletion packages/vchart/src/component/label/util.ts
Original file line number Diff line number Diff line change
Expand Up @@ -288,7 +288,7 @@ export function stackLabel(
const offset = labelSpec.offset || 0;

const datum = datumTransform ? datumTransform(label.data) : label.data;
const attribute = textAttribute(labelInfo, datum, labelSpec.formatMethod);
const attribute = textAttribute(labelInfo, datum, labelSpec.formatMethod, labelSpec.formatter);

attribute.x = stackLabelX(datum, series, pos, offset);
attribute.y = stackLabelY(datum, series, pos, offset);
Expand Down
Loading