Skip to content
Open
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
106 changes: 100 additions & 6 deletions examples/x6-example-features/src/pages/undo/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,46 @@ export default class Example extends React.Component<
container: this.container,
width: 800,
height: 600,
grid: true,
history: true,
grid: {
size: 10,
visible: true,
type: 'doubleMesh',
args: [
{
color: '#e6e6e6',
thickness: 1
},
{
color: '#ddd',
thickness: 1,
factor: 4
}
]
},
history: {
enabled: true,
beforeAddCommand(event, args) {
if (args && 'options' in args && args.options) {
return args.options.ignore !== true
}
}
},
selecting: {
enabled: true
},
embedding: {
enabled: true,
findParent({ node }) {
const bbox = node.getBBox()
return this.getNodes().filter((node) => {
const data = node.getData<any>()
if (data && data.parent) {
const targetBBox = node.getBBox()
return bbox.isIntersectWithRect(targetBBox)
}
return false
})
}
},
})

Expand All @@ -42,6 +78,7 @@ export default class Example extends React.Component<
y: 120,
width: 100,
height: 40,
zIndex: 10,
attrs: {
label: {
text: 'Hello',
Expand All @@ -50,13 +87,14 @@ export default class Example extends React.Component<
strokeWidth: 1,
},
},
})
}, { ignore: true })

const target = graph.addNode({
x: 300,
y: 320,
width: 100,
height: 40,
zIndex: 10,
attrs: {
label: {
text: 'World',
Expand All @@ -65,13 +103,14 @@ export default class Example extends React.Component<
strokeWidth: 1,
},
},
})
}, { ignore: true })

graph.addNode({
x: 400,
y: 100,
width: 150,
height: 150,
zIndex: 1,
attrs: {
label: {
text: '🌎',
Expand All @@ -80,9 +119,64 @@ export default class Example extends React.Component<
strokeWidth: 1,
},
},
data: {
parent: true
},
}, { ignore: true })

graph.addEdge(
{
source,
target,
arrts: {
line: {
strokeWidth: 1
}
},
vertices: [
{
x: 220,
y: 220
},
{
x: 120,
y: 320
},
{
x: 300,
y: 400
}
]
},
{ ignore: true }
)

graph.on('edge:click', ({ cell }) => {
if (!cell.hasTool('vertices')) {
cell.addTools(
{
name: 'vertices',
args: {
stopPropagation: false,
addable: true,
removeable: false,
removeRedundancies: false,
snapRadius: 10,
attrs: {
r: 4
}
}
}
)
}
})

graph.addEdge({ source, target, arrts: { line: { strokeWidth: 1 } } })
graph.on('edge:unselected', ({ cell }) => {
cell.removeTools()
})
graph.on('edge:mouseup', ({ cell }) => {
console.log('edge:mouseup', cell)
})
}

onUndo = () => {
Expand All @@ -100,7 +194,7 @@ export default class Example extends React.Component<
render() {
return (
<div className="x6-graph-wrap">
<h1>Default Settings</h1>
<h1>Edge Vertices & History & Embedding</h1>
<div className="x6-graph-tools">
<Button.Group>
<Button onClick={this.onUndo} disabled={!this.state.canUndo}>
Expand Down
18 changes: 8 additions & 10 deletions packages/x6/src/registry/tool/vertices.ts
Original file line number Diff line number Diff line change
Expand Up @@ -179,17 +179,15 @@ export class Vertices extends ToolsView.ToolItem<EdgeView, Vertices.Options> {
this.updatePath()
}

if (!options.removeRedundancies) {
return
}

const verticesRemoved = edgeView.removeRedundantLinearVertices({
ui: true,
toolId: this.cid,
})
if (options.removeRedundancies) {
const verticesRemoved = edgeView.removeRedundantLinearVertices({
ui: true,
toolId: this.cid,
})

if (verticesRemoved) {
this.render()
if (verticesRemoved) {
this.render()
}
}

this.blur()
Expand Down
Loading