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

DragElementForce

Previous
DragElement
Next
FixElementSize

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

DragElementForce is a built-in behavior in G6 for implementing node dragging under d3-force and d3-force-3d layouts. During dragging, the layout is recalculated in real-time, allowing the graph layout to dynamically adjust to accommodate the new position of the nodes.

Effect of DragElementForce

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: ['drag-element-force'],
});

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: 'drag-element-force',
key: 'drag-element-force-1',
fixed: true, // Fix node position after dragging
},
],
});

Configuration Options

OptionDescriptionTypeDefaultRequired
typeBehavior type name, set type: 'drag-element-force' to enable this behaviorstringdrag-element-force✓
keyUnique identifier for the behavior, used for subsequent operationsstring-
fixedWhether to keep the node position fixed after dragging ends, boolean values represent:
- true: After dragging ends, the node's position will remain fixed and not be affected by the layout algorithm
- false: After dragging ends, the node's position will continue to be affected by the layout algorithm
booleanfalse
enableWhether to enable the drag function, by default nodes and combos can be draggedboolean | ((event: IElementDragEvent) => boolean)['node', 'combo'].includes(event.targetType)
stateIdentifier for the selected state of nodes, when multi-selection is enabled, it will find the selected nodes based on this statestringselected
hideEdgeControls the display state of edges during dragging, optional values are:
- none: Do not hide any edges
- out: Hide edges with the current node as the source node
- in: Hide edges with the current node as the target node
- both: Hide all edges related to the current node
- all: Hide all edges in the graph
⚠️ Note: When shadow (ghost node) is enabled, the hideEdge configuration will not take effect.
none | all | in | out | bothnone
cursorCustomize the mouse style during dragging, example{ default?: Cursor; grab: Cursor; grabbing: Cursor }-

cursor

cursor is used to customize the mouse pointer style during dragging:

  • default: Pointer style in default state
  • grab: Pointer style when hovering over a draggable element
  • grabbing: Pointer style when dragging

Optional values are: 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

Example configuration:

cursor: {
default: 'default', // Use normal pointer by default
grab: 'grab', // Show grab pointer when draggable
grabbing: 'grabbing' // Show grabbing pointer when dragging
}

FAQ

1. What is the difference between DragElementForce and DragElement?

  • DragElementForce is specifically used for d3-force or d3-force-3d layouts, and recalculates the layout in real-time during dragging
  • DragElement is a general drag interaction and does not trigger layout recalculation

Practical Example

Mesh Effect

Fix Dragged Nodes

Shadow Style

shadow{BaseStyleProps}

An expression like icon{TextStyleProps} indicates that properties of the TextStyleProps type are prefixed with icon in camelCase format.

TextStyleProps includes the following properties:

  • fill
  • fontSize
  • fontWeight
  • ...

icon{TextStyleProps} means you need to use the following property names:

  • iconFill
  • iconFontSize
  • iconFontWeight
  • ...