Skip to content

Commit

Permalink
feat: ✨ add insertPort api (#1763)
Browse files Browse the repository at this point in the history
  • Loading branch information
NewByVector authored Jan 16, 2022
1 parent d1d8635 commit 6809dba
Show file tree
Hide file tree
Showing 5 changed files with 51 additions and 5 deletions.
8 changes: 5 additions & 3 deletions packages/x6/src/model/edge.ts
Original file line number Diff line number Diff line change
Expand Up @@ -905,9 +905,11 @@ export class Edge<
}

getPolyline() {
const points = [this.getSourcePoint(), this.getTargetPoint()]
const vertices = this.getVertices()
vertices.forEach((p) => points.push(Point.create(p)))
const points = [
this.getSourcePoint(),
...this.getVertices().map((vertice) => Point.create(vertice)),
this.getTargetPoint(),
]
return new Polyline(points)
}

Expand Down
11 changes: 11 additions & 0 deletions packages/x6/src/model/node.ts
Original file line number Diff line number Diff line change
Expand Up @@ -787,6 +787,17 @@ export class Node<
return this
}

insertPort(
index: number,
port: PortManager.PortMetadata,
options?: Node.SetOptions,
) {
const ports = [...this.ports.items]
ports.splice(index, 0, port)
this.setPropByPath('ports/items', ports, options)
return this
}

removePort(
port: PortManager.PortMetadata | string,
options: Node.SetOptions = {},
Expand Down
2 changes: 1 addition & 1 deletion packages/x6/src/registry/router/manhattan/options.ts
Original file line number Diff line number Diff line change
Expand Up @@ -162,8 +162,8 @@ export const defaults: ManhattanRouterOptions = {

return [
{ cost, offsetX: step, offsetY: 0 },
{ cost, offsetX: 0, offsetY: step },
{ cost, offsetX: -step, offsetY: 0 },
{ cost, offsetX: 0, offsetY: step },
{ cost, offsetX: 0, offsetY: -step },
]
},
Expand Down
17 changes: 17 additions & 0 deletions sites/x6-sites/docs/api/model/node.en.md
Original file line number Diff line number Diff line change
Expand Up @@ -652,6 +652,23 @@ addPorts(ports: PortMetadata[], options?: Node.SetOptions)
| options...others | object | | | 其他自定义键值对,可以在事件回调中使用。 |


#### insertPort(...)

```sign
insertPort(index: number, port: PortMetadata, options?: Node.SetOptions): this
```

在指定位置添加连接桩。

<span class="tag-param">参数<span>

| 名称 | 类型 | 必选 | 默认值 | 描述 |
|------------------|------------------------|:----:|---------|---------------------------------------------------|
| index | number || | 连接桩位置。 |
| port | [PortMetadata](#ports) || | 链接桩。 |
| options.silent | boolean | | `false` |`true` 时不触发 `'change:ports'` 事件和画布重绘。 |
| options...others | object | | | 其他自定义键值对,可以在事件回调中使用。 |

#### hasPort(...)

```sign
Expand Down
18 changes: 17 additions & 1 deletion sites/x6-sites/docs/api/model/node.zh.md
Original file line number Diff line number Diff line change
Expand Up @@ -634,7 +634,6 @@ addPort(port: PortMetadata, options?: Node.SetOptions): this
| options.silent | boolean | | `false` |`true` 时不触发 `'change:ports'` 事件和画布重绘。 |
| options...others | object | | | 其他自定义键值对,可以在事件回调中使用。 |


#### addPorts(...)

```sign
Expand All @@ -652,6 +651,23 @@ addPorts(ports: PortMetadata[], options?: Node.SetOptions)
| options...others | object | | | 其他自定义键值对,可以在事件回调中使用。 |


#### insertPort(...)

```sign
insertPort(index: number, port: PortMetadata, options?: Node.SetOptions): this
```

在指定位置添加连接桩。

<span class="tag-param">参数<span>

| 名称 | 类型 | 必选 | 默认值 | 描述 |
|------------------|------------------------|:----:|---------|---------------------------------------------------|
| index | number || | 连接桩位置。 |
| port | [PortMetadata](#ports) || | 链接桩。 |
| options.silent | boolean | | `false` |`true` 时不触发 `'change:ports'` 事件和画布重绘。 |
| options...others | object | | | 其他自定义键值对,可以在事件回调中使用。 |

#### hasPort(...)

```sign
Expand Down

0 comments on commit 6809dba

Please sign in to comment.