logo

G6

  • Docs
  • API
  • Playground
  • Community
  • Productsantv logo arrow
  • 5.0.49
  • 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
      • Common Node Configuration
      • Circle Node
      • Diamond Node
      • Donut Node
      • Ellipse Node
      • Hexagon Node
      • HTML Node
      • Image Node
      • Rect Node
      • Star Node
      • Triangle Node
      • Custom Node
      • Define Nodes with React
    • Edge
      • Edge Overview
      • Edge Common Configuration
      • Cubic Bezier Curve Edge
      • CubicHorizontal Bezier Curve Edge
      • CubicVertical Bezier Curve Edge
      • Line Edge
      • Polyline Edge
      • Quadratic Bezier Curve Edge
      • Custom Edge
    • Combo
      • Combo Overview
      • Combo Common Options
      • Circle Combo
      • Rect Combo
      • Custom Combo
    • Shape
      • Shape and KeyShape
      • Atomic Shapes and Their Properties
      • Design and Implementation of Composite Shape
  • Layout
    • Layout Overview
    • Common Layout Configuration Options
    • AntvDagre Layout
    • Circular Layout
    • ComboCombined Layout
    • CompactBox Layout
    • Concentric Layout
    • 3D Force-Directed Layout
    • D3 Force-Directed Layout
    • Dagre Layout
    • Dendrogram Layout
    • Fishbone Layout
    • ForceAtlas2 Force-directed Layout
    • 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
    • ZoomCanvas
    • AutoAdaptLabel
    • BrushSelect
    • ClickSelect
    • CollapseExpand
    • CreateEdge
    • DragCanvas
    • DragElement
    • DragElementForce
    • FixElementSize
    • FocusElement
    • HoverActivate
    • LassoSelect
    • OptimizeViewportTransform
    • ScrollCanvas
    • Custom Behavior
  • Plugin
    • Plugin Overview
    • Background
    • BubbleSets
    • Contextmenu
    • EdgeBundling
    • EdgeFilterLens
    • Fisheye
    • Fullscreen
    • GridLine
    • History
    • Hull
    • Legend
    • Minimap
    • Snapline
    • Timebar
    • Toolbar
    • Tooltip
    • Watermark
    • Custom Plugin
  • Transform
    • Data Transformation Overview
    • 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

BrushSelect

Previous
AutoAdaptLabel
Next
ClickSelect

Resource

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-Interactive solution
xtechLiven Experience technology
© Copyright 2025 Ant Group Co., Ltd..备案号:京ICP备15032932号-38

Loading...

Overview

Brush select allows users to click and drag a box to enclose elements, selecting the elements within the box.

Usage Scenarios

This interaction is mainly used for:

  • Quickly selecting a batch of elements
  • Quickly deselecting a batch of elements

Online Experience

createGraph(
{
data: {
nodes: [
{ id: 'node-1', style: { x: 200, y: 100 } },
{ id: 'node-2', style: { x: 360, y: 100 } },
{ id: 'node-3', style: { x: 280, y: 220 } },
],
edges: [
{ source: 'node-1', target: 'node-2' },
{ source: 'node-1', target: 'node-3' },
{ source: 'node-2', target: 'node-3' },
],
},
node: {
style: { fill: '#7e3feb' },
state: {
custom: { fill: '#ffa940' },
},
},
edge: {
stroke: '#8b9baf',
state: {
custom: { stroke: '#ffa940' },
},
},
behaviors: [
{
type: 'brush-select',
key: 'brush-select',
},
],
plugins: [{ type: 'grid-line', size: 30 }],
animation: true,
},
{ width: 600, height: 300 },
(gui, graph) => {
const options = {
key: 'brush-select',
type: 'brush-select',
animation: false,
enable: true,
enableElements: ['node', 'edge', 'combo'],
immediately: false,
mode: 'default',
state: 'selected',
trigger: 'shift+drag',
};
const optionFolder = gui.addFolder('BrushSelect Options');
optionFolder.add(options, 'type').disable(true);
optionFolder.add(options, 'animation');
optionFolder.add(options, 'enable');
optionFolder.add(options, 'enableElements', [
['node', 'edge', 'combo'],
['node', 'edge'],
['node', 'combo'],
['combo', 'edge'],
['node'],
['edge'],
['combo'],
]);
optionFolder.add(options, 'trigger', {
'shift+drag': ['shift'],
drag: [],
});
optionFolder.add(options, 'state', ['active', 'selected', 'custom']);
optionFolder.add(options, 'mode', ['union', 'intersect', 'diff', 'default']).onChange((e) => {
immediately.show(e === 'default');
});
const immediately = optionFolder.add(options, 'immediately');
optionFolder.onChange(({ property, value }) => {
graph.updateBehavior({
key: 'brush-select',
[property]: value,
});
graph.render();
});
},
);

Basic Usage

Add this interaction 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: ['brush-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: 'brush-select',
key: 'brush-select-1',
immediately: true, // Elements are immediately selected as the box encloses them
trigger: ['shift', 'alt', 'control'], // Use multiple keys for selection
},
],
});

Configuration Options

OptionDescriptionTypeDefaultRequired
typeInteraction type name. This plugin is built-in, and you can use it with type: 'brush-select'.brush-select | stringbrush-select✓
animationWhether to enable animationbooleanfalse
enableWhether to enable brush select functionalityboolean | ((event: Event) => boolean)true
enableElementsTypes of elements that can be selected( node | edge | combo )[][node, combo, edge]
immediatelyWhether to select immediately, only effective when selection mode is default, examplebooleanfalse
modeSelection mode, exampleunion | intersect | diff | defaultdefault
onSelectCallback for selected element state(states:Record<string,string|string[]>) =>Record<string,string|string[]>
stateSwitch to this state when selectedstring | selected | active | inactive | disabled | highlightselected
styleSpecify the style of the selection box, configuration optionsSee below
triggerPress this shortcut key in combination with a mouse click to perform selection Key reference: MDN Key Values. If set to an empty array, it means selection can be performed with a mouse click without pressing other keys
⚠️ Note, setting trigger to ['drag'] will cause the drag-canvas behavior to fail. The two cannot be configured simultaneously.
string[] | (Control | Shift| Alt | ......)[][shift]

immediately

Whether to select immediately, only effective when selection mode is default

const graph = new Graph({
behaviors: [
{
type: 'brush-select',
key: 'brush-select',
immediately: true, // Elements are immediately selected as the box encloses them
trigger: [], // No need to press other keys, just click and drag the mouse to select
},
],
});

import { Graph } from '@antv/g6';
const graph = new Graph({
container: 'container',
width: 400,
height: 200,
data: {
nodes: [
{ id: 'node-1', style: { x: 100, y: 50 } },
{ id: 'node-2', style: { x: 260, y: 50 } },
{ id: 'node-3', style: { x: 280, y: 100 } },
],
edges: [
{ source: 'node-1', target: 'node-2' },
{ source: 'node-1', target: 'node-3' },
{ source: 'node-2', target: 'node-3' },
],
},
node: {
style: { fill: '#7e3feb' },
},
edge: {
stroke: '#8b9baf',
},
behaviors: [
{
type: 'brush-select',
key: 'brush-select',
immediately: true, // Immediate selection
trigger: [],
},
],
plugins: [{ type: 'grid-line', size: 30 }],
});
graph.render();

mode

Four selection modes are built-in:

  • union: Retain the current state of selected elements and add the specified state.
  • intersect: If the selected elements already have the specified state, retain it; otherwise, clear the state.
  • diff: Invert the specified state of the selected elements.
  • default: Clear the current state of selected elements and add the specified state.
const graph = new Graph({
behaviors: [
{
type: 'brush-select',
key: 'brush-select',
mode: 'default', // Selection mode, default selection mode
},
],
});

createGraph(
{
data: {
nodes: [
{ id: 'node-1', style: { x: 200, y: 100 } },
{ id: 'node-2', style: { x: 360, y: 100 } },
{ id: 'node-3', style: { x: 280, y: 220 } },
],
edges: [
{ source: 'node-1', target: 'node-2' },
{ source: 'node-1', target: 'node-3' },
{ source: 'node-2', target: 'node-3' },
],
},
node: {
style: { fill: '#7e3feb' },
state: {
custom: { fill: '#ffa940' },
},
},
edge: {
stroke: '#8b9baf',
state: {
custom: { stroke: '#ffa940' },
},
},
behaviors: [
{
type: 'brush-select',
key: 'brush-select',
trigger: [],
immediately: true,
},
],
plugins: [{ type: 'grid-line', size: 30 }],
animation: true,
},
{ width: 600, height: 300 },
(gui, graph) => {
const options = {
key: 'brush-select',
type: 'brush-select',
animation: false,
enable: true,
enableElements: ['node', 'edge', 'combo'],
mode: 'default',
state: 'selected',
};
const optionFolder = gui.addFolder('BrushSelect Options');
optionFolder.add(options, 'type').disable(true);
optionFolder.add(options, 'state', ['active', 'selected', 'custom']);
optionFolder.add(options, 'mode', ['union', 'intersect', 'diff', 'default']);
// .onChange((e) => {
// immediately.show(e === 'default');
// });
optionFolder.onChange(({ property, value }) => {
graph.updateBehavior({
key: 'brush-select',
[property]: value,
});
graph.render();
});
},
);

style

AttributeDescriptionTypeDefault
cursorMouse stylestring
fillFill colorstring | Pattern | null#1677FF
fillOpacityFill opacitynumber | string0.1
isBillboardEnable billboard modeboolean
isSizeAttenuationEnable size attenuationboolean
lineCapLine end stylebutt | round | square
lineDashDash configurationnumber | string | (string | number)[]
lineDashOffsetDash offsetnumber
lineJoinLine join stylemiter | round | bevel
lineWidthLine widthnumber | string1
opacityOverall opacitynumber | string
radiusRectangle corner radiusnumber | string | number[]
shadowBlurShadow blur degreenumber
shadowColorShadow colorstring
shadowOffsetXShadow X direction offsetnumber
shadowOffsetYShadow Y direction offsetnumber
strokeStroke colorstring | Pattern | null#1677FF
strokeOpacityStroke opacitynumber | string
visibilityVisibilityvisible | hidden
zIndexRendering levelnumber2

Example:

const graph = new Graph({
behaviors: [
{
type: 'brush-select',
key: 'brush-select',
style: {
width: 0,
height: 0,
lineWidth: 4,
lineDash: [2, 2], // Dashed outline
// RGB super colorful box
fill: 'linear-gradient(217deg, rgba(255,0,0,.8), rgba(255,0,0,0) 70.71%),linear-gradient(127deg, rgba(0,255,0,.8), rgba(0,255,0,0) 70.71%),linear-gradient(336deg, rgba(0,0,255,.8), rgba(0,0,255,0) 70.71%)',
stroke: 'pink',
fillOpacity: 0.2,
zIndex: 2,
pointerEvents: 'none',
},
},
],
});

import { Graph } from '@antv/g6';
const graph = new Graph({
container: 'container',
width: 600,
height: 300,
data: {
nodes: [
{ id: 'node-1', style: { x: 200, y: 100 } },
{ id: 'node-2', style: { x: 360, y: 100 } },
{ id: 'node-3', style: { x: 280, y: 220 } },
],
edges: [
{ source: 'node-1', target: 'node-2' },
{ source: 'node-1', target: 'node-3' },
{ source: 'node-2', target: 'node-3' },
],
},
node: {
style: { fill: '#7e3feb' },
},
edge: {
stroke: '#8b9baf',
},
behaviors: [
{
type: 'brush-select',
key: 'brush-select',
trigger: [],
immediately: true,
style: {
width: 0,
height: 0,
lineWidth: 4,
lineDash: [2, 2], // Dashed outline
// RGB super colorful box
fill: 'linear-gradient(217deg, rgba(255,0,0,.8), rgba(255,0,0,0) 70.71%),linear-gradient(127deg, rgba(0,255,0,.8), rgba(0,255,0,0) 70.71%),linear-gradient(336deg, rgba(0,0,255,.8), rgba(0,0,255,0) 70.71%)',
stroke: 'pink',
fillOpacity: 0.2,
zIndex: 2,
pointerEvents: 'none',
},
},
],
plugins: [{ type: 'grid-line', size: 30 }],
animation: true,
});
graph.render();

Practical Example

import { Graph } from '@antv/g6';
const graph = new Graph({
container: 'container',
data: {
nodes: [
{ id: 'node-1', style: { x: 200, y: 250 } },
{ id: 'node-2', style: { x: 250, y: 200 } },
{ id: 'node-3', style: { x: 300, y: 250 } },
{ id: 'node-4', style: { x: 250, y: 300 } },
],
edges: [
{ source: 'node-1', target: 'node-2' },
{ source: 'node-2', target: 'node-3' },
{ source: 'node-3', target: 'node-4' },
{ source: 'node-4', target: 'node-1' },
],
},
behaviors: [
{
key: 'brush-select',
type: 'brush-select',
enable: true,
animation: false,
mode: 'default', // union intersect diff default
state: 'selected', // 'active', 'selected', 'inactive', ...
trigger: [], // ['Shift', 'Alt', 'Control', 'Drag', 'Meta', ...]
style: {
width: 0,
height: 0,
lineWidth: 4,
lineDash: [2, 2],
fill: 'linear-gradient(217deg, rgba(255,0,0,.8), rgba(255,0,0,0) 70.71%),linear-gradient(127deg, rgba(0,255,0,.8), rgba(0,255,0,0) 70.71%),linear-gradient(336deg, rgba(0,0,255,.8), rgba(0,0,255,0) 70.71%)',
stroke: 'pink',
fillOpacity: 0.2,
zIndex: 2,
pointerEvents: 'none',
},
},
],
});
graph.render();