Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: createWidget and clearWidget #3337

Merged
merged 6 commits into from
Mar 16, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 25 additions & 0 deletions packages/x6-plugin-transform/src/api.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,30 @@
import { Graph, Node } from '@antv/x6'
import { TransformImpl } from './transform'
import { Transform } from './index'

declare module '@antv/x6/lib/graph/graph' {
interface Graph {
createTransformWidget: (node: Node) => Graph
clearTransformWidgets: () => Graph
}
}

declare module '@antv/x6/lib/graph/events' {
interface EventArgs extends TransformImpl.EventArgs {}
}

Graph.prototype.createTransformWidget = function (node) {
const transform = this.getPlugin('transform') as Transform
if (transform) {
transform.createWidget(node)
}
return this
}

Graph.prototype.clearTransformWidgets = function () {
const transform = this.getPlugin('transform') as Transform
if (transform) {
transform.clearWidgets()
}
return this
}
8 changes: 6 additions & 2 deletions packages/x6-plugin-transform/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ export class Transform extends Basecoat<Transform.EventArgs> {
return !this.disabled
}

protected onNodeClick({ node }: EventArgs['node:click']) {
createWidget(node: Node) {
this.clearWidgets()
const widget = this.createTransform(node)
if (widget) {
Expand All @@ -62,6 +62,10 @@ export class Transform extends Basecoat<Transform.EventArgs> {
}
}

protected onNodeClick({ node }: EventArgs['node:click']) {
this.createWidget(node)
}

protected onBlankMouseDown() {
this.clearWidgets()
}
Expand Down Expand Up @@ -135,7 +139,7 @@ export class Transform extends Basecoat<Transform.EventArgs> {
return options
}

protected clearWidgets() {
clearWidgets() {
this.widgets.forEach((widget, node) => {
if (this.graph.getCellById(node.id)) {
widget.dispose()
Expand Down
11 changes: 11 additions & 0 deletions sites/x6-sites/docs/tutorial/plugins/transform.zh.md
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,17 @@ graph.use(

## 配置


## API

### graph.createTransformWidget(node: Node)

给节点创建widget

### graph.clearTransformWidgets()

清除所有widget

### 调整尺寸

| 属性名 | 类型 | 默认值 | 必选 | 描述 |
Expand Down