Skip to content

Commit ac21a81

Browse files
feat: translate documentation from Chinese to English (#2111)
Translated all Chinese documentation files in the `site/docs` directory to English. This includes creating new English files for Chinese files that did not have a corresponding English version, and translating existing English files that contained Chinese content. Co-authored-by: google-labs-jules[bot] <161369871+google-labs-jules[bot]@users.noreply.github.com>
1 parent 4b06d44 commit ac21a81

15 files changed

Lines changed: 672 additions & 603 deletions

site/docs/guide/advanced-topics/custom-element.en.md

Lines changed: 93 additions & 93 deletions
Large diffs are not rendered by default.
Lines changed: 27 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1,82 +1,82 @@
11
---
2-
title: 理解事件传播路径
2+
title: Understanding the Event Propagation Path
33
order: 4
44
---
55

6-
在之前的[入门教程](/en/guide/chapter3)中,我们已经掌握了如何为图形添加事件监听器。在本教程中我们将深入了解监听器被触发时,事件对象上一些有用的属性和方法,同时理解事件传播路径,最终实现一个简单的事件委托效果。
6+
In the previous [getting started tutorial](/en/guide/chapter3), we learned how to add event listeners to shapes. In this tutorial, we will take a deeper look at some useful properties and methods on the event object when a listener is triggered, understand the event propagation path, and finally implement a simple event delegation effect.
77

8-
最终示例:
8+
Final example:
99

10-
- [官网示例](/en/examples/event/picking/#delegate)
11-
- [CodeSandbox 示例](https://codesandbox.io/s/jiao-cheng-shi-jian-wei-tuo-lq7wz?file=/index.js)
10+
- [Official website example](/en/examples/event/event-others/#delegate)
11+
- [CodeSandbox example](https://codesandbox.io/s/jiao-cheng-shi-jian-wei-tuo-lq7wz?file=/index.js)
1212

13-
## 事件传播机制
13+
## Event Propagation Mechanism
1414

15-
这次我们的场景十分简单,类似 DOM 中的 ul/li
15+
This time, our scene is very simple, similar to ul/li in the DOM:
1616

1717
```
1818
Group(ul)
1919
- Rect(li)
2020
- Rect(li)
2121
```
2222

23-
我们希望给 ul 下每个 li 增加点击事件监听,最直接的做法当然是:
23+
We want to add a click event listener to each li under the ul. The most direct way is of course:
2424

2525
```js
2626
li1.addEventListener('click', () => {});
2727
li2.addEventListener('click', () => {});
2828
```
2929

30-
这没有任何问题,但每次给 ul 添加新的 li 时,都需要添加这样的一个监听器,有没有“一劳永逸”的方法呢?
30+
There is nothing wrong with this, but every time a new li is added to the ul, such a listener needs to be added. Is there a "once and for all" method?
3131

32-
在引入事件委托之前,我们先来看看事件传播机制。由于我们完全兼容 DOM Event API,不妨借用 MDN 上的教程来说明。在下图中,当我们点击 `<video>` 元素时,会依次触发捕获(capturing)和冒泡(bubbling)两个阶段,前者从根节点一路进行到目标节点,触发路径上每个节点的 onclick 事件监听器(如有),后者则相反。
32+
Before introducing event delegation, let's first look at the event propagation mechanism. Since we are fully compatible with the DOM Event API, we might as well use the tutorial on MDN to illustrate. In the figure below, when we click on the `<video>` element, two stages will be triggered in sequence: capturing and bubbling. The former proceeds from the root node all the way to the target node, triggering the onclick event listener of each node on the path (if any), while the latter is the opposite.
3333

34-
<https://developer.mozilla.org/zh-CN/docs/Learn/JavaScript/Building_blocks/Events>
34+
<https://developer.mozilla.org/en-US/docs/Learn/JavaScript/Building_blocks/Events>
3535

3636
![](https://mdn.mozillademos.org/files/14075/bubbling-capturing.png)
3737

38-
在我们的示例场景中,点击每一个 li 时同样也会经历上述传播阶段,因此只需要在父节点 ul 上监听即可,事件自然会冒泡上来,这就是事件委托:
38+
In our example scene, clicking on each li will also go through the above propagation stages, so you only need to listen on the parent node ul, and the event will naturally bubble up. This is event delegation:
3939

4040
```js
4141
ul.addEventListener('click', (ev) => {
4242
ev.target; // li1 li2...
4343
});
4444
```
4545

46-
## 事件对象
46+
## Event Object
4747

48-
事件对象上有很多有用的属性,我们先来看看上一节中提到的事件传播路径,通过[composedPath()](/en/api/event/event-object#composedpath)方法可以获取它。当我们点击 li1 时,此时路径会返回如下结果:
48+
There are many useful properties on the event object. Let's first look at the event propagation path mentioned in the previous section. You can get it through the [composedPath()](/en/api/event/event-object#composedpath) method. When we click on li1, the path will return the following result:
4949

5050
```js
5151
ev.composedPath(); // [Rect(li1), Group(ul), Group(root), Document, Canvas];
5252
```
5353

54-
该结果是一个数组,依次展示了从事件触发的目标节点到根节点的路径,我们从后往前看:
54+
The result is an array that shows the path from the target node that triggered the event to the root node in sequence. Let's look at it from back to front:
5555

56-
- [Canvas](/en/api/canvas/intro) 即画布对象,可以对应 `window`
57-
- [Document](/en/api/builtin-objects/document) 文档,可以对应 `window.document`
58-
- [Group(root)](/en/api/builtin-objects/document#documentelement) 文档根节点,可以对应 `window.document.documentElement`
56+
- [Canvas](/en/api/canvas/intro) is the canvas object, which can correspond to `window`.
57+
- [Document](/en/api/builtin-objects/document) is the document, which can correspond to `window.document`.
58+
- [Group(root)](/en/api/builtin-objects/document#documentelement) is the root node of the document, which can correspond to `window.document.documentElement`.
5959

60-
除了事件传播路径,事件对象上其他的常用属性有:
60+
In addition to the event propagation path, other commonly used properties on the event object are:
6161

62-
- [target](/en/api/event/event-object#target) 返回当前触发事件的图形
63-
- [currentTarget](/en/api/event/event-object#currenttarget) 总是指向事件绑定的图形
64-
- 各个坐标系下的[事件坐标](/en/api/event/event-object#canvasxy)
62+
- [target](/en/api/event/event-object#target) returns the shape that currently triggered the event.
63+
- [currentTarget](/en/api/event/event-object#currenttarget) always points to the shape to which the event is bound.
64+
- [Event coordinates](/en/api/event/event-object#canvasxy) in various coordinate systems.
6565

66-
## 添加事件监听器的高级用法
66+
## Advanced Usage of Adding Event Listeners
6767

68-
还有一些常见的需求可以在绑定事件时做到,例如绑定一个“一次性”的监听器:
68+
There are some other common requirements that can be met when binding events, such as binding a "one-time" listener:
6969

7070
```js
7171
circle.addEventListener('click', () => {}, { once: true });
7272
```
7373

74-
再比如注册一个仅在事件捕获阶段执行的监听器:
74+
Another example is to register a listener that is only executed during the event capture phase:
7575

7676
```js
7777
circle.addEventListener('click', () => {}, { capture: true });
78-
// 或者
78+
// or
7979
circle.addEventListener('click', () => {}, true);
8080
```
8181

82-
更多用法可以参考 [addEventListener()](/en/api/event/intro#addeventlistener) 的文档。
82+
For more usage, you can refer to the documentation for [addEventListener()](/en/api/event/intro#addeventlistener).
Lines changed: 40 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -1,54 +1,54 @@
11
---
2-
title: Using lite version
2+
title: Using the Lite Version
33
order: 6
44
---
55

6-
As browsers iterate over new features, they get bigger and bigger. Although we want to achieve a "small browser", in size sensitive scenarios, users still want to use a minimal feature set. This requires that we split the existing features in a reasonable way, trying to achieve a minimal core + incremental enhancements model.
6+
As browsers continue to iterate and add new features, their size will inevitably increase. Although we aim to create a "small browser," in size-sensitive scenarios, users still prefer to use a minimal feature set. This requires us to reasonably split the existing features and strive to achieve a model of a minimal core + progressive enhancement.
77

8-
The following figure shows the composition of the bundle `@antv/g`.
8+
The following figure shows the bundle composition of `@antv/g`.
99

1010
<img src="https://gw.alipayobjects.com/mdn/rms_6ae20b/afts/img/A*lBr-T54VZpcAAAAAAAAAAAAAARQnAQ" alt="bundle viz" width="100%">
1111

12-
The full version `@antv/g` consists of the following parts.
12+
The full version of `@antv/g` consists of the following parts:
1313

14-
- `@antv/g-lite` Includes [canvas](/en/api/canvas/intro), [basic graphics](/en/api/basic/concept), [event system](/en/api/event/intro), [plugins system](/en/plugins/intro) and other core functions
15-
- Provides DOM Mutation Observer API
16-
- `web-animations-api` Provides an animation system compatible with the [Web Animations API](https://developer.mozilla.org/zh-CN/docs/Web/API/Web_Animations_API)
17-
- `camera-api` Provides full camera motion and animation capabilities
14+
- `@antv/g-lite`: Contains core features such as the [Canvas](/en/api/canvas/intro), [basic shapes](/en/api/basic/concept), the [event system](/en/api/event/intro), and the [plugin system](/en/plugins/intro).
15+
- Provides the DOM Mutation Observer API.
16+
- `web-animations-api`: Provides an animation system compatible with the [Web Animations API](https://developer.mozilla.org/en-US/docs/Web/API/Web_Animations_API).
17+
- `camera-api`: Provides full camera actions and animation functions.
1818

1919
## Usage
2020

21-
The Lite version is identical to the full version in the use of core functions, such as creating canvases, basic graphics, using the renderer, etc.
21+
The lite version is used in the same way as the full version for core functions, such as creating a canvas, basic shapes, and using a renderer:
2222

2323
```js
2424
import { Canvas, Circle } from '@antv/g-lite';
2525
import { Renderer } from '@antv/g-canvas';
2626
```
2727

28-
Calling the element's animation method at this point will have no effect
28+
At this point, calling the element's animation method will have no effect:
2929

3030
```js
3131
circle.animate([], {});
3232
```
3333

34-
Manual introduction of `web-animations-api` is required for this to take effect.
34+
You need to manually import `web-animations-api` for it to take effect:
3535

3636
```js
3737
import { Canvas, Circle } from '@antv/g-lite';
3838
import '@antv/g';
3939
```
4040

41-
Other progressive features can be introduced on-demand using a similar approach.
41+
Other progressive features can be imported on demand in a similar way.
4242

43-
## Function Introduction
43+
## Feature Introduction
4444

45-
The following is a detailed description of the functions of each part after splitting.
45+
The following is a detailed introduction to the functions of each part after splitting.
4646

4747
### g-lite
4848

49-
Contains core functions such as [canvas](/en/api/canvas/intro), [basic graphics](/en/api/basic/concept), [event system](/en/api/event/intro), [plugins system](/en/plugins/intro).
49+
Contains core features such as the [Canvas](/en/api/canvas/intro), [basic shapes](/en/api/basic/concept), the [event system](/en/api/event/intro), and the [plugin system](/en/plugins/intro).
5050

51-
There is no change in the way the above functions are used, [example](/en/examples/ecosystem/lite/#lite).
51+
The usage of the above functions has not changed. [Example](/en/examples/ecosystem/lite/#lite):
5252

5353
```js
5454
import { Canvas, Circle } from '@antv/g-lite';
@@ -68,40 +68,42 @@ const circle = new Circle({
6868

6969
### camera-api
7070

71-
`@antv/g-lite` contains a simple camera implementation, but it does not work with [camera action](/en/api/camera/action) and [camera animation](/en/api/camera/animation).
71+
`@antv/g-lite` includes a simple camera implementation, but you cannot use [camera actions](/en/api/camera/action) and [camera animations](/en/api/camera/animation):
7272

7373
```js
7474
camera.pan(); // throw new Error('Method not implemented.');
7575
camera.createLandmark(); // throw new Error('Method not implemented.');
7676
```
7777

78+
It can be used normally after being imported.
79+
7880
### web-animations-api
7981

80-
Provides [animation capabilities](/en/api/animation/waapi) for base graphics compatible with the [Web Animations API](https://developer.mozilla.org/zh-CN/docs/Web/API/Web_Animations_API). The `object.animate()` method can still be called without this capability, but without any effect.
82+
Provides basic shapes with [animation capabilities](/en/api/animation/waapi) compatible with the [Web Animations API](https://developer.mozilla.org/en-US/docs/Web/API/Web_Animations_API). Without this feature, you can still call the `object.animate()` method, but it will have no effect.
8183

8284
### dom-mutation-observer-api
8385

84-
In the DOM API, we can use [MutationObserver](https://developer.mozilla.org/en-US/docs/Web/API/MutationObserver) when we want to sense modifications in the DOM tree nodes, such as new nodes added, attribute values changed.
86+
In the DOM API, when we want to perceive changes to DOM tree nodes, such as new nodes being added or attribute values changing, we can use [MutationObserver](https://developer.mozilla.org/en-US/docs/Web/API/MutationObserver).
8587

86-
In G we also implement this [API](/en/api/builtin-objects/mutation-observer) to listen to changes in the scene graph.
88+
In G, we have also implemented this [API](/en/api/builtin-objects/mutation-observer) to listen for changes in the scene graph.
8789

8890
### g-compat
8991

90-
Methods compatible with older versions are provided on the base graphics, most of which have DOM API-compatible implementations in newer versions. The use of these methods is therefore not recommended and may be removed at any time subsequently.
91-
92-
- `getCount` Get the number of child nodes, the new version uses [childElementCount](/en/api/builtin-objects/element#childelementcount)
93-
- `getParent` Get the parent, the new version uses [parentElement](/en/api/builtin-objects/node#parentelement)
94-
- `getChildren` Get the list of child nodes, the new version uses [children](/en/api/builtin-objects/element#children)
95-
- `getFirst` Get the first child node, the new version uses [firstElementChild](/en/api/builtin-objects/element#firstelementchild)
96-
- `getLast` Get the last child node, the new version uses [lastElementChild](/en/api/builtin-objects/element#lastelementchild)
97-
- `getChildByIndex` the new version uses `this.children[index]`
98-
- `add` the new version uses [appendChild](/en/api/builtin-objects/node#appendchild)
99-
- `setClip` the new version uses [clipPath](/en/api/basic/display-object#clippath)
100-
- `getClip` ld.
101-
- `set` Storing key-value pairs on initialized configurations
102-
- `get` Read values on initialized configuration
103-
- `show` the new version uses [visibility](/en/api/basic/display-object#visibility)
104-
- `hide` ld.
105-
- `moveTo` the new version uses [setPosition](/en/api/basic/display-object#平移)
106-
- `move` ld.
107-
- `setZIndex` the new version uses [zIndex](/en/api/basic/display-object#zindex)
92+
Provides methods on basic shapes that are compatible with older versions. Most of them have implementations compatible with the DOM API in the new version. Therefore, it is not recommended to use these methods, as they may be removed at any time in the future:
93+
94+
- `getCount`: Gets the number of child nodes. The new version uses [childElementCount](/en/api/builtin-objects/element#childelementcount).
95+
- `getParent`: Gets the parent node. The new version uses [parentElement](/en/api/builtin-objects/node#parentelement).
96+
- `getChildren`: Gets the list of child nodes. The new version uses [children](/en/api/builtin-objects/element#children).
97+
- `getFirst`: Gets the first child node. The new version uses [firstElementChild](/en/api/builtin-objects/element#firstelementchild).
98+
- `getLast`: Gets the last child node. The new version uses [lastElementChild](/en/api/builtin-objects/element#lastelementchild).
99+
- `getChildByIndex`: Gets a child node by index. The new version uses `this.children[index]`.
100+
- `add`: Adds a child node. The new version uses [appendChild](/en/api/builtin-objects/node#appendchild).
101+
- `setClip`: Sets the clipping shape. The new version uses [clipPath](/en/api/basic/display-object#clippath).
102+
- `getClip`: Gets the clipping shape. Same as above.
103+
- `set`: Stores a key-value pair on the initial configuration.
104+
- `get`: Reads a value from the initial configuration.
105+
- `show`: Shows the shape. The new version uses [visibility](/en/api/basic/display-object#visibility).
106+
- `hide`: Hides the shape. Same as above.
107+
- `moveTo`: Moves the shape in world coordinates. The new version uses [setPosition](/en/api/basic/display-object#translation).
108+
- `move`: Same as above.
109+
- `setZIndex`: Sets the rendering order. The new version uses [zIndex](/en/api/basic/display-object#zindex).

0 commit comments

Comments
 (0)