logo

G6

  • Docs
  • API
  • Playground
  • Community
  • Productsantv logo arrow
  • 5.0.45
  • 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 Overview
      • Shape Properties
  • Layout
    • Layout Overview
    • Build-in Layout
      • AntvDagre
      • Circular
      • ComboCombined
      • Common Layout Configuration Options
      • CompactBox
      • Concentric
      • D3Force
      • D3Force3D
      • Dagre
      • Dendrogram
      • Fishbone
      • Force
      • ForceAtlas2
      • Fruchterman
      • Grid Layout
      • Indented
      • Mds
      • Mindmap
      • Radial
      • Random
      • Snake
    • 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

FixElementSize

Previous
DragElementForce
Next
FocusElement

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

FixElementSize is a built-in interaction provided by G6, used to maintain the size of certain elements within nodes unchanged during the zooming process. It enhances visual consistency and operability during zooming. By listening to viewport changes, it automatically scales elements marked as "fixed size" to ensure they maintain a relatively constant display size at different zoom levels. It supports global enablement and also allows control over specific elements or nodes as needed.

Use Cases

This interaction is mainly used for:

  • Graphical elements or embedded components (buttons, labels, etc.) that need to maintain a fixed visual size

Online Experience

createGraph(
{
data: {
nodes: [
{ id: 'node1', style: { x: 200, y: 100, labelText: 'node1' } },
{ id: 'node2', style: { x: 360, y: 100, labelText: 'node2' } },
{ id: 'node3', style: { x: 280, y: 220, labelText: 'node3' } },
],
edges: [
{ source: 'node1', target: 'node2' },
{ source: 'node1', target: 'node3' },
{ source: 'node2', target: 'node3' },
],
},
node: {
style: { label: true, labelFill: '#666', labelFontSize: 14, labelPlacement: 'bottom' },
state: {
custom: { fill: '#ffa940' },
},
},
edge: {
stroke: '#8b9baf',
state: {
custom: { stroke: '#ffa940' },
},
},
behaviors: ['zoom-canvas', 'drag-canvas', { key: 'fix-element-size', type: 'fix-element-size' }],
plugins: [{ type: 'grid-line', size: 30 }],
animation: true,
},
{ width: 800, height: 400 },
(gui, graph) => {
const options = {
key: 'fix-element-size',
type: 'fix-element-size',
animation: true,
enable: true,
reset: true,
};
const optionFolder = gui.addFolder('CollapseExpand Options');
optionFolder.add(options, 'type').disable(true);
optionFolder.add(options, 'animation');
optionFolder.add(options, 'enable');
optionFolder.add(options, 'reset');
optionFolder.onChange(({ property, value }) => {
graph.updateBehavior({
key: 'fix-element-size',
[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: ['fix-element-size'],
});

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: 'fix-element-size',
enable: true, // Enable this interaction
state: 'selected', // State of elements to fix size
reset: true, // Restore style when elements are redrawn
},
],
});

Configuration Options

OptionDescriptionTypeDefaultRequired
typeInteraction type namestringfix-element-size✓
enableWhether to enable this interaction, exampleboolean | ((event: Event) => boolean)true
resetWhether to restore style when elements are redrawnbooleanfalse
stateSpecify the state of elements to fix sizestring""
nodeNode configuration item, used to define which attributes maintain a fixed visual size. If not specified (i.e., undefined), the entire node will be fixed, exampleFixShapeConfig | FixShapeConfig[]
nodeFilterNode filter, used to filter which nodes maintain a fixed size during zooming(datum: NodeData) => boolean() => true
edgeEdge configuration item, used to define which attributes maintain a fixed visual size. By default, the lineWidth and labelFontSize attributes are fixed, usage is the same as node configuration itemFixShapeConfig | FixShapeConfig[][ shape: 'key', fields: ['lineWidth'] , shape: 'halo', fields: ['lineWidth'] , shape: 'label' ]
edgeFilterEdge filter, used to filter which edges maintain a fixed size during zooming(datum: EdgeData) => boolean() => true
comboCombo configuration item, used to define which attributes maintain a fixed visual size. By default, the entire Combo will be fixed, usage is the same as node configuration itemFixShapeConfig | FixShapeConfig[]
comboFilterCombo filter, used to filter which Combos maintain a fixed size during zooming(datum: ComboData) => boolean() => true

enable

Whether to enable the fixed element size interaction. By default, it is enabled when zooming out the canvas

By default, it is enabled when zooming out the canvas, set enable: (event) => event.data.scale < 1; if you want to enable it when zooming in, set enable: (event) => event.data.scale > 1; if you want to enable it when both zooming in and out, set enable: true

node

Node configuration item, used to define which attributes maintain a fixed visual size. If not specified (i.e., undefined), the entire node will be fixed

Example

If you want to fix the lineWidth of the main shape of the node during zooming, you can configure it like this:

{
node: [{ shape: 'key', fields: ['lineWidth'] }];
}

If you want to keep the size of the element label unchanged during zooming, you can configure it like this:

{
shape: 'label';
}

FixShapeConfig

ParameterDescriptionTypeDefaultRequired
shapeSpecify the shape to fix size, it can be the class name of the shape, or a function that receives all shapes constituting the element and returns the target shapestring | ((shapes: DisplayObject[]) => DisplayObject)-✓
fieldsSpecify the fields of the shape to fix size. If not specified, the entire shape size is fixed by defaultstring[]-✘

Practical Example