Skip to content

Commit 9c53e95

Browse files
authored
docs(GridLine): 重写网格线插件文档,提升使用说明和示例 (#6884)
1 parent 1607697 commit 9c53e95

File tree

2 files changed

+168
-60
lines changed

2 files changed

+168
-60
lines changed

packages/site/common/api/plugins/grid-line.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ createGraph(
66
edge: { style: { stroke: '#8b9baf' } },
77
layout: { type: 'force' },
88
behaviors: ['drag-canvas'],
9-
plugins: [{ type: 'grid-line', size: 30 }],
9+
plugins: [{ type: 'grid-line', key: 'grid-line', size: 30 }],
1010
},
1111
{ width: 600, height: 300 },
1212
(gui, graph) => {

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

Lines changed: 167 additions & 59 deletions
Original file line numberDiff line numberDiff line change
@@ -2,72 +2,180 @@
22
title: GridLine 网格线
33
---
44

5-
网格线插件,多用于辅助绘图
5+
## 概述
66

7-
<embed src="@/common/api/plugins/grid-line.md"></embed>
8-
9-
**参考示例**
10-
11-
- [网格线](/examples/plugin/grid-line/#basic)
12-
13-
## 配置项
14-
15-
### <Badge type="success">Required</Badge> type
16-
17-
> _`grid-line` \| string_
18-
19-
此插件已内置,你可以通过 `type: 'grid-line'` 来使用它。
20-
21-
### border
22-
23-
> _boolean_ **Default:** `true`
24-
25-
是否显示边框
26-
27-
### borderLineWidth
28-
29-
> _number_ **Default:** `1`
30-
31-
边框线宽
7+
网格线插件为画布提供可视化辅助线,帮助用户精确定位和对齐图形元素,是图形绘制中不可或缺的辅助工具。
328

33-
### borderStroke
9+
## 使用场景
3410

35-
> _string_ **Default:** `'#0001'`
11+
网格线插件主要适用于以下场景:
3612

37-
边框颜色
13+
- 辅助用户精确绘图和元素对齐
14+
- 提供视觉参考,增强空间感知
15+
- 在设计和编辑图形时构建结构化的参考系统
3816

39-
完整属性定义参考 [CSS border-color](https://developer.mozilla.org/zh-CN/docs/Web/CSS/border-color)
17+
## 基本用法
4018

41-
### borderStyle
19+
```js
20+
const graph = new Graph({
21+
plugins: [
22+
{
23+
type: 'grid-line',
24+
key: 'my-grid-line', // 指定唯一标识符,便于后续动态更新
25+
size: 20,
26+
stroke: '#0001',
27+
follow: true,
28+
},
29+
],
30+
});
31+
```
4232

43-
> _string_ **Default:** `'solid'`
33+
## 在线体验
4434

45-
边框样式
46-
47-
完整属性定义参考 [CSS border-style](https://developer.mozilla.org/zh-CN/docs/Web/CSS/border-style)
48-
49-
### follow
50-
51-
> _boolean_ **Default:** `false`
52-
53-
是否跟随图移动
54-
55-
### lineWidth
56-
57-
> _number \| string_ **Default:** `1`
58-
59-
网格线宽
60-
61-
### size
62-
63-
> _number_ **Default:** `20`
64-
65-
单个网格的大小
66-
67-
### stroke
68-
69-
> _string_ **Default:** `'#0001'`
35+
<embed src="@/common/api/plugins/grid-line.md"></embed>
7036

71-
网格线颜色
37+
## 配置项
7238

73-
## API
39+
| 属性 | 描述 | 类型 | 默认值 | 必选 |
40+
| --------------- | -------------------------------------------------------------------------------------------------------- | ---------------- | ----------- | ---- |
41+
| type | 插件类型 | string | `grid-line` ||
42+
| key | 插件唯一标识符,用于后续更新 | string | - | |
43+
| border | 是否显示边框 | boolean | true | |
44+
| borderLineWidth | 边框线宽 | number | 1 | |
45+
| borderStroke | 边框颜色,详细属性参考 [CSS border-color](https://developer.mozilla.org/zh-CN/docs/Web/CSS/border-color) | string | `#eee` | |
46+
| borderStyle | 边框样式,详细属性参考 [CSS border-style](https://developer.mozilla.org/zh-CN/docs/Web/CSS/border-style) | string | `solid` | |
47+
| follow | 是否跟随画布移动,启用后网格会随着画布的平移而移动 | boolean | false | |
48+
| lineWidth | 网格线宽度 | number \| string | 1 | |
49+
| size | 网格单元大小,单位为像素 | number | 20 | |
50+
| stroke | 网格线颜色 | string | `#eee` | |
51+
52+
## 代码示例
53+
54+
### 基础网格线
55+
56+
最简单的方式是直接使用预设配置:
57+
58+
```js
59+
const graph = new Graph({
60+
// 其他配置...
61+
plugins: ['grid-line'],
62+
});
63+
```
64+
65+
效果如下:
66+
67+
```js | ob { pin: false }
68+
createGraph(
69+
{
70+
data: { nodes: [{ id: 'node-1', style: { x: 150, y: 75 } }] },
71+
behaviors: ['drag-canvas'],
72+
plugins: ['grid-line'],
73+
},
74+
{ width: 300, height: 150 },
75+
);
76+
```
77+
78+
### 自定义样式
79+
80+
您可以根据需要自定义网格线的样式:
81+
82+
```js
83+
const graph = new Graph({
84+
// 其他配置...
85+
plugins: [
86+
{
87+
type: 'grid-line',
88+
stroke: '#1890ff33', // 蓝色半透明网格线
89+
lineWidth: 2,
90+
size: 40, // 更大的网格单元
91+
borderStroke: '#1890ff', // 蓝色边框
92+
borderLineWidth: 2,
93+
},
94+
],
95+
});
96+
```
97+
98+
效果如下:
99+
100+
```js | ob { pin: false }
101+
createGraph(
102+
{
103+
data: { nodes: [{ id: 'node-1', style: { x: 150, y: 75 } }] },
104+
behaviors: ['drag-canvas'],
105+
plugins: [
106+
{
107+
type: 'grid-line',
108+
stroke: '#1890ff33', // 蓝色半透明网格线
109+
lineWidth: 2,
110+
size: 40, // 更大的网格
111+
borderStroke: '#1890ff', // 蓝色边框
112+
borderLineWidth: 2,
113+
},
114+
],
115+
},
116+
{ width: 300, height: 150 },
117+
);
118+
```
119+
120+
### 跟随移动
121+
122+
启用 follow 选项可以让网格跟随画布移动,增强用户体验:
123+
124+
```js
125+
const graph = new Graph({
126+
// 其他配置...
127+
plugins: [
128+
{
129+
type: 'grid-line',
130+
follow: true, // 网格跟随画布移动
131+
},
132+
],
133+
});
134+
```
135+
136+
试着拖拽画布,观察网格的跟随效果:
137+
138+
```js | ob { pin: false }
139+
createGraph(
140+
{
141+
data: { nodes: [{ id: 'node-1', style: { x: 150, y: 75 } }] },
142+
behaviors: ['drag-canvas'],
143+
plugins: [
144+
{
145+
type: 'grid-line',
146+
follow: true, // 网格跟随画布移动
147+
},
148+
],
149+
},
150+
{ width: 300, height: 150 },
151+
);
152+
```
153+
154+
### 动态更新网格
155+
156+
使用 key 标识符可以在运行时动态更新网格属性:
157+
158+
```js
159+
// 初始化配置
160+
const graph = new Graph({
161+
// 其他配置...
162+
plugins: [
163+
{
164+
type: 'grid-line',
165+
key: 'my-grid',
166+
size: 20,
167+
},
168+
],
169+
});
170+
171+
// 后续动态更新
172+
graph.updatePlugin({
173+
key: 'my-grid',
174+
size: 40, // 更新网格大小
175+
stroke: '#ff4d4f', // 更新网格颜色
176+
});
177+
```
178+
179+
## 实际案例
180+
181+
<Playground path="plugin/grid-line/demo/basic.js" rid="grid-line-basic"></Playground>

0 commit comments

Comments
 (0)