Loading...
In position calculations, we often need to perform coordinate conversions. In X6, there are two coordinate systems: the local canvas coordinate system local
and the graph coordinate system graph
. Sometimes, we also need to involve the browser coordinate system. Here's a unified explanation:
local
: The local canvas coordinate system, which defaults to being consistent with the graph
coordinate system but will change with canvas scaling and translation. All node coordinates in the canvas are based on the local
coordinate system.graph
: The graph coordinate system, which is the canvas viewport we see and will not change with canvas scaling and translation.client
: The browser coordinate system, where e.clientX
and e.clientY
in mouse events are relative to the browser coordinate system.page
: The page coordinate system, which considers page horizontal and vertical scrolling compared to client
. e.pageX
and e.pageY
in mouse events are relative to the page coordinate system.pageToLocal(rect: Rectangle.RectangleLike): RectanglepageToLocal(x: number, y: number, width: number, height: number): RectanglepageToLocal(p: Point.PointLike): PointpageToLocal(x: number, y: number): Point
Converts page coordinates to local canvas coordinates.
localToPage(rect: Rectangle.RectangleLike): RectanglelocalToPage(x: number, y: number, width: number, height: number): RectanglelocalToPage(p: Point.PointLike): PointlocalToPage(x: number, y: number): Point
Converts local canvas coordinates to page coordinates.
clientToLocal(rect: Rectangle.RectangleLike): RectangleclientToLocal(x: number, y: number, width: number, height: number): RectangleclientToLocal(p: Point.PointLike): PointclientToLocal(x: number, y: number): Point
Converts browser coordinates to local canvas coordinates.
localToClient(rect: Rectangle.RectangleLike): RectanglelocalToClient(x: number, y: number, width: number, height: number): RectanglelocalToClient(p: Point.PointLike): PointlocalToClient(x: number, y: number): Point
Converts local canvas coordinates to browser coordinates.
localToGraph(rect: Rectangle.RectangleLike): RectanglelocalToGraph(x: number, y: number, width: number, height: number): RectanglelocalToGraphPoint(p: Point.PointLike): PointlocalToGraphPoint(x: number, y: number): Point
Converts local canvas coordinates to graph coordinates.
graphToLocal(rect: Rectangle.RectangleLike): RectanglegraphToLocal(x: number, y: number, width: number, height: number): RectanglegraphToLocal(p: Point.PointLike): PointgraphToLocal(x: number, y: number): Point
Converts graph coordinates to local canvas coordinates.
snapToGrid(p: Point.PointLike): PointsnapToGrid(x: number, y: number): Point
Convert browser coordinates to canvas local coordinates and align to the canvas grid.