Skip to content

RelationGraph 人物关系图 ​

基于 @antv/g6 封装的关系图组件,用于展示人物之间的关联关系。

安装 ​

依赖 ​

bash
pnpm add @antv/g6

基础用法 ​

传入节点 `nodes` 和关系边 `edges` 数据即可渲染关系图。

自定义节点样式 ​

通过 `style` 属性为节点设置图片、大小和边框颜色。

径向布局 ​

通过 `layoutType="radial"` 使用径向布局,适合展示层级关系。

折叠展开 ​

通过 `collapsible` 启用折叠展开功能,双击节点可切换其子节点的显示/隐藏。

带小地图 ​

通过 `showMinimap` 显示小地图,方便浏览大规模关系网络。

节点事件 ​

支持节点点击和双击事件,可在事件回调中获取节点数据。

点击节点-角色-

通讯关系 ​

展示人物及其虚拟账号(电话、微信、QQ、抖音等)。账号自动展开为独立节点并连线到人物。

全局配置 ​

可通过 HxConfigProvider 在应用顶层统一配置关系图的默认值:

vue
<template>
  <HxConfigProvider :relationGraph="{ showSearch: false, nodeMenu: false }">
    <App />
  </HxConfigProvider>
</template>

API ​

Props ​

属性说明类型默认值
nodes人物节点列表RelationNode[][]
edges关系边列表RelationEdge[][]
width画布宽度number | string'100%'
height画布高度number | string'500px'
showSearch是否显示搜索框booleantrue
nodeMenu是否启用节点点击菜单booleantrue
showMinimap是否显示小地图booleanfalse
layoutType布局类型'force' | 'radial''force'
unitRadius径向布局每层半径number100
linkDistance边长度number120
nodeSize节点默认大小number60
collapsible是否启用折叠展开booleanfalse
defaultIcon默认图标配置RelationGraphIconConfig{ type: 'iconify', icon: 'mdi:account' }

RelationNode 节点数据 ​

属性说明类型默认值
id节点唯一标识string-
name姓名string-
avatar头像 URLstring-
role职位/角色string-
gender性别(用于默认头像)'male' | 'female' | 'unknown'-
contactAccounts关联的虚拟账号列表ContactAccount[]-
nodeType节点类型'person' | 'account''person'
style节点样式配置RelationNodeStyle-
[key: string]其他自定义字段unknown-

ContactAccount 虚拟账号 ​

属性说明类型默认值
type账号类型AccountType-
value账号值string-

AccountType 账号类型 ​

'phone' \| 'qq' \| 'weixin' \| 'douyin' \| 'email' \| 'other'

类型说明图标
phone电话lucide:phone
qqQQlogos:qq
weixin微信logos:wechat
douyin抖音logos:tiktok
email邮箱lucide:mail
other其他lucide:at-sign

RelationNodeStyle 节点样式 ​

属性说明类型默认值
size节点大小number60
img头像/图标 URLstring-
stroke边框颜色string'#5B8FF9'

RelationEdge 边数据 ​

属性说明类型默认值
source源节点 IDstring-
target目标节点 IDstring-
label关系标签string-
data边数据配置RelationEdgeData-
[key: string]其他自定义字段unknown-

RelationEdgeData 边数据配置 ​

属性说明类型默认值
stroke边的颜色string'#b1b1b1'
label关系标签string-

RelationGraphIconConfig 默认图标配置 ​

属性说明类型默认值
type图标类型'svg' | 'iconify''iconify'
svgSVG symbol id(type 为 svg 时使用)string-
iconiconify 图标名(type 为 iconify 时使用)string'mdi:account'

Events ​

事件名说明回调参数
node-click点击节点(event: RelationNodeClickEvent) => void
node-dblclick双击节点(event: RelationNodeClickEvent) => void

RelationNodeClickEvent ​

属性说明类型
node节点数据RelationNode
x点击位置的 X 坐标number
y点击位置的 Y 坐标number

类型定义 ​

ts
import type { RelationGraphProps, RelationNode, RelationEdge, RelationNodeStyle, RelationEdgeData, RelationGraphIconConfig, RelationNodeClickEvent, AccountType, ContactAccount } from '@whhx/ui'

Released under the MIT License.