= (props) => {
+ // @ts-ignore
const { children, ...rest } = props;
return (
diff --git a/packages/react-node/src/ReactNode/Shape/Ellipse.tsx b/packages/react-node/src/ReactNode/Shape/Ellipse.tsx
index b9c1eacc85a..71b0909062e 100644
--- a/packages/react-node/src/ReactNode/Shape/Ellipse.tsx
+++ b/packages/react-node/src/ReactNode/Shape/Ellipse.tsx
@@ -23,6 +23,7 @@ interface EllipseProps extends CommonProps {
}
const Ellipse: React.FC
= (props) => {
+ // @ts-ignore
const { children, ...rest } = props;
return (
diff --git a/packages/react-node/src/ReactNode/Shape/Image.tsx b/packages/react-node/src/ReactNode/Shape/Image.tsx
index 1ce6ba98413..b1feece4cf6 100644
--- a/packages/react-node/src/ReactNode/Shape/Image.tsx
+++ b/packages/react-node/src/ReactNode/Shape/Image.tsx
@@ -28,6 +28,7 @@ interface ImageProps extends CommonProps {
}
const Image: React.FC = (props) => {
+ // @ts-ignore
const { children, ...rest } = props;
return (
diff --git a/packages/react-node/src/ReactNode/Shape/Marker.tsx b/packages/react-node/src/ReactNode/Shape/Marker.tsx
index 06dbca70e29..2f3447c4a4b 100644
--- a/packages/react-node/src/ReactNode/Shape/Marker.tsx
+++ b/packages/react-node/src/ReactNode/Shape/Marker.tsx
@@ -13,12 +13,12 @@ export interface MarkerStyle extends CommonShapeProps {
* @description.zh-CN 内建标记 或者 生成标记路径的函数
*/
symbol:
- | 'circle'
- | 'square'
- | 'diamond'
- | 'triangle'
- | 'triangle-down'
- | ((x: number, y: number, r: number) => GPath[]);
+ | 'circle'
+ | 'square'
+ | 'diamond'
+ | 'triangle'
+ | 'triangle-down'
+ | ((x: number, y: number, r: number) => GPath[]);
}
interface MarkerProps extends CommonProps {
@@ -29,6 +29,7 @@ interface MarkerProps extends CommonProps {
}
const Marker: React.FC = (props) => {
+ // @ts-ignore
const { children, ...rest } = props;
return (
diff --git a/packages/react-node/src/ReactNode/Shape/Path.tsx b/packages/react-node/src/ReactNode/Shape/Path.tsx
index 3c720fa7b08..af98ba0e02b 100644
--- a/packages/react-node/src/ReactNode/Shape/Path.tsx
+++ b/packages/react-node/src/ReactNode/Shape/Path.tsx
@@ -50,6 +50,7 @@ interface PathProps extends CommonProps {
}
const Path: React.FC = (props) => {
+ // @ts-ignore
const { children, ...rest } = props;
return (
diff --git a/packages/react-node/src/ReactNode/Shape/Polygon.tsx b/packages/react-node/src/ReactNode/Shape/Polygon.tsx
index 0f63be020a1..e7527993f5e 100644
--- a/packages/react-node/src/ReactNode/Shape/Polygon.tsx
+++ b/packages/react-node/src/ReactNode/Shape/Polygon.tsx
@@ -18,6 +18,7 @@ interface PolygonProps extends CommonProps {
}
const Polygon: React.FC = (props) => {
+ // @ts-ignore
const { children, ...rest } = props;
return (
diff --git a/packages/react-node/src/ReactNode/Shape/Rect.tsx b/packages/react-node/src/ReactNode/Shape/Rect.tsx
index 9bdc99e3cff..6c1527e36d2 100644
--- a/packages/react-node/src/ReactNode/Shape/Rect.tsx
+++ b/packages/react-node/src/ReactNode/Shape/Rect.tsx
@@ -28,6 +28,7 @@ interface RectProps extends CommonProps {
}
const Rect: React.FC = (props) => {
+ // @ts-ignore
const { children, ...rest } = props;
return (
diff --git a/packages/react-node/src/ReactNode/Shape/Text.tsx b/packages/react-node/src/ReactNode/Shape/Text.tsx
index 3ca5260733a..1efffac27ca 100644
--- a/packages/react-node/src/ReactNode/Shape/Text.tsx
+++ b/packages/react-node/src/ReactNode/Shape/Text.tsx
@@ -52,6 +52,7 @@ interface TextProps extends CommonProps {
}
const Text: React.FC = (props) => {
+ // @ts-ignore
const { children, ...rest } = props;
return (
diff --git a/packages/react-node/src/ReactNode/demo.tsx b/packages/react-node/src/ReactNode/demo.tsx
index e4db7a3bee5..521ef12d0f7 100644
--- a/packages/react-node/src/ReactNode/demo.tsx
+++ b/packages/react-node/src/ReactNode/demo.tsx
@@ -1,5 +1,5 @@
import React, { useEffect } from 'react';
-import G6 from '@antv/g6';
+import G6, { GraphData } from '@antv/g6';
import { appenAutoShapeListener } from '../Register/event';
export const G6MiniDemo = ({
@@ -23,11 +23,26 @@ export const G6MiniDemo = ({
meta: {
creatorName: 'a_creator',
},
- id: 'node' + i + Math.random().toString(16).slice(-4),
+ id:
+ 'node' +
+ i +
+ Math.random()
+ .toString(16)
+ .slice(-4),
type: nodeType,
})),
edges: [],
- };
+ } as GraphData;
+
+ if (data && data.nodes && data.nodes.length > 1) {
+ data.edges!.push({
+ source: data.nodes[0].id,
+ target: data.nodes[1].id,
+ style: {
+ endArrow: true,
+ },
+ });
+ }
const width = document.getElementById('container')?.clientWidth || 800;
@@ -41,6 +56,7 @@ export const G6MiniDemo = ({
},
layout: {
type: 'dagre',
+ rankdir: 'LR',
},
});
graph.data(data);
diff --git a/packages/react-node/src/Register/event.ts b/packages/react-node/src/Register/event.ts
index 6fb31690132..cfcfc7aa4cc 100644
--- a/packages/react-node/src/Register/event.ts
+++ b/packages/react-node/src/Register/event.ts
@@ -1,5 +1,5 @@
import { IShape } from '@antv/g-base';
-import { IAbstractGraph, IG6GraphEvent, Item } from '@antv/g6-pc';
+import { IAbstractGraph, IG6GraphEvent, Item } from '@antv/g6-core';
export type ShapeEventListner = (
event: IG6GraphEvent,
diff --git a/packages/react-node/src/Register/getDataFromReactNode.ts b/packages/react-node/src/Register/getDataFromReactNode.ts
index 8e6d0666d97..85a3254aa39 100644
--- a/packages/react-node/src/Register/getDataFromReactNode.ts
+++ b/packages/react-node/src/Register/getDataFromReactNode.ts
@@ -15,7 +15,7 @@ const getShapeFromReact = (REl: ReactElement): RawNode => {
if (typeof REl.type === 'string') {
const data = REl.props['data-attr'] || {};
const { style: attrs = {}, type, ...props } = data;
- const { children: ochildren } = REl.props;
+ let { children: ochildren } = REl.props;
if (type === 'text') {
attrs.text = ochildren.join ? ochildren.join('') : ochildren;
return {
@@ -29,6 +29,7 @@ const getShapeFromReact = (REl: ReactElement): RawNode => {
if (typeof ochildren === 'object' && ochildren?.length) {
children = ochildren
.filter((e: any) => !!e)
+ .reduce((a: any, b: any) => a.concat(b.concat ? b : [b]), [])
.map((e: ReactElement) => getShapeFromReact(e));
} else if (ochildren) {
children = [getShapeFromReact(ochildren)];
diff --git a/packages/react-node/src/Register/register.tsx b/packages/react-node/src/Register/register.tsx
index 413bfe9dd0b..9c5c9856dc6 100644
--- a/packages/react-node/src/Register/register.tsx
+++ b/packages/react-node/src/Register/register.tsx
@@ -1,6 +1,12 @@
import React, { ReactElement } from 'react';
-import { Item, ModelConfig, ShapeOptions } from '@antv/g6-core/lib';
-import { IGroup } from '@antv/g-base';
+import {
+ INode,
+ IEdge,
+ ICombo,
+ ModelConfig,
+ ShapeOptions,
+} from '@antv/g6-core/lib';
+import { IGroup, IShape } from '@antv/g-base';
import getShapeFromReact from '@/Register/getDataFromReactNode';
import getPositionUsingYoga, {
LayoutedNode,
@@ -27,20 +33,22 @@ const renderTarget = (target: LayoutedNode, group: any) => {
},
...props,
});
- keyshape = shape;
+ if (props.keyShape) {
+ keyshape = shape;
+ }
animateShapeWithConfig(shape, props.animation);
} else {
g = group.addGroup(props);
- keyshape = g;
+ if (!keyshape) {
+ keyshape = g;
+ }
}
if (target.children) {
const keyshapes = target.children
- .map((n) => renderTarget(n, g))
- .filter((e) => e);
- if (keyshapes.length) {
- keyshape = keyshapes.pop();
- }
+ .map(n => renderTarget(n, g))
+ .filter(e => e);
+ keyshape = keyshapes.find(shape => !shape.isGroup()) || keyshape;
}
return keyshape;
};
@@ -92,23 +100,26 @@ const diffTarget = (container: IGroup, shapeArr: LayoutedNode[]) => {
}
};
-export function createNodeFromReact(Component: React.FC<{ cfg: ModelConfig }>) {
+export function createNodeFromReact(
+ Component: React.FC<{ cfg: ModelConfig }>,
+): { [key: string]: any } {
const compileXML = (cfg: ModelConfig) =>
registerNodeReact();
return {
- draw(cfg: ModelConfig, fatherGroup: any) {
+ draw(cfg: ModelConfig | undefined, fatherGroup: IGroup | undefined) {
const resultTarget = compileXML(cfg || {});
- let keyshape = fatherGroup;
- keyshape = renderTarget(resultTarget, fatherGroup);
+ const keyshape: IShape = renderTarget(resultTarget, fatherGroup);
return keyshape;
},
- update(cfg: ModelConfig, node: Item) {
+ update(cfg: ModelConfig, node: INode | IEdge | ICombo | undefined) {
const resultTarget = compileXML(cfg || {});
- const nodeGroup = node.getContainer();
- const realTarget = getRealStructure(resultTarget);
+ if (node) {
+ const nodeGroup = node.getContainer();
+ const realTarget = getRealStructure(resultTarget);
- diffTarget(nodeGroup, realTarget);
+ diffTarget(nodeGroup, realTarget);
+ }
},
getAnchorPoints() {
return [
@@ -118,5 +129,5 @@ export function createNodeFromReact(Component: React.FC<{ cfg: ModelConfig }>) {
[0.5, 0],
];
},
- } as ShapeOptions;
+ };
}
diff --git a/packages/site/docs/api/Items/nodeProperties.en.md b/packages/site/docs/api/Items/nodeProperties.en.md
index e1701491ec8..ceff1adcbfd 100644
--- a/packages/site/docs/api/Items/nodeProperties.en.md
+++ b/packages/site/docs/api/Items/nodeProperties.en.md
@@ -47,7 +47,7 @@ The interactions of the node and related edges. It can be null. [0, 0] represent
_Object_ **optional**
-The node style. `style` is an object to configure the filling color, stroke color, shadow, and so on. Please refer to: [Shape Properties](/en/docs/api/shapeProperties.zh.md)。
+The node style. `style` is an object to configure the filling color, stroke color, shadow, and so on. Please refer to: [Shape Properties](/en/docs/api/shapeProperties)。
### label
diff --git a/packages/site/docs/api/Items/nodeProperties.zh.md b/packages/site/docs/api/Items/nodeProperties.zh.md
index 8b224e39306..aa7f8be2d12 100644
--- a/packages/site/docs/api/Items/nodeProperties.zh.md
+++ b/packages/site/docs/api/Items/nodeProperties.zh.md
@@ -47,7 +47,7 @@ y 坐标。
_Object_ **optional**
-通过 `style` 配置来修改节点关键图形的填充色、边框颜色、阴影等属性,具体配置属性见:[图形样式属性](/zh/docs/api/shapeProperties.zh.md)。
+通过 `style` 配置来修改节点关键图形的填充色、边框颜色、阴影等属性,具体配置属性见:[图形样式属性](/zh/docs/api/shapeProperties)。
### label
diff --git a/packages/site/docs/api/graphFunc/transform.en.md b/packages/site/docs/api/graphFunc/transform.en.md
index 3a1359a927b..ef966c41483 100644
--- a/packages/site/docs/api/graphFunc/transform.en.md
+++ b/packages/site/docs/api/graphFunc/transform.en.md
@@ -141,7 +141,7 @@ graph.moveTo(200, 300, true, {
});
```
-### graph.fitView(padding)
+### graph.fitView(padding, rules, animate, animateCfg)
Fit the graph to the view port.
@@ -151,6 +151,8 @@ Fit the graph to the view port.
| --- | --- | --- | --- | --- | --- | --- |
| padding | Number / Array | false | The padding of [top, right, bottom, left]. |
| rules | { onlyOutOfViewPort?: boolean; direction?: 'x' / 'y' / 'both'; ratioRule?: 'max' / 'min} | false | rules of fitView |
+| animate | boolean | false | _Supported by v4.6.15._ Whether move the graph with animation. If it is not assigned, animates following the graph's `animate`. |
+| animateCfg | Object | false | _Supported by v4.6.15._ The animation's configuraiton. Its configurations can be found in [Basic Animation Docs](/en/docs/manual/middle/animation). If it is not assigned, animates following the graph's `animateCfg`. |
**Usage**
@@ -178,6 +180,13 @@ graph.fitView(0, { onlyOutOfViewPort: true, direction: 'y' });
_Supported by v3.5.1._ Translate the graph to align its center with the canvas.
+**Parameters**
+
+| Name | Type | Required | Description |
+| --- | --- | --- | --- | --- | --- | --- |
+| animate | boolean | false | _Supported by v4.6.15._ Whether move the graph with animation. If it is not assigned, animates following the graph's `animate`. |
+| animateCfg | Object | false | _Supported by v4.6.15._ The animation's configuraiton. Its configurations can be found in [Basic Animation Docs](/en/docs/manual/middle/animation). If it is not assigned, animates following the graph's `animateCfg`. |
+
**Usage**
```javascript
diff --git a/packages/site/docs/api/graphFunc/transform.zh.md b/packages/site/docs/api/graphFunc/transform.zh.md
index 3635c7c7565..b96c3b8eb97 100644
--- a/packages/site/docs/api/graphFunc/transform.zh.md
+++ b/packages/site/docs/api/graphFunc/transform.zh.md
@@ -142,7 +142,7 @@ graph.moveTo(200, 300, true, {
});
```
-### graph.fitView(padding)
+### graph.fitView(padding, rules, animate, animateCfg)
让画布内容适应视口。
@@ -152,6 +152,8 @@ graph.moveTo(200, 300, true, {
| --- | --- | --- | --- | --- | --- | --- |
| padding | Number / Array | false | [top, right, bottom, left] 四个方向上的间距值 |
| rules | { onlyOutOfViewPort?: boolean; direction?: 'x' / 'y' / 'both'; ratioRule?: 'max' / 'min} | false | fitView 的规则 |
+| animate | boolean | false | *v4.6.15 后支持。*是否带有动画。若未配置,则跟随 graph 的 `animate` 参数 |
+| animateCfg | Object | false | *v4.6.15 后支持。*若带有动画,可配置动画,参见[基础动画教程](/zh/docs/manual/middle/animation)。若未配置,则跟随 graph 的 `animateCfg` 参数 |
**用法**
@@ -175,10 +177,17 @@ graph.fitView(0, {});
graph.fitView(0, { onlyOutOfViewPort: true, direction: 'y' });
```
-### graph.fitCenter()
+### graph.fitCenter(animate, animateCfg)
*v3.5.1 后支持。*平移图到中心将对齐到画布中心,但不缩放。优先级低于 fitView。
+**参数**
+
+| 名称 | 类型 | 是否必选 | 描述 |
+| --- | --- | --- | --- | --- | --- | --- |
+| animate | boolean | false | *v4.6.15 后支持。*是否带有动画。若未配置,则跟随 graph 的 `animate` 参数 |
+| animateCfg | Object | false | *v4.6.15 后支持。*若带有动画,可配置动画,参见[基础动画教程](/zh/docs/manual/middle/animation)。若未配置,则跟随 graph 的 `animateCfg` 参数 |
+
**用法**
```javascript
diff --git a/packages/site/docs/api/graphLayout/dagre.en.md b/packages/site/docs/api/graphLayout/dagre.en.md
index 69d16f1ddb6..aac4f488f89 100644
--- a/packages/site/docs/api/graphLayout/dagre.en.md
+++ b/packages/site/docs/api/graphLayout/dagre.en.md
@@ -103,7 +103,7 @@ _Supported by G6 v4.5.1_
_Supported by G6 v4.5.0_
-**Type**: string[]
**Default** undefined
**Required**: false
**Description**: The refered order array for the nodes in the same layer. If it is not specified, the order of the nodes will be decided by the dagre algorithm.
+**Type**: string[]
**Default** undefined
**Required**: false
**Description**: The refered order array for the nodes in the same layer, stores the id values of each node. If it is not specified, the order of the nodes will be decided by the dagre algorithm.
## layoutCfg.preset
diff --git a/packages/site/docs/api/graphLayout/dagre.zh.md b/packages/site/docs/api/graphLayout/dagre.zh.md
index 334a37da1d9..392e3c89b29 100644
--- a/packages/site/docs/api/graphLayout/dagre.zh.md
+++ b/packages/site/docs/api/graphLayout/dagre.zh.md
@@ -101,7 +101,7 @@ _自 G6 v4.5.1 起支持。_
_自 G6 v4.5.0 起支持。_
-**类型**: string[]
**默认值**: undefined
**是否必须**: false
**说明**: 同层节点顺序的参考数组。若未指定,则将按照 dagre 本身机制排列同层节点顺序。
+**类型**: string[]
**默认值**: undefined
**是否必须**: false
**说明**: 同层节点顺序的参考数组,存放节点 id 值。若未指定,则将按照 dagre 本身机制排列同层节点顺序。
## layoutCfg.preset
diff --git a/packages/site/examples/scatter/changePosition/index.en.md b/packages/site/examples/scatter/changePosition/index.en.md
index e39ecd1fffb..062d6bcee1a 100644
--- a/packages/site/examples/scatter/changePosition/index.en.md
+++ b/packages/site/examples/scatter/changePosition/index.en.md
@@ -1,6 +1,6 @@
---
title: Node Move Animation
-order: 4
+order: 5
---
Change the node positions by `changeData` method is a simple way to realize the node animation.
diff --git a/packages/site/examples/scatter/changePosition/index.zh.md b/packages/site/examples/scatter/changePosition/index.zh.md
index 4328e6a2d05..6457dcbc4f3 100644
--- a/packages/site/examples/scatter/changePosition/index.zh.md
+++ b/packages/site/examples/scatter/changePosition/index.zh.md
@@ -1,6 +1,6 @@
---
title: 节点移动动画
-order: 4
+order: 5
---
通过 `changeData` 方法不断地改变节点位置,以达到动画的效果。
diff --git a/packages/site/examples/scatter/customAnimate/index.en.md b/packages/site/examples/scatter/customAnimate/index.en.md
index 2d808bf4afb..575deb7286b 100644
--- a/packages/site/examples/scatter/customAnimate/index.en.md
+++ b/packages/site/examples/scatter/customAnimate/index.en.md
@@ -1,6 +1,6 @@
---
title: Custom Animation
-order: 5
+order: 6
---
Configuration `animateCfg` of `Graph` is designed for global animation.
diff --git a/packages/site/examples/scatter/customAnimate/index.zh.md b/packages/site/examples/scatter/customAnimate/index.zh.md
index a60b9d694de..b59c634c2ec 100644
--- a/packages/site/examples/scatter/customAnimate/index.zh.md
+++ b/packages/site/examples/scatter/customAnimate/index.zh.md
@@ -1,6 +1,6 @@
---
title: 自定义动画
-order: 5
+order: 6
---
在实例化 `Graph` 时,可以通过 `animateCfg` 配置项设置全局动画。
diff --git a/packages/site/examples/scatter/edge/demo/arrowAnimate.js b/packages/site/examples/scatter/edge/demo/arrowAnimate.js
index 17e255ee472..4ccabeb4224 100644
--- a/packages/site/examples/scatter/edge/demo/arrowAnimate.js
+++ b/packages/site/examples/scatter/edge/demo/arrowAnimate.js
@@ -1,10 +1,7 @@
import G6 from "@antv/g6";
import { ext } from "@antv/matrix-util";
-// import {getLabelPosition} from '@antv/g6/util'
-const { getLabelPosition } = G6.Util;
-console.log("getLabelPosition", getLabelPosition);
-const transform = ext.transform;
+const { getLabelPosition, transform } = G6.Util;
G6.registerEdge(
"arrow-running",
diff --git a/packages/site/examples/scatter/edge/index.en.md b/packages/site/examples/scatter/edge/index.en.md
index 9383db77984..e1437f773d8 100644
--- a/packages/site/examples/scatter/edge/index.en.md
+++ b/packages/site/examples/scatter/edge/index.en.md
@@ -1,6 +1,6 @@
---
title: Edge Animation
-order: 1
+order: 2
---
Edge animation can be realized by customing an edge.
diff --git a/packages/site/examples/scatter/edge/index.zh.md b/packages/site/examples/scatter/edge/index.zh.md
index a78c771e933..8c2ea846471 100644
--- a/packages/site/examples/scatter/edge/index.zh.md
+++ b/packages/site/examples/scatter/edge/index.zh.md
@@ -1,6 +1,6 @@
---
title: 边动画
-order: 1
+order: 2
---
通过自定义边,可以实现边的动画效果。
diff --git a/packages/site/examples/scatter/node/index.en.md b/packages/site/examples/scatter/node/index.en.md
index e1655bbec15..40cd8f3d116 100644
--- a/packages/site/examples/scatter/node/index.en.md
+++ b/packages/site/examples/scatter/node/index.en.md
@@ -1,6 +1,6 @@
---
title: Node Animation
-order: 0
+order: 1
---
Node animation can be realized by customing a node.
diff --git a/packages/site/examples/scatter/node/index.zh.md b/packages/site/examples/scatter/node/index.zh.md
index 92ea594e2fb..cdabdde3d39 100644
--- a/packages/site/examples/scatter/node/index.zh.md
+++ b/packages/site/examples/scatter/node/index.zh.md
@@ -1,6 +1,6 @@
---
title: 节点动画
-order: 0
+order: 1
---
通过自定义节点,可以实现节点的动画效果。
diff --git a/packages/site/examples/scatter/stateChange/index.en.md b/packages/site/examples/scatter/stateChange/index.en.md
index be9dfd889d3..6d4a0039c7f 100644
--- a/packages/site/examples/scatter/stateChange/index.en.md
+++ b/packages/site/examples/scatter/stateChange/index.en.md
@@ -1,6 +1,6 @@
---
title: State Switch
-order: 2
+order: 3
---
State of G6 includes interaction states and bussiness states.
diff --git a/packages/site/examples/scatter/stateChange/index.zh.md b/packages/site/examples/scatter/stateChange/index.zh.md
index 9b0b28c3282..c6cbe1740c8 100644
--- a/packages/site/examples/scatter/stateChange/index.zh.md
+++ b/packages/site/examples/scatter/stateChange/index.zh.md
@@ -1,6 +1,6 @@
---
title: 状态切换
-order: 2
+order: 3
---
G6 中的 state,指的是状态,包括交互状态和业务状态两种。
diff --git a/packages/site/examples/scatter/viewport/API.en.md b/packages/site/examples/scatter/viewport/API.en.md
new file mode 100644
index 00000000000..51e686f842e
--- /dev/null
+++ b/packages/site/examples/scatter/viewport/API.en.md
@@ -0,0 +1,5 @@
+---
+title: API
+---
+
+`markdown:docs/api/graphFunc/transform.en.md`
diff --git a/packages/site/examples/scatter/viewport/API.zh.md b/packages/site/examples/scatter/viewport/API.zh.md
new file mode 100644
index 00000000000..d67b3ce5171
--- /dev/null
+++ b/packages/site/examples/scatter/viewport/API.zh.md
@@ -0,0 +1,5 @@
+---
+title: API
+---
+
+`markdown:docs/api/graphFunc/transform.zh.md`
diff --git a/packages/site/examples/scatter/viewport/demo/default.js b/packages/site/examples/scatter/viewport/demo/default.js
new file mode 100644
index 00000000000..96740658bfe
--- /dev/null
+++ b/packages/site/examples/scatter/viewport/demo/default.js
@@ -0,0 +1,115 @@
+import G6 from '@antv/g6';
+
+const tipDiv = document.createElement('div');
+tipDiv.innerHTML = `Click node or edge to focus on it with animate. 点击节点或边可带动画地聚焦到该元素上`;
+document.getElementById('container').appendChild(tipDiv);
+const tipDiv2 = document.createElement('div');
+tipDiv2.innerHTML = `Click the button on toolbar to see viewport change animately. 点击 Toolbar 上的按钮可带动画地操作视图`;
+document.getElementById('container').appendChild(tipDiv2);
+
+const data = {
+ nodes: [
+ {
+ id: 'a',
+ x: 200,
+ y: 100,
+ style: { fill: '#5B8FF9', stroke: null },
+ },
+ {
+ id: 'b',
+ x: 100,
+ y: 200,
+ style: { fill: '#5AD8A6', stroke: null },
+ },
+ {
+ id: 'c',
+ x: 300,
+ y: 200,
+ style: { fill: '#5D7092', stroke: null },
+ },
+ ],
+ edges: [
+ {
+ id: 'a2b',
+ source: 'a',
+ target: 'b',
+ },
+ {
+ id: 'a2c',
+ source: 'a',
+ target: 'c',
+ },
+ ],
+};
+
+const animateCfg = { duration: 200, easing: 'easeCubic' }
+
+const toolbar = new G6.ToolBar({
+ position: { x: 10, y: 70 },
+ getContent: () => `
+ `,
+ handleClick: (code, graph) => {
+ switch (code) {
+ case 'zoomOut':
+ graph.zoom(1.2, undefined, true, animateCfg);
+ break;
+ case 'zoomIn':
+ graph.zoom(0.8, undefined, true, animateCfg);
+ break;
+ case 'realZoom':
+ graph.zoomTo(1, undefined, true, animateCfg);
+ break;
+ case 'autoZoom':
+ graph.fitView(20, undefined, true, animateCfg);
+ break;
+ }
+ }
+})
+
+const container = document.getElementById('container');
+const width = container.scrollWidth;
+const height = (container.scrollHeight || 500) - 50;
+const graph = new G6.Graph({
+ container: 'container',
+ width,
+ height,
+ plugins: [toolbar],
+});
+
+graph.data(data);
+graph.render();
+
+graph.on('node:click', e => {
+ graph.focusItem(e.item, true, animateCfg)
+})
+graph.on('edge:click', e => {
+ graph.focusItem(e.item, true, animateCfg)
+})
+
+if (typeof window !== 'undefined')
+ window.onresize = () => {
+ if (!graph || graph.get('destroyed')) return;
+ if (!container || !container.scrollWidth || !container.scrollHeight) return;
+ graph.changeSize(container.scrollWidth, container.scrollHeight);
+ };
diff --git a/packages/site/examples/scatter/viewport/demo/meta.json b/packages/site/examples/scatter/viewport/demo/meta.json
new file mode 100644
index 00000000000..52c4a01efa9
--- /dev/null
+++ b/packages/site/examples/scatter/viewport/demo/meta.json
@@ -0,0 +1,16 @@
+{
+ "title": {
+ "zh": "中文分类",
+ "en": "Category"
+ },
+ "demos": [
+ {
+ "filename": "default.js",
+ "title": {
+ "zh": "视口变换动画",
+ "en": "Viewport Animation"
+ },
+ "screenshot": "https://gw.alipayobjects.com/mdn/rms_f8c6a0/afts/img/A*HRIpRobLTr0AAAAAAAAAAAAAARQnAQ"
+ }
+ ]
+}
\ No newline at end of file
diff --git a/packages/site/examples/scatter/viewport/index.en.md b/packages/site/examples/scatter/viewport/index.en.md
new file mode 100644
index 00000000000..747bab2f521
--- /dev/null
+++ b/packages/site/examples/scatter/viewport/index.en.md
@@ -0,0 +1,10 @@
+---
+title: Viewport Animation
+order: 0
+---
+
+Configure animtions for viewport move, zoom, fitView, fitCenter, etc.
+
+### Usage
+
+Viewport update with animations could be achieved easily by configuring `animate` and `animateCfg` to the corresponding APIs, e.g. `graph.translate`, `graph.moveTo`, `graph.zoom`, `graph.zoomTo`, `graph.fitView`, `graph.fitCenter`, `graph.focusItem`. Please refer to the document [Graph Viewport API](/en/docs/api/graphFunc/transform).
diff --git a/packages/site/examples/scatter/viewport/index.zh.md b/packages/site/examples/scatter/viewport/index.zh.md
new file mode 100644
index 00000000000..93768700c0d
--- /dev/null
+++ b/packages/site/examples/scatter/viewport/index.zh.md
@@ -0,0 +1,10 @@
+---
+title: 视口变换动画
+order: 0
+---
+
+为视口/全图的平移、缩放、自适应等配置动画。
+
+### 使用指南
+
+通过在调用各个视口操作 API 时配置 `animate` 和 `animateCfg` 参数,可以非常快捷地为这些变换配置动画。这些 API 包括 `graph.translate`, `graph.moveTo`, `graph.zoom`, `graph.zoomTo`, `graph.fitView`, `graph.fitCenter`, `graph.focusItem` 等。详见 [图视口 API](/zh/docs/api/graphFunc/transform)。
\ No newline at end of file
diff --git a/packages/site/package.json b/packages/site/package.json
index e597a045763..a2847dace89 100644
--- a/packages/site/package.json
+++ b/packages/site/package.json
@@ -1,7 +1,7 @@
{
"private": true,
"name": "@antv/g6-site",
- "version": "4.6.11",
+ "version": "4.6.15",
"description": "G6 sites deployed on gh-pages",
"keywords": [
"antv",
@@ -36,7 +36,7 @@
"dependencies": {
"@ant-design/icons": "^4.0.6",
"@antv/chart-node-g6": "^0.0.3",
- "@antv/g6": "4.6.11",
+ "@antv/g6": "4.6.15",
"@antv/gatsby-theme-antv": "1.1.15",
"@antv/util": "^2.0.9",
"@antv/vis-predict-engine": "^0.1.1",