-
Notifications
You must be signed in to change notification settings - Fork 472
docs: add area example #3118
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
Open
lxfu1
wants to merge
1
commit into
master
Choose a base branch
from
docs/examples-area
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+356
−0
Open
docs: add area example #3118
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,348 @@ | ||
| import { Area } from '@ant-design/plots'; | ||
| import React from 'react'; | ||
| import { createRoot } from 'react-dom/client'; | ||
|
|
||
| const DemoSegmentedArea = () => { | ||
| const config = { | ||
| paddingLeft: 25, | ||
| data: [ | ||
| { | ||
| 'gained > 100$': 7, | ||
| 'gained <= 100$': 21, | ||
| 'lost <= 100$': -59, | ||
| 'lost > 100$': -13, | ||
| user: 'John', | ||
| key: 'lost > 100$', | ||
| value: -13, | ||
| }, | ||
| { | ||
| 'gained > 100$': 7, | ||
| 'gained <= 100$': 21, | ||
| 'lost <= 100$': -59, | ||
| 'lost > 100$': -13, | ||
| user: 'John', | ||
| key: 'lost <= 100$', | ||
| value: -59, | ||
| }, | ||
| { | ||
| 'gained > 100$': 7, | ||
| 'gained <= 100$': 21, | ||
| 'lost <= 100$': -59, | ||
| 'lost > 100$': -13, | ||
| user: 'John', | ||
| key: 'gained <= 100$', | ||
| value: 21, | ||
| }, | ||
| { | ||
| 'gained > 100$': 7, | ||
| 'gained <= 100$': 21, | ||
| 'lost <= 100$': -59, | ||
| 'lost > 100$': -13, | ||
| user: 'John', | ||
| key: 'gained > 100$', | ||
| value: 7, | ||
| }, | ||
| { | ||
| 'gained > 100$': 13, | ||
| 'gained <= 100$': 33, | ||
| 'lost <= 100$': -51, | ||
| 'lost > 100$': -3, | ||
| user: 'Raoul', | ||
| key: 'lost > 100$', | ||
| value: -3, | ||
| }, | ||
| { | ||
| 'gained > 100$': 13, | ||
| 'gained <= 100$': 33, | ||
| 'lost <= 100$': -51, | ||
| 'lost > 100$': -3, | ||
| user: 'Raoul', | ||
| key: 'lost <= 100$', | ||
| value: -51, | ||
| }, | ||
| { | ||
| 'gained > 100$': 13, | ||
| 'gained <= 100$': 33, | ||
| 'lost <= 100$': -51, | ||
| 'lost > 100$': -3, | ||
| user: 'Raoul', | ||
| key: 'gained <= 100$', | ||
| value: 33, | ||
| }, | ||
| { | ||
| 'gained > 100$': 13, | ||
| 'gained <= 100$': 33, | ||
| 'lost <= 100$': -51, | ||
| 'lost > 100$': -3, | ||
| user: 'Raoul', | ||
| key: 'gained > 100$', | ||
| value: 13, | ||
| }, | ||
| { | ||
| 'gained > 100$': 24, | ||
| 'gained <= 100$': 47, | ||
| 'lost <= 100$': -29, | ||
| 'lost > 100$': 0, | ||
| user: 'Jane', | ||
| key: 'lost > 100$', | ||
| value: 0, | ||
| }, | ||
| { | ||
| 'gained > 100$': 24, | ||
| 'gained <= 100$': 47, | ||
| 'lost <= 100$': -29, | ||
| 'lost > 100$': 0, | ||
| user: 'Jane', | ||
| key: 'lost <= 100$', | ||
| value: -29, | ||
| }, | ||
| { | ||
| 'gained > 100$': 24, | ||
| 'gained <= 100$': 47, | ||
| 'lost <= 100$': -29, | ||
| 'lost > 100$': 0, | ||
| user: 'Jane', | ||
| key: 'gained <= 100$', | ||
| value: 47, | ||
| }, | ||
| { | ||
| 'gained > 100$': 24, | ||
| 'gained <= 100$': 47, | ||
| 'lost <= 100$': -29, | ||
| 'lost > 100$': 0, | ||
| user: 'Jane', | ||
| key: 'gained > 100$', | ||
| value: 24, | ||
| }, | ||
| { | ||
| 'gained > 100$': 0, | ||
| 'gained <= 100$': 16, | ||
| 'lost <= 100$': -84, | ||
| 'lost > 100$': 0, | ||
| user: 'Marcel', | ||
| key: 'lost > 100$', | ||
| value: 0, | ||
| }, | ||
| { | ||
| 'gained > 100$': 0, | ||
| 'gained <= 100$': 16, | ||
| 'lost <= 100$': -84, | ||
| 'lost > 100$': 0, | ||
| user: 'Marcel', | ||
| key: 'lost <= 100$', | ||
| value: -84, | ||
| }, | ||
| { | ||
| 'gained > 100$': 0, | ||
| 'gained <= 100$': 16, | ||
| 'lost <= 100$': -84, | ||
| 'lost > 100$': 0, | ||
| user: 'Marcel', | ||
| key: 'gained <= 100$', | ||
| value: 16, | ||
| }, | ||
| { | ||
| 'gained > 100$': 0, | ||
| 'gained <= 100$': 16, | ||
| 'lost <= 100$': -84, | ||
| 'lost > 100$': 0, | ||
| user: 'Marcel', | ||
| key: 'gained > 100$', | ||
| value: 0, | ||
| }, | ||
| { | ||
| 'gained > 100$': 23, | ||
| 'gained <= 100$': 44, | ||
| 'lost <= 100$': -20, | ||
| 'lost > 100$': -13, | ||
| user: 'Ibrahim', | ||
| key: 'lost > 100$', | ||
| value: -13, | ||
| }, | ||
| { | ||
| 'gained > 100$': 23, | ||
| 'gained <= 100$': 44, | ||
| 'lost <= 100$': -20, | ||
| 'lost > 100$': -13, | ||
| user: 'Ibrahim', | ||
| key: 'lost <= 100$', | ||
| value: -20, | ||
| }, | ||
| { | ||
| 'gained > 100$': 23, | ||
| 'gained <= 100$': 44, | ||
| 'lost <= 100$': -20, | ||
| 'lost > 100$': -13, | ||
| user: 'Ibrahim', | ||
| key: 'gained <= 100$', | ||
| value: 44, | ||
| }, | ||
| { | ||
| 'gained > 100$': 23, | ||
| 'gained <= 100$': 44, | ||
| 'lost <= 100$': -20, | ||
| 'lost > 100$': -13, | ||
| user: 'Ibrahim', | ||
| key: 'gained > 100$', | ||
| value: 23, | ||
| }, | ||
| { | ||
| 'gained > 100$': 3, | ||
| 'gained <= 100$': 38, | ||
| 'lost <= 100$': -42, | ||
| 'lost > 100$': -17, | ||
| user: 'Junko', | ||
| key: 'lost > 100$', | ||
| value: -17, | ||
| }, | ||
| { | ||
| 'gained > 100$': 3, | ||
| 'gained <= 100$': 38, | ||
| 'lost <= 100$': -42, | ||
| 'lost > 100$': -17, | ||
| user: 'Junko', | ||
| key: 'lost <= 100$', | ||
| value: -42, | ||
| }, | ||
| { | ||
| 'gained > 100$': 3, | ||
| 'gained <= 100$': 38, | ||
| 'lost <= 100$': -42, | ||
| 'lost > 100$': -17, | ||
| user: 'Junko', | ||
| key: 'gained <= 100$', | ||
| value: 38, | ||
| }, | ||
| { | ||
| 'gained > 100$': 3, | ||
| 'gained <= 100$': 38, | ||
| 'lost <= 100$': -42, | ||
| 'lost > 100$': -17, | ||
| user: 'Junko', | ||
| key: 'gained > 100$', | ||
| value: 3, | ||
| }, | ||
| { | ||
| 'gained > 100$': 1, | ||
| 'gained <= 100$': 3, | ||
| 'lost <= 100$': -77, | ||
| 'lost > 100$': -19, | ||
| user: 'Lyu', | ||
| key: 'lost > 100$', | ||
| value: -19, | ||
| }, | ||
| { | ||
| 'gained > 100$': 1, | ||
| 'gained <= 100$': 3, | ||
| 'lost <= 100$': -77, | ||
| 'lost > 100$': -19, | ||
| user: 'Lyu', | ||
| key: 'lost <= 100$', | ||
| value: -77, | ||
| }, | ||
| { | ||
| 'gained > 100$': 1, | ||
| 'gained <= 100$': 3, | ||
| 'lost <= 100$': -77, | ||
| 'lost > 100$': -19, | ||
| user: 'Lyu', | ||
| key: 'gained <= 100$', | ||
| value: 3, | ||
| }, | ||
| { | ||
| 'gained > 100$': 1, | ||
| 'gained <= 100$': 3, | ||
| 'lost <= 100$': -77, | ||
| 'lost > 100$': -19, | ||
| user: 'Lyu', | ||
| key: 'gained > 100$', | ||
| value: 1, | ||
| }, | ||
| { | ||
| 'gained > 100$': 28, | ||
| 'gained <= 100$': 59, | ||
| 'lost <= 100$': -9, | ||
| 'lost > 100$': -4, | ||
| user: 'André', | ||
| key: 'lost > 100$', | ||
| value: -4, | ||
| }, | ||
| { | ||
| 'gained > 100$': 28, | ||
| 'gained <= 100$': 59, | ||
| 'lost <= 100$': -9, | ||
| 'lost > 100$': -4, | ||
| user: 'André', | ||
| key: 'lost <= 100$', | ||
| value: -9, | ||
| }, | ||
| { | ||
| 'gained > 100$': 28, | ||
| 'gained <= 100$': 59, | ||
| 'lost <= 100$': -9, | ||
| 'lost > 100$': -4, | ||
| user: 'André', | ||
| key: 'gained <= 100$', | ||
| value: 59, | ||
| }, | ||
| { | ||
| 'gained > 100$': 28, | ||
| 'gained <= 100$': 59, | ||
| 'lost <= 100$': -9, | ||
| 'lost > 100$': -4, | ||
| user: 'André', | ||
| key: 'gained > 100$', | ||
| value: 28, | ||
| }, | ||
| { | ||
| 'gained > 100$': 1, | ||
| 'gained <= 100$': 9, | ||
| 'lost <= 100$': -80, | ||
| 'lost > 100$': -10, | ||
| user: 'Maki', | ||
| key: 'lost > 100$', | ||
| value: -10, | ||
| }, | ||
| { | ||
| 'gained > 100$': 1, | ||
| 'gained <= 100$': 9, | ||
| 'lost <= 100$': -80, | ||
| 'lost > 100$': -10, | ||
| user: 'Maki', | ||
| key: 'lost <= 100$', | ||
| value: -80, | ||
| }, | ||
| { | ||
| 'gained > 100$': 1, | ||
| 'gained <= 100$': 9, | ||
| 'lost <= 100$': -80, | ||
| 'lost > 100$': -10, | ||
| user: 'Maki', | ||
| key: 'gained <= 100$', | ||
| value: 9, | ||
| }, | ||
| { | ||
| 'gained > 100$': 1, | ||
| 'gained <= 100$': 9, | ||
| 'lost <= 100$': -80, | ||
| 'lost > 100$': -10, | ||
| user: 'Maki', | ||
| key: 'gained > 100$', | ||
| value: 1, | ||
| }, | ||
| ], | ||
| encode: { x: 'user', y: 'value', color: 'key' }, | ||
| shapeField: 'smooth', | ||
| scale: { | ||
| y: { domainMin: -100, domainMax: 100 }, | ||
| color: { | ||
| domain: ['lost > 100$', 'lost <= 100$', 'gained <= 100$', 'gained > 100$'], | ||
| range: ['#61cdbb', '#97e3d5', '#f47560', '#e25c3b'], | ||
| }, | ||
| }, | ||
| }; | ||
|
|
||
| return <Area {...config} />; | ||
| }; | ||
|
|
||
| createRoot(document.getElementById('container')).render(<DemoSegmentedArea />); | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 挂载点可能为 null:建议加守卫避免 demo 页直接报错 -createRoot(document.getElementById('container')).render(<DemoSegmentedArea />);
+const container = document.getElementById('container');
+if (container) {
+ createRoot(container).render(<DemoSegmentedArea />);
+}🤖 Prompt for AI Agents |
||
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 |
|---|---|---|
|
|
@@ -107,6 +107,14 @@ | |
| "en": "Quadrants" | ||
| }, | ||
| "screenshot": "https://mdn.alipayobjects.com/huamei_qa8qxu/afts/img/A*g8i_Ra_TBKkAAAAAQ3AAAAgAemJ7AQ/fmt.webp" | ||
| }, | ||
| { | ||
| "filename": "area-fill.js", | ||
| "title": { | ||
| "zh": "根据数值填充面积颜色", | ||
| "en": "According to value fill area color" | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
| }, | ||
| "screenshot": "https://mdn.alipayobjects.com/huamei_qa8qxu/afts/img/A*NK-mRpMz-UUAAAAARNAAAAgAemJ7AQ/fmt.webp" | ||
| } | ||
| ] | ||
| } | ||
Oops, something went wrong.
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.
The component implementation can be improved for correctness, readability, and maintainability.
configobject literal is missing commas between its properties (data,encode,shapeField), which will cause a JavaScript syntax error and prevent the component from rendering.shapeField: 'smooth'property is not the correct way to create a smooth area chart. You should useshape: 'smooth'instead.dataarray is extremely verbose and contains a lot of redundant information. This makes the code hard to read and maintain. It's much cleaner to define the source data in a compact "wide" format and then programmatically transform it into the "long" format required by the chart.I've combined fixes for all these issues into a single refactoring suggestion for the entire component.