logo

G6

  • Docs
  • API
  • Playground
  • Community
  • Productsantv logo arrow
  • 5.0.47
  • Introduction
  • Data
  • Getting Started
    • Quick Start
    • Installation
    • Integration
      • react
      • vue
      • angular
    • Step-by-step guide
  • Graph
    • Extensions En
    • Graph
    • Options
    • extension
  • Element
    • Element Overview
    • Element State
    • Node
      • Node Overview
      • Build-in Node
        • Common Node Configurations
        • Diamond
        • Donut
        • Ellipse
        • Hexagon
        • Html
        • Image
        • Rect
        • Star
        • Triangle
        • Circle
      • Custom Node
      • Define Nodes with React
    • Edge
      • Edge Overview
      • Build-in Edge
        • Common Edge Configurations
        • Cubic Bezier Curve
        • CubicHorizontal Bezier Curve
        • CubicVertical Bezier Curve
        • Line
        • Polyline
        • Quadratic Bezier Curve
      • Custom Edge
    • Combo
      • Combo Overview
      • Build-in Combo
        • Circle
        • Combo Configuration Options
        • Rect
      • Custom Combo
    • Shape
      • Shape and KeyShape
      • Atomic Shapes and Their Properties
      • Design and Implementation of Composite Shape
  • Layout
    • Layout Overview
    • Build-in Layout
      • 3D Force-Directed Layout
      • AntvDagre Layout
      • Circular Layout
      • ComboCombined Layout
      • Common Layout Configuration Options
      • CompactBox
      • Concentric Layout
      • D3 Force-Directed Layout
      • Dagre Layout
      • Dendrogram Layout
      • Fishbone Layout
      • Force Force-directed Layout
      • ForceAtlas2 Force-directed Layout
      • Fruchterman Force-directed Layout
      • Grid Layout
      • Indented Tree
      • MDS High-dimensional Data Dimensionality Reduction Layout
      • Mindmap Tree
      • Radial Layout
      • Random Layout
      • Snake Layout
    • Custom Layout
  • Behavior
    • Behavior Overview
    • Build-in Behavior
      • AutoAdaptLabel
      • BrushSelect
      • ClickSelect
      • CollapseExpand
      • CreateEdge
      • DragCanvas
      • DragElement
      • DragElementForce
      • FixElementSize
      • FocusElement
      • HoverActivate
      • LassoSelect
      • OptimizeViewportTransform
      • ScrollCanvas
      • ZoomCanvas
    • Custom Behavior
  • Plugin
    • Plugin Overview
    • Build-in Plugin
      • Background
      • BubbleSets
      • Contextmenu
      • EdgeBundling
      • EdgeFilterLens
      • Fisheye
      • Fullscreen
      • GridLine
      • History
      • Hull
      • Legend
      • Minimap
      • Snapline
      • Timebar
      • Toolbar
      • Tooltip
      • Watermark
    • Custom Plugin
  • Transform
    • Data Transformation Overview
    • Build-in Transform
      • MapNodeSize
      • PlaceRadialLabels
      • ProcessParallelEdges
    • Custom Transform
  • Theme
    • Theme Overview
    • Custom Theme
    • Palette
    • Custom Palette
  • Animation
    • Animation Overview
    • Custom Animation
  • Further Reading
    • Event
    • renderer
    • coordinate
    • download-image
    • Using Iconfont
    • Use 3D
    • Bundle Project
  • What's new
    • Feature
    • Upgrade To 5.0
  • FAQ
  • contribute

ClickSelect

Previous
BrushSelect
Next
CollapseExpand

Resources

Ant Design
Galacea Effects
Umi-React Application Framework
Dumi-Component doc generator
ahooks-React Hooks Library

Community

Ant Financial Experience Tech
seeconfSEE Conf-Experience Tech Conference

Help

GitHub
StackOverflow

more productsMore Productions

Ant DesignAnt Design-Enterprise UI design language
yuqueYuque-Knowledge creation and Sharing tool
EggEgg-Enterprise-class Node development framework
kitchenKitchen-Sketch Tool set
GalaceanGalacean-互动图形解决方案
xtechLiven Experience technology
© Copyright 2025 Ant Group Co., Ltd..备案号:京ICP备15032932号-38

Loading...

Overview

When an element is clicked, it will be highlighted.

Usage Scenarios

This behavior is mainly used for:

  • Focusing on elements
  • Viewing element details
  • Viewing element relationships

Online Experience

createGraph(
{
data: {
nodes: [
{ id: 'node-1', style: { x: 280, y: 60, fill: '#E4504D', labelText: 'degree: 0' } },
{ id: 'node-2-1', style: { x: 330, y: 140, fill: '#FFC40C', labelText: 'degree: 1' } },
{ id: 'node-2-2', style: { x: 230, y: 140, fill: '#FFC40C', labelText: 'degree: 1' } },
{ id: 'node-3-1', style: { x: 380, y: 220, fill: '#0f0', labelText: 'degree: 2' } },
{ id: 'node-3-2', style: { x: 180, y: 220, fill: '#0f0', labelText: 'degree: 2' } },
{
id: 'degree引导',
style: {
x: 525,
y: 110,
fill: null,
labelText: '这里可以修改degree ->',
labelFontWeight: 700,
labelFontSize: 10,
},
},
],
edges: [
{ source: 'node-1', target: 'node-2-1' },
{ source: 'node-1', target: 'node-2-2' },
{ source: 'node-2-1', target: 'node-3-1' },
{ source: 'node-2-2', target: 'node-3-2' },
],
},
node: {
style: { label: true, labelFill: '#666', labelFontSize: 14, labelPlacement: 'bottom' },
state: {
custom: { fill: '#ffa940' },
},
},
edge: {
stroke: '#8b9baf',
state: {
custom: { stroke: '#ffa940' },
},
},
behaviors: [
{
type: 'click-select',
key: 'click-select',
},
],
plugins: [{ type: 'grid-line', size: 30 }],
animation: true,
},
{ width: 600, height: 300 },
(gui, graph) => {
const options = {
key: 'click-select',
type: 'click-select',
animation: true,
enable: true,
multiple: false,
trigger: 'shift+click',
state: 'selected',
unselectedState: undefined,
degree: 0,
};
const optionFolder = gui.addFolder('Click Select Options');
optionFolder.add(options, 'type').disable(true);
optionFolder.add(options, 'animation');
optionFolder.add(options, 'enable');
optionFolder.add(options, 'degree', 0, 2, 1);
optionFolder.add(options, 'state', ['active', 'selected', 'custom']);
optionFolder.add(options, 'unselectedState', [undefined, 'inactive']);
const trigger = optionFolder
.add(options, 'trigger', {
'shift+click': ['shift'],
'meta+click': ['Meta'],
})
.hide();
optionFolder.add(options, 'multiple').onChange((v) => trigger.show(v));
optionFolder.onChange(({ property, value }) => {
graph.updateBehavior({
key: 'click-select',
[property]: value,
});
graph.render();
});
},
);

Basic Usage

Add this behavior in the graph configuration:

1. Quick Configuration (Static)

Declare directly using a string form. This method is simple but only supports default configuration and cannot be dynamically modified after configuration:

const graph = new Graph({
// Other configurations...
behaviors: ['click-select'],
});

2. Object Configuration (Recommended)

Configure using an object form, supporting custom parameters, and can dynamically update the configuration at runtime:

const graph = new Graph({
// Other configurations...
behaviors: [
{
type: 'click-select',
key: 'click-select-1',
degree: 2, // Selection spread range
state: 'active', // Selected state
neighborState: 'neighborActive', // Neighbor node attached state
unselectedState: 'inactive', // Unselected node state
},
],
});

Configuration Options

OptionDescriptionTypeDefaultRequired
typeBehavior type name. This behavior is built-in, and you can use it with type: 'click-select'.click-select | stringclick-select✓
animationWhether to enable animation effects when switching element statesbooleantrue
degreeControls the highlight spread range, examplenumber | (event:Event) => number0
enableWhether to enable the click element function, supports dynamic control through functions, exampleboolean | ((event: Event) => boolean)true
multipleWhether to allow multiple selectionsbooleanfalse
stateThe state applied when an element is selectedstring | selected | active| inactive| disabled| highlightselected
neighborStateThe state applied to elements with n-degree relationships when an element is selected. The value of n is controlled by the degree attribute, for example, degree 1 means directly adjacent elements, examplestring | selected | active| inactive| disabled| highlightselected
unselectedStateThe state applied to all other elements except the selected element and its affected neighbor elements when an element is selected, examplestring | selected | active| inactive| disabled| highlight
onClickCallback when an element is clicked(event: Event) => void
triggerPress this shortcut key in combination with a mouse click to perform multi-selection, key reference: MDN Key Valuesstring[] | (Control | Shift| Alt | ......)[]['shift']

degree

Controls the highlight spread range

  • For nodes, 0 means only the current node is selected, 1 means the current node and its directly adjacent nodes and edges are selected, and so on.
  • For edges, 0 means only the current edge is selected, 1 means the current edge and its directly adjacent nodes are selected, and so on.

In the following example, when degree: 0 only the red point is highlighted; When degree: 1 the red and orange points are highlighted.

createGraph(
{
data: {
nodes: [
{ id: 'node-1', style: { x: 280, y: 60, fill: '#E4504D', labelText: 'degree: 0' } },
{ id: 'node-2-1', style: { x: 330, y: 140, fill: '#FFC40C', labelText: 'degree: 1' } },
{ id: 'node-2-2', style: { x: 230, y: 140, fill: '#FFC40C', labelText: 'degree: 1' } },
{ id: 'node-3-1', style: { x: 380, y: 220, fill: '#0f0', labelText: 'degree: 2' } },
{ id: 'node-3-2', style: { x: 180, y: 220, fill: '#0f0', labelText: 'degree: 2' } },
{
id: 'degree引导',
style: {
x: 525,
y: 110,
fill: null,
labelText: '这里可以修改degree ->',
labelFontWeight: 700,
labelFontSize: 10,
},
},
],
edges: [
{ source: 'node-1', target: 'node-2-1' },
{ source: 'node-1', target: 'node-2-2' },
{ source: 'node-2-1', target: 'node-3-1' },
{ source: 'node-2-2', target: 'node-3-2' },
],
},
node: {
style: { label: true, labelFill: '#666', labelFontSize: 14, labelPlacement: 'bottom' },
state: {
custom: { fill: '#ffa940' },
},
},
edge: {
stroke: '#8b9baf',
state: {
custom: { stroke: '#ffa940' },
},
},
behaviors: [
{
type: 'click-select',
key: 'click-select',
},
],
plugins: [{ type: 'grid-line', size: 30 }],
animation: true,
},
{ width: 600, height: 300 },
(gui, graph) => {
const options = {
key: 'click-select',
type: 'click-select',
animation: true,
enable: true,
multiple: false,
trigger: 'shift+click',
state: 'selected',
unselectedState: undefined,
degree: 0,
};
const optionFolder = gui.addFolder('Click Select Options');
optionFolder.add(options, 'type').disable(true);
optionFolder.add(options, 'animation');
optionFolder.add(options, 'enable');
optionFolder.add(options, 'degree', 0, 2, 1);
optionFolder.add(options, 'state', ['active', 'selected', 'custom']);
optionFolder.add(options, 'unselectedState', [undefined, 'inactive']);
const trigger = optionFolder
.add(options, 'trigger', {
'shift+click': ['shift'],
'meta+click': ['Meta'],
})
.hide();
optionFolder.add(options, 'multiple').onChange((v) => trigger.show(v));
optionFolder.onChange(({ property, value }) => {
graph.updateBehavior({
key: 'click-select',
[property]: value,
});
graph.render();
});
},
);

enable

Whether to enable the click element function

It can be dynamically controlled through functions, for example, only enabled when a node is selected.

{
//⚠️ Note, you need to set both the node and the canvas, otherwise the user will not listen to the event when clicking the canvas
enable: (event) => ['node', 'canvas'].includes(event.targetType);
}

createGraph(
{
data: {
nodes: [
{ id: 'node1', style: { x: 100, y: 60 } },
{ id: 'node2', style: { x: 200, y: 60 } },
{ id: 'node3', style: { x: 300, y: 60 } },
],
edges: [
{ source: 'node1', target: 'node2' },
{ source: 'node2', target: 'node3' },
],
},
node: {
style: {
fill: '#E4504D',
},
state: {
active: {
fill: '#0f0',
},
neighborActive: {
fill: '#FFC40C',
},
},
},
behaviors: [
{
type: 'click-select',
degree: 1,
state: 'active',
neighborState: 'neighborActive',
enable: (event) => ['node', 'canvas'].includes(event.targetType),
},
],
},
{ width: 400, height: 200 },
);

Similarly, if you only want edges to be selected:

{
enable: (event) => ['edge', 'canvas'].includes(event.targetType);
}

neighborState

The state applied to elements with n-degree relationships when an element is selected. The value of n is controlled by the degree attribute, for example, degree 1 means directly adjacent elements

const graph = new Graph({
behaviors: [
{
type: 'click-select',
degree: 1,
// State attached to the directly clicked node
state: 'active',
// State attached to adjacent nodes
neighborState: 'neighborActive',
},
],
});

createGraph(
{
layout: {
type: 'grid',
},
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' },
],
},
node: {
style: {
fill: '#E4504D',
},
state: {
active: {
fill: '#0f0',
},
neighborActive: {
fill: '#FFC40C',
halo: true,
},
},
},
behaviors: [
{
type: 'click-select',
degree: 1,
state: 'active',
neighborState: 'neighborActive',
},
],
},
{ width: 400, height: 200 },
);

unselectedState

When an element is selected, the state applied to all other elements except the selected element and the spread neighbor elements.

Built-in states: selected active inactive disabled highlight

const graph = new Graph({
behaviors: [
{
type: 'click-select',
degree: 1,
unselectedState: 'inactive',
},
],
});

createGraph(
{
layout: {
type: 'grid',
},
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' },
],
},
node: {
style: {
fill: '#E4504D',
},
state: {
active: {
fill: '#0f0',
},
neighborActive: {
fill: '#FFC40C',
},
},
},
behaviors: [
{
type: 'click-select',
degree: 1,
state: 'active',
neighborState: 'neighborActive',
unselectedState: 'inactive',
},
],
},
{ width: 400, height: 200 },
);

Example

Click to select nodes and their directly connected nodes

Clicking a node will switch from default state to active
Adjacent nodes will switch from default state to neighborActive

const graph = new Graph({
node: {
style: {
fill: '#E4504D',
},
state: {
// Selected node state
active: {
fill: '#0f0',
},
// Adjacent node state
neighborActive: {
fill: '#FFC40C',
},
},
},
behaviors: [
{
type: 'click-select',
degree: 1,
state: 'active',
// State attached to adjacent nodes
neighborState: 'neighborActive',
// Unselected node state
unselectedState: 'inactive',
},
],
});

createGraph(
{
layout: {
type: 'grid',
},
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' },
],
},
node: {
style: {
fill: '#E4504D',
},
state: {
active: {
fill: '#0f0',
},
neighborActive: {
fill: '#FFC40C',
},
},
},
behaviors: [
{
type: 'click-select',
degree: 1,
state: 'active',
neighborState: 'neighborActive',
unselectedState: 'inactive',
},
],
},
{ width: 400, height: 200 },
);

Practical Example