-
Notifications
You must be signed in to change notification settings - Fork 1.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* feat(mark): add chord mark * docs: add docs for chord mark --------- Co-authored-by: GavinChen <[email protected]>
- Loading branch information
1 parent
2f9c729
commit 42fdab2
Showing
15 changed files
with
1,092 additions
and
6 deletions.
There are no files selected for viewing
This file contains 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,67 @@ | ||
[ | ||
{ | ||
"source": "北京", | ||
"target": "天津", | ||
"value": 30 | ||
}, | ||
{ | ||
"source": "北京", | ||
"target": "上海", | ||
"value": 80 | ||
}, | ||
{ | ||
"source": "北京", | ||
"target": "河北", | ||
"value": 46 | ||
}, | ||
{ | ||
"source": "北京", | ||
"target": "辽宁", | ||
"value": 49 | ||
}, | ||
{ | ||
"source": "北京", | ||
"target": "黑龙江", | ||
"value": 69 | ||
}, | ||
{ | ||
"source": "北京", | ||
"target": "吉林", | ||
"value": 19 | ||
}, | ||
{ | ||
"source": "天津", | ||
"target": "河北", | ||
"value": 62 | ||
}, | ||
{ | ||
"source": "天津", | ||
"target": "辽宁", | ||
"value": 82 | ||
}, | ||
{ | ||
"source": "天津", | ||
"target": "上海", | ||
"value": 16 | ||
}, | ||
{ | ||
"source": "上海", | ||
"target": "黑龙江", | ||
"value": 16 | ||
}, | ||
{ | ||
"source": "河北", | ||
"target": "黑龙江", | ||
"value": 76 | ||
}, | ||
{ | ||
"source": "河北", | ||
"target": "内蒙古", | ||
"value": 24 | ||
}, | ||
{ | ||
"source": "内蒙古", | ||
"target": "北京", | ||
"value": 32 | ||
} | ||
] |
650 changes: 650 additions & 0 deletions
650
__tests__/integration/snapshots/static/populationFlowChordDefault.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains 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 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,17 @@ | ||
import { G2Spec } from '../../../src'; | ||
|
||
export async function populationFlowChordDefault(): Promise<G2Spec> { | ||
return { | ||
type: 'chord', | ||
data: { | ||
type: 'fetch', | ||
value: 'data/population-flow.json', | ||
transform: [ | ||
{ | ||
type: 'custom', | ||
callback: (d) => ({ links: d }), | ||
}, | ||
], | ||
}, | ||
}; | ||
} |
This file contains 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 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 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,5 @@ | ||
--- | ||
title: chord | ||
order: 1 | ||
--- | ||
`<embed src="@/docs/spec/mark/chord.zh.md"></embed>` |
This file contains 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,45 @@ | ||
--- | ||
title: chord | ||
order: 1 | ||
--- | ||
弦图(Chord diagram)是一种用于可视化关系和连接的图表形式。它主要用于展示多个实体之间的相互关系、联系的强度或流量的分布。 | ||
|
||
## 开始使用 | ||
|
||
<img alt="chord" src="https://mdn.alipayobjects.com/huamei_qa8qxu/afts/img/A*x6h_RZR7r0QAAAAAAAAAAAAADmJ7AQ/original" width="600" /> | ||
|
||
```js | ||
import { Chart } from '@antv/g2'; | ||
|
||
const chart = new Chart({ | ||
container: 'container', | ||
autoFit: true, | ||
}); | ||
|
||
chart.chord().data({ | ||
type: 'fetch', | ||
value: 'https://assets.antv.antgroup.com/g2/population-flow.json', | ||
transform: [ | ||
{ | ||
type: 'custom', | ||
callback: (d) => ({ links: d }), | ||
}, | ||
], | ||
}); | ||
|
||
chart.render(); | ||
``` | ||
|
||
## 选项 | ||
|
||
| 属性 | 描述 | 类型 | 默认值 | | ||
| ---------------- | --------------------------------------------------------- | ----------------------------- | ----------------------------- | | ||
| y | 布局时y轴的坐标 | `number` | `0` | | ||
| id | 节点的键 | `Function<string \| number>` | `(node) => node.key` | | ||
| source | 设置弦图的来源节点数据字段 | `Function<string>` | `(node) => node.source` | | ||
| target | 设置弦图的目标节点数据字段 | `Function<string>` | `(node) => node.target` | | ||
| sourceWeight | 来源的权重 | `Function<number>` | `(node) => node.value \|\| 1` | | ||
| targetWeight | 目标的权重 | `Function<number>` | `(node) => node.value \|\| 1` | | ||
| sortBy | 排序方法,可选id, weight, frequency排序或者自定义排序方法 | `string \| Function<number>` | - | | ||
| nodeWidthRatio | 弦图节点的宽度配置,0 ~ 1,参考画布的宽度 | `number` | `0.05` | | ||
| nodePaddingRatio | 弦图节点之间的间距,0 ~ 1,参考画布的高度 | `number` | `0.1` | |
This file contains 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,90 @@ | ||
import { Chart } from '@antv/g2'; | ||
import { schemeTableau10 } from 'd3-scale-chromatic'; | ||
|
||
const chart = new Chart({ | ||
container: 'container', | ||
width: 900, | ||
height: 600, | ||
}); | ||
|
||
const data = [ | ||
{ | ||
source: '北京', | ||
target: '天津', | ||
value: 30, | ||
}, | ||
{ | ||
source: '北京', | ||
target: '上海', | ||
value: 80, | ||
}, | ||
{ | ||
source: '北京', | ||
target: '河北', | ||
value: 46, | ||
}, | ||
{ | ||
source: '北京', | ||
target: '辽宁', | ||
value: 49, | ||
}, | ||
{ | ||
source: '北京', | ||
target: '黑龙江', | ||
value: 69, | ||
}, | ||
{ | ||
source: '北京', | ||
target: '吉林', | ||
value: 19, | ||
}, | ||
{ | ||
source: '天津', | ||
target: '河北', | ||
value: 62, | ||
}, | ||
{ | ||
source: '天津', | ||
target: '辽宁', | ||
value: 82, | ||
}, | ||
{ | ||
source: '天津', | ||
target: '上海', | ||
value: 16, | ||
}, | ||
{ | ||
source: '上海', | ||
target: '黑龙江', | ||
value: 16, | ||
}, | ||
{ | ||
source: '河北', | ||
target: '黑龙江', | ||
value: 76, | ||
}, | ||
{ | ||
source: '河北', | ||
target: '内蒙古', | ||
value: 24, | ||
}, | ||
{ | ||
source: '内蒙古', | ||
target: '北京', | ||
value: 32, | ||
}, | ||
]; | ||
|
||
chart | ||
.chord() | ||
.data({ | ||
value: { links: data }, | ||
}) | ||
.layout({ | ||
nodeWidthRatio: 0.05, | ||
}) | ||
.scale('color', { range: schemeTableau10 }) | ||
.style('labelFontSize', 15) | ||
.style('linkFillOpacity', 0.6); | ||
|
||
chart.render(); |
This file contains 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 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 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
Oops, something went wrong.