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
  • 常见问题
  • 参与贡献

组合配置项

上一篇
组合总览
下一篇
Circle 圆形

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...

本文介绍组合属性配置,配置位置如下:

import { Graph } from '@antv/g6';
const graph = new Graph({
// 其他配置...
combo: {
type: 'circle', // 组合类型
style: {}, // 组合样式
state: {}, // 状态样式
palette: {}, // 色板配置
animation: {}, // 动画配置
},
});

ComboOptions

属性描述类型默认值必选
type组合类型,内置组合类型名称或自定义组合的名称Typecircle
style组合样式,包括颜色、大小等Style-
state定义组合在不同状态下的样式State-
palette定义组合的色板,用于根据不同数据映射颜色Palette-
animation定义组合的动画效果Animation-

Type

指定组合类型,内置组合类型名称或自定义组合的名称。默认为 circle(圆形组合)。

const graph = new Graph({
// 其他配置...
combo: {
type: 'circle',
},
});

可选值有:

  • circle:圆形组合
  • rect:矩形组合

Style

在此处定义组合的样式,包括颜色、大小等。

const graph = new Graph({
// 其他配置...
combo: {
style: {},
},
});
  • key :组合的主图形,表示组合的主要形状,例如圆形、矩形等;
  • halo :主图形周围展示的光晕效果的图形;
  • label :文本标签,通常用于展示组合的名称或描述;

以下样式配置将按原子图形依次说明:

展开时样式

组合展开时的主图形样式

属性描述类型默认值必选
collapsed当前组合是否收起booleanfalse
cursor组合鼠标移入样式,配置项stringdefault
fill组合填充色string#99ADD1
fillOpacity组合填充色透明度number | string0.04
increasedLineWidthForHitTesting当 lineWidth 较小时,可交互区域也随之变小,有时我们想增大这个区域,让“细线”更容易被拾取到number0
lineCap组合描边端点样式round | square | buttbutt
lineDash组合描边虚线样式number[]-
lineDashOffset组合描边虚线偏移量number-
lineJoin组合描边连接处样式round | bevel | mitermiter
lineWidth组合描边宽度number1
opacity组合透明度number | string1
shadowBlur组合阴影模糊度number-
shadowColor组合阴影颜色string-
shadowOffsetX组合阴影在 x 轴方向上的偏移量number | string-
shadowOffsetY组合阴影在 y 轴方向上的偏移量number | string-
shadowType组合阴影类型inner | outerouter
stroke组合描边色string#99add1
strokeOpacity组合描边色透明度number | string1
visibility组合是否可见visible | hiddenvisible
x组合 x 坐标number0
y组合 y 坐标number0
z组合 z 坐标number0
zIndex组合渲染层级number0
{styleProps}更多图形配置,参考 BaseStyleProps 配置项BaseStyleProps-

Cursor

可选值有:auto | default | none | context-menu | help | pointer | progress | wait | cell | crosshair | text | vertical-text | alias | copy | move | no-drop | not-allowed | grab | grabbing | all-scroll | col-resize | row-resize | n-resize | e-resize | s-resize | w-resize | ne-resize | nw-resize | se-resize | sw-resize | ew-resize | ns-resize | nesw-resize | nwse-resize | zoom-in | zoom-out

示例:

const graph = new Graph({
// 其他配置...
combo: {
style: {
fill: '#1783FF', // 填充色
stroke: '#000', // 描边色
lineWidth: 2, // 描边宽度
},
},
});

效果如下:

createGraph(
{
autoFit: 'center',
data: {
nodes: [{ id: 'node1', combo: 'combo1' }],
combos: [{ id: 'combo1' }],
},
combo: {
style: { fill: '#1783FF', stroke: '#000', lineWidth: 2 },
},
},
{ width: 240, height: 100 },
);

收起时样式

当 collapsed 为 true 时生效

属性描述类型默认值必选
collapsedCursor组合收起时的鼠标移入样式,配置项string默认与展开时的 cursor 一致
collapsedFill组合收起时的填充色string默认与展开时的 fill 一致
collapsedFillOpacity组合收起时的填充色透明度number | string1
collapsedIncreasedLineWidthForHitTesting组合收起时,当 lineWidth 较小时,可交互区域也随之变小,有时我们想增大这个区域,让“细线”更容易被拾取到number0
collapsedLineCap组合收起时的描边端点样式round | square | butt默认与展开时的 lineCap 一致
collapsedLineDash组合收起时的描边虚线样式number[]默认与展开时的 lineDash 一致
collapsedLineDashOffset组合收起时的描边虚线偏移量number默认与展开时的 lineDashOffset 一致
collapsedLineJoin组合收起时的描边连接处样式round | bevel | miter默认与展开时的 lineJoin 一致
collapsedLineWidth组合收起时的描边宽度number默认与展开时的 lineWidth 一致
collapsedMarker组合收起时是否显示标记,配置项booleantrue
collapsedOpacity组合收起时的透明度number | string默认与展开时的 opacity 一致
collapsedShadowBlur组合收起时的阴影模糊度number默认与展开时的 shadowBlur 一致
collapsedShadowColor组合收起时的阴影颜色string默认与展开时的 shadowColor 一致
collapsedShadowOffsetX组合收起时的阴影在 x 轴方向上的偏移量number | string默认与展开时的 shadowOffsetX 一致
collapsedShadowOffsetY组合收起时的阴影在 y 轴方向上的偏移量number | string默认与展开时的 shadowOffsetY 一致
collapsedShadowType组合收起时的阴影类型inner | outer默认与展开时的 shadowType 一致
collapsedSize组合收起时的大小number | [number, number] | [number, number, number]32
collapsedStroke组合收起时的描边色string默认与展开时的 stroke 一致
collapsedStrokeOpacity组合收起时的描边色透明度number | string默认与展开时的 strokeOpacity 一致
collapsedVisibility组合收起时是否可见visible | hidden默认与展开时的 visibility 一致
collapsed{styleProps}更多图形配置,参考 BaseStyleProps 配置项BaseStyleProps-

示例:

const graph = new Graph({
// 其他配置...
combo: {
style: {
collapsedFill: '#1783FF', // 填充色
collapsedStroke: '#000', // 描边色
collapsedLineWidth: 2, // 描边宽度
},
},
});

效果如下:

createGraph(
{
autoFit: 'center',
data: {
nodes: [{ id: 'node1', combo: 'combo1' }],
combos: [{ id: 'combo1', style: { collapsed: true } }],
},
combo: {
style: { collapsedFill: '#1783FF', collapsedStroke: '#000', collapsedLineWidth: 2 },
},
},
{ width: 240, height: 100 },
);

收起时标记样式

当 collapsedMarker 为 true 时生效

属性描述类型默认值必选
collapsedMarkerType组合收起时显示的标记类型
- 'child-count': 子元素数量(包括 Node 和 Combo)
- 'descendant-count': 后代元素数量(包括 Node 和 Combo)
- 'node-count': 后代元素数量(只包括 Node)
- (children: NodeLikeData[]) => string: 自定义处理逻辑
child-count | descendant-count | node-count | ((children: NodeData | ComboData[]) => string)child-count
collapsedMarkerFill图标文字颜色string#fff
collapsedMarkerFillOpacity图标文字颜色透明度number1
collapsedMarkerFontSize图标字体大小number12
collapsedMarkerFontWeight图标字体粗细number | stringnormal
collapsedMarkerRadius图标圆角半径number0
collapsedMarkerSrc图片来源。其优先级高于 collapsedMarkerTextstring-
collapsedMarkerText图标文字string-
collapsedMarkerTextAlign图标文字水平对齐方式center | end | left | right | startcenter
collapsedMarkerTextBaseline图标文字对齐基线alphabetic | bottom | hanging | ideographic | middle | topmiddle
collapsedMarkerWidth图标宽度number-
collapsedMarkerHeight图标高度number-
collapsedMarkerZIndex图标层级number1
collapsedMarker{StyleProps}更多图标样式配置,参考 TextStyleProps、ImageStyleProps 配置项。例如 collapsedMarkerFontSize 代表文字图标的字体大小TextStyleProps | ImageStyleProps-

示例:

const graph = new Graph({
// 其他配置...
combo: {
style: {
collapsedMarkerFill: '#1783FF', // 填充色
collapsedMarkerFontSize: 30, // 图标字体大小
},
},
});

效果如下:

createGraph(
{
autoFit: 'center',
data: {
nodes: [
{ id: 'node1', combo: 'combo1' },
{ id: 'node2', combo: 'combo1' },
],
combos: [{ id: 'combo1', style: { collapsed: true } }],
},
combo: {
style: {
collapsedMarkerFill: '#1783FF',
collapsedMarkerFontSize: 30,
},
},
},
{ width: 240, height: 100 },
);

标签样式

标签用于显示组合的文本信息:

属性描述类型默认值必选
label是否显示组合标签booleantrue
labelCursor鼠标移入组合标签时显示的样式,配置项stringdefault
labelFill组合标签文字颜色string#000
labelFillOpacity组合标签文字颜色的透明度number1
labelFontFamily组合标签字体族string-
labelFontSize组合标签字体大小number12
labelFontStyle组合标签字体样式normal | italic | oblique-
labelFontVariant组合标签字体变种normal | small-caps | string-
labelFontWeight组合标签字体粗细normal | bold | bolder | lighter | number400
labelLeading行间距number0
labelLetterSpacing组合标签字间距number | string-
labelLineHeight组合标签行高number | string-
labelMaxLines组合标签最大行数number1
labelMaxWidth组合标签最大宽度,配置项number | string200%
labelOffsetX组合标签在 x 轴方向上的偏移量number0
labelOffsetY组合标签在 y 轴方向上的偏移量number0
labelPadding组合标签内边距number | number[]0
labelPlacement组合标签相对于组合主图形的位置,配置项stringbottom
labelText组合标签文字内容string-
labelTextAlign组合标签文本水平对齐方式start | center | middle | end | left | right' | left`
labelTextBaseline组合标签文本基线top | hanging | middle | alphabetic | ideographic | bottom-
labelTextDecorationColor组合标签文本装饰线颜色string-
labelTextDecorationLine组合标签文本装饰线string-
labelTextDecorationStyle组合标签文本装饰线样式solid | double | dotted | dashed | wavy-
labelTextOverflow组合标签文本溢出处理方式clip | ellipsis | string-
labelTextPath组合标签文本路径Path-
labelWordWrap组合标签是否开启自动折行。开启 labelWordWrap 后,超出 labelMaxWidth 的部分自动换行booleanfalse
labelZIndex组合标签渲染层级number0
label{StyleProps}更多标签样式配置,参考 TextStyleProps 属性值。比如 labelOpacity 代表标签透明度TextStyleProps-

LabelPlacement

可选值有:left | right | top | bottom | left-top | left-bottom | right-top | right-bottom | top-left | top-right | bottom-left | bottom-right | center | bottom

LabelMaxWidth

开启自动折行 labelWordWrap 后,超出该宽度则换行:

  • string: 表示以相对于组合元素宽度的百分比形式定义最大宽度。例如 50% 表示标签宽度不超过组合宽度的一半
  • number: 表示以像素值为单位定义最大宽度。例如 100 表示标签的最大宽度为 100 像素

比如,设置多行标签文字:

{
"labelWordWrap": true,
"labelMaxWidth": 200,
"labelMaxLines": 3
}

示例:

const graph = new Graph({
// 其他配置
combo: {
style: {
label: true, // 是否显示组合标签
labelText: '组合名称', // 标签文字内容
labelFill: '#000', // 标签文字颜色
labelFontSize: 12, // 标签字体大小
labelFontWeight: 'normal', // 标签字体粗细
labelPlacement: 'bottom', // 标签相对于组合主图形的位置
},
},
});

效果如下:

createGraph(
{
autoFit: 'center',
data: {
nodes: [{ id: 'node1', combo: 'combo1' }],
combos: [
{
id: 'combo1',
style: {
label: true,
labelText: '组合名称',
labelFill: '#000',
labelFontSize: 12,
labelFontWeight: 'normal',
labelPlacement: 'bottom',
},
},
],
},
},
{ width: 240, height: 100 },
);

标签背景样式

标签背景用于显示组合标签的背景:

属性描述类型默认值
labelBackground组合标签背景是否显示booleanfalse
labelBackgroundCursor组合标签背景鼠标移入样式,配置项stringdefault
labelBackgroundFill组合标签背景填充色string#000
labelBackgroundFillOpacity组合标签背景透明度number0.75
labelBackgroundHeight组合标签背景高度string | number-
labelBackgroundLineDash组合标签背景虚线配置number | string |(number | string )[]-
labelBackgroundLineDashOffset组合标签背景虚线偏移量number-
labelBackgroundLineWidth组合标签背景描边线宽number-
labelBackgroundPadding组合标签背景内间距number | number[][2, 4, 2, 4]
labelBackgroundRadius组合标签背景圆角半径
- number: 统一设置四个圆角半径
- number[]: 分别设置四个圆角半径,不足则自动补充
number | number[]0
labelBackgroundShadowBlur组合标签背景阴影模糊程度number-
labelBackgroundShadowColor组合标签背景阴影颜色string-
labelBackgroundShadowOffsetX组合标签背景阴影 X 方向偏移number-
labelBackgroundShadowOffsetY组合标签背景阴影 Y 方向偏移number-
labelBackgroundStroke组合标签背景描边颜色string-
labelBackgroundStrokeOpacity组合标签背景描边透明度number | string1
labelBackgroundVisibility组合标签背景是否可见visible | hidden-
labelBackgroundZIndex组合标签背景渲染层级number1
labelBackground{StyleProps}更多标签背景样式配置,参考 RectStyleProps 属性值。例如 labelBackgroundOpacity 代表标签背景透明度RectStyleProps-

示例:

const graph = new Graph({
// 其他配置...
combo: {
style: {
labelBackground: true, // 是否显示组合标签背景
labelBackgroundFill: '#000', // label背景填充
labelBackgroundRadius: 10, // label背景圆角
labelBackgroundFillOpacity: 0.5, // label背景填充色透明度
},
},
});

效果如下:

createGraph(
{
autoFit: 'center',
data: {
nodes: [{ id: 'node1', combo: 'combo1' }],
combos: [
{
id: 'combo1',
style: {
label: true,
labelText: '组合名称',
labelFill: '#000',
labelFontSize: 12,
labelFontWeight: 'normal',
labelPlacement: 'bottom',
labelBackground: true,
labelBackgroundFill: '#000',
labelBackgroundRadius: 10,
labelBackgroundFillOpacity: 0.5,
},
},
],
},
},
{ width: 240, height: 100 },
);

光晕样式

属性描述类型默认值必选
halo是否显示组合光晕booleanfalse
haloCursor组合光晕鼠标移入样式,配置项stringdefault
haloDraggable组合光晕是否允许拖拽booleantrue
haloDroppable组合光晕是否允许接收被拖拽的元素booleanfalse
haloFill光晕填充色string与主图形的填充色 fill 一致
haloFillRule组合光晕填充规则nonzero | evenodd-
haloFilter组合光晕滤镜string-
haloLineWidth组合光晕描边宽度number12
haloPointerEvents组合光晕效果是否响应指针事件,配置项stringnone
haloStroke组合光晕描边色,此属性用于设置组合周围光晕的颜色,帮助突出显示组合string#99add1
haloStrokeOpacity组合光晕描边色透明度number0.25
haloVisibility组合光晕可见性visible | hiddenvisible
haloZIndex组合光晕渲染层级number-1
halo{StyleProps}更多光晕样式配置,参考 DisplayObject 配置项。例如 haloFillOpacity 代表光晕填充色透明度DisplayObject-

PointerEvents

可选值有: visible | visiblepainted | visiblestroke | non-transparent-pixel | visiblefill | visible | painted | fill | stroke | all | none | auto | inherit | initial | unset

示例:

const graph = new Graph({
// 其他配置...
combo: {
style: {
halo: true, // 是否显示组合光晕
haloStroke: '#FF0000', // 组合光晕描边色
haloLineWidth: 10, // 组合光晕描边宽度
},
},
});

效果如下:

createGraph(
{
autoFit: 'center',
data: {
nodes: [{ id: 'node1', combo: 'combo1' }],
combos: [{ id: 'combo1' }],
},
combo: {
style: {
halo: true,
haloStroke: '#FF0000',
haloLineWidth: 10,
},
},
},
{ width: 240, height: 100 },
);

图标样式

属性描述类型默认值
icon是否显示组合图标booleantrue
iconFill组合图标文字颜色string-
iconFontFamily组合图标字体族string-
iconFontSize组合图标字体大小number16
iconFontStyle组合图标字体样式normal | italic | obliquenormal
iconFontVariant组合图标字体变种normal | small-caps | stringnormal
iconFontWeight组合图标字体粗细number | stringnormal
iconHeight组合图标高度number主图形高度的一半
iconLetterSpacing组合图标文本字间距number | string-
iconLineHeight组合图标文本行高number | string-
iconMaxLines组合图标文本最大行数number1
iconRadius组合图标圆角半径number0
iconSrc组合图片来源。其优先级高于 iconTextstring-
iconText组合图标文字string-
iconTextAlign组合图标文本水平对齐方式start | center | middle | end | left | rightleft
iconTextBaseline组合图标文本基线top | hanging | middle | alphabetic | ideographic | bottomalphabetic
iconTextDecorationColor组合图标文本装饰线颜色string-
iconTextDecorationLine组合图标文本装饰线string-
iconTextDecorationStyle组合图标文本装饰线样式solid | double | dotted | dashed | wavysolid
iconTextOverflow组合图标文本溢出处理方式clip | ellipsis | stringclip
iconWidth组合图标宽度number主图形宽度的一半
iconWordWrap组合图标文本是否自动换行boolean-

示例:

const graph = new Graph({
// 其他配置...
combo: {
style: {
iconText: '文本', // 图标文本
iconFill: '#FF0000', // 图标文本颜色
iconFontSize: 14, // 图标文本大小
iconFontWeight: 'bold', // 图标文本粗细
iconFontStyle: 'italic', // 图标文本样式
},
},
});

效果如下:

createGraph(
{
autoFit: 'center',
data: {
combos: [{ id: 'combo1' }],
},
combo: {
style: {
iconText: '文本',
iconFill: '#FF0000',
iconFontSize: 14,
iconFontWeight: 'bold',
iconFontStyle: 'italic',
},
},
},
{ width: 240, height: 100 },
);

State

在一些交互行为中,比如点击选中一个组合或鼠标悬停激活一个边,仅仅是在该元素做了某些状态的标识。为了将这些状态反应到终端用户所见的视觉空间中,我们需要为不同的状态设置不同的图元素样式,以响应该图元素状态的变化。

G6 提供了几种内置的状态,包括选中(selected)、高亮(highlight)、激活(active)、不活跃(inactive)和禁用(disabled)。此外,它还支持自定义状态,以满足更特定的需求。对于每个状态,开发者可以定义一套样式规则,这些规则会覆盖元素的默认样式。

数据结构如下:

type ComboState = {
[state: string]: ComboStyle;
};

例如,当组合处于 focus 状态时,可以为其添加一个宽度为 3 且颜色为橙色的描边。

const graph = new Graph({
combo: {
state: {
focus: {
lineWidth: 3, // 描边宽度
stroke: 'orange', // 描边颜色
},
},
},
});

效果如下图所示:

createGraph(
{
autoFit: 'center',
data: {
nodes: [{ id: 'node1', combo: 'combo1' }],
combos: [{ id: 'combo1', states: ['focus'] }],
},
combo: {
state: {
focus: {
lineWidth: 3,
stroke: 'orange',
fill: 'orange',
fillOpacity: 0.2,
},
},
},
},
{ width: 200, height: 100 },
);

Animation

定义组合的动画效果,支持下列两种配置方式:

  1. 关闭组合全部动画
{
"combo": {
"animation": false
}
}
  1. 配置阶段动画

阶段动画是指组合在进入画布、更新、离开画布时的动画效果。目前支持的阶段包括:

  • enter: 组合进入画布时的动画
  • update: 组合更新时的动画
  • exit: 组合离开画布时的动画
  • show: 组合从隐藏状态显示时的动画
  • hide: 组合隐藏时的动画
  • collapse: 组合收起时的动画
  • expand: 组合展开时的动画

你可以参考 动画范式 使用动画语法来配置组合,如:

{
"combo": {
"animation": {
"update": [
{
"fields": ["x", "y"], // 更新时只对 x 和 y 属性进行动画
"duration": 1000, // 动画持续时间
"easing": "linear" // 缓动函数
}
],
}
}

也可以使用内置的动画效果:

{
"combo": {
"animation": {
"enter": "fade", // 使用渐变动画
"update": "translate", // 使用平移动画
"exit": "fade" // 使用渐变动画
}
}
}

你可以传入 false 来关闭特定阶段的动画:

{
"combo": {
"animation": {
"enter": false // 关闭组合入场动画
}
}
}

Palette

定义组合的色板,即预定义组合颜色池,并根据规则进行分配,将颜色映射到 fill 属性。

有关色板的定义,请参考 色板。

属性描述类型默认值
type指定当前色板类型。
- group: 离散色板
- value: 连续色板
group | valuegroup
field指定元素数据中的分组字段。若不指定,默认取 id 作为分组字段string | ((datum) => string)id
color色板颜色。如果色板注册过,可以直接指定其注册名,也接受一个颜色数组string | string[]-
invert是否反转色板booleanfalse

如将一组数据按 category 字段分配组合颜色,使得同类别的组合颜色相同:

{
"combo": {
"palette": {
"type": "group",
"field": "category",
"color": ["#1783FF", "#F08F56", "#D580FF", "#00C9C9", "#7863FF"]
}
}
}

效果如下图所示:

createGraph(
{
data: {
combos: new Array(8)
.fill(0)
.map((_, i) => ({ id: `combo-${i}`, data: { category: ['A', 'B', 'C', 'D', 'E'][i % 5] } })),
},
layout: { type: 'grid', cols: 8 },
combo: {
style: { fillOpacity: 0.4 },
palette: {
type: 'group',
field: 'category',
color: ['#1783FF', '#F08F56', '#D580FF', '#00C9C9', '#7863FF'],
},
},
},
{ width: 600, height: 100 },
);

也可以使用默认配置:

{
"combo": {
"palette": "tableau" // tableau 为色板名,默认根据 ID 分配颜色
}
}

效果如下图所示:

createGraph(
{
data: {
combos: new Array(8)
.fill(0)
.map((_, i) => ({ id: `combo-${i}`, data: { category: ['A', 'B', 'C', 'D', 'E'][i % 5] } })),
},
layout: { type: 'grid', cols: 8 },
combo: {
style: { fillOpacity: 0.4 },
palette: 'tableau',
},
},
{ width: 600, height: 100 },
);