-
Notifications
You must be signed in to change notification settings - Fork 490
docs: add waterfall component documentation #3002
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,13 +1,10 @@ | ||
| import type { Options, AttrStyle } from '../../types/common'; | ||
|
|
||
| export type WaterfallOptions = Omit<Options, 'xField' | 'children'> & { | ||
| export type WaterfallOptions = Omit<Options, 'children'> & { | ||
| /** | ||
| * @title 连线样式 | ||
| */ | ||
| linkStyle?: AttrStyle; | ||
| /** | ||
| * @title x轴字段 | ||
| */ | ||
| xField?: string | string[]; | ||
| children?: Array<WaterfallOptions & { zIndex?: number }>; | ||
| connector?: Partial<Options> & { reverse?: boolean }; | ||
| }; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,51 @@ | ||
| import { Waterfall } from '@ant-design/plots'; | ||
| import React from 'react'; | ||
| import { createRoot } from 'react-dom'; | ||
|
|
||
| const DemoWaterfall = () => { | ||
| const config = { | ||
| data: [ | ||
| { x: 'Net Sales', value: 5085000 }, | ||
| { x: 'Cost of Sales', value: -1250450 }, | ||
| { x: 'Operating Expenses', value: -2350050 }, | ||
| { x: 'Other Income', value: 750000 }, | ||
| { x: 'Extraordinary Gain', value: -230050 }, | ||
| { x: 'Interest Expense', value: -500000 }, | ||
| { x: 'Taxes', value: 490000 }, | ||
| { x: 'Net Income', isTotal: true, value: 1994450 }, | ||
| ], | ||
| xField: 'x', | ||
| yField: 'value', | ||
| linkStyle: { | ||
| lineDash: [4, 2], | ||
| stroke: '#ccc', | ||
| }, | ||
| style: { | ||
| maxWidth: 25, | ||
| stroke: '#ccc', | ||
| fill: (d, idx) => { | ||
| return idx === 0 || d.isTotal ? '#96a6a6' : d.value > 0 ? '#64b5f6' : '#ef6c00'; | ||
| }, | ||
| }, | ||
| label: { | ||
| text: 'value', | ||
| formatter: '~s', | ||
| position: (d) => (d.value > 0 ? 'top' : 'bottom'), | ||
| textBaseline: (d) => (d.value > 0 ? 'bottom' : 'top'), | ||
| fontSize: 10, | ||
| dy: (d) => (d.value > 0 ? -4 : 4), | ||
| }, | ||
| connector: { | ||
| label: { | ||
| text: (d) => `${d.y2 - d.y1}`, | ||
| formatter: '~s', | ||
| fontSize: 14, | ||
| dy: 2, | ||
| }, | ||
| style: { stroke: '#697474', offset: 16 }, | ||
| }, | ||
| }; | ||
| return <Waterfall {...config} />; | ||
| }; | ||
|
|
||
| createRoot(document.getElementById('container')).render(<DemoWaterfall />); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🛠️ Refactor suggestion
connectorTransform 函数实现需要改进
函数逻辑基本正确,但存在几个问题:
data数组为空或只有一个元素时,data[data.length - 1]可能导致问题data[0].x和data[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
🤖 Prompt for AI Agents