!!!###!!!title=内置节点——VisActor/VGraph 教程文档!!!###!!!!!!###!!!description=内置节点有以下几种 (rect, circle, image, tittle, category, tag, capsule, icon, imageTag) 。所有内置节点都支持基本图形绘制,锚点,icon,label 文本标签。可见[内置节点](/vgraph/demo/nodes/defaultNode)<img src="/vgraph/guide/node/inset_nodes.png" width="800">!!!###!!!

内置节点

内置节点有以下几种 (rect, circle, image, tittle, category, tag, capsule, icon, imageTag) 。所有内置节点都支持基本图形绘制,锚点,icon,label 文本标签。可见内置节点

内置节点类型

rect

字段类型描述
radiusnumber | number[]圆角半径。如为 number, 则四个圆角取相同半径

circle

字段类型描述
rnumber圆半径。会覆盖 width。
widthnumber指定圆的半径。r = width/2。

rhombus

菱形节点。

字段类型描述
radiusnumber | number[]圆角半径。如为 number, 则四个圆角取相同半径

image

image 的 KeyShape 一般为矩形,但矩形的圆角半径超过其宽高的一半时,设置 KeyShape 为圆形。image 节点由背景矩形,图片和文本标签三部分组成。这时候配置 strokeStyle 和 fillStyle 字段会在背景矩形上生效,形成图片节点外边框和背景色,如果不配置则是透明底。image 默认结构为图片在上,文本在下。在通用节点的基础上 image 节点支持配置 image 项:

字段类型描述
urlstring**[必填]**图片链接
widthnumber图片宽度,默认为节点宽度
heightnumber图片高度,默认为节点高度。如果需展示文本标签,则需要扩大节点高度,设置图片图片高度,为文本标签提出空间。例如上图节点,配置如下:
{
    id: 'image',
    type: 'image',
    x: 310,
    y: 100,
    width: 115,
    // 节点总高度
    height: 50,
    image: {
      width: 115,
      // 图片高度,剩下高度分配给 label
      height: 28,
      url: 'imageUrl',
    },
    label: 'image',
}

title

此类型在 rect 的基础上扩展出了一个标题文本和标题背景。其中内容文本对应 label 配置,会根据节点剩余高度自适应排布,支持多行和溢出省略。标题仅支持单行文本,支持溢出省略。title 字段配置如下:

字段类型描述
textstring标题文本
heightnumber标题高度
borderColorstring标题背景边框色
backgroundColorstring标题背景填充色
fillStylestring文本颜色
fontSizenumber文本字号
fontWeightnumber文本字重

其中 title 文字支持的全量配置可见Text 图形配置。上图中 title 节点的定义为:

{
    id: 'nodeId',
    type: 'title',
    x: 120,
    y: 200,
    width: 100,
    height: 60,
    // 标题定义
    title: {
      text: 'title',
      fillStyle: '#666',
      backgroundColor: '#ccc',
    },
    // 内容定义为通用的 Label 配置
    label: '这是一个 title 类型的节点默认样式',
  }

category

category 为带分类色块的矩形节点。此时 color配置的是分类色块的颜色,而 strokeStyle是节点边框色。上图中分类节点的定义为:

{
    id: 'nodeId', 
    type: 'category',
    x: 270,
    y: 200,
    width: 100,
    height: 30,
    radius: 2,
    color: '#3073f2',
    label: 'category',
  }
字段类型描述
colorstring色条颜色
position'center' | 'top'指定色条的位置

tag

tag 为带 icon 、label 或 title 的圆角矩形节点,color 配置的是主题颜色, theme 可以为 outlined(线框风格)、 filled(实心风格)或者 lighted(亮色风格),默认为lighted,通常情况下不推荐同时使用 icon 和 title

字段类型描述
colorstring主题颜色,会根据选取的theme自动计算各个部分的实际颜色
theme'outlined' | 'filled'主题
icon?String | object图标,可以直接使用iconfont,也可以使用对象来定义,size表示icon大小,background可以定义icon部分的背景宽度和背景色。
labelString | object定义标签
title?String | object若定义title,则title将作为标题,label作为描述信息
{
    type: 'tag',
    x: 100,
    y: 350,
    width: 150,
    height: 40,
    color: '#3073F2',
    label: '更大的icon',
    icon: {
      icon: '&#xe68c;',
      size: 25,
      background: {
        width: 50
      }
    },
}

capsule

capsule 为带 icon、title 或 label 的胶囊节点,color 配置的是主题颜色,配置项与 tag 类似,但将 icon.background.width 替换为 icon.background.radius,用于表示 icon 背景圆的半径。

{
    type: 'capsule',
    x: 500,
    y: 350,
    width: 150,
    height: 40,
    color: '#3073F2',
    theme: 'outlined',
    label: '更大icon',
    icon: {
      icon: '&#xe698;',
      size: 20,
      background: {
        radius: 20
      }
    },
}

icon

仅带icon的节点。

字段类型描述
colorstring主题颜色,会根据选取的theme自动计算各个部分的实际颜色
theme'outlined' | 'filled'主题
iconstring | object图标
sizenumber图标大小
labelstring | object定义标签

imageTag

图片和文本标签并排的节点,支持多行文本垂直居中排布。

字段类型描述
imagestring | object节点图片。当类型为 string 时会以默认配置画 url 为 image 的图片。也可传 object 进行进一步自定义。
image.sizenumber图片大小。目前仅支持长宽相等的方形图片。
image.urlstring图片链接。
labelstring | object定义文本标签

通用配置项

字段类型描述
idstring[必填] 节点的唯一标识,边引用节点的标识
type'rect' | 'circle' | 'image' | 'title' | 'category' | 'tag' | 'capsule' | 'icon' | ...节点类型。vGraph 内置了 8 种类型的节点,用户也可以基于这些节点类型扩展引用。默认值为 'rect'。具体请见 内置节点
xnumber节点中心位置的横坐标
ynumber节点中心位置的纵坐标
widthnumber节点的宽度
heightnumber节点的高度
groupIdstring节点所属的 group 的 Id
colorstring节点颜色,根据节点类型不同表现不同
labelstring | LabelConfigs标签文本配置。若为 string,则根据节点类型不同摆放在默认位置。自定义配追具体请见下方 LabelConfigs
iconsIconConfigs[]设置节点上的图标数组。具体请见下方 IconConfigs
anchorsnumber[][] | AnchorConfigs[]设置节点上的锚点。具体请见下方 AnchorConfigs

KeyShape 配置项

字段类型描述
opacitynumber透明度
fillStylestring填充色
strokeStylestring描边颜色
lineWidthnumber描边宽度
lineDashnumber | number[]划线模式,可参考CanvasRenderingContext2D.setLineDash()
shadowBlurnumber阴影模糊量,可参考CanvasRenderingContext2D.shadowBlur
shadowColorstring阴影色
shadowOffsetXnumber阴影水平偏移量,可参考CanvasRenderingContext2D.shadowOffsetX
shadowOffsetYnumber阴影垂直偏移量,可参考CanvasRenderingContext2D.shadowOffsetY
clipShapeBase裁剪形状,将指定形状设置为裁剪路径,位于该裁剪形状路径范围内的部分将会保留,其余部分会被剔除,可参考CanvasRenderingContext2D.clip()
cursorstring当该形状获得光标焦点时,光标的类型。详情参考CSS Cursor