Skip to content

docs: add waterfall component documentation#3002

Merged
lxfu1 merged 1 commit into
v2from
docs/waterfall-component
Jun 26, 2025
Merged

docs: add waterfall component documentation#3002
lxfu1 merged 1 commit into
v2from
docs/waterfall-component

Conversation

@lxfu1
Copy link
Copy Markdown
Member

@lxfu1 lxfu1 commented Jun 26, 2025

Summary by CodeRabbit

  • 新功能

    • 瀑布图组件新增“连接线(connector)”配置项,支持自定义连接线样式及方向(支持反向)。
    • 支持为连接线添加标签,展示数值变化。
    • Primitive 类型支持 string[],提升编码灵活性。
  • 文档

    • 瀑布图和面积图文档大幅扩充,包含详细用法说明、属性表、事件/方法参考及丰富示例。
    • 新增瀑布图连接线与反向连接线的代码演示和说明。
    • 示例列表更新,新增相关截图与演示入口。

@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented Jun 26, 2025

📝 Walkthrough

Walkthrough

本次变更主要围绕瀑布图(Waterfall)文档的重构与扩充,涵盖了文档内容、示例代码、配置项说明和部分核心类型定义的完善。同时,新增了瀑布图连接线(connector)相关的配置和功能支持,并对相关类型、常量及示例进行了同步更新。

Changes

文件/文件组 变更摘要
packages/plots/src/core/constants/index.ts 在 CONFIG_SHAPE 常量中新增 connector 配置项。
packages/plots/src/core/plots/waterfall/adaptor.ts 引入 connectorTransform,支持 connector 配置及其数据处理逻辑,调整 adaptor 流程。
packages/plots/src/core/plots/waterfall/type.ts WaterfallOptions 类型新增 connector 属性,调整 xField 相关定义。
packages/plots/src/core/types/common.ts Primitive 类型新增 string[] 支持。
site/docs/components/plots/area.zh.md 优化和扩展面积图简介内容。
site/docs/components/plots/waterfall.zh.md 全面重写瀑布图文档,补充简介、代码演示、配置项、事件、方法等结构化内容。
site/examples/statistics/waterfall/demo/connector.js 新增带 connector 配置的瀑布图示例。
site/examples/statistics/waterfall/demo/meta.json 调整和新增瀑布图示例元数据,包括 basic、connector、reverse 三个 demo。
site/examples/statistics/waterfall/demo/reverse.js 优化示例,新增 connector.reverse 配置及样式。

Sequence Diagram(s)

sequenceDiagram
    participant 用户
    participant Waterfall组件
    participant adaptor
    participant connectorTransform

    用户->>Waterfall组件: 配置带 connector 的瀑布图
    Waterfall组件->>adaptor: 传递 options
    adaptor->>connectorTransform: 检查并处理 connector 配置
    connectorTransform-->>adaptor: 返回处理后的参数
    adaptor->>Waterfall组件: 渲染瀑布图及连接线
Loading

Assessment against linked issues

Objective Addressed Explanation
完善瀑布图文档,包含简介、代码演示、配置项、事件、方法等结构化内容(#2944
示例代码覆盖瀑布图主要配置,包含 connector 相关用法,示例代码位于指定目录(#2944
配置项表格包含属性、描述、类型、默认值、必选等信息,属性罗列完整(#2944
文档语义通顺、格式正确,代码示例可正确编译(#2944

Poem

(=^・ω・^=)
瀑布新文落纸间,
连接线下水潺潺。
示例代码齐展现,
配置项表细如烟。
兔子挥笔写春天,
文档焕彩更耀眼!

Warning

There were issues while running some tools. Please review the errors and either fix the tool's configuration or disable the tool if it's a critical failure.

🔧 ESLint

If the error stems from missing dependencies, add them to the package.json file. For unrecoverable errors (e.g., due to private dependencies), disable the tool in the CodeRabbit configuration.

site/examples/statistics/waterfall/demo/reverse.js

Oops! Something went wrong! :(

ESLint: 8.57.1

ESLint couldn't find the plugin "eslint-plugin-react".

(The package "eslint-plugin-react" was not found when loaded as a Node module from the directory "/site".)

It's likely that the plugin isn't installed correctly. Try reinstalling by running the following:

npm install eslint-plugin-react@latest --save-dev

The plugin "eslint-plugin-react" was referenced from the config file in "site/.eslintrc.js » /node_modules/.pnpm/@umijs+fabric@2.14.1/node_modules/@umijs/fabric/dist/eslint.js".

If you still can't figure out the problem, please stop by https://eslint.org/chat/help to chat with the team.

site/examples/statistics/waterfall/demo/connector.js

Oops! Something went wrong! :(

ESLint: 8.57.1

ESLint couldn't find the plugin "eslint-plugin-react".

(The package "eslint-plugin-react" was not found when loaded as a Node module from the directory "/site".)

It's likely that the plugin isn't installed correctly. Try reinstalling by running the following:

npm install eslint-plugin-react@latest --save-dev

The plugin "eslint-plugin-react" was referenced from the config file in "site/.eslintrc.js » /node_modules/.pnpm/@umijs+fabric@2.14.1/node_modules/@umijs/fabric/dist/eslint.js".

If you still can't figure out the problem, please stop by https://eslint.org/chat/help to chat with the team.

✨ Finishing Touches
  • 📝 Generate Docstrings
🧪 Generate Unit Tests
  • Create PR with Unit Tests
  • Post Copyable Unit Tests in Comment
  • Commit Unit Tests in branch docs/waterfall-component

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Explain this complex logic.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai explain this code block.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and explain its main purpose.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Support

Need help? Create a ticket on our support page for assistance with any issues or questions.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR.
  • @coderabbitai generate sequence diagram to generate a sequence diagram of the changes in this PR.
  • @coderabbitai auto-generate unit tests to generate unit tests for this PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link
Copy Markdown

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 2

🧹 Nitpick comments (1)
site/examples/statistics/waterfall/demo/reverse.js (1)

44-47: 考虑提取样式配置以提高可读性

连接线的样式配置是正确的,但可以考虑将样式对象提取为常量以提高代码可读性。

可以这样重构:

+const connectorStyle = {
+  reverse: true,
+  style: { stroke: '#697474', offset: 16 },
+};
+
 connector: {
-  reverse: true,
-  style: { stroke: '#697474', offset: 16 },
+  ...connectorStyle,
 },
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 9cf6941 and 9b22b7f.

📒 Files selected for processing (9)
  • packages/plots/src/core/constants/index.ts (1 hunks)
  • packages/plots/src/core/plots/waterfall/adaptor.ts (2 hunks)
  • packages/plots/src/core/plots/waterfall/type.ts (1 hunks)
  • packages/plots/src/core/types/common.ts (1 hunks)
  • site/docs/components/plots/area.zh.md (1 hunks)
  • site/docs/components/plots/waterfall.zh.md (1 hunks)
  • site/examples/statistics/waterfall/demo/connector.js (1 hunks)
  • site/examples/statistics/waterfall/demo/meta.json (1 hunks)
  • site/examples/statistics/waterfall/demo/reverse.js (1 hunks)
🧰 Additional context used
🧬 Code Graph Analysis (2)
packages/plots/src/core/plots/waterfall/type.ts (1)
packages/plots/src/core/types/common.ts (2)
  • Options (93-119)
  • AttrStyle (127-127)
site/examples/statistics/waterfall/demo/connector.js (2)
site/examples/statistics/waterfall/demo/basic.js (2)
  • DemoWaterfall (5-47)
  • config (13-45)
site/examples/statistics/waterfall/demo/reverse.js (2)
  • DemoWaterfall (5-50)
  • config (6-48)
⏰ Context from checks skipped due to timeout of 90000ms (1)
  • GitHub Check: deploy
🔇 Additional comments (17)
packages/plots/src/core/constants/index.ts (1)

248-252: 代码实现符合既定模式!

新增的 connector 配置项遵循了现有的结构模式,具有正确的 keytypeextend_keys 属性。空的 extend_keys 数组对于连接线功能来说是合理的,因为它不需要继承通用的字段扩展。

site/docs/components/plots/area.zh.md (1)

13-13: 文档描述改进得很好!

新的面积图描述更加全面和详细,准确地解释了面积图的概念、用途和优势,将折线图的趋势表达与柱状图的面积对比优势结合得很好。

site/examples/statistics/waterfall/demo/reverse.js (1)

1-53: React 组件实现正确!

该示例正确使用了 React 18 的 createRoot API,瀑布图配置完整,包含了新的反向连接线功能。数据结构和样式配置都很合理,条件渲染逻辑也实现得很好。

packages/plots/src/core/types/common.ts (1)

13-13: 类型扩展合理且必要!

string[] 添加到 Primitive 类型中是合理的,这扩展了编码规范中可使用的原始值类型,支持字符串数组的场景,与新增的连接线功能需求相匹配。

site/examples/statistics/waterfall/demo/meta.json (1)

1-32: 示例元数据更新正确!

元数据正确反映了瀑布图示例的重组和扩展,包含了基础用法、连接线和反向连接线三个示例。文件命名清晰,标题描述准确,JSON 结构完整有效。

packages/plots/src/core/plots/waterfall/type.ts (2)

3-3: 类型定义更改合理

移除了对 xField 的排除,这样 WaterfallOptions 可以继承基础 Options 类型中的 xField 属性,使类型定义更加一致和灵活。


9-9: 新增 connector 属性类型定义正确

新增的 connector 属性类型定义合理:

  • 使用 Partial<Options> 允许继承所有基础配置选项
  • 添加可选的 reverse 布尔标志用于控制连接线方向
  • 类型定义与实现逻辑保持一致
packages/plots/src/core/plots/waterfall/adaptor.ts (2)

1-1: 导入语句更新正确

添加了 isObjectset 工具函数的导入,这些函数在新的 connectorTransform 函数中被正确使用。


95-95: 流程更新正确

marktransformOptions 之间正确添加了 connectorTransform 步骤,确保连接线变换在标记处理之后、选项变换之前执行。

site/examples/statistics/waterfall/demo/connector.js (4)

1-4: 导入语句正确

导入了必要的依赖项:Waterfall 组件、React 和 createRoot,符合现代 React 应用的最佳实践。


7-16: 示例数据设计良好

财务数据结构合理,包含了:

  • 正值和负值的混合,很好地展示了瀑布图的特点
  • 合适的数据标识(isTotal 标记总计项)
  • 真实的财务场景数据,便于用户理解

38-46: connector 配置展示完整

很好地演示了新的 connector 功能:

  • 标签配置显示数值差异 ${d.y2 - d.y1}
  • 使用格式化器 '~s' 简化数值显示
  • 自定义样式包括颜色和偏移量
  • 配置选项全面且实用

51-51: React 渲染方式现代化

使用了 React 18 的 createRoot API,符合最新的 React 最佳实践。

site/docs/components/plots/waterfall.zh.md (4)

10-18: 简介部分内容详实且准确

新增的瀑布图简介很好地解释了:

  • 瀑布图的别名和基本概念
  • 核心特征的详细说明
  • 视觉隐喻的生动描述

内容专业且易于理解,能够帮助用户快速了解瀑布图的用途和特点。


20-34: 代码演示部分组织合理

演示部分的结构清晰:

  • 基础用法展示核心功能
  • 连接线标记展示新功能
  • 反向连接线标记展示高级用法

每个示例都有明确的标题和对应的 playground 路径,便于用户理解和实践。


48-61: 配置项表格内容完整

配置项表格涵盖了瀑布图组件的所有主要配置选项:

  • 基础数据配置(data, xField, yField)
  • 样式配置(style, linkStyle, theme)
  • 功能配置(label, tooltip, legend)
  • 高级配置(animate, interaction, state)

每个配置项都包含了说明、类型和默认值,便于开发者参考使用。


63-69: 文档引用部分完善

正确添加了事件和方法部分的引用链接,使文档结构更加完整,便于用户查找相关信息。

Comment on lines +75 to +93
const connectorTransform = (params: Params) => {
const { options } = params;
const { data = [], connector } = options;
if (!connector) return params;
set(options, 'connector', {
xField: connector.reverse ? ['x2', 'x1'] : ['x1', 'x2'],
yField: connector.reverse ? ['y2', 'y1'] : ['y1', 'y2'],
data: [
{
x1: data[0].x,
y1: data[0][END_KEY],
x2: data[data.length - 1].x,
y2: data[data.length - 1][END_KEY],
},
],
...(isObject(connector) ? connector : {}),
})
return params;
};
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🛠️ Refactor suggestion

connectorTransform 函数实现需要改进

函数逻辑基本正确,但存在几个问题:

  1. 缺少数据长度检查:当 data 数组为空或只有一个元素时,data[data.length - 1] 可能导致问题
  2. 字段访问可能失败data[0].xdata[0][END_KEY] 没有进行安全检查

建议添加数据验证:

 const connectorTransform = (params: Params) => {
   const { options } = params;
   const { data = [], connector } = options;
   if (!connector) return params;
+  if (data.length < 2) return params;
+  
+  const firstItem = data[0];
+  const lastItem = data[data.length - 1];
+  if (!firstItem || !lastItem) return params;
+  
   set(options, 'connector', {
     xField: connector.reverse ? ['x2', 'x1'] : ['x1', 'x2'],
     yField: connector.reverse ? ['y2', 'y1'] : ['y1', 'y2'],
     data: [
       {
-        x1: data[0].x,
-        y1: data[0][END_KEY],
-        x2: data[data.length - 1].x,
-        y2: data[data.length - 1][END_KEY],
+        x1: firstItem.x,
+        y1: firstItem[END_KEY],
+        x2: lastItem.x,
+        y2: lastItem[END_KEY],
       },
     ],
     ...(isObject(connector) ? connector : {}),
   })
   return params;
 };
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
const connectorTransform = (params: Params) => {
const { options } = params;
const { data = [], connector } = options;
if (!connector) return params;
set(options, 'connector', {
xField: connector.reverse ? ['x2', 'x1'] : ['x1', 'x2'],
yField: connector.reverse ? ['y2', 'y1'] : ['y1', 'y2'],
data: [
{
x1: data[0].x,
y1: data[0][END_KEY],
x2: data[data.length - 1].x,
y2: data[data.length - 1][END_KEY],
},
],
...(isObject(connector) ? connector : {}),
})
return params;
};
const connectorTransform = (params: Params) => {
const { options } = params;
const { data = [], connector } = options;
if (!connector) return params;
if (data.length < 2) return params;
const firstItem = data[0];
const lastItem = data[data.length - 1];
if (!firstItem || !lastItem) return params;
set(options, 'connector', {
xField: connector.reverse ? ['x2', 'x1'] : ['x1', 'x2'],
yField: connector.reverse ? ['y2', 'y1'] : ['y1', 'y2'],
data: [
{
x1: firstItem.x,
y1: firstItem[END_KEY],
x2: lastItem.x,
y2: lastItem[END_KEY],
},
],
...(isObject(connector) ? connector : {}),
})
return params;
};
🤖 Prompt for AI Agents
In packages/plots/src/core/plots/waterfall/adaptor.ts around lines 75 to 93, the
connectorTransform function lacks validation for the data array length and safe
access to its elements. To fix this, add checks to ensure data has at least two
elements before accessing data[0] and data[data.length - 1]. Also, verify that
data[0].x and data[0][END_KEY] exist before using them to prevent runtime
errors. If the data is insufficient or fields are missing, return params early
or handle the case gracefully.

Comment thread site/docs/components/plots/waterfall.zh.md
@lxfu1 lxfu1 merged commit 1c15015 into v2 Jun 26, 2025
9 checks passed
@lxfu1 lxfu1 deleted the docs/waterfall-component branch June 26, 2025 09:33
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Docs]: 新增文档「图表组件-统计图表-瀑布图(Waterfall)」

1 participant