docs: add coordinate docs (#6117)

Co-authored-by: antv <antv@antfin.com>
This commit is contained in:
Aaron 2024-08-02 16:08:01 +08:00 committed by GitHub
parent 5016fe2bcc
commit 6b2ec3d41c
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 87 additions and 7 deletions

View File

@ -1382,9 +1382,9 @@ export class Graph extends EventEmitter {
* <en/> Get the position of the graph
* @returns <zh/> | <en/> position of the graph
* @remarks
* <zh/> [0, 0]
* <zh/> [0, 0]
*
* <en/> By default, the position of the graph is [0, 0]
* <en/> That is, the position of the canvas origin in the viewport coordinate system. By default, the position of the graph is [0, 0]
* @apiCategory viewport
*/
public getPosition(): Point {
@ -1843,10 +1843,10 @@ export class Graph extends EventEmitter {
}
/**
* <zh/>
* <zh/>
*
* <en/> Get the canvas coordinates of the canvas center
* @returns <zh/> | <en/> Canvas coordinates of the canvas center
* <en/> Get the viewport coordinates of the viewport center
* @returns <zh/> | <en/> Viewport coordinates of the viewport center
* @apiCategory viewport
*/
public getCanvasCenter(): Point {

View File

@ -3,4 +3,45 @@ title: coordinate
order: 1
---
Coming soon...
## Overview
There are three coordinate systems in G6 5.0: Canvas, Viewport, and Client.
### Canvas Coordinate System
The coordinate system used when drawing G6 elements is not affected by camera zooming or panning. To change the position of an element, you need to directly modify the element's position properties (x/y/z).
The canvas space is theoretically infinite. In the initial state (no panning, zoom ratio is 1), the origin of the canvas coordinate system is located at the upper-left corner of the viewport.
### Viewport Coordinate System
The viewport coordinate system is the projection of the camera coordinate system. When the camera pans or zooms, the position of elements in the canvas will also change in the viewport coordinate system.
The size of the viewport is the size of the canvas DOM container. The origin of the viewport coordinate system is located at the upper-left corner of the viewport, with the x-axis pointing to the right and the y-axis pointing down.
![viewport](https://developer.mozilla.org/en-US/Web/API/Canvas_API/Tutorial/Drawing_shapes/canvas_default_grid.png)
### Client Coordinate System
The client coordinate system has the browser's upper-left corner as the origin, with the x-axis pointing to the right and the y-axis pointing down.
The following figure describes the relationship between the viewport coordinate system and the client coordinate system:
<img width="300" src="https://mdn.alipayobjects.com/huamei_qa8qxu/afts/img/A*HOcfToHFDIYAAAAAAAAAAAAADmJ7AQ/original" />
## Coordinate System Conversion
G6 provides methods for coordinate system conversion, making it easy to convert between different coordinate systems.
- Canvas coordinate system to viewport coordinate system: [getViewportByCanvas](/en/api/graph/method#graphgetviewportbycanvaspoint)
- Client coordinate system to canvas coordinate system: [getCanvasByClient](/en/api/graph/method#graphgetcanvasbyclientpoint)
- Viewport coordinate system to canvas coordinate system: [getCanvasByViewport](/en/api/graph/method#graphgetcanvasbyviewportpoint)
- Canvas coordinate system to client coordinate system: [getClientByCanvas](/en/api/graph/method#graphgetclientbycanvaspoint)
Other related APIs are also provided:
- Get the viewport center in viewport coordinates: [getCanvasCenter](/en/api/graph/method#graphgetcanvascenter)
- Get the viewport center in canvas coordinates: [getViewportCenter](/en/api/graph/method#graphgetviewportcenter)
- Get the position of the graph origin in the viewport coordinate system: [getPosition](/en/api/graph/method#graphgetposition)

View File

@ -3,4 +3,43 @@ title: 坐标系
order: 1
---
建设中...
## 概述
在 G6 5.0 中主要会涉及三个坐标系:画布坐标系(Canvas)、视口坐标系(Viewport)和浏览器坐标系(Client)。
### 画布坐标系
G6 元素绘制时所使用的坐标系,其不受相机缩放、平移的影响,要改变一个元素的位置,需要直接修改元素的位置属性(x/y/z)。
画布空间理论上是无限大的在初始状态下无平移、缩放倍率为1画布坐标系的原点位于视口左上角位置。
### 视口坐标系
视口坐标系是相机坐标系的投影,当相机发生平移、缩放时,画布中元素位置在视口坐标系中的位置也会发生变化。
视口的大小即画布 DOM 容器的大小视口坐标系的原点位于视口左上角位置x 轴正方向向右y 轴正方向向下。
![viewport](https://developer.mozilla.org/en-US/Web/API/Canvas_API/Tutorial/Drawing_shapes/canvas_default_grid.png)
### 浏览器坐标系
浏览器坐标系以浏览器左上角为原点x 轴正方向向右y 轴正方向向下。
下图描述了视口坐标系和浏览器坐标系之间的关系:
<img width="300" src="https://mdn.alipayobjects.com/huamei_qa8qxu/afts/img/A*HOcfToHFDIYAAAAAAAAAAAAADmJ7AQ/original" />
## 坐标系转换
G6 提供了坐标系转换的方法,可以方便地在不同坐标系之间进行转换。
- 画布坐标系转视口坐标系:[getViewportByCanvas](/api/graph/method#graphgetviewportbycanvaspoint)
- 浏览器坐标系转画布坐标系:[getCanvasByClient](/api/graph/method#graphgetcanvasbyclientpoint)
- 视口坐标系转画布坐标系:[getCanvasByViewport](/api/graph/method#graphgetcanvasbyviewportpoint)
- 画布坐标系转浏览器坐标系:[getClientByCanvas](/api/graph/method#graphgetclientbycanvaspoint)
另外还提供了其他相关 API
- 获取视口中心的视口坐标:[getCanvasCenter](/api/graph/method#graphgetcanvascenter)
- 获取视口中心的画布坐标:[getViewportCenter](/api/graph/method#graphgetviewportcenter)
- 获取图原点在视口坐标系中的位置:[getPosition](/api/graph/method#graphgetposition)