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

AutoAdaptLabel

Previous
Behavior Overview
Next
BrushSelect

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

Auto-adapt label display is a dynamic label management strategy designed to intelligently adjust which labels should be displayed or hidden based on factors such as spatial allocation of the current visible range and node importance. By analyzing the visible area in real-time, it ensures that users receive the most relevant and clear information display in different interaction scenarios, while avoiding visual overload and information redundancy.

Usage Scenarios

This interaction is mainly used for:

  • Node size changes
  • Graph scaling

Online Experience

createGraph(
{
data: {
nodes: [
{ id: 'node1', style: { x: 200, y: 100, labelText: '短标签' } },
{ id: 'node2', style: { x: 360, y: 100, labelText: '中等长度的标签' } },
{ id: 'node3', style: { x: 280, y: 220, labelText: '这是一个非常非常长的标签,需要自适应显示' } },
],
edges: [
{ source: 'node1', target: 'node2' },
{ source: 'node1', target: 'node3' },
{ source: 'node2', target: 'node3' },
],
},
node: {
style: { label: true, fill: '#7e3feb', labelFill: '#666', labelFontSize: 14, labelPlacement: 'bottom' },
state: {
custom: { fill: '#ffa940' },
},
},
edge: {
stroke: '#8b9baf',
state: {
custom: { stroke: '#ffa940' },
},
},
behaviors: ['zoom-canvas', 'drag-canvas', { key: 'auto-adapt-label', type: 'auto-adapt-label' }],
plugins: [{ type: 'grid-line', size: 30 }],
animation: true,
},
{ width: 600, height: 400 },
(gui, graph) => {
const options = {
key: 'auto-adapt-label',
type: 'auto-adapt-label',
animation: true,
enable: true,
throttle: 100,
padding: 0
};
const optionFolder = gui.addFolder('CollapseExpand Options');
optionFolder.add(options, 'type').disable(true);
optionFolder.add(options, 'animation');
optionFolder.add(options, 'enable');
optionFolder.add(options, 'throttle', 0, 900, 100);
optionFolder.add(options, 'padding', 0, 20, 1);
optionFolder.onChange(({ property, value }) => {
graph.updateBehavior({
key: 'auto-adapt-label',
[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: ['auto-adapt-label'],
});

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: 'auto-adapt-label',
throttle: 200, // Throttle time
padding: 10, // Extra spacing when detecting overlap
},
],
});

Configuration Options

OptionDescriptionTypeDefaultRequired
typeInteraction type namestringauto-adapt-label√
enableWhether to enable this interactionboolean | ((event: Event) => boolean)true
throttleLabel update throttle time (ms)number100
paddingExtra spacing when detecting label overlapnumber | number[]0
sortCustom sorting function, sorting elements from high to low importance, with higher importance elements having higher label display priority. Generally, combo > node > edge(a: ElementDatum, b: ElementDatum) => -1 | 0 | 1
sortNodeSort nodes from high to low importance, with higher importance nodes having higher label display priority. Several built-in centrality algorithms are available, or a custom sorting function can be used. Note that if sort is set, sortNode will not take effectNodeCentralityOptions | (nodeA: NodeData, nodeB: NodeData => -1 | 0 | 1)type: 'degree'
sortEdgeSort edges from high to low importance, with higher importance edges having higher label display priority. By default, it is sorted according to the order of data. Note that if sort is set, sortEdge will not take effect(edgeA: EdgeData, edgeB: EdgeData) => -1 | 0 | 1
sortComboSort groups from high to low importance, with higher importance groups having higher label display priority. By default, it is sorted according to the order of data. Note that if sort is set, sortCombo will not take effect(comboA: ComboData, comboB: ComboData) => -1 | 0 | 1

NodeCentralityOptions

Methods for measuring node centrality

  • 'degree': Degree centrality, measured by the degree of the node (number of connected edges). Nodes with high degree centrality usually have more direct connections and may play important roles in the network
  • 'betweenness': Betweenness centrality, measured by the number of times a node appears in all shortest paths. Nodes with high betweenness centrality usually act as bridges in the network, controlling the flow of information
  • 'closeness': Closeness centrality, measured by the reciprocal of the sum of the shortest path lengths from the node to all other nodes. Nodes with high closeness centrality can usually reach other nodes in the network more quickly
  • 'eigenvector': Eigenvector centrality, measured by the degree of connection of the node to other central nodes. Nodes with high eigenvector centrality are usually connected to other important nodes
  • 'pagerank': PageRank centrality, measured by the number of times a node is referenced by other nodes, commonly used in directed graphs. Nodes with high PageRank centrality usually have high influence in the network, similar to webpage ranking algorithms
type NodeCentralityOptions =
| { type: 'degree'; direction?: 'in' | 'out' | 'both' }
| { type: 'betweenness'; directed?: boolean; weightPropertyName?: string }
| { type: 'closeness'; directed?: boolean; weightPropertyName?: string }
| { type: 'eigenvector'; directed?: boolean }
| { type: 'pagerank'; epsilon?: number; linkProb?: number };

Practical Example