Skip to content

Commit 8dfd544

Browse files
docs: 改造文档「插件 - 内置插件 - Fullscreen 全屏显示」 (#7031)
* fix: docs/update-fullscreen * fix: docs/update-fullscreen
1 parent a729a53 commit 8dfd544

File tree

3 files changed

+196
-37
lines changed

3 files changed

+196
-37
lines changed
Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
```js | ob { pin: false }
2+
createGraph(
3+
{
4+
data: { nodes: [{ id: 'node-1' }, { id: 'node-2' }], edges: [{ source: 'node-1', target: 'node-2' }] },
5+
node: { style: { fill: '#7e3feb', width: 30, height: 30 } },
6+
edge: { style: { stroke: '#8b9baf', strokeWidth: 2 } },
7+
layout: { type: 'force', center: [300, 150] },
8+
behaviors: ['drag-canvas', 'drag-node'],
9+
plugins: [
10+
{
11+
type: 'fullscreen',
12+
key: 'fullscreen',
13+
enabled: false,
14+
},
15+
function () {
16+
const graph = this;
17+
return {
18+
type: 'toolbar',
19+
key: 'toolbar',
20+
position: 'top-left',
21+
onClick: (item) => {
22+
const fullscreenPlugin = graph.getPluginInstance('fullscreen');
23+
if (item === 'request-fullscreen') {
24+
fullscreenPlugin.request();
25+
}
26+
if (item === 'exit-fullscreen') {
27+
fullscreenPlugin.exit();
28+
}
29+
},
30+
getItems: () => {
31+
return [
32+
{ id: 'request-fullscreen', value: 'request-fullscreen' },
33+
{ id: 'exit-fullscreen', value: 'exit-fullscreen' },
34+
];
35+
},
36+
};
37+
},
38+
],
39+
},
40+
{ width: 600, height: 300 },
41+
(gui, graph) => {
42+
const KEY_OPTIONS = ['f11', 'ctrl+f', 'meta+f']; // 常见全屏快捷键
43+
const options = {
44+
type: 'fullscreen',
45+
enabled: true,
46+
triggerKey: 'f11', // 触发全屏的快捷键
47+
closeOnEscape: true, // 按ESC键退出全屏
48+
};
49+
50+
const optionFolder = gui.addFolder('Fullscreen Options');
51+
optionFolder.add(options, 'type').disable(true); // 固定插件类型
52+
optionFolder.add(options, 'enabled').name('启用全屏'); // 开关选项
53+
optionFolder.add(options, 'triggerKey', KEY_OPTIONS).name('触发快捷键'); // 快捷键选择
54+
optionFolder.add(options, 'closeOnEscape').name('ESC键退出'); // 退出全屏方式
55+
56+
optionFolder.onChange(({ property, value }) => {
57+
// 更新插件配置
58+
graph.updatePlugin({
59+
key: 'fullscreen', // 对应插件的key
60+
[property]: property === 'triggerKey' ? value : value, // 直接赋值对应属性
61+
});
62+
63+
// 特殊处理:如果启用状态变化,直接触发全屏切换
64+
if (property === 'enabled') {
65+
value ? graph.plugins['fullscreen'].enter() : graph.plugins['fullscreen'].exit();
66+
}
67+
68+
graph.render();
69+
});
70+
},
71+
);
72+
```

packages/site/docs/manual/plugin/build-in/Fullscreen.zh.md

Lines changed: 123 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -2,65 +2,154 @@
22
title: Fullscreen 全屏展示
33
---
44

5-
**参考示例**
6-
7-
- [结合 Toolbar 插件实现全屏效果](/examples/plugin/fullscreen/#basic)
5+
## 概述
6+
7+
全屏展示插件允许用户将图可视化内容扩展到整个屏幕,提供更广阔的视图和更好的沉浸式体验。
8+
9+
## 使用场景
10+
11+
全屏展示插件主要适用于以下场景:
12+
13+
- 提供更广阔的视图,便于查看复杂图数据
14+
- 增强沉浸式体验,专注于图可视化内容
15+
- 在演示或报告中展示图数据
16+
17+
## 基本用法
18+
19+
```js
20+
const graph = new Graph({
21+
plugins: [
22+
{
23+
type: 'fullscreen',
24+
key: 'my-fullscreen', // 指定唯一标识符,便于后续动态更新
25+
autoFit: true,
26+
trigger: {
27+
request: 'F', // 使用快捷键 F 进入全屏
28+
exit: 'Esc', // 使用快捷键 Esc 退出全屏
29+
},
30+
onEnter: () => {
31+
console.log('进入全屏模式');
32+
},
33+
onExit: () => {
34+
console.log('退出全屏模式');
35+
},
36+
},
37+
],
38+
});
39+
```
840

941
## 配置项
1042

11-
### <Badge type="success">Required</Badge> type
43+
| 属性 | 描述 | 类型 | 默认值 | 必选 |
44+
| ------- | ---------------------------------------------------- | ------------------------------------ | ------------ | ---- |
45+
| type | 插件类型 | string | `fullscreen` ||
46+
| key | 插件唯一标识符,用于后续更新 | string | - | |
47+
| autoFit | 是否自适应画布尺寸,全屏后画布尺寸会自动适应屏幕尺寸 | boolean | true | |
48+
| trigger | 触发全屏的方式 | { request?: string; exit?: string; } | - | |
49+
| onEnter | 进入全屏后的回调 | () => void | - | |
50+
| onExit | 退出全屏后的回调 | () => void | - | |
1251

13-
> _`fullscreen` \| string_
52+
### trigger
1453

15-
此插件已内置,你可以通过 `type: 'fullscreen'` 来使用它。
54+
trigger 属性用于控制触发全屏的方式。它支持两种配置方式:
1655

17-
### autoFit
56+
#### 快捷键配置
1857

19-
> _boolean_ **Default:** `true`
58+
使用键盘快捷键来触发全屏和退出全屏。
2059

21-
是否自适应画布尺寸,全屏后画布尺寸会自动适应屏幕尺寸
60+
```js
61+
const graph = new Graph({
62+
plugins: [
63+
{
64+
type: 'fullscreen',
65+
trigger: {
66+
request: 'F', // 使用快捷键 F 进入全屏
67+
exit: 'Esc', // 使用快捷键 Esc 退出全屏
68+
},
69+
},
70+
],
71+
});
72+
```
2273

23-
### onEnter
74+
#### 自定义触发
2475

25-
> _() => void_
76+
通过API方式调用 request 和 exit 方法来控制全屏。
2677

27-
进入全屏后的回调
78+
```js
79+
const graph = new Graph({
80+
plugins: [
81+
{
82+
type: 'fullscreen',
83+
key: 'my-fullscreen',
84+
},
85+
],
86+
});
2887

29-
### onExit
88+
// 进入全屏
89+
graph.getPluginInstance('my-fullscreen').request();
3090

31-
> _() => void_
91+
// 退出全屏
92+
graph.getPluginInstance('my-fullscreen').exit();
93+
```
3294

33-
退出全屏后的回调
95+
### autoFit
3496

35-
### trigger
97+
> _boolean_ **Default:** true
3698
37-
> _{ request?: string[]; exit?: string[]; }_
99+
是否自适应画布尺寸,全屏后画布尺寸会自动适应屏幕尺寸。
38100

39-
触发全屏的方式
101+
- 设置为 true 时,画布会自动调整大小以适应整个屏幕。
102+
- 设置为 false 时,画布大小保持不变。
40103

41-
- `request` : 请求全屏
42-
- `exit` : 退出全屏
104+
```js
105+
const graph = new Graph({
106+
plugins: [
107+
{
108+
type: 'fullscreen',
109+
autoFit: true,
110+
},
111+
],
112+
});
113+
```
43114

44-
## API
115+
### onEnter
45116

46-
### Fullscreen.destroy()
117+
> _() => void_
47118
48-
```typescript
49-
destroy(): void;
119+
进入全屏后的回调函数。
120+
121+
```js
122+
const graph = new Graph({
123+
plugins: [
124+
{
125+
type: 'fullscreen',
126+
onEnter: () => {
127+
console.log('进入全屏模式');
128+
},
129+
},
130+
],
131+
});
50132
```
51133

52-
### Fullscreen.exit()
134+
### onExit
53135

54-
退出全屏
136+
> _() => void_
55137
56-
```typescript
57-
exit(): void;
138+
退出全屏后的回调函数。
139+
140+
```js
141+
const graph = new Graph({
142+
plugins: [
143+
{
144+
type: 'fullscreen',
145+
onExit: () => {
146+
console.log('退出全屏模式');
147+
},
148+
},
149+
],
150+
});
58151
```
59152

60-
### Fullscreen.request()
153+
## 实际案例
61154

62-
请求全屏
63-
64-
```typescript
65-
request(): void;
66-
```
155+
<Playground path="plugin/fullscreen/demo/basic.js" rid="fullscreen-basic-rid"></Playground>

packages/site/examples/plugin/fullscreen/demo/basic.js

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,7 @@
11
import { Graph } from '@antv/g6';
22

33
const graph = new Graph({
4-
data: {
5-
nodes: [{ id: 'node1' }],
6-
},
4+
data: { nodes: Array.from({ length: 20 }).map((_, i) => ({ id: `node${i}` })) },
75
autoFit: 'center',
86
background: '#fff',
97
plugins: [

0 commit comments

Comments
 (0)