-
Notifications
You must be signed in to change notification settings - Fork 647
docs: 补充自动旋转隐藏例子 #2135
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
docs: 补充自动旋转隐藏例子 #2135
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,22 @@ | ||
| /** @jsx jsx */ | ||
| import { Axis, Canvas, Chart, Interval, jsx } from '@antv/f2'; | ||
|
|
||
| const context = document.getElementById('container').getContext('2d'); | ||
|
|
||
| const data = Array.from({ length: 100 }, (_, i) => ({ | ||
| category: `Cat${i + 1}`, | ||
| value: ((i % 10) + 1) * 10, | ||
| })); | ||
|
|
||
| const { props } = ( | ||
| <Canvas context={context} pixelRatio={window.devicePixelRatio}> | ||
| <Chart data={data}> | ||
| <Axis field="category" labelAutoHide={true} /> | ||
| <Axis field="value" /> | ||
| <Interval x="category" y="value" color="#722ED1" /> | ||
| </Chart> | ||
| </Canvas> | ||
| ); | ||
|
|
||
| const canvas = new Canvas(props); | ||
| canvas.render(); |
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,35 @@ | ||
| /** @jsx jsx */ | ||
| import { Axis, Canvas, Chart, Interval, jsx } from '@antv/f2'; | ||
|
|
||
| const context = document.getElementById('container').getContext('2d'); | ||
|
|
||
| const data = [ | ||
| { category: 'Category1', value: 10 }, | ||
| { category: 'Category2', value: 15 }, | ||
| { category: 'Category3', value: 20 }, | ||
| { category: 'Category4', value: 25 }, | ||
| { category: 'Category5', value: 30 }, | ||
| { category: 'Category6', value: 35 }, | ||
| { category: 'Category7', value: 40 }, | ||
| { category: 'Category8', value: 45 }, | ||
| { category: 'Category9', value: 50 }, | ||
| { category: 'Category10', value: 55 }, | ||
| { category: 'Category11', value: 60 }, | ||
| { category: 'Category12', value: 65 }, | ||
| { category: 'Category13', value: 70 }, | ||
| { category: 'Category14', value: 75 }, | ||
| { category: 'Category15', value: 80 }, | ||
| ]; | ||
|
|
||
| const { props } = ( | ||
| <Canvas context={context} pixelRatio={window.devicePixelRatio}> | ||
| <Chart data={data}> | ||
| <Axis field="category" labelAutoRotate={true} /> | ||
| <Axis field="value" /> | ||
| <Interval x="category" y="value" color="#2FC25B" /> | ||
| </Chart> | ||
| </Canvas> | ||
| ); | ||
|
|
||
| const canvas = new Canvas(props); | ||
| canvas.render(); |
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,18 @@ | ||
| { | ||
| "title": { | ||
| "zh": "中文分类", | ||
| "en": "Category" | ||
| }, | ||
| "demos": [ | ||
| { | ||
| "filename": "labelAutoHide.jsx", | ||
| "title": "文本标注", | ||
| "screenshot": "https://gw.alipayobjects.com/zos/finxbff/compress-tinypng/c95b75fc-d81e-4ae2-8cbf-29f4ba7bf706.png" | ||
| }, | ||
| { | ||
| "filename": "labelAutoRotate.jsx", | ||
| "title": "点标注", | ||
|
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://gw.alipayobjects.com/zos/finxbff/compress-tinypng/eecfc128-cb32-4797-b41c-697823ff2336.png" | ||
| } | ||
| ] | ||
| } | ||
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,4 @@ | ||
| --- | ||
| title: Axis | ||
| order: 3 | ||
| --- |
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,77 @@ | ||
| --- | ||
| title: 坐标轴 Axis | ||
| order: 3 | ||
| --- | ||
|
|
||
| 坐标轴(Axis)是图表中用于展示数据范围和刻度的组件,帮助用户理解数据的分布和趋势。F2 提供了灵活的坐标轴配置,支持自动旋转、自动隐藏、自定义样式等功能。 | ||
|
|
||
| ## 代码演示 | ||
|
|
||
| ### 自动旋转标签 | ||
|
|
||
| 当坐标轴标签过长或数量过多时,可以启用自动旋转功能,避免标签重叠。 | ||
|
|
||
| ```jsx | ||
| import { jsx, Canvas, Chart, Interval, Axis } from '@antv/f2'; | ||
|
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. |
||
|
|
||
| const data = [ | ||
| { category: 'Category1', value: 10 }, | ||
| { category: 'Category2', value: 15 }, | ||
| { category: 'Category3', value: 20 }, | ||
| { category: 'Category4', value: 25 }, | ||
| { category: 'Category5', value: 30 }, | ||
| { category: 'Category6', value: 35 }, | ||
| { category: 'Category7', value: 40 }, | ||
| { category: 'Category8', value: 45 }, | ||
| { category: 'Category9', value: 50 }, | ||
| { category: 'Category10', value: 55 }, | ||
| { category: 'Category11', value: 60 }, | ||
| { category: 'Category12', value: 65 }, | ||
| { category: 'Category13', value: 70 }, | ||
| { category: 'Category14', value: 75 }, | ||
| { category: 'Category15', value: 80 }, | ||
| ]; | ||
|
|
||
| const { props } = ( | ||
| <Canvas context={context} pixelRatio={window.devicePixelRatio}> | ||
| <Chart data={data}> | ||
| <Axis field="category" labelAutoRotate={true} /> | ||
| <Axis field="value" /> | ||
| <Interval x="category" y="value" color="#2FC25B" /> | ||
| </Chart> | ||
| </Canvas> | ||
| ); | ||
| ``` | ||
|
|
||
| ### 自动隐藏标签 | ||
|
|
||
| 当标签过多时,可以启用自动隐藏功能,自动隐藏部分标签以避免重叠。 | ||
|
|
||
| ```jsx | ||
| import { jsx, Canvas, Chart, Interval, Axis } from '@antv/f2'; | ||
|
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. |
||
|
|
||
| const data = Array.from({ length: 100 }, (_, i) => ({ | ||
| category: `Cat${i + 1}`, | ||
| value: ((i % 10) + 1) * 10, | ||
| })); | ||
|
|
||
| const { props } = ( | ||
| <Canvas context={context} pixelRatio={window.devicePixelRatio}> | ||
| <Chart data={data}> | ||
| <Axis field="category" labelAutoHide={true} /> | ||
| <Axis field="value" /> | ||
| <Interval x="category" y="value" color="#722ED1" /> | ||
| </Chart> | ||
| </Canvas> | ||
| ); | ||
| ``` | ||
|
|
||
| ## API | ||
|
|
||
| | 属性名 | 类型 | 默认值 | 说明 | | ||
| | --------------- | ------- | ------ | ------------------------------------ | | ||
| | field | string | - | 绑定的数据字段名 | | ||
| | labelAutoRotate | boolean | false | 是否启用标签自动旋转 | | ||
| | labelAutoHide | boolean | false | 是否启用标签自动隐藏 | | ||
| | safetyDistance | number | 0 | 标签之间的安全距离,用于自动旋转计算 | | ||
| | style | object | - | 自定义样式配置 | | ||
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.
当前标题 “文本标注” 描述不够具体。为了更清晰地说明该示例的功能,建议修改为 “自动隐藏标签”,这与
index.zh.md中的章节标题也能保持一致。