Skip to content

Commit

Permalink
fix: 🐛 unified panning api (#1151)
Browse files Browse the repository at this point in the history
* fix: 🐛 unified panning api

* docs: 📚️ add doc for panning api
  • Loading branch information
NewByVector authored Jul 5, 2021
1 parent edafef2 commit d60e9d8
Show file tree
Hide file tree
Showing 3 changed files with 70 additions and 33 deletions.
85 changes: 52 additions & 33 deletions packages/x6/src/graph/graph.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1427,6 +1427,58 @@ export class Graph extends Basecoat<EventArgs> {

// #endregion

// #region panning

isPannable() {
const scroller = this.scroller.widget
if (scroller) {
return this.scroller.pannable
}
return this.panning.pannable
}

enablePanning() {
const scroller = this.scroller.widget
if (scroller) {
this.scroller.enablePanning()
} else {
this.panning.enablePanning()
}

return this
}

disablePanning() {
const scroller = this.scroller.widget
if (scroller) {
this.scroller.disablePanning()
} else {
this.panning.disablePanning()
}

return this
}

togglePanning(pannable?: boolean) {
if (pannable == null) {
if (this.isPannable()) {
this.disablePanning()
} else {
this.enablePanning()
}
} else if (pannable !== this.isPannable()) {
if (pannable) {
this.enablePanning()
} else {
this.disablePanning()
}
}

return this
}

// #endregion

// #region scroller

@Decorator.checkScroller()
Expand Down Expand Up @@ -1529,39 +1581,6 @@ export class Graph extends Basecoat<EventArgs> {
scroller.transitionToRect(rect, options)
return this
}

isPannable() {
return this.scroller.pannable
}

enablePanning() {
this.scroller.enablePanning()
return this
}

disablePanning() {
this.scroller.disablePanning()
return this
}

togglePanning(pannable?: boolean) {
if (pannable == null) {
if (this.isPannable()) {
this.disablePanning()
} else {
this.enablePanning()
}
} else if (pannable !== this.isPannable()) {
if (pannable) {
this.enablePanning()
} else {
this.disablePanning()
}
}

return this
}

// #endregion

// #region selection
Expand Down
9 changes: 9 additions & 0 deletions sites/x6-sites/docs/tutorial/basic/graph.en.md
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,15 @@ const graph = new Graph({
})
```

可以通过以下 API 来启用/禁止画布平移:

```ts
graph.isPannable() // 画布是否可以平移
graph.enablePanning() // 启用画布平移
graph.disablePanning() // 禁止画布平移
graph.togglePanning() // 切换画布平移状态
```

### 画布缩放

普通画布(未开启 [scroller](/en/docs/tutorial/basic/scroller) 模式)通过开启 [mousewheel](/en/docs/tutorial/basic/mousewheel) 选项来支持画布缩放。这里说明怎么通过代码来进行画布缩放:
Expand Down
9 changes: 9 additions & 0 deletions sites/x6-sites/docs/tutorial/basic/graph.zh.md
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,15 @@ const graph = new Graph({
})
```

可以通过以下 API 来启用/禁止画布平移:

```ts
graph.isPannable() // 画布是否可以平移
graph.enablePanning() // 启用画布平移
graph.disablePanning() // 禁止画布平移
graph.togglePanning() // 切换画布平移状态
```

### 画布缩放

普通画布(未开启 [scroller](/zh/docs/tutorial/basic/scroller) 模式)通过开启 [mousewheel](/zh/docs/tutorial/basic/mousewheel) 选项来支持画布缩放。这里说明怎么通过代码来进行画布缩放:
Expand Down

0 comments on commit d60e9d8

Please sign in to comment.