Skip to content

Commit

Permalink
fix: remove connection strategy option (antvis#3456)
Browse files Browse the repository at this point in the history
  • Loading branch information
NewByVector authored Apr 1, 2023
1 parent 506ab14 commit ba370df
Show file tree
Hide file tree
Showing 7 changed files with 2 additions and 81 deletions.
2 changes: 1 addition & 1 deletion packages/x6/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@antv/x6",
"version": "2.9.2",
"version": "2.9.4",
"description": "JavaScript diagramming library that uses SVG and HTML for rendering",
"main": "lib/index.js",
"module": "es/index.js",
Expand Down
6 changes: 0 additions & 6 deletions packages/x6/src/graph/options.ts
Original file line number Diff line number Diff line change
Expand Up @@ -105,9 +105,6 @@ export namespace Options {
| ConnectionPoint.NativeItem
| ConnectionPoint.ManaualItem

type ConnectNodeStrategy = 'closest'
type ConnectEdgeStrategy = 'closest'

export interface Connecting {
/**
* Snap edge to the closest node/port in the given radius on dragging.
Expand Down Expand Up @@ -174,9 +171,6 @@ export namespace Options {
sourceEdgeAnchor?: EdgeAnchorOptions
targetEdgeAnchor?: EdgeAnchorOptions

connectNodeStrategy?: ConnectNodeStrategy // take effect in 2.9.1
connectEdgeStrategy?: ConnectEdgeStrategy // take effect in 2.9.1

connectionPoint: ConnectionPointOptions
sourceConnectionPoint?: ConnectionPointOptions
targetConnectionPoint?: ConnectionPointOptions
Expand Down
9 changes: 0 additions & 9 deletions packages/x6/src/view/cell.ts
Original file line number Diff line number Diff line change
Expand Up @@ -481,10 +481,6 @@ export class CellView<

// #endregion

geConnectionTerminalAnchor(
connectionPoint: PointLike,
): Edge.NodeAnchorItem | Edge.EdgeAnchorItem | void {}

getEdgeTerminal(
magnet: Element,
x: number,
Expand All @@ -511,11 +507,6 @@ export class CellView<
}
} else if (selector == null && this.container !== magnet) {
terminal.selector = this.getSelector(magnet)
} else if (type === 'target') {
const anchor = this.geConnectionTerminalAnchor({ x, y })
if (anchor) {
terminal.anchor = anchor
}
}

return terminal
Expand Down
21 changes: 0 additions & 21 deletions packages/x6/src/view/edge.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2358,27 +2358,6 @@ export class EdgeView<
stopLabelDragging(e: Dom.MouseUpEvent, x: number, y: number) {}

// #endregion

// #region connection strategy

geConnectionTerminalAnchor(
connectionPoint: Point.PointLike,
): Edge.EdgeAnchorItem | void {
const strategy = this.graph.options.connecting.connectEdgeStrategy
if (strategy === 'closest') {
const length = this.getClosestPointLength(connectionPoint)
if (length !== null) {
return {
name: 'length',
args: {
length,
},
}
}
}
}

// #endregion
}

export namespace EdgeView {
Expand Down
23 changes: 1 addition & 22 deletions packages/x6/src/view/node.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { ArrayExt, FunctionExt, Dom, PointLike } from '@antv/x6-common'
import { ArrayExt, FunctionExt, Dom } from '@antv/x6-common'
import { Rectangle, Point, GeometryUtil } from '@antv/x6-geometry'
import { Config } from '../config'
import { Attr, PortLayout } from '../registry'
Expand Down Expand Up @@ -1117,27 +1117,6 @@ export class NodeView<
}

// #endregion

// #region connection strategy

geConnectionTerminalAnchor(
connectionPoint: PointLike,
): Edge.NodeAnchorItem | void {
const strategy = this.graph.options.connecting.connectNodeStrategy
if (strategy === 'closest') {
const bbox = this.cell.getBBox()
const point = bbox.getNearestPointToPoint(connectionPoint)
return {
name: 'topLeft',
args: {
dx: point.x - bbox.topLeft.x,
dy: point.y - bbox.topLeft.y,
},
}
}
}

// #endregion
}

export namespace NodeView {
Expand Down
16 changes: 0 additions & 16 deletions sites/x6-sites/docs/api/interacting/interaction.zh.md
Original file line number Diff line number Diff line change
Expand Up @@ -162,22 +162,6 @@ targetEdgeAnchor?: EdgeAnchorOptions

当连接到边时,通过 `targetEdgeAnchor` 来指定目标边的锚点。

### connectNodeStrategy

```typescript
connectNodeStrategy?: 'closest'
```

连接到目标节点的策略,例如 `closest` 策略连线终端就会自动吸附到最近的节点边缘(默认是中心)。

### connectEdgeStrategy

```typescript
connectEdgeStrategy?: 'closest'
```

连接到目标边的策略,例如 `closest` 策略连线终端就会自动吸附到边上最近的点(默认是中心)。

### connectionPoint

```typescript
Expand Down
6 changes: 0 additions & 6 deletions sites/x6-sites/docs/tutorial/basic/interacting.zh.md
Original file line number Diff line number Diff line change
Expand Up @@ -100,12 +100,6 @@ new Graph({

<code id="interacting-validate" src="@/src/tutorial/basic/interacting/validate/index.tsx"></code>

### 连接策略 <Badge>2.9.1</Badge>

连接到目标元素的时候, 连线终端会吸附到目标锚点,在一些场景中,目标锚点不能提前预设,需要在连接过程中确定,比如连接到离鼠标最近的点,这时候可以用 `connectNodeStrategy` 或者 `connectEdgeStrategy`

<code id="interacting-connect-strategy" src="@/src/tutorial/basic/interacting/connect-strategy/index.tsx"></code>

## 组合

有时候我们需要将一个节点拖动到另一个节点中,使其成为另一节点的子节点,这时我们可以通过 `embedding` 选项来开启,在节点被移动时通过 `findParent` 指定的方法返回父节点。更详细的配置参考 [API](/zh/docs/api/interacting/interacting#组合)
Expand Down

0 comments on commit ba370df

Please sign in to comment.