-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* feat: add snapline plugin * test: add snapline unit tests * refactor(plugin): support auto snap and ignore items outside viewport * fix: fix cr issues
- Loading branch information
Showing
36 changed files
with
1,935 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
import { Graph, Node } from '@antv/g6'; | ||
|
||
export const pluginSnapline: TestCase = async (context) => { | ||
const graph = new Graph({ | ||
...context, | ||
data: { | ||
nodes: [ | ||
{ id: 'node1', style: { x: 100, y: 100 } }, | ||
{ id: 'node2', style: { x: 300, y: 300 } }, | ||
{ id: 'node3', style: { x: 120, y: 200 } }, | ||
], | ||
}, | ||
node: { | ||
type: (datum) => (datum.id === 'node3' ? 'circle' : 'rect'), | ||
style: { | ||
size: (datum) => (datum.id === 'node3' ? 40 : [60, 30]), | ||
fill: 'transparent', | ||
lineWidth: 2, | ||
labelText: (datum) => datum.id, | ||
}, | ||
}, | ||
behaviors: ['drag-element', 'drag-canvas'], | ||
plugins: [ | ||
{ | ||
type: 'snapline', | ||
key: 'snapline', | ||
verticalLineStyle: { stroke: '#F08F56', lineWidth: 2 }, | ||
horizontalLineStyle: { stroke: '#17C76F', lineWidth: 2 }, | ||
autoSnap: false, | ||
}, | ||
], | ||
}); | ||
|
||
await graph.render(); | ||
|
||
const config = { | ||
filter: false, | ||
offset: 20, | ||
}; | ||
|
||
pluginSnapline.form = (panel) => { | ||
return [ | ||
panel | ||
.add(config, 'filter') | ||
.name('Add Filter(exclude circle)') | ||
.onChange((filter: boolean) => { | ||
graph.updatePlugin({ | ||
key: 'snapline', | ||
filter: (node: Node) => (filter ? node.id !== 'node3' : true), | ||
}); | ||
graph.render(); | ||
}), | ||
panel | ||
.add(config, 'offset', [0, 20, Infinity]) | ||
.name('Offset') | ||
.onChange((offset: string) => { | ||
graph.updatePlugin({ | ||
key: 'snapline', | ||
offset, | ||
}); | ||
graph.render(); | ||
}), | ||
]; | ||
}; | ||
return graph; | ||
}; |
51 changes: 51 additions & 0 deletions
51
packages/g6/__tests__/snapshots/plugins/snapline/auto-snap.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
45 changes: 45 additions & 0 deletions
45
packages/g6/__tests__/snapshots/plugins/snapline/default.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
51 changes: 51 additions & 0 deletions
51
packages/g6/__tests__/snapshots/plugins/snapline/drag-node3-horizontal-0.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
51 changes: 51 additions & 0 deletions
51
packages/g6/__tests__/snapshots/plugins/snapline/drag-node3-horizontal-1.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
51 changes: 51 additions & 0 deletions
51
packages/g6/__tests__/snapshots/plugins/snapline/drag-node3-horizontal-10.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
51 changes: 51 additions & 0 deletions
51
packages/g6/__tests__/snapshots/plugins/snapline/drag-node3-horizontal-2.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Oops, something went wrong.