logo

G6

  • 文档
  • API
  • 图表示例
  • 社区
  • 所有产品antv logo arrow
  • 5.0.47
  • 简介
  • 开始使用
    • 快速开始
    • 安装
    • 前端框架集成
      • 在 React 中使用
      • 在 Vue 中使用
      • 在 Angular 中使用
    • 详细教程
  • 图 Graph
    • Graph - 图
    • Options 配置项
    • 内置扩展
    • Extension - 扩展
  • 数据 Data
  • 元素 Element
    • 元素总览
    • 元素状态
    • 节点 Node
      • 节点总览
      • 内置节点
        • 节点通用配置项
        • Diamond 菱形
        • Donut 甜甜圈
        • Ellipse 椭圆形
        • Hexagon 六边形
        • Html HTML
        • Image 图片
        • Rect 矩形
        • Star 五角形
        • Triangle 三角形
        • Circle 圆形
      • 自定义节点
      • 使用 React 定义节点
    • 边 Edge
      • 边总览
      • 内置边
        • 边通用配置项
        • Cubic 三次贝塞尔曲线
        • CubicHorizontal 水平三次贝塞尔曲线
        • CubicVertical 垂直三次贝塞尔曲线
        • Line 直线
        • Polyline 折线
        • Quadratic 二次贝塞尔曲线
      • 自定义边
    • 组合 Combo
      • 组合总览
      • 内置组合
        • 组合配置项
        • Circle 圆形
        • Rect 矩形
      • 自定义 Combo
    • 图形 Shape
      • 图形 Shape 与 KeyShape
      • 原子 Shape 以及其属性
      • 复合 Shape 的设计与实现
  • 布局 Layout
    • 布局总览
    • 内置布局
      • 布局通用配置项
      • AntvDagre 布局
      • Circular 环形布局
      • ComboCombined 复合布局
      • CompactBox 紧凑树
      • Concentric 同心圆布局
      • D3Force 力导向布局
      • D3Force3D 3D 力导向布局
      • Dagre 布局
      • Dendrogram 生态树
      • Fishbone 鱼骨布局
      • Force 力导向布局
      • ForceAtlas2 力导向布局
      • Fruchterman 力导向布局
      • Grid 网格布局
      • Indented 缩进树
      • MDS 高维数据降维布局
      • Mindmap 脑图树
      • Radial 径向布局
      • Random 随机布局
      • Snake 蛇形布局
    • 自定义布局
  • 交互 Behavior
    • 交互总览
    • 内置交互
      • AutoAdaptLabel 标签自适应显示
      • BrushSelect 框选
      • ClickSelect 点击选中
      • CollapseExpand 展开/收起元素
      • CreateEdge 创建边
      • DragCanvas 拖拽画布
      • DragElement 拖拽元素
      • DragElementForce 力导向拖拽元素
      • FixElementSize 缩放画布时固定元素大小
      • FocusElement 聚焦元素
      • HoverActivate 悬停激活
      • LassoSelect 套索选择
      • OptimizeViewportTransform 优化视口变换
      • ScrollCanvas 滚动画布
      • ZoomCanvas 缩放画布
    • 自定义交互
  • 插件 Plugin
    • 插件总览
    • 内置插件
      • Background 背景
      • BubbleSets 气泡集
      • Contextmenu 上下文菜单
      • EdgeBundling 边绑定
      • EdgeFilterLens 边过滤镜
      • Fisheye 鱼眼放大镜
      • Fullscreen 全屏展示
      • GridLine 网格线
      • History 历史记录
      • Hull 轮廓包围
      • Legend 图例
      • Minimap 小地图
      • Snapline 对齐线
      • Timebar 时间条
      • Toolbar 工具栏
      • Tooltip 提示框
      • Watermark 水印
    • 自定义插件
  • 数据处理 Transform
    • 数据处理总览
    • 内置数据处理
      • MapNodeSize 动态调整节点大小
      • PlaceRadialLabels 径向标签
      • ProcessParallelEdges 平行边
    • 自定义数据处理
  • 主题 Theme
    • 主题总览
    • 自定义主题
    • 色板
    • 自定义色板
  • 动画 Animation
    • 动画总览
    • 自定义动画
  • 扩展阅读
    • 事件
    • 渲染器
    • 坐标系
    • 下载图片
    • 使用 iconfont
    • 使用 3D
    • 项目打包
  • 版本特性
    • 新版本特性
    • 升级到 5.0
  • 常见问题
  • 参与贡献

MapNodeSize 动态调整节点大小

上一篇
数据处理总览
下一篇
PlaceRadialLabels 径向标签

Resources

Ant Design
Galacea Effects
Umi-React 应用开发框架
Dumi-组件/文档研发工具
ahooks-React Hooks 库

社区

体验科技专栏
seeconfSEE Conf-蚂蚁体验科技大会

帮助

GitHub
StackOverflow

more products更多产品

Ant DesignAnt Design-企业级 UI 设计语言
yuque语雀-知识创作与分享工具
EggEgg-企业级 Node 开发框架
kitchenKitchen-Sketch 工具集
GalaceanGalacean-互动图形解决方案
xtech蚂蚁体验科技
© Copyright 2025 Ant Group Co., Ltd..备案号:京ICP备15032932号-38

Loading...

概述

在图可视化中,节点的大小通常用于传达节点的重要性或影响力。通过根据节点中心性调整节点的大小,我们可以更直观地展示网络中各个节点的重要性,从而帮助用户更好地理解和分析复杂的网络结构。

使用场景

需要通过节点大小来突出节点的重要性和影响力时,可使用此数据处理。

以下为常见的场景:

  • 社交网络分析:比如分析社交媒体平台中用户的活跃度与影响力,通过节点大小突出高互动用户。

  • 金融风险传导网络:比如识别金融系统中承担关键资金流转职能的机构,预防系统性风险。

  • 交通枢纽规划:比如优化城市地铁网络设计,识别换乘压力点。

配置项

属性描述类型默认值必选
type数据处理类型map-node-size-✓
centrality节点中心性的度量方法,配置项NodeCentralityOptions | ((graphData: GraphData) => Map<string, number>){ type: 'degree' }
mapLabelSize是否同步调整标签大小boolean | [number, number]false
maxSize节点最大尺寸number | [number, number] | [number, number, number]80
minSize节点最小尺寸number | [number, number] | [number, number, number]20
scale插值函数,用于将节点中心性映射到节点大小,配置项linear | log | pow | sqrt | ((value: number, domain: [number, number], range: [number, number]) => number)log

centrality

节点中心性的度量方法

  • 'degree':度中心性,通过节点的度数(连接的边的数量)来衡量其重要性。度中心性高的节点通常具有较多的直接连接,在网络中可能扮演着重要的角色
  • 'betweenness':介数中心性,通过节点在所有最短路径中出现的次数来衡量其重要性。介数中心性高的节点通常在网络中起到桥梁作用,控制着信息的流动
  • 'closeness':接近中心性,通过节点到其他所有节点的最短路径长度总和的倒数来衡量其重要性。接近中心性高的节点通常能够更快地到达网络中的其他节点
  • 'eigenvector':特征向量中心性,通过节点与其他中心节点的连接程度来衡量其重要性。特征向量中心性高的节点通常连接着其他重要节点
  • 'pagerank':PageRank 中心性,通过节点被其他节点引用的次数来衡量其重要性,常用于有向图。PageRank 中心性高的节点通常在网络中具有较高的影响力,类似于网页排名算法
  • 自定义中心性计算方法:(graphData: GraphData) => Map<ID, number>,其中 graphData 为图数据,Map<ID, number> 为节点 ID 到中心性值的映射

示例:

const graph = new Graph({
// 其他配置...
transforms: [
{
type: 'map-node-size',
centrality: {
type: 'degree',
direction: 'both',
},
},
],
});

效果如下(可切换度量方法查看不同效果,示例中节点 label 为${节点 id } - ${节点大小}):

createGraph(
{
autoFit: 'center',
data: {
nodes: [{ id: 'node1' }, { id: 'node2' }, { id: 'node3' }, { id: 'node4' }, { id: 'node5' }],
edges: [
{ source: 'node1', target: 'node2' },
{ source: 'node2', target: 'node3' },
{ source: 'node3', target: 'node4' },
{ source: 'node4', target: 'node5' },
{ source: 'node1', target: 'node4' },
{ source: 'node1', target: 'node3' },
],
},
node: {
type: 'circle',
style: {
labelText: (d) => d.id + ' - ' + d.style.size[0].toFixed(0),
},
},
layout: {
type: 'circular',
radius: 180,
},
behaviors: ['drag-canvas'],
transforms: [
{
key: 'map-node-size',
type: 'map-node-size',
centrality: {
type: 'pagerank',
},
},
],
},
{ width: 600, height: 460 },
(gui, graph) => {
const options = {
type: 'degree',
};
const optionFolder = gui.addFolder('Centrality Options');
optionFolder.add(options, 'type', ['degree', 'betweenness', 'closeness', 'eigenvector', 'pagerank']);
optionFolder.onChange(async ({ property, value }) => {
graph.updateTransform({
key: 'map-node-size',
centrality: {
[property]: value,
},
});
graph.render();
});
},
);

NodeCentralityOptions

type NodeCentralityOptions =
| { type: 'degree'; direction?: 'in' | 'out' | 'both' }
| { type: 'betweenness'; directed?: boolean; weightPropertyName?: string }
| { type: 'closeness'; directed?: boolean; weightPropertyName?: string }
| { type: 'eigenvector'; directed?: boolean }
| { type: 'pagerank'; epsilon?: number; linkProb?: number };

direction:表示统计哪些方向的边,in -入边、 out -出边、 both -入边和出边都考虑进去

directed:是否为有向图

weightPropertyName:边的权重属性名

epsilon:PageRank 算法的收敛容差

linkProb:PageRank 算法的阻尼系数,指任意时刻,用户访问到某节点后继续访问该节点链接的下一个节点的概率,经验值 0.85

scale

  • 'linear':线性插值函数,将一个值从一个范围线性映射到另一个范围,常用于处理中心性值的差异较小的情况
  • 'log':对数插值函数,将一个值从一个范围对数映射到另一个范围,常用于处理中心性值的差异较大的情况
  • 'pow':幂律插值函数,将一个值从一个范围幂律映射到另一个范围,常用于处理中心性值的差异较大的情况
  • 'sqrt':平方根插值函数,将一个值从一个范围平方根映射到另一个范围,常用于处理中心性值的差异较大的情况
  • 自定义插值函数:(value: number, domain: [number, number], range: [number, number]) => number,其中 value 为需要映射的值,domain 为输入值的范围,range 为输出值的范围

示例:

const graph = new Graph({
// 其他配置...
transforms: [
{
type: 'map-node-size',
centrality: {
type: 'degree',
},
scale: 'linear',
},
],
});

效果如下(该示例为基于度中心性 degree ,可切换插值函数查看不同效果,示例中节点 label 为${节点 id } - ${节点大小}):

createGraph(
{
autoFit: 'center',
data: {
nodes: [
{ id: 'node1' },
{ id: 'node2' },
{ id: 'node3' },
{ id: 'node4' },
{ id: 'node5' },
{ id: 'node6' },
{ id: 'node7' },
],
edges: [
{ source: 'node1', target: 'node2' },
{ source: 'node1', target: 'node3' },
{ source: 'node1', target: 'node4' },
{ source: 'node2', target: 'node5' },
{ source: 'node3', target: 'node6' },
{ source: 'node4', target: 'node7' },
],
},
node: {
type: 'circle',
style: {
labelText: (d) => d.id + ' - ' + d.style.size[0].toFixed(0),
},
},
layout: {
type: 'antv-dagre',
},
behaviors: ['drag-canvas'],
transforms: [
{
key: 'map-node-size',
type: 'map-node-size',
centrality: {
type: 'degree',
},
scale: 'log',
},
],
},
{ width: 600, height: 400 },
(gui, graph) => {
const options = {
scale: 'log',
};
const optionFolder = gui.addFolder('MapNodeSize Options');
optionFolder.add(options, 'scale', ['log', 'linear', 'pow', 'sqrt']);
optionFolder.onChange(async ({ property, value }) => {
graph.updateTransform({
key: 'map-node-size',
[property]: value,
});
graph.render();
});
},
);

实际案例

  • 场景案例:独角兽和他们的投资者