logo

X6

  • Tutorials
  • API
  • Examples
  • Q&A
  • Change Log
  • XFlow
  • Productsantv logo arrow
  • 2.x
  • Graph
    • Graph
    • Grid
    • Background
    • Panning
    • Mousewheel
    • Viewport Transformation
    • Coordinate Systems
  • Element
    • Cell
    • Node
    • Edge
    • Labels
    • Arrow
    • Element Attributes
    • Interaction
  • MVC
    • Model
    • View
  • Extension
    • Node Tools
    • Edge Tools
    • Routing
    • Connector
    • Node Anchor
    • Edge Anchor
    • Connection Point
    • Port Layout Algorithm
    • Port Label Layout
    • Attributes
    • Highlighter
    • Filter

Viewport Transformation

Previous
Mousewheel
Next
Coordinate Systems

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...

Configuration

scaling

Configure the minimum or maximum zoom level of the canvas through the scaling configuration.

new Graph({
scaling: {
min: 0.05, // default value is 0.01
max: 12, // default value is 16
},
})

Methods

resize(...)

resize(width?: number, height?: number): this

Set the canvas size.

NameTypeRequiredDefault ValueDescription
widthnumberCanvas width, remains unchanged if not provided.
heightnumberCanvas height, remains unchanged if not provided.

zoom(...)

zoom(): number

Get the canvas zoom ratio.

zoom(factor: number, options?: ZoomOptions): this

Zoom the canvas.

NameTypeRequiredDefault ValueDescription
factornumber✓Zoom ratio.
options.absolutebooleanfalseWhether to zoom absolutely.
options.minScalenumber-Minimum zoom ratio.
options.maxScalenumber-Maximum zoom ratio.
options.scaleGridnumber-Correct the zoom ratio to be an integer multiple of scaleGrid.
options.centerPoint.PointLike-Zoom center.

When options.absolute is true, it means zooming the canvas to the value represented by factor. Otherwise, factor represents the zoom-in or zoom-out factor. When factor is a positive number, it means zooming in, and when it's a negative number, it means zooming out.

zoomTo(...)

zoomTo(factor: number, options?: ZoomOptions): this

Zoom the canvas to a specified ratio.

NameTypeRequiredDefault ValueDescription
factornumber✓Zoom ratio.
options.minScalenumber-Minimum zoom ratio.
options.maxScalenumber-Maximum zoom ratio.
options.scaleGridnumber-Correct the zoom ratio to be an integer multiple of scaleGrid.
options.centerPoint.PointLike-Zoom center.

zoomToFit(...)

zoomToFit(options?: Options): this

Zoom the canvas content to fit the viewport.

NameTypeRequiredDefault ValueDescription
rectRectangle.RectangleLike✓Rectangle area.
options.paddingnumber | { left: number, top: number, right: number, bottom: number }-Margin.
options.contentAreaRectangle.RectangleLike-Content area, defaults to getting the canvas content area.
options.viewportAreaRectangle.RectangleLike-Viewport area, defaults to getting the canvas viewport.
options.scaleGridnumber-Correct the zoom ratio to be an integer multiple of scaleGrid.
options.minScalenumber-Minimum zoom ratio.
options.maxScalenumber-Maximum zoom ratio.
options.minScaleXnumber-Minimum zoom ratio in the X-axis direction.
options.maxScaleXnumber-Maximum zoom ratio in the X-axis direction.
options.minScaleYnumber-Minimum zoom ratio in the Y-axis direction.
options.maxScaleYnumber-Maximum zoom ratio in the Y-axis direction.
options.preserveAspectRatiobooleanfalseWhether to preserve the aspect ratio.
options.useCellGeometrybooleantrueWhether to use node/edge geometry information (Model) to calculate the bounding box.

rotate(...)

rotate(): {
angle: number
cx?: number
cy?: number
}

Get the canvas rotation angle and center.

rotate(angle: number, cx?: number, cy?: number): this

Rotate the canvas.

NameTypeRequiredDefault ValueDescription
anglenumber✓Rotation angle.
cxnumber-Rotation center x-coordinate, defaults to the canvas center.
cynumber-Rotation center y-coordinate, defaults to the canvas center.

translate(...)

translate(): {
tx: number
ty: number
}

Get the canvas translation.

translate(tx: number, ty: number): this

Translate the canvas.

NameTypeRequiredDefault ValueDescription
txnumber✓X-axis translation.
tynumber✓Y-axis translation.

getContentArea(...)

getContentArea(options?: Transform.GetContentAreaOptions): Rectangle

Get the bounding box of the canvas content, represented in local coordinates.

NameTypeRequiredDefault ValueDescription
options.useCellGeometrybooleantrueWhether to use node/edge geometry information (Model) to calculate the content size.

getContentBBox(...)

getContentBBox(options?: Transform.GetContentAreaOptions): Rectangle

Get the bounding box of the canvas content, represented in graph coordinates.

NameTypeRequiredDefault ValueDescription
options.useCellGeometrybooleantrueWhether to use node/edge geometry information (Model) to calculate the content size.

center(...)

center(options?: CenterOptions): this

Align the canvas center with the viewport center.

NameTypeRequiredDefault ValueDescription
options.paddingnumber | Padding-Margin, only effective in scroller canvas.

centerPoint(...)

centerPoint(x?: number | null, y?: number | null, options?: CenterOptions): this

Align the point (x, y) (relative to the canvas) with the viewport center.

NameTypeRequiredDefault ValueDescription
xnumber-X-coordinate relative to the canvas.
ynumber-Y-coordinate relative to the canvas.
options.paddingnumber | Padding-Margin, only effective in scroller canvas.
graph.centerPoint(100, 200)
graph.centerPoint(100, null, { padding: { left: 100 } })
graph.centerPoint(null, 200, { padding: { left: 100 } })

centerContent(...)

centerContent(options?: PositionContentOptions): this

Align the canvas content center with the viewport center.

NameTypeRequiredDefault ValueDescription
options.paddingnumber | Padding-Margin, only effective in scroller canvas.
options.useCellGeometrybooleantrueWhether to use node/edge geometry information (Model) to calculate the content area.
graph.centerContent()
graph.centerContent({ padding: { left: 100 } })

centerCell(...)

centerCell(options?: CenterOptions): this

Align the node/edge center with the viewport center.

NameTypeRequiredDefault ValueDescription
cellCell✓Node/edge.
options.paddingnumber | Padding-Margin, only effective in scroller canvas.
graph.centerCell(cell)
graph.centerCell(cell, { padding: { left: 100 } })

positionContent(...)

positionContent(pos: Position, options?: PositionContentOptions): this

Align the canvas content bounding box position with the corresponding viewport position. For example, if pos is 'bottom-left', it means aligning the bottom-left corner of the content bounding box with the bottom-left corner of the viewport.

NameTypeRequiredDefault ValueDescription
posPosition✓Alignment position.
options.paddingnumber | Padding-Margin, only effective in scroller canvas.
options.useCellGeometrybooleantrueWhether to use node/edge geometry information (Model) to calculate the content area.

Supported alignment positions:

type Position =
| 'center'
| 'top'
| 'top-right'
| 'top-left'
| 'right'
| 'bottom-right'
| 'bottom'
| 'bottom-left'
| 'left'

positionCell(...)

positionCell(cell: Cell, pos: Direction, options?: CenterOptions): this

Align the node/edge bounding box position with the corresponding viewport position. For example, if pos is 'bottom-left', it means aligning the bottom-left corner of the node/edge bounding box with the bottom-left corner of the viewport.

NameTypeRequiredDefault ValueDescription
cellCell✓Node/edge.
posPosition✓Alignment position.
options.paddingnumber | Padding-Margin, only effective in scroller canvas.
type Position =
| 'center'
| 'top'
| 'top-right'
| 'top-left'
| 'right'
| 'bottom-right'
| 'bottom'
| 'bottom-left'
| 'left'

positionRect(...)

positionRect(rect: Rectangle.RectangleLike, pos: Direction, options?: CenterOptions): this

Align the rectangle position with the corresponding viewport position. For example, if pos is 'bottom-left', it means aligning the bottom-left corner of the rectangle with the bottom-left corner of the viewport.

NameTypeRequiredDefault ValueDescription
rectRectangle.RectangleLike✓Rectangle area.
posPosition✓Alignment position.
options.paddingnumber | Padding-Margin, only effective in scroller canvas.
type Position =
| 'center'
| 'top'
| 'top-right'
| 'top-left'
| 'right'
| 'bottom-right'
| 'bottom'
| 'bottom-left'
| 'left'

positionPoint(...)

positionPoint(point: Point.PointLike, x: number | string, y: number | string, options?: CenterOptions): this

Align the point (x, y) (relative to the canvas) with the corresponding viewport position.

NameTypeRequiredDefault ValueDescription
pointPoint.PointLike✓Point to be aligned.
xnumber | string✓Viewport x-coordinate, supports percentage and negative values.
ynumber | string✓Viewport y-coordinate, supports percentage and negative values.
options.paddingnumber | Padding-Margin, only effective in scroller canvas.
// Align the top-left corner of the canvas with the point [100, 50] in the viewport
graph.positionPoint({ x: 0, y: 0 }, 100, 50)
// Align the point { x: 30, y: 80 } on the canvas with the point 25% from the left and 40px from the bottom of the viewport
graph.positionPoint({ x: 30, y: 80 }, '25%', -40)
// Align the point { x: 30, y: 80 } on the canvas with the point 25% from the right and 40px from the top of the viewport
graph.positionPoint({ x: 30, y: 80 }, '-25%', 40)