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

Add "canSwapEdge" #221

Merged
merged 3 commits into from
Jul 23, 2020
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
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -217,6 +217,7 @@ All props are detailed below.
| `canDeleteNode` | `func` | `false` | Called before a node is deleted. |
| `canCreateEdge` | `func` | `false` | Called before an edge is created. |
| `canDeleteEdge` | `func` | `false` | Called before an edge is deleted. |
| `canSwapEdge` | `func` | `false` | Called before an edge 'target' is swapped.
| `afterRenderEdge` | `func` | `false` | Called after an edge is rendered. |
| `renderNode` | `func` | `false` | Called to render node geometry. |
| `renderNodeText` | `func` | `false` | Called to render the node text |
Expand Down Expand Up @@ -289,6 +290,7 @@ Prop Types:
canDeleteNode?: (selected: any) => boolean;
canDeleteEdge?: (selected: any) => boolean;
canCreateEdge?: (startNode?: INode, endNode?: INode) => boolean;
canSwapEdge?: (sourceNode: INode, targetNode: INode, edge: IEdge) => boolean;
afterRenderEdge?: (id: string, element: any, edge: IEdge, edgeContainer: any, isEdgeSelected: boolean) => void;
onUndo?: () => void;
onCopySelected?: () => void;
Expand Down
4 changes: 3 additions & 1 deletion src/components/graph-view.js
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ type IGraphViewState = {
class GraphView extends React.Component<IGraphViewProps, IGraphViewState> {
static defaultProps = {
canCreateEdge: (startNode?: INode, endNode?: INode) => true,
canSwapEdge: () => true,
canDeleteEdge: () => true,
canDeleteNode: () => true,
edgeArrowSize: 8,
Expand Down Expand Up @@ -456,7 +457,8 @@ class GraphView extends React.Component<IGraphViewProps, IGraphViewState> {
hoveredNode &&
sourceNode !== hoveredNode &&
(swapEdge.source !== sourceNode[this.props.nodeKey] ||
swapEdge.target !== hoveredNode[this.props.nodeKey])
swapEdge.target !== hoveredNode[this.props.nodeKey]) &&
canSwapEdge(sourceNode, hoveredNode, swapEdge)
);
}

Expand Down