Skip to content
Open
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
11 changes: 6 additions & 5 deletions src/plots/funnel/geometries/common.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,12 @@ export function transformData(
// format 数据
formatData = map(data, (row, index) => {
const percent = (row[yField] || 0) / maxYFieldValue;
row[FUNNEL_PERCENT] = percent;
row[FUNNEL_MAPPING_VALUE] = (max - min) * percent + min;
// 转化率数据存储前后数据
row[FUNNEL_CONVERSATION] = [get(data, [index - 1, yField]), row[yField]];
return row;
return {
...row,
[FUNNEL_PERCENT]: percent,
[FUNNEL_MAPPING_VALUE]: (max - min) * percent + min,
[FUNNEL_CONVERSATION]: [get(data, [index - 1, yField]), row[yField]],
};
});
Comment on lines 26 to 34

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

这个修改很棒,通过返回新对象而不是修改原始对象,避免了副作用。为了保证这个修复的长期有效性并防止回归,建议增加一个单元测试来验证 transformData 的调用不会修改传入的 data 数组中的对象。例如,可以在测试中保留一份原始数据的副本,并在调用 render 后断言原始数据未被更改。


return formatData;
Expand Down